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 


Hardware Breakpoints

 
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: Fri May 25, 2012 9:33 pm    Post subject: Hardware Breakpoints Reply with quote

I understand that the DR0 - DR3 registers are the registers where you set the address for your breakpoint. I can't seem to understand how the Dr7 register works though. I do know that they are the conditions set for the breakpoint but what i'm doing doesn't work.

Code:

// Create our variable
   CONTEXT c;

   // Obtain thread information
   c.ContextFlags = CONTEXT_DEBUG_REGISTERS;
   GetThreadContext ( GetCurrentThread (), &c );

   // Adjust breakpoint
   c.Dr0 = dwAddr;
   c.Dr7 = ( 3 << 16 ); // 11b for data read/write

   // Set breakpoint
   SetThreadContext ( GetCurrentThread (), &c );


Dr0 is the address i'm setting for my breakpoint, and Dr7 is the conditions for the breakpoint. What am I missing?
Back to top
View user's profile Send private message MSN Messenger
Innovation
Grandmaster Cheater
Reputation: 12

Joined: 14 Aug 2008
Posts: 617

PostPosted: Fri May 25, 2012 10:08 pm    Post subject: Reply with quote

You need to set the debug registers in every thread in the process (excluding the one in which you're doing this). Also, you should use SuspendThread and ResumeThread respectively before and after messing with the registers to ensure you don't accidentally screw up the context as the thread is still running. See this for an example.

To correctly use DR0 in your case, you should set the 0th, 16th, and 17th bits and unset the 1st, 18th, and 19th bits of DR7 (assuming you only want a breakpoint for one byte).
Code:
c.Dr7 |= 0x00030001; // 1 | (3 << 16)
c.Dr7 &= 0xFFF3FFFD; // ~((1 << 1) | (3 << 18))

See this for more information.
Back to top
View user's profile Send private message
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