I'm trying to write some program to directly call a system call without going through ntdll.dll
My code ( Visual Studio syntax...):
#include <windows.h>
int main()
{
_asm{
push arg1
push arg2
push arg3
mov eax,syscall_id
mov edx,esp
_emit 0xf
_emit 0x34 //sysenter opcodes...
}
When the program tries to execute the sysenter instruction the program crash with this access violation:
CALL DWORD PTR DS:[EAX+EDX*4] // Access Violation when reading [00000128]
EAX == 0x00000000
EDX == 0x0000004D
I tried to put a hw breakpoint using a kernel debugger in the desired system call and the execution flow is not reaching there...
I guess the problem has something to do with stack order/depth.
Thanks a lot!
SOLVED:
I guess the problem was that i was trying to execute a win32k system call without loading user32 and gdi32 dlls.
just added:
LoadLibraryW(L"user32.dll");
LoadLibraryW(L"gdi32.dll");
and problem solved..
If anyone has a better idea why this happens without loading those dlls , i will be pleased to know :)