View previous topic :: View next topic |
Author |
Message |
GBRA4.669 How do I cheat?
Reputation: 0
Joined: 17 Dec 2021 Posts: 9
|
Posted: Fri Dec 17, 2021 8:01 pm Post subject: debugger_onBreakpoint questions |
|
|
Hi legends,
I am trying to automate a procedure that I am currently doing manually with CE.
The procedure is:
attach to exe > memory view > go to address > right click on the address > break and trace instr > get a value from RBX.
Then I add the address manually with the value from RBX + 1 as type Byte.
Then invert the value (if 1, change it to 0 and vice versa).
Done.
I am getting sick of doing this every time, so I was trying to do it with lua,
but I am not even sure I am getting the value for RBX.
Code: |
[ENABLE]
{$lua}
_1test = [[
define(aSymbol,"myTestGame.exe"+0x53CF425)
registerSymbol(aSymbol)
]]
function debugger_onBreakpoint()
-- here I want the value of RBX + 1
-- then "add address manually" RBX + 1 as type Byte
-- invert value stored in RBX + 1 (e.g if 1 set it to 0 and viceversa)
end
reinitializeSymbolhandler()
autoAssemble(_1test)
debugProcess(2)
debug_setBreakpoint(aSymbol, debugger_onBreakpoint())
debug_removeBreakpoint(aSymbol)
[DISABLE]
{$lua}
print("exited")
{$asm}
unregistersymbol(aSymbol)
|
Any help is appreciated, no need to feed me the full solution.
Even understanding how to print the value of RBX + 1 as type Byte would be really helpful.
Thanks DB for this awesome tool.
|
|
Back to top |
|
 |
TheyCallMeTim13 Wiki Contributor
Reputation: 51
Joined: 24 Feb 2017 Posts: 976 Location: Pluto
|
Posted: Fri Dec 17, 2021 10:44 pm Post subject: |
|
|
It sounds like you'd be better off using ASM and code injection. Look up injection copy, you just want the base address so you can have a memory record of [base address]+1. And you can invert the value in injection script.
_________________
|
|
Back to top |
|
 |
