C++: Loading an EXE as a DLL, local vftable problem -


OK, so it is very unpleasant to explain to me so stupid ..

My Pass is an exe named test.exe which is usually used as a stand alone application. I use this exe as a module (a DLL) in another application, app. XE I want to use in

The code in test.exe is actually something simple:

  zero doTest () {MyClass * inst = new MyClass (); Inst-> SomeMethod (); }  

Where someMethod () is virtual and virtual is DOR in MyClass.
from doTest () Test.exe and thus creates a lib called test.lib - app.exe connects to this libil when test.exe is static Loads from.

When I'm running test.exe -Allon it runs just fine, but when I load it from within the app.exe, it crashes.
Going into the code with the debugger revealed that the crash call is for the virtual method. It has been learned that vftable is badly damaged in any way

After some investigation it has been discovered that when the code inside the MyClass constructor is running, vftable is the same thing, but when < Code> new , it turns out to be another "local vftable" called me.

One day after debugging I found that the indicators in this "local vftable" are the same in both cases, when test.exe stands alone and when loaded as a module This can not be correct because test.exe has been loaded in a different address ...
To test this principle, I changed the loading address to the location where the test.exe loaded in the Linker options It's been in the app when it's exe and now, lo and d EEP, everything works.

Obviously, this is not a permanent solution because next time it can be randomly selected address, the same problem will be reduced again.

> So my question is: Is it "local vftable" connected to the address of why the exe is loading steady? Loading an exe as a module is a bad thing? Why does EXE assume that it is loaded at its stationary address?

Just for reference: It is all done with MSVC 2008, Windows XP x64.

itemprop = "text">

VC ++. Normally strips the reloc information from .exes because normally they do not need to be restored.

You can force it to maintain it with Reloc info / Fixed: Do not see:


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

php - jQuery AJAX Post not working -