Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to hook NtClose Function without detours.first i change 5 bytes of a NtClose Function with a jump instruction to myNtClose Funtion but after that when i want get back that 5 bytes of the NtClose Funtion with memcpy(OriginalFunction, oldBytes, SIZE); instruction the errors show up.this error is Unhandled exception at 0x1027ca34(msvcr100d.dll) in myproject.exe:0xc0000005: access violation writing location 0x7c90cfee.
please help me what should i do?
Posted
Comments
Richard MacCutchan 10-Mar-14 8:09am    
Don't try dynamic patching, it is dangerous.
pasztorpisti 11-Mar-14 19:32pm    
What is the OriginalFunction you mentioned? Do you try to copy bytes onto the beginning of your hook function? Because that wont work.
soosi 12-Mar-14 4:13am    
oringinalfunction is the address of the NtClose function in ntdll.dll. I want to copy bytes like jump instruction to myNtClose function onto the begining of the NtClose function. Does not it work?

1 solution

I can't see your code so don't know for sure.

You may have a simple pointer bug or you aren't using VirtualProtect correctly.

Here's an example similar to what you're doing.

http://stackoverflow.com/questions/13461771/hooks-why-do-we-need-to-virtualprotect-again-to-restore-permissions[^]

Normally, you use VirtualProtect to make the memory executable and read-write, make a copy, overwrite the original, and restore execute only access with VirtualProtect.

If you write a single function to do this, it can be used both for setting and restoring the hooked API function.
 
Share this answer
 
v2
Comments
soosi 11-Mar-14 5:28am    
i exactly do what you said and i write all of them in an exe file. i defined my function and write the hooking instructions in the main function but i have another error which is said access violation reading location do you know why?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900