4

Just for fun and giggles I'm trying to create a 64k intro in delphi. One of the best executable packers for applications of this size is kkrunchy by Farbrausch. However, when I run it on an (otherwise empty) Delphi executable, I get the following output

 - ERROR: files with exports or tls data are not supported

I'm guessing with a Delphi executable both could be the culprit, and I have no real troubles putting in the sweaty hours trying to figure out which one it is and post modifying the executable or something similar... but perhaps one of you already knows, or even has some information on how to circumvent this problem?

000
  • 26,951
  • 10
  • 71
  • 101
Paul-Jan
  • 16,746
  • 1
  • 63
  • 95
  • 1
    Yeah, the RaiseListPtr is related to exception handling, and it has to be a threadvar because each thread needs its own raise list. Not sure if there's any way to change this. – Mason Wheeler Jan 29 '11 at 22:07
  • I'm not sure yet whether I really _need_ to change it. I can live without exceptions and proper IO error handling (for this particular application). I'm not convinced me messing up GetTLS is what causes the application to crash... seems to be _after_ ExitProcess. – Paul-Jan Jan 29 '11 at 22:32
  • Moved my edits to a separate answer to make it fit the Q&A format better (improve future referencing), and marked Mason's answer as the correct one. – Paul-Jan Feb 01 '11 at 08:23
  • 1
    I'm also using kkrinkler with Delphi and it works fine with the exception that antivirus sometimes reacts on it. For even more compression here is an article about how to use Crinkler with Delphi: http://translate.google.com/translate?js=n&prev=_t&hl=en&ie=UTF-8&layout=2&eotf=1&sl=ru&tl=en&u=http%3A%2F%2Fxproger.mentalx.org%2Farchives%2F408 – Ville Krumlinde Feb 02 '11 at 11:53
  • Crinkler is even more extreme, thanks for the link! Automatic translation isn't all that, but it was a fun read anyway! – Paul-Jan Feb 02 '11 at 18:57

2 Answers2

3

Exports are for DLLs; it's not likely that your EXE is doing any exporting. TLS, on the other hand, is thread-local storage. If you have any threadvar variabled declared somewhere, that might be causing it. Also, I think TLS is uses in the built-in exception handling, but I'm not clear on all the details. If that's it, then you might not be able to use this packer at all.

Mason Wheeler
  • 82,511
  • 50
  • 270
  • 477
  • Thanks, Mason! It definitely is the TLS. I seem to remember Delphi always preallocates it (then does the actual thread storage management manually). I'll start browsing through system.pas. – Paul-Jan Jan 29 '11 at 20:58
1

(In addition to Mason's answer, which is correct).

I fired up a PE Viewer/Editor, and can confirm there are no exports. So now the question is: why is there a TLS allocated in an application without threads, and what do I do about it? Removing it from the PE table works nicely, except for the application error at shutdown.

System.pas contains 2 threadvars, InOutRes (for IO errors) and RaiseListPtr. I don't need those two to be threadvars in my application, but they seem kinda hardwired throughout system.pas. Looks like a hard nut to crack.

As a workaround, I now prematurely terminate my own process using

TerminateProcess( GetCurrentProcess, 0 )

to prevent any errors during proper shutdown (deep inside the more elegant ExitProcess from Delphi's _Halt0). In a postbuild step I remove the TLS from the PE and pack with kkrunchy. Down to 8192 bytes, and no problems. For now. Code-ethically, it feels like I should be put behind bars. :)

Paul-Jan
  • 16,746
  • 1
  • 63
  • 95