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 


Kernel patching

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
cziter15
Newbie cheater
Reputation: 0

Joined: 24 May 2009
Posts: 10

PostPosted: Thu May 05, 2011 9:34 am    Post subject: Kernel patching Reply with quote

Hi,

I'm wondering how to safely patch kernel routines like ZwOpenProcess, ZwQuerySystemInformation. I know, first 5 bytes can be changed by writing to them directly:

Code:
*(byte*)ZwOpenProcess = 0xE9;
*(DWORD*)(ZwOpenProcess+1) = dst - src;


But.... I saw, some people are using MDL's for that. Some other people are doing something with cr0.

So... my question is...
How to patch the kernel correctly ?

Thanks,
Chris
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Fri May 06, 2011 3:14 pm    Post subject: Reply with quote

You are altering something that isn't supposed to be tampered with. There is no 'correct' way to do it. The most you can do is extensive error checking to prevent invalid data from being written to help prevent crashing. But ultimately there is no correct way to do it as its not meant to be done.
_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Innovation
Grandmaster Cheater
Reputation: 12

Joined: 14 Aug 2008
Posts: 617

PostPosted: Fri May 06, 2011 3:32 pm    Post subject: Reply with quote

To add onto Wiccan's post, Microsoft imposed Kernel Patch Protection for a reason. It simply becomes too difficult to manage when companies such as Symantec rely on internals that may change in future versions. "[The kernel's] stability is critical to the stability of your system." Nothing about patching the kernel is "safe." While it is still possible to bypass such restrictions, it is recommended that you don't.

Kernel Patch Protection: Frequently Asked Questions


Last edited by Innovation on Mon Jan 07, 2013 12:46 am; edited 1 time in total
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

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

PostPosted: Fri May 06, 2011 4:06 pm    Post subject: Reply with quote

The only "correct" method of hooking certain stuff is getting yourself a class 3 business certificate ,sign your driver and use the ObRegisterCallbacks api

That way you can decide if a handle to your process is allowed to be created or not

_________________
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
cziter15
Newbie cheater
Reputation: 0

Joined: 24 May 2009
Posts: 10

PostPosted: Sat May 07, 2011 4:08 am    Post subject: Reply with quote

ObCallbacks are not sufficient for me. I want to provide my solution for older operating systems, like Windows 2000, XP. ObCallbacks are not implemented there.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

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

PostPosted: Sat May 07, 2011 8:37 am    Post subject: Reply with quote

Then just patch the kernel using the official method that was designed back then(as official as possible that is)

Most hookable functions start with at least 5 unused bytes in front and starts with a mov edi,edi

write a "jmp specific address" in the 5 unused bytes before the function and then change the mov edi,edi into jmp eip-7 (eb f9)

this is the safest method of hooking such a function with the least chance of replacing the first instruction with a half working instruction (And if you write those two bytes in a word format at once 0% chance)

_________________
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
cziter15
Newbie cheater
Reputation: 0

Joined: 24 May 2009
Posts: 10

PostPosted: Tue May 10, 2011 1:01 am    Post subject: Reply with quote

Good idea, thanks. But, I heard, sometimes kernel pages are not mapped and writing to nonpaged memory can result BSOD. Is it true ? What to do with this ?
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

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

PostPosted: Tue May 10, 2011 4:13 am    Post subject: Reply with quote

Then just crash.

Really, if non-paged code has been paged out then there is some serious problem with windows or the hardware you're on. Non-paged memory is specifically there so it never gets paged out, not even when low on memory.

The kernel resides in non-paged memory which means that the functions you may want to hook are present 100% of the time, and if for some reason the code does not reside in non-paged memory and has been paged out then there still will be no bsod because the access will cause windows to page that code back into memory.

In short, don't worry

_________________
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