I tried to write a peloader. I first load the executable image and all it's dependent dlls(include kernel32.dll and ntdll.dll) into memory, process all import address table, rewrite all data which need relocation.
Then I call all image's EntryPoint in order. I get the return code 0 from ntdll.dll's EntryPoint, but kernel32.dll returns 0xC0000000. When I tried to call the executable image's EntryPoint, the program crashed.
I know the windows system already load ntdll.dll and kernel32.dll into process memory when the process is created. My question is how can I load another copy of ntdll.dll and kernel32.dll into memory, and link my module to the copy ones.
I make an experiment: 1. copy ntdll.dll -> a.dll
- copy kernel32.dll -> b.dll
- modify PE image file b.dll to make it not depends on ntdll.dll but a.dll
- write a simple program a.exe, and modify the PE image file a.exe to make it not depends on kernel32.dll but b.dll
- run a.exe, and the program crashed
Is it possible to make a.exe run correctly?
It's my first question on stack overflow, sorry for my poor english. Thanks.