Difference between revisions of "Lua Debugging"

From Cheat Engine
Jump to navigation Jump to search
(debug_continueFromBreakpoint takes an integer)
(Lua Debugging)
Line 5: Line 5:
 
* '''openProcess(name)''' - Open a running process
 
* '''openProcess(name)''' - Open a running process
 
* '''debugProcess()''' - Start debugging the open process
 
* '''debugProcess()''' - Start debugging the open process
* '''debug_setBreakpoint(address)''' - Add a breakpoint at an address
+
* '''debug_setBreakpoint(address)''' - Add a breakpoint at an address, optional parameters are size and type
 
* '''debug_continueFromBreakpoint(method)''' - Continue execution, methods are "co_run", "co_stepinto" and "co_stepover"
 
* '''debug_continueFromBreakpoint(method)''' - Continue execution, methods are "co_run", "co_stepinto" and "co_stepover"
(and possibly "co_runtill" which is in TContinueOption but not shown in main.lua).
+
("co_runtill" is in TContinueOption but not shown in main.lua, probably because it needs to know what address to run to).
  
 
In addition, you can create the event function '''debugger_onBreakpoint()''' that will
 
In addition, you can create the event function '''debugger_onBreakpoint()''' that will
Line 32: Line 32:
 
debugProcess()
 
debugProcess()
 
debug_setBreakpoint(0x00406002)
 
debug_setBreakpoint(0x00406002)
 +
</pre>
 +
 +
=== debug_setBreakpoint() ===
 +
 +
Add a breakpoint at an address, optional parameters are size and type.
 +
* size: number of bytes to break for counting from the address (default: 1, not used if type is bptExecute)
 +
* type: type of breakpoint (default bptExecute)
 +
** bptExecute: break when the instruction pointer EIP is in the area
 +
** bptAccess: break when memory in the area is accessed
 +
** bptWrite: break when memory in the area is written to
 +
 +
Types from debuggertypedefinitions.pas:
 +
<pre>
 +
type
 +
  TContinueOption = (co_run=0, co_stepinto=1, co_stepover=2, co_runtill=3); 
 +
 +
type
 +
  TBreakpointTrigger = (bptExecute=0, bptAccess=1, bptWrite=2);
 +
 +
type
 +
  TContinueOption = (co_run=0, co_stepinto=1, co_stepover=2, co_runtill=3);
 
</pre>
 
</pre>

Revision as of 12:03, 14 December 2011

Lua Debugging

There are functions exposed to LUA that enable scripts to control the debugger:

  • openProcess(name) - Open a running process
  • debugProcess() - Start debugging the open process
  • debug_setBreakpoint(address) - Add a breakpoint at an address, optional parameters are size and type
  • debug_continueFromBreakpoint(method) - Continue execution, methods are "co_run", "co_stepinto" and "co_stepover"

("co_runtill" is in TContinueOption but not shown in main.lua, probably because it needs to know what address to run to).

In addition, you can create the event function debugger_onBreakpoint() that will be called by Cheat Engine whenever a breakpoint is hit.

Here's an example for Space Pirates and Zomies that tracks ships that have their armor decreased. By debugging I found that at 0x406002, ECX has a pointer to a structure with the armor float at 0x60. This code will track those values in the armors table with the key being the address and the value being the actual armor value:

if not armors then
   armors = { }
end

function debugger_onBreakpoint()
         if (EIP ~= 0x00406002) then return 0 end -- ignore user-set breakpoints
         armors[ECX] = readFloat(ECX+0x60) -- store armor in table
         debug_continueFromBreakpoint(co_run) -- continue execution
         return 1 -- let CE know we handled breakpoint, no need to update debugger form
end

openProcess("SpazGame.exe")
debugProcess()
debug_setBreakpoint(0x00406002)

debug_setBreakpoint()

Add a breakpoint at an address, optional parameters are size and type.

  • size: number of bytes to break for counting from the address (default: 1, not used if type is bptExecute)
  • type: type of breakpoint (default bptExecute)
    • bptExecute: break when the instruction pointer EIP is in the area
    • bptAccess: break when memory in the area is accessed
    • bptWrite: break when memory in the area is written to

Types from debuggertypedefinitions.pas:

type
  TContinueOption = (co_run=0, co_stepinto=1, co_stepover=2, co_runtill=3);  

type
  TBreakpointTrigger = (bptExecute=0, bptAccess=1, bptWrite=2); 

type
  TContinueOption = (co_run=0, co_stepinto=1, co_stepover=2, co_runtill=3);