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 


How to trace until return

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Slushnas
How do I cheat?
Reputation: 0

Joined: 28 Nov 2019
Posts: 2

PostPosted: Thu Nov 28, 2019 11:33 am    Post subject: How to trace until return Reply with quote

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
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

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

PostPosted: Fri Nov 29, 2019 3:20 am    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
Slushnas
How do I cheat?
Reputation: 0

Joined: 28 Nov 2019
Posts: 2

PostPosted: Fri Nov 29, 2019 11:02 pm    Post subject: Reply with quote

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
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

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

PostPosted: Sat Nov 30, 2019 4:13 am    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting 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