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 


Reversing question

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
ulysse31
Master Cheater
Reputation: 2

Joined: 19 Mar 2015
Posts: 324
Location: Paris

PostPosted: Mon Aug 10, 2015 5:09 am    Post subject: Reversing question Reply with quote

Hello,

I am reversing a packet encryption function, there are 2 instructions which I cannot seem to understand.
They are always together :

016B8336 - 1B C0 - sbb eax,eax
016B8338 - F7 D8 - neg eax

I ve done research and tried to figure out for a significant amount of time, every source I found on the web said that :

sbb eax,eax will do eax = eax - eax - (CF value (carry flag value)).
Therefore the result of this instruction could either be FFFFFFFF which is minus 1 either 0.

neg eax is going to do eax = 0-eax.
Sources say it will set the carry flag to 0 if eax is 0 and otherwise it will set the carry flag to 1.
Source :
http://www.blueraja.com/blog/285/branchless-conditionals-compiler-optimization-technique

This is what I have seen with debugging :
sbb eax,eax is a mystery to me. Sometimes if CF = 1 it sets eax to FFFFFFFF as you would expect but sometimes it sets EAX to 0 even tho CF is 1.
Then I have also seen sbb eax,eax turn eax into FFFFFFFF while CF was 0, if someone could explain me why that happens i'd be very gratefull.

As for neg eax, I witness the exact opposite of what i was expecting by reading net sources :
if eax is 0, neg eax always sets the CF to 1 instead of 0 and if eax is not 0 the neg simply switches the CF flag (turns it to 1 if it was 0 and to 0 if it was 1).
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Mon Aug 10, 2015 11:31 am    Post subject: Reply with quote

For SBB, take a look at this:
http://x86.renejeschke.de/html/file_module_x86_id_286.html

The example of what would make use of SBB is something like this:
Code:
Destination = Destination - (Source + CF);


For NEG, take a look at this:
http://x86.renejeschke.de/html/file_module_x86_id_216.html

The example of what would make use of NEG is something like this:
Code:
if(Destination == 0) CF = 0;
else CF = 1;
Destination = -Destination;

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming 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