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: Sat Feb 01, 2014 11:35 pm    Post subject: Hardware Breakpoints Reply with quote

there is maximum capacity of 4 addresses which you can set a hardware breakpoint on (dr0 - dr3) but 4 aren't usually enough. I was wondering if it was possible to set one hardware breakpoint on a specific thread that would enable me to control the entire application.

an acquaintance of mine has actually accomplished this. apparently he did something with the main thread of the application.

if it is possible, how would someone go about accomplishing this?
Back to top
View user's profile Send private message MSN Messenger
661089799107
Expert Cheater
Reputation: 3

Joined: 25 Jan 2009
Posts: 186

PostPosted: Sun Feb 02, 2014 3:17 pm    Post subject: Reply with quote

So you want to set one HW breakpoint on a single threads context, and want all threads to break on it?
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

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

PostPosted: Sun Feb 02, 2014 3:25 pm    Post subject: Reply with quote

Try something like page exceptions which can have an unlimited amount of breakpoints (including read and write watches)

Or you could single step every thread and every step it does check if one of the addresses has been accessed/modified (slower than page exceptions)

And if it's a java program you could use a read or write watch on a class field using the jvm itself

_________________
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
iPromise
Grandmaster Cheater
Reputation: -1

Joined: 27 Jun 2009
Posts: 529
Location: Canada

PostPosted: Sun Feb 02, 2014 7:47 pm    Post subject: Reply with quote

@Blackknight Something of that nature is possible.

@Dark_Byte

Now that you've mentioned it, my buddy did tell me that he single stepped the main thread or something similar.

Is there any documentation on single stepping a thread, I haven't found any decent ones. How does it work because you only have the ability to set a maximum of 4 hardware breakpoints on a single address; how do you exploit that to monitor EACH address?
Back to top
View user's profile Send private message MSN Messenger
Dark Byte
Site Admin
Reputation: 471

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

PostPosted: Mon Feb 03, 2014 12:17 am    Post subject: Reply with quote

as long as the TF bit in the Flags register is set it will raise an debug event when an instruction has been executed
Depending on the operating system you have to manually set the TF back every instruction

_________________
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
iPromise
Grandmaster Cheater
Reputation: -1

Joined: 27 Jun 2009
Posts: 529
Location: Canada

PostPosted: Mon Feb 03, 2014 9:46 pm    Post subject: Reply with quote

I am injected into the debugee so using a vectored exception handler would be appropriate in my case right?

I go through all the threads in the application, I set CONTEXT_CONTROL to get the flag register and then I set the trap flag in the EFlag member of context.

In my exception handler, I would then write down in a text file the address of the breakpoint to confirm that I had been able to go through every instruction at will.

What am I doing wrong here, the results in my text file weren't what I had expected them to be.

Code:

void SetBreakpoint ( DWORD dwThreadId )
{
   HANDLE hThread = OpenThread ( THREAD_SUSPEND_RESUME | THREAD_GET_CONTEXT | THREAD_SET_CONTEXT, false, dwThreadId );

   CONTEXT c;
   c.ContextFlags = CONTEXT_CONTROL;
   
   SuspendThread ( hThread );
   GetThreadContext ( hThread, &c );

   c.EFlags = 0x100;

   SetThreadContext ( hThread, &c );
   ResumeThread ( hThread );
   CloseHandle ( hThread );
}
//

LONG CALLBACK ExceptionHandler ( PEXCEPTION_POINTERS ExceptionInfo )
{
   if ( ExceptionInfo->ExceptionRecord->ExceptionCode == EXCEPTION_SINGLE_STEP )
   {
      test << ExceptionInfo->ExceptionRecord->ExceptionAddress << endl;

      return EXCEPTION_CONTINUE_EXECUTION;
   }

   return EXCEPTION_CONTINUE_SEARCH;
}
//
Back to top
View user's profile Send private message MSN Messenger
Dark Byte
Site Admin
Reputation: 471

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

PostPosted: Tue Feb 04, 2014 3:08 am    Post subject: Reply with quote

Make sure you don't call setBreakpoint on your own thread, because it'll freeze after suspendThread

In the exception handler you may need to set the TF flag back in the context structure of the exceptioninfo structure

And what is the result of your text file and what did you expect? (Remember that because you've done multiple threads the results will be random addresses)

_________________
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
iPromise
Grandmaster Cheater
Reputation: -1

Joined: 27 Jun 2009
Posts: 529
Location: Canada

PostPosted: Wed Feb 05, 2014 5:23 pm    Post subject: Reply with quote

I followed your suggestions but that made the application hang, and it also crashed other running applications. I was expecting to see the majority of addresses in the text file starting from the entry-point to the last address being executed.

Code:

void SetBreakpoint ( DWORD dwThreadId )
{
   if ( dwThreadId != GetCurrentThreadId () )
   {
      HANDLE hThread = OpenThread ( THREAD_SUSPEND_RESUME | THREAD_GET_CONTEXT | THREAD_SET_CONTEXT, false, dwThreadId );

      CONTEXT c;
      c.ContextFlags = CONTEXT_CONTROL;
      
      SuspendThread ( hThread );
      GetThreadContext ( hThread, &c );

      c.EFlags = 0x100;

      SetThreadContext ( hThread, &c );
      ResumeThread ( hThread );
      CloseHandle ( hThread );
   }
}

LONG CALLBACK ExceptionHandler ( PEXCEPTION_POINTERS ExceptionInfo )
{
   if ( ExceptionInfo->ExceptionRecord->ExceptionCode == EXCEPTION_SINGLE_STEP )
   {
      ExceptionInfo->ContextRecord->EFlags = 0x100;

      test << ExceptionInfo->ExceptionRecord->ExceptionAddress << endl;

      return EXCEPTION_CONTINUE_EXECUTION;
   }

   return EXCEPTION_CONTINUE_SEARCH;
}


My results were addresses far away from the applications entry-point for the majority of them. Maybe targeting specific threads causes the computer to become unstable, hence forth the reason behind why all other running applications crash?

Quote:
778211F8
778211FA
778211FD
778211FF
77839DF6
77839DFC
77821205
7782120C
77821249
7782124B
77839E07
77839E0A
77AF239B
77AF239D
77AF239E
77AF23A0
77AF23A3
77AF23A6
77AF23AB
77AF23AD
77AF23B1
77AF23B7
778AD0E8
778AD0EA
778AD0EC
778AD0EE
778AD0F0
778AD0F5
778AD0F7
778AD0FC
778AD0FE
778AD100
778AD105
778AD10E
778AD113
778AD115
778AD120
778AD122
778AD123
778AD126
778AD12E
778AD135
778AD14F
778AD151
778AD153
778AD156
77AF239B
77AF239D
77AF239E
025911C4
77AF23A3025911DA

025911DF77AF23A6

025911E077AF23AB

77AF23AD025926E9
77AF23B9025927D5
...
Back to top
View user's profile Send private message MSN Messenger
Dark Byte
Site Admin
Reputation: 471

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

PostPosted: Wed Feb 05, 2014 5:54 pm    Post subject: Reply with quote

Processes don't start at the entry point. They start at the launcher stub, which sets up the main modules, kernel32 init, tls setup, etc...
only after a very long time it'll reach the entry point

as for other programs crashing not sure. You're not using a global windows hook to inject the dll are you? Because if so that dll will be running in ALL gui processes, and if you didn't add in a specific process targeter, that'll cause a crash as well

Also, don't use "test << ExceptionInfo->ExceptionRecord->ExceptionAddress << endl;" inside the exception handler

the console output is not re-entrant.
Explanation:
Code:

  MainThread executes printf
  printf obtains a lock to the console
  <exception triggers>
  exception executes printf
  printf waits till the console lock is clear
  ...waits...
  ...waits...
  ...waits...
  ...

_________________
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