GBRA4.669 How do I cheat?
Reputation: 0
Joined: 17 Dec 2021 Posts: 9
|
Posted: Sat Dec 18, 2021 8:01 am Post subject: |
|
|
I understand your point, however, this is not the full picture, the script is way bigger (i have other functions working already) and it was simplified to make it easier to read and understand. Also, I am trying to learn LUA + CE so I would try to stick with it for a while.
I also have a C++ script (I can post it if some1 is interested but it's very messy) that does the same exact thing.
Today I will try it again and post here the solution if I can find it.
Or maybe add some clarifications in the wiki.
To me,debugger_onBreakpoint() it's unclear how to get access to the registries when the hook (event) debugger_onBreakpoint() it's triggered.
I've seen people calling getAddress inside of it, and people that don't do it.
I've seen people doing stuff like RIP=getAddress("aSymbol") inside of it.
Are they going to get RIP registry or just the address? Is there some kind of destructuring going on or just bad variable naming (shouldn't be local RIP instead)?
Thank you <3
|
|
Back to top |
|
 |
TheyCallMeTim13 Wiki Contributor
Reputation: 51
Joined: 24 Feb 2017 Posts: 976 Location: Pluto
|
Posted: Sat Dec 18, 2021 8:25 am Post subject: |
|
|
I'm just thinking creating memory records and what not will slow things down a bit, so you might look at launching a seperate thread for that. As far as the code you posted you are setting the breakpoint then immediately removing it thus it's likely never triggered.
RIP is the instruction pointer it holds the address of the currently executing instruction. And unless they are using "read...(RIP)" they're just getting the address of RIP and not the value/code at that address. If they are setting RIP (RIP=getAddress(...) is setting RIP) they are changing the execution location for what I understand; but it's a bit weird and I've never done this, seems like it would just cause crashes but I'm not really sure.
_________________
|
|
Back to top |
|
 |
GBRA4.669 How do I cheat?
Reputation: 0
Joined: 17 Dec 2021 Posts: 9
|
Posted: Sat Dec 18, 2021 8:56 am Post subject: |
|
|
I am hitting the breakpoint (I can print from there),
Let's suppose I use LUA only:
Code: |
local address = getAddress("myTestGame.exe")+0x30CE324;
function debugger_onBreakpoint()
local RAXVal = 0x1C795614115 + 1; -- how to get RAX + 1 dynamically here??
if readBytes(RAXVal, 1, false) then
writeBytes(RAXVal, 1)
else
writeBytes(RAXVal, 0)
end
end
debugProcess(2);
debug_setBreakpoint(address, 1, bptAccess, bpmInt3, debugger_onBreakpoint());
debug_continueFromBreakpoint(co_run)
debug_removeBreakpoint(address)
|
Now everything works except I need to manually hardcode the value of RAX. I am manually finding it with break and trace instruction (1, software breakpoint) and looking at what is inside the RAX registry.
Pls, help me to automate this last step, I spent to many hours on this small detail. thank you so much
|
|
Back to top |
|
 |
Dark Byte Site Admin
Reputation: 467
Joined: 09 May 2003 Posts: 25702 Location: The netherlands
|
Posted: Sat Dec 18, 2021 3:25 pm Post subject: |
|
|
Code: |
local RAXVal = 0x1C795614115 + 1; -- how to get RAX + 1 dynamically here??
|
like this:
Code: |
local RAXVal = RAX+1
|
also, you might prefer hardware breakpoints, as int3's will trigger integrity checks
_________________
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 |
|
 |
TheyCallMeTim13 Wiki Contributor
Reputation: 51
Joined: 24 Feb 2017 Posts: 976 Location: Pluto
|
Posted: Sat Dec 18, 2021 3:32 pm Post subject: |
|
|
Try something like this, this is for the CE tutorial step 2.
Code: | function debugger_onBreakpoint()
if RIP == getAddress('Tutorial-x86_64.exe+2B09B') then
print(RAX)
debug_continueFromBreakpoint(co_run)
return 0
end
end
debugProcess(2)
debug_setBreakpoint('Tutorial-x86_64.exe+2B09B')
|
_________________
|
|
Back to top |
|
 |
GBRA4.669 How do I cheat?
Reputation: 0
Joined: 17 Dec 2021 Posts: 9
|
Posted: Sat Dec 18, 2021 4:24 pm Post subject: |
|
|
I am confused guys, I have tried that, but I have no idea why I get nil for RAX (or any other register RIP, RDX, RBX). Yes, 64bit game.
Code: |
local address = getAddress("myTestGame.exe")+0x31CF606;
function debugger_onBreakpoint()
local RAXVal = RAX + 1;
if readBytes(RAXVal, 1, false) then
writeBytes(RAXVal, 1)
else
writeBytes(RAXVal, 0)
end
return 1
end
openProcess("myTestGame.exe");
debugProcess(2);
debug_setBreakpoint(address, 1, bptAccess, bpmDebugRegister, debugger_onBreakpoint());
debug_continueFromBreakpoint(co_run)
debug_removeBreakpoint(address)
|
When I execute it, I get this Script Error:
Error:[string "local address = getAddress("myTestGame.exe"..."]:4: attempt to perform arithmetic on a nil value (global 'RAX')
|
|
Back to top |
|
 |
TheyCallMeTim13 Wiki Contributor
Reputation: 51
Joined: 24 Feb 2017 Posts: 976 Location: Pluto
|
Posted: Sat Dec 18, 2021 5:19 pm Post subject: |
|
|
Not sure where the error is but, with how you're using "getAddress" before "openProcess" this could have unforeseen behavior. And you use the global function "debugger_onBreakpoint" and don't check the instruction pointer for the intended instruction, so any breakpoints hit will call that function and this could cause problems. Plus the random semicolons says this is spaghetti code and you might be better off starting small with it till you get the breakpoint code working and have a better understanding of how it works, try a simplified version with the CE tutorial. And with "if readBytes(RAXVal, 1, false) then" so long as it reads any value it will equate as true (i.e.: any number is true in Lua).
_________________
|
|
Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 150
Joined: 06 Jul 2014 Posts: 4646
|
Posted: Sat Dec 18, 2021 5:27 pm Post subject: |
|
|
"debugger_onBreakpoint()" is invoking the function debugger_onBreakpoint.
You shouldn't be defining that function as the global variable "debugger_onBreakpoint" if you don't want it to be the global breakpoint handler.
Code that isn't indented is horrible to read. There might be problems in such functions... I didn't look.
bptAccess triggers when a value in memory at that address is accessed. I'm guessing you want it to trigger when the code at that address is executed.
Here's how I'd print the value of rbx in step 2 of the CE tutorial (64-bit):
Code: | local inject = getAddress'Tutorial-x86_64.exe+2B42C'
assert(readInteger(inject) == 0x07F88329, 'should be "sub [rbx+000007F8],eax"')
debug_setBreakpoint(inject, 1, bptExecute, function()
print(('RBX: %08X'):format(RBX))
debug_removeBreakpoint(inject)
debug_continueFromBreakpoint(co_run)
return 0
end) |
You'd also need to use AddressList.createMemoryRecord to create a new memory record. Use a search engine to find examples. The CE wiki might have examples too.
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
Back to top |
|
 |
GBRA4.669 How do I cheat?
Reputation: 0
Joined: 17 Dec 2021 Posts: 9
|
Posted: Sat Dec 18, 2021 5:56 pm Post subject: |
|
|
sorry for the bad indentation.
This is a cleaner version of the script:
Code: |
function aFn()
print(RAX);
debug_continueFromBreakpoint(co_run);
return 1;
end
openProcess("MyTestGame.exe");
local address = getAddress("MyTestGame.exe")+0x31BF346;
debugProcess(2);
debug_setBreakpoint(address, 1, bptAccess, bpmInt3, aFn());
|
RAX is printing an empty line inside aFn
|
|
Back to top |
|
 |
TheyCallMeTim13 Wiki Contributor
Reputation: 51
Joined: 24 Feb 2017 Posts: 976 Location: Pluto
|
Posted: Sat Dec 18, 2021 6:38 pm Post subject: |
|
|
"debug_setBreakpoint" needs the function not it's return value.
i.e.:
Code: |
debug_setBreakpoint(address, aFn);
|
_________________
|
|
Back to top |
|
 |
GBRA4.669 How do I cheat?
Reputation: 0
Joined: 17 Dec 2021 Posts: 9
|
Posted: Sat Dec 18, 2021 8:32 pm Post subject: |
|
|
even in its simplest form (coming from the Wiki), using the global debugger_onBreakpoint(), it is not working for me.
Code: |
openProcess("myTestGame.exe");
local inject = getAddress'myTestGame.exe + 0x21BF323';
debugProcess(2);
function debugger_onBreakpoint()
print("inside a breakpoint");
end
debug_setBreakpoint(inject);
|
I never see the print statement executed, it's like the function is never called.
The breakpoint is set but there is no print.
I have tried to launch this both from Lua engine (memory view > tools > Lua engine) and with auto assemble (enable/disable). Print statement not executed.
Wiki URL: wiki.cheatengine title=Lua:debugger_onBreakpoint (cannot post URL)
Tried also returning 0 and 1, tried with "debug_continueFromBreakpoint(co_run)"
"debug_removeBreakpoint(inject)" in different order inside and outside the callback function.
|
|
Back to top |
|
 |
Dark Byte Site Admin
Reputation: 467
Joined: 09 May 2003 Posts: 25702 Location: The netherlands
|
Posted: Sat Dec 18, 2021 9:23 pm Post subject: |
|
|
is the address correct and is the breakpoint actually set at the address? (red/green line)
_________________
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 |
|
 |
GBRA4.669 How do I cheat?
Reputation: 0
Joined: 17 Dec 2021 Posts: 9
|
Posted: Sun Dec 19, 2021 5:16 am Post subject: |
|
|
Yes DB. I am left with a game frozen, the breakpoint is set and it's red when that line is not highlighted in the memory view and green if highlighted (I guess red + blue makes it green).
I have to manually go into memory, go to that place in memory, right-click on the breakpoint and remove it or my game is left frozen. Thanks for the help.
Last edited by GBRA4.669 on Sun Dec 19, 2021 5:46 am; edited 1 time in total |
|
Back to top |
|
 |
|