h3x1c Master Cheater
Reputation: 17
Joined: 27 Apr 2013 Posts: 306
|
Posted: Sun Jul 31, 2016 12:52 pm Post subject: How to consolidate script logic with the CMOVcc instruction! |
|
|
Click above to watch the video!
I was recently hacking a game and noticed a whole bunch of instructions I had never seen before, one of which being CMOVB, which is a conditional move--of which there are many, as detailed here.
These instructions give you the opportunity to directly move values based on the state of flags, so where you might have otherwise branched and written a number of instructions just to move a value, you can avoid that altogether in the right scenario!
In the video above, I outline a case where I immediately found this instruction useful. CMOVcc has its quirks, like only being able to move from a memory address or register to a register (so, no moving immediate values or moving into memory addresses), but I think it's a very handy instruction to be aware of and put to good use.
Here's a quick look at the example from the video, for those who only need to see it:
Code: | newcode:
cmp [rcx+B0],0 //Compare offset to check if enemy or player
cmove eax,[rcx+A0] //If equal, move max health into eax
cmovne eax,[rcx+64] //If not equal, move 0 into eax (one-hit kill)
jmp originalcode
originalcode:
mov [rcx+000000A4],eax //Original instruction writing to health
jmp exit |
_________________
|
|