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 


Change register at breakpoint

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Tutorials -> LUA Tutorials
View previous topic :: View next topic  
Author Message
Dark Byte
Site Admin
Reputation: 457

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

PostPosted: Tue Mar 01, 2011 7:04 am    Post subject: Change register at breakpoint This post has 1 review(s) Reply with quote

the following code will change the eax register to 0 when the breakpoint at 0x00420f3e hits and then continues after handling it

If you use it on the 32-bit tutorial that comes with ce 6 it will cause the health in step 2 to not go down



Code:

changeregaddress=0x00420f3e --change this to the address you want
debug_removeBreakpoint(changeregaddress) --remove it if it was set

function debugger_onBreakpoint()
  if (EIP == changeregaddress) then
    hasChangedARegister=true --obsolete in 6.1
    EAX=0
    changedEAX=true  --obsolete in 6.1

    debug_continueFromBreakpoint(0) --run (bug in 6.0: it's always run)
   
    return 1 --I handled it so don't tell the user
  else
    return 0 --unexpected breakpoint, show the the user
  end
end

 
debug_setBreakpoint(changeregaddress)

_________________
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
n1vX
Advanced Cheater
Reputation: 0

Joined: 27 May 2007
Posts: 61

PostPosted: Mon Mar 21, 2011 10:32 pm    Post subject: Reply with quote

This script just handle 1 breakpoint, how to handle several breakpoint ?
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

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

PostPosted: Mon Mar 21, 2011 11:40 pm    Post subject: Reply with quote

Just set a second breakpoint

Then also check if the current eip is that second breakpoint
e.g after the else, or replace the return 0 / 1 with a variable (retval=0 /retval=1) that is set and only at the end of the function return with the value (return retval)

_________________
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
Refocus
How do I cheat?
Reputation: 0

Joined: 03 Apr 2011
Posts: 7

PostPosted: Wed Apr 06, 2011 6:28 pm    Post subject: Reply with quote

Very nice tut Dark Byte! Good to see some more activity in the LUA section.
Back to top
View user's profile Send private message
Popinman32
Cheater
Reputation: 0

Joined: 23 Jul 2010
Posts: 29

PostPosted: Tue Apr 19, 2011 3:10 pm    Post subject: Reply with quote

Could this method be used to print the value of a register?
_________________
I had a life? O.o
I thought my job was to collect information and help, then one day hope to use it. :S
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

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

PostPosted: Tue Apr 19, 2011 10:37 pm    Post subject: Reply with quote

sure, you can add a line to write the register to the output of the lua console, or to a file, or a memo in a self created form with memo object (next version will have more display methods)
_________________
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
listito
Cheater
Reputation: 0

Joined: 31 Dec 2010
Posts: 35

PostPosted: Wed Apr 20, 2011 8:53 pm    Post subject: Reply with quote

lol, this is just the answer of my question in another subforum

dark, how about the performance of eip=anything? it decrewases the software performance too much?
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

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

PostPosted: Thu Apr 21, 2011 3:09 am    Post subject: Reply with quote

it will only break on the given breakpoints. The eip check is only for cases when you have set multiple breakpoints or are tracing (it will be slower than the normal break and trace)
_________________
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
HelloBuddySup :-)
How do I cheat?
Reputation: 0

Joined: 09 Feb 2014
Posts: 8

PostPosted: Sun Feb 09, 2014 6:01 pm    Post subject: Re: Change register at breakpoint Reply with quote

Dark Byte wrote:
the following code will change the eax register to 0 when the breakpoint at 0x00420f3e hits and then continues after handling it

If you use it on the 32-bit tutorial that comes with ce 6 it will cause the health in step 2 to not go down



Code:

changeregaddress=0x00420f3e --change this to the address you want
debug_removeBreakpoint(changeregaddress) --remove it if it was set

function debugger_onBreakpoint()
  if (EIP == changeregaddress) then
    hasChangedARegister=true --obsolete in 6.1
    EAX=0
    changedEAX=true  --obsolete in 6.1

    debug_continueFromBreakpoint(0) --run (bug in 6.0: it's always run)
   
    return 1 --I handled it so don't tell the user
  else
    return 0 --unexpected breakpoint, show the the user
  end
end

 
debug_setBreakpoint(changeregaddress)

'Ello, I was wondering how could I use this with writeBytes?
Help is always appreciated, thanks!
Back to top
View user's profile Send private message
ta_trainer
Advanced Cheater
Reputation: 0

Joined: 24 Dec 2006
Posts: 76

PostPosted: Thu Feb 12, 2015 4:48 am    Post subject: Reply with quote

Dark Byte wrote:
Just set a second breakpoint

Then also check if the current eip is that second breakpoint
e.g after the else, or replace the return 0 / 1 with a variable (retval=0 /retval=1) that is set and only at the end of the function return with the value (return retval)


is there a limitation on the number of breakpoints I can use in this way?
if there is a limitation.

if there is a limitation, would removing/setting breakpoints dynamiccaly (debug_removeBreakpoint) be a feasible workaround.

something like this:
<code>
<debug_addBreakpoint1>
<do something>
<debug_removeBreakpoint1>
<debug_addBreakpoint2>

then
<code>
<on breakpoint 2>
<do something>
<debug_removeBreakpoint2>
<add back brakpoint 1>

as long as I keep the sequence in sync with the code execution.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

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

PostPosted: Thu Feb 12, 2015 5:00 am    Post subject: Reply with quote

it depends on the target. if the reason you do this is because of integrity checks, then 4, else infinite (software breakpoints change the first byte of an instruction)
_________________
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
skillcoder
How do I cheat?
Reputation: 0

Joined: 28 Mar 2015
Posts: 1

PostPosted: Sat Mar 28, 2015 7:49 am    Post subject: Mapping one-byte registers Reply with quote

I found that one-byte registers not mapping to LUA vars (LIKE AL/AH, BL/BH, CL/CH, DL/DH ...)
I had to use a terrible/agly way
to get DL
Code:
("0x"..string.sub(string.format("%x", EDX), -2, -1))+0

AND to set it to CC
Code:
EDX=('0x'..string.sub(string.format("%x", EDX), 1, -3)..'CC')+0


May u can add mapping for OTHER registers not only for EAX, EBX, ECX, EDX, ...
Or if i noob give me code for get/set one-byte register without STRING manipulations
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

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

PostPosted: Sat Mar 28, 2015 8:51 am    Post subject: Reply with quote

AL and AH are part of EAX (RAX in 64-bit) so it won't make sense to map them into those (and would cause a giant overhead)

what you can use :
[code]
x=dwordToByteTable(0x11223344)
AL=x[1]
AH=x[2]

AX=byteTableToWord(x)
[code]

use byteTableToDword(bytetable) to build the EAX register back with the new values if you changed them

_________________
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 Tutorials -> LUA Tutorials 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 cannot download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites