c++ - Calling NtQuerydirectoryFile from a Kernel Hook Crashes the Kernel -


i'm using latest version of easyhook hook kernel functions. did setup debugging important on windows 8.1 64-bit based virtual machine, , tested hooking both of ntquerydirectoryfile , ntquerysysteminformation in user mode , ntquerysysteminformation in kernel mode without problem.

my current problem hooking ntquerydirectoryfile using same code used user mode hook, fails when call original function giving me access violation error. i'm using following code kernel mode hook:

ntstatus ntquerydirectoryfile_hook(     __in handle filehandle,     __in_opt handle event,     __in_opt pio_apc_routine apcroutine,     __in_opt pvoid apccontext,     __out pio_status_block iostatusblock,     __out_bcount(length) pvoid fileinformation,     __in ulong length,     __in file_information_class fileinformationclass,     __in boolean returnsingleentry,     __in punicode_string filename optional,     __in boolean restartscan     ) {     ntstatus status;     status = ntquerydirectoryfile(filehandle, event, apcroutine, apccontext, iostatusblock, fileinformation, length, fileinformationclass, returnsingleentry, filename, restartscan);     return status; } 

as mentioned before, original trampoline jump modified rax register, replaced trampoline:

50                             push   rax 48 b8 00 00 00 00 00 00 00 00  mov rax, 0x0 48 87 04 24                    xchg   qword ptr [rsp],rax c3                             ret 

in addition fixing function rely on hard-coded size of trampoline jump code since newer version bigger. it's working without problem.


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -