View previous topic :: View next topic |
Author |
Message |
Slushnas How do I cheat?
Reputation: 0
Joined: 28 Nov 2019 Posts: 2
|
Posted: Thu Nov 28, 2019 11:33 am Post subject: How to trace until return |
|
|
Hello everyone. I am new to Cheat Engine and LUA scripting. I'm trying to break on a function and step over until the return statement so that I can log the result of the function.
I came across a post on the forum that had an example script:
forum.cheatengine.org/viewtopic.php?p=5577427
Code: | BreakpointAddress = 0x5AA8A0
FoundIt = 0
debug_removeBreakpoint(BreakpointAddress)
function debugger_onBreakpoint()
if(FoundIt == 0) then
debug_continueFromBreakpoint(co_stepover)
extra, opcode, bytes, addy = splitDisassembledString(disassemble(EIP))
RetFound = string.find(opcode, "ret")
if (RetFound) then
print(opcode)
FoundIt=1
local result = readFloat(ESP+0x18)
print("Result: ",result)
debug_removeBreakpoint(BreakpointAddress)
return 1
end
end
return 0
end
debug_setBreakpoint(BreakpointAddress) |
The code breaks but returns control back to the Cheat Engine interface. My understanding of returning 0 vs. 1 is that 0 returns control back to the interface and 1 does not (continues).
Is that a correct interpretation?
If I change the second return statement to return 1 instead, it doesn't return to the UI and still breaks - I inserted a print statement to be sure : 'print(string.format('%x',EIP))' but EIP never changes. It is like the 'debug_continueFromBreakpoint(co_stepover)' function is not actually stepping over to the next statement.
Is my understanding of how to use co_stepover flawed? If I change it to use co_stepinto instead, EIP does change and it does find the return statement inside the first call that it steps into. This is not what I want however because then I would have to keep track of every call it steps into - I just want to reach the return of the main function whatever line that ends up being.[/code]
|
|
Back to top |
|
 |
Dark Byte Site Admin
Reputation: 470
Joined: 09 May 2003 Posts: 25796 Location: The netherlands
|
Posted: Fri Nov 29, 2019 3:20 am Post subject: |
|
|
debug_continueFromBreakpoint stepover currently doesn't seem to work from inside a debugger_onBreakpoint (stepover is a special case as it goes for the gui stepover, which is not available at that time)
temporary fix:
add this code to your breakpoint code:
Code: |
getMemoryViewForm().miDebugStepOver.Enabled=true
|
_________________
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 |
|
 |
Slushnas How do I cheat?
Reputation: 0
Joined: 28 Nov 2019 Posts: 2
|
Posted: Fri Nov 29, 2019 11:02 pm Post subject: |
|
|
Thanks Dark Byte!
It works as expected with that line added. You called it a temporary fix. Does this mean that the behavior may change with a later release?
|
|
Back to top |
|
 |
Dark Byte Site Admin
Reputation: 470
Joined: 09 May 2003 Posts: 25796 Location: The netherlands
|
Posted: Sat Nov 30, 2019 4:13 am Post subject: |
|
|
Next version i'll try to make it execute the onclick code even if the menuitem is disabled
that code i posted won't have a negative effect so don't worry about that
_________________
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 |
|
 |
|