garph0
November 30th, 2000, 20:44
I managed to complete the API hooking project i was talking about some time ago 
I use this tecnique:
1) prepare a memory mapped file with into the code i want to execute
2) run the target process suspended
3) copy the code at program entry point in the MMF
4) overwrite the code at program entry point with some code that maps MMF by name and jumps into it
5) resume the program
this works fine, and i widh to thanks killexx a lot
but for some programs i get "Application was not correctly initialized" as soon as i start this work...
Killexx told me that is a PE Loader problem, so i thought i could avoid this by injectiong the code at run-time.
this is pretty like the previous tecnique, but
1) i freeze the process main thread,
2) i save the CONTEXT
3) I do the operations as previously descripted
4) i fix the CONTEXT.EIP to program EP
5) i resume the thread
the code injected this time will not jump back to PEP after having put back original code, but will:
a) launch another thread and enter in a loop
b) this new thread will suspend the first one
c) will put back the original CONTEXT
d) will resume the original thread
ok. all this seems to work! the pain comes as soon as i want to close the second thread (the one generated just to fix the main thread):
- if i use a ret it will obviously fall back in nonsense crap somewhere in memory
- i cannot simply freeze it, 'cause it seems that windows doesn't like it too much (i have read that for correct message handling every thread needs to run for a little now and then), and anyway i'd prefer to close it
- a call to ExitThread() doesn't seem to work...
does anybody have an idea?
thank you very much
garph0
PS i know about CreateRemoteThread, but i want all this to work also under win9x

I use this tecnique:
1) prepare a memory mapped file with into the code i want to execute
2) run the target process suspended
3) copy the code at program entry point in the MMF
4) overwrite the code at program entry point with some code that maps MMF by name and jumps into it
5) resume the program
this works fine, and i widh to thanks killexx a lot

but for some programs i get "Application was not correctly initialized" as soon as i start this work...
Killexx told me that is a PE Loader problem, so i thought i could avoid this by injectiong the code at run-time.
this is pretty like the previous tecnique, but
1) i freeze the process main thread,
2) i save the CONTEXT
3) I do the operations as previously descripted
4) i fix the CONTEXT.EIP to program EP
5) i resume the thread
the code injected this time will not jump back to PEP after having put back original code, but will:
a) launch another thread and enter in a loop
b) this new thread will suspend the first one
c) will put back the original CONTEXT
d) will resume the original thread
ok. all this seems to work! the pain comes as soon as i want to close the second thread (the one generated just to fix the main thread):
- if i use a ret it will obviously fall back in nonsense crap somewhere in memory
- i cannot simply freeze it, 'cause it seems that windows doesn't like it too much (i have read that for correct message handling every thread needs to run for a little now and then), and anyway i'd prefer to close it
- a call to ExitThread() doesn't seem to work...
does anybody have an idea?
thank you very much
garph0
PS i know about CreateRemoteThread, but i want all this to work also under win9x
