Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


BSOD for emulating a function

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
iPromise
Grandmaster Cheater
Reputation: -1

Joined: 27 Jun 2009
Posts: 529
Location: Canada

PostPosted: Sun Nov 11, 2012 1:00 pm    Post subject: BSOD for emulating a function Reply with quote

So basically i'm making a test to see if can emulate a function supported by the DDK if I have its address. The function is inside my driver and i'm emulating ZwOpenFile. Each time I invoke this emulated function I get a BSOD without any reason being specified.

Here is the code:

Code:

NTSTATUS NTAPI ZwOpenFileX ( PHANDLE FileHandle, ACCESS_MASK DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes,
                        PIO_STATUS_BLOCK IoStatusBlock, ULONG ShareAccess, ULONG OpenOptions )
{
   __asm
   {
      jmp [ dwFuncAddr ];
   }
}


same parameters, same everything, dwProtectMemory doesn't return 0.

dwFuncAddr:

Code:

RtlInitUnicodeString ( &pText, L"ZwOpenFile" );
dwFuncAddr = (DWORD) MmGetSystemRoutineAddress ( &pText );
Back to top
View user's profile Send private message MSN Messenger
Dark Byte
Site Admin
Reputation: 471

Joined: 09 May 2003
Posts: 25837
Location: The netherlands

PostPosted: Mon Nov 12, 2012 1:17 am    Post subject: This post has 1 review(s) Reply with quote

You didn't declare it as a naked function
this will create the assembler code:
Code:

push ebp
mov ebp,esp
jmp [dwFuncAddrr]
ret 18

As you see, the stack will be broken

Another thing you can do without defining a naked type is the hook method, where you define dwFuncAddr as a function type with the same declaration as ZwOpenFile, and then pass the parameters you got on to the new function call
e.g:
Code:

typedef NTSTATUS NTAPI (*MYZWOPENPROCESS) ( PHANDLE FileHandle, ACCESS_MASK DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes,
                        PIO_STATUS_BLOCK IoStatusBlock, ULONG ShareAccess, ULONG OpenOptions ) ;

MYZWOPENPROCESS dwFuncAddr;
...
...

return dwFuncAddr(FileHandle, DesiredAccess, ObjectAttributes, IoStatusBlock, ShareAccess, OpenOptions);

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites