| View previous topic :: View next topic |
| Author |
Message |
Pingpongus How do I cheat?
Reputation: 0
Joined: 11 Sep 2021 Posts: 6
|
Posted: Tue Sep 21, 2021 1:11 pm Post subject: Responding to function calls |
|
|
Hey guys, I have been plugging away on my project finally having wrapped my head around how to scan for pointers. However, now I want to do something a little more complicated.
If I have the address of a function, and I want to write some code that will execute when this function is called inside the process, how would I go about doing that? I don't want to inject anything, I just want to detect the fact that the function was called (and probably get the values of its params). WaitForSingleObject (sorry, cant post urls yet), a function I am utilizing elsewhere to wait for the attached process to close seemed promising, but it doesn't appear to work for functions.
This is on Windows, and I am trying to accomplish it using the Win32 API. Thanks in advance for any help!  |
|
| Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 152
Joined: 06 Jul 2014 Posts: 4711
|
|
| Back to top |
|
 |
Pingpongus How do I cheat?
Reputation: 0
Joined: 11 Sep 2021 Posts: 6
|
Posted: Tue Sep 21, 2021 1:45 pm Post subject: |
|
|
Oh! I think you are definitely right. Could you give me a bit more of a nudge? I think WaitForDebugEvent() is what I need, but it seems that the DEBUG_EVENT struct only has codes for things like process created, process exit, etc. Nothing like "function called".
Edit: Sorry, I jumped the gun! I dove into the docs you posted but now I see you said simply, "use a breakpoint" I think DebugBreakProcess is what I need
Edit: Edit: I wish I could double post lol. Well I'm still not entirely clear how to use this DebugBreakProcess. It can be used to break out of the process, but I'm not sure how to tell it to do it on that particular function call. |
|
| Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 152
Joined: 06 Jul 2014 Posts: 4711
|
Posted: Tue Sep 21, 2021 2:39 pm Post subject: |
|
|
General idea:
- Overwrite an instruction at/near the beginning of the function with an int3 (0xCC) instruction
- When that instruction is executed, the processor generates interrupt 3
- The kernel handles the interrupt and notifies the debugger attached to the process that an interrupt occurred (windows calls this event a "breakpoint exception")
- The debugger then does something
- After the debugger is done, it restores the original instruction so that the process can execute it as normal
- The debugger might overwrite it again with an int3 if it wants to continue to break when the function is run
For more information, search for tutorials on how to make a debugger in Windows. _________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
| Back to top |
|
 |
Pingpongus How do I cheat?
Reputation: 0
Joined: 11 Sep 2021 Posts: 6
|
Posted: Tue Sep 21, 2021 2:49 pm Post subject: |
|
|
| Ahhh I think I get it, thank you very much for the detailed answer. So basically if I want to achieve this behavior, this is the end of my "no writing to memory" approach. I will have to insert that break instruction into game memory. I don't think this is a problem at all though, as I see other projects on github writing little bits to the games memory. Really appreciate the help! |
|
| Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 152
Joined: 06 Jul 2014 Posts: 4711
|
Posted: Tue Sep 21, 2021 3:05 pm Post subject: |
|
|
int3 is a software breakpoint. You could use hardware breakpoints if you really don't want to write to memory, but they have limitations too (i.e. only 4 available).
https://en.wikipedia.org/wiki/X86_debug_register
All else being equal I'd use software breakpoints over hardware breakpoints for stopping at code. _________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
| Back to top |
|
 |
|