Kkrunchy - how to get rid of tls data in a Delphi executable?

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 from Farbrausch. However, when I run it on a (otherwise empty) Delphi executable, I get the following output

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

I assume that both the Delphi executable can be the culprits, and I have no real problems that arise during the sweaty hours, trying to figure out which one is there and post a modification of the executable or something like that ... but, perhaps one of you already knows , or even has some information on how to get around this problem?

+4
source share
2 answers

Export for DLL; it is unlikely that your exe does any export. TLS, on the other hand, is local storage. If you have any threadvar modified variant declared somewhere, this can cause it. Also, I think TLS uses built-in exception handling, but I don't understand all the details. If this happens, you may not be able to use this package.

+3
source

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

I launched PE Viewer / Editor and can confirm no export. So now the question is: why is TLS allocated in the application without threads, and what should I do about it? Removing it from the PE table works fine, except for an application error on shutdown.

System.pas contains 2 threads, InOutRes (for I / O errors) and RaiseListPtr. I do not need these two to be threadvars in my application, but they seem invisible to the whole system. It looks like a tough nut.

As a workaround, I prematurely terminate my own process using

 TerminateProcess( GetCurrentProcess, 0 ) 

to prevent any errors when shutting down properly (deep inside the more elegant ExitProcess from Delphi _Halt0). In the postbuild phase, I remove TLS from PE and package using kkrunchy. Up to 8192 bytes, and no problem. Presently. The code is ethical, it seems to me that I should be put in jail. :)

+1
source

Source: https://habr.com/ru/post/1337613/


All Articles