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 


Problem with debug registers

 
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 Jan 06, 2013 11:30 pm    Post subject: Problem with debug registers Reply with quote

While hacking a game I set 3 of the 4 debug registers (Dr0, Dr1, Dr2) to my targets but i'm only getting a breakpoint for the first one (Dr0).

Code:

Context.Dr0 = dwTarget1;
Context.Dr1 = dwTarget2;
Context.Dr2 = dwTarget3;


I traced to see if there were any calls from the game to SetThreadContext but there were none which meant that they were not setting any breakpoints for the debug registers to be full. And even if they did, my debug registers would overwrite theres.

Why is only one debug register being called? Is there something I missed out on? I can't seem to solve that question.

My Breakpoint function works fine, but if you guys want to double check:

Code:

while ( Thread32Next ( hSnapshot, &te ) )
      {
         // Check the thread
         if ( te.th32OwnerProcessID == GetCurrentProcessId () && te.th32ThreadID != GetCurrentThreadId () )
         {
            // Open the thread
            HANDLE hThread = OpenThread ( THREAD_SUSPEND_RESUME | THREAD_SET_CONTEXT | THREAD_GET_CONTEXT, false, te.th32ThreadID );

            // Suspend the thread
            SuspendThread ( hThread );

            // Obtain the thread information
            CONTEXT Context;
            Context.ContextFlags = CONTEXT_DEBUG_REGISTERS;

            // Obtain the thread information
            GetThreadContext ( hThread, &Context );

            // Find an available regiser and set it
            Context.Dr0 = dwTarget1;
            Context.Dr1 = dwTarget2;
            Context.Dr2 = dwTarget3;

            // Set the Dr7 register
            Context.Dr7 = 0x1;

            // Set the thread information
            SetThreadContext ( hThread, &Context );

            // Resume the thread
            ResumeThread ( hThread );
            CloseHandle  ( hThread );
         }
      }
Back to top
View user's profile Send private message MSN Messenger
Innovation
Grandmaster Cheater
Reputation: 12

Joined: 14 Aug 2008
Posts: 617

PostPosted: Sun Jan 06, 2013 11:41 pm    Post subject: Reply with quote

http://en.wikipedia.org/wiki/X86_debug_register#DR7_-_Debug_control

Code:
Context.Dr7 &= 0xF000FFD5; // ~((3 << 26) | (3 << 24) | (3 << 22) | (3 << 20) | (3 << 18) | (3 << 16) | (1 << 5) | (1 << 3) | (1 << 1))
Context.Dr7 |= 0x00000015; // (1 << 4) | (1 << 2) | (1 << 0)


Also, you're skipping the first thread in the list by calling Thread32Next immediately after Thread32First (use a do-while loop instead).

Deja vu? I strangely recall making a similar reply to you over a year and a half ago...
Back to top
View user's profile Send private message
iPromise
Grandmaster Cheater
Reputation: -1

Joined: 27 Jun 2009
Posts: 529
Location: Canada

PostPosted: Mon Jan 07, 2013 7:23 am    Post subject: Reply with quote

No I make my call to Thread32First, I just wanted to show my hooking code.

In that topic, I asked on how to set the bits for the Dr7 breakpoint..
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