I’m currently working on hooking ntdll.dll calls via dll injection.
At first, I create thread in existing process via CreateRemoteThread() then I load my dll via LoadLibrary and finally hook calls on PROCESS_ATTACH.
Injection works fine, but then I want to log all registry and file system queries. And the problem is that it doesn’t work properly.
I decided to publish code via PasteBin, because piece is pretty big. Here is the link:
http://pastebin.com/39r4Me6B
I’m trying to hook ZwOpenKey, then log key content and then launch “true” function by pointer. Function NOpenKey gets executed, but process stops without any errors.
Does anyone see any issues?
If you use OllyDbg,
ZwOpenKeystarts with 5 bytesMOV EAX, 77.You can overwrite these bytes like so
JMP _myZwOpenKeythen from there you can do whatever with the values on the stack, restore all registers then do aJMP 7C90D5B5which is address ofZwOpenKey+ 5 bytes.I usually do these in Assembly that way I don’t have to mess around a lot with type casting and all that. Hope this helps.