libpeconv icon indicating copy to clipboard operation
libpeconv copied to clipboard

initterm crash when loading unreal engine binaries

Open maximegmd opened this issue 2 years ago • 1 comments

Using the sample loader project on an Unreal Engine 4 compiled binary crashes with a null access within the initterm call in __scrt_common_main_seh.

So far I haven't been able to locate the cause of this, I have tried disabling reloc but had no success.

Note that the function called by initterm uses TLS, I am thinking that maybe run_tls_callbacks may not work correctly or that some additional TLS code is required.

maximegmd avatar Mar 18 '22 16:03 maximegmd

Hi! The best would be if you could share the binary, so that I can have a look at it. You can send it to my e-mail: hasherezade-at-pm.me

Is it 32 or 64 bit? You are right that there may be something wrong with how TLS callbacks are executed, but I also suspect it may be related to exceptions handler. During the manual load (as libPEconv does) the exception handlers are not installed - so they also need to be set up manually. I implemented it for 64-bit targets (although it is not enabled in the default loader). You can see it in this sample code:

https://github.com/hasherezade/libpeconv/blob/93fe6efa532de976fe96062858949ffa13a92a67/tests/test_exceptions.cpp#L25

Which is a part of a testcase 18:

https://github.com/hasherezade/libpeconv/blob/93fe6efa532de976fe96062858949ffa13a92a67/tests/main.cpp#L49

For the 32-bit targets I didn't implement it yet (it is very different than in 64-bit, the same APIs are not available).

But if your application is 64bit we can make a test, and check if running it with exceptions table installed could help. Just compile libPEConv along with test cases, and then run:

tests.exe 18 {your_app.exe}

This will load your app via loader with exceptions table set up. Please let me know what is the result.

hasherezade avatar Mar 19 '22 11:03 hasherezade