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 


ASM Instruction Question

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
AhMunRa
Grandmaster Cheater Supreme
Reputation: 27

Joined: 06 Aug 2010
Posts: 1117

PostPosted: Thu Nov 04, 2010 10:53 am    Post subject: ASM Instruction Question Reply with quote

I know the NOT instruction takes 1 operand. What I am not comprehending about it is that it takes a value say: 0x52
Code:

EAX = 00000052

NOT EAX;

EAX then becomes FFFFFFAD


My question is exactly what has happened here?

Some links to a good explanation are welcome as well.

_________________
<Wiccaan> Bah that was supposed to say 'not saying its dead' lol. Fixing >.>
Back to top
View user's profile Send private message
tombana
Master Cheater
Reputation: 2

Joined: 14 Jun 2007
Posts: 456
Location: The Netherlands

PostPosted: Thu Nov 04, 2010 11:14 am    Post subject: Reply with quote

The NOT instruction will invert all bits.
Back to top
View user's profile Send private message
AhMunRa
Grandmaster Cheater Supreme
Reputation: 27

Joined: 06 Aug 2010
Posts: 1117

PostPosted: Thu Nov 04, 2010 11:29 am    Post subject: Reply with quote

Right, my trouble is that I am trying to mathematically reproduce this using base 10, and it's not working.

Got it. In C#

Code:

for( int x = 1; x < len; x++ )
{
     value = arrStr[x] + 1;
     value = System.Math.Abs(value) * (-1);
}


If arrstr[x] = 52
value = arrStr[52] + 1;
value = -53
Converted to hex is FFFFFFAD
which is the same as NOT 52

_________________
<Wiccaan> Bah that was supposed to say 'not saying its dead' lol. Fixing >.>
Back to top
View user's profile Send private message
AtheistCrusader
Grandmaster Cheater
Reputation: 6

Joined: 23 Sep 2006
Posts: 681

PostPosted: Thu Nov 04, 2010 1:07 pm    Post subject: Reply with quote

Go over each one
15-x=inverted
15-2 = 13, in hex is D
Back to top
View user's profile Send private message
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Fri Nov 05, 2010 2:25 am    Post subject: Reply with quote

AhMunRa wrote:
Right, my trouble is that I am trying to mathematically reproduce this using base 10, and it's not working.
Mathematically? Bitwise much?
Code:
int i = 0x52;
i = ~i;
// i is now 0xFFFFFFAD
Back to top
View user's profile Send private message
AhMunRa
Grandmaster Cheater Supreme
Reputation: 27

Joined: 06 Aug 2010
Posts: 1117

PostPosted: Fri Nov 05, 2010 8:05 am    Post subject: Reply with quote

Yeah already sorted that.

That works better than what I was using Jani, now though instead of actually being 0xFFAD the value is -53.

I really hate that you can't work with actual hex values. This would be so much easier.

_________________
<Wiccaan> Bah that was supposed to say 'not saying its dead' lol. Fixing >.>
Back to top
View user's profile Send private message
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Sat Nov 06, 2010 7:57 am    Post subject: Reply with quote

AhMunRa wrote:
That works better than what I was using Jani, now though instead of actually being 0xFFAD the value is -53.
-53 is the same as 0xFFAD, if the type is signed short.

AhMunRa wrote:
I really hate that you can't work with actual hex values. This would be so much easier.
What do you mean? int i = 170 and i is 0xAA. Everything is stored as binary, hex and dec are just representation forms for us humans to make it easier to read.
Back to top
View user's profile Send private message
AhMunRa
Grandmaster Cheater Supreme
Reputation: 27

Joined: 06 Aug 2010
Posts: 1117

PostPosted: Mon Nov 08, 2010 12:00 pm    Post subject: Reply with quote

The type is not singed short it is int, was running into conversion errors due to every 3rd line having to convert between decimal and hex.

I've already manually solved the problem, but I have not completed the task and written code to perform it for me.

All my values should be no larger than dword, yet some are overflowing and causing errors during byte conversion.

I'm starting to think it's the language I've chosen to write this in is too constrained.

Right Jani, but it sucks that the computer will treat cin.get('H'); as 72 and not 0x48 unless you specify 0x

_________________
<Wiccaan> Bah that was supposed to say 'not saying its dead' lol. Fixing >.>
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Mon Nov 08, 2010 12:20 pm    Post subject: Reply with quote

they are the same thing.

72 is 0x48
0x48 is 72
Back to top
View user's profile Send private message
AhMunRa
Grandmaster Cheater Supreme
Reputation: 27

Joined: 06 Aug 2010
Posts: 1117

PostPosted: Mon Nov 08, 2010 3:13 pm    Post subject: Reply with quote

Thank you all for the help, in this case I couldn't see the forest for the tree. My value kept coming out wrong due to me not setting it properly before moving on in my code. I was setting the hex value to a var prevInt in which I was using it later as a decimal instead of hex, was causing my screw up.

Final result


Code:

for (int x = 0; x < len; x++)
{
     if (x < 1)
     {
          byteStr = arrStr[x].ToString();
          bByte = Convert.ToByte(byteStr);
          bInt = ~bByte;
          int test = Convert.ToInt32(byteStr);
          test = test / 2;
          value2 = bInt & test;
          outPut = String.Format("{0:x2}", value2);
          prevInt = Convert.ToInt32(outPut, 16);
     }
     else
     {
          value = arrStr[x] - prevInt;
          value2 = value / 2;
          prevInt = Convert.ToInt32(value2.ToString("X"), 16);
          if (x == 2 || x == 4 || x == 6 || x == 8 || x == 10 || x == 12 || x == 14 || x == 16)
          {
               outPut += String.Format("-{0:x2}", value2);
          }
          else
          {
               outPut += String.Format("{0:x2}", value2);
          }
     }
}


If someone can offer a better solution to add the hyphen in there I'm willing to listen. Best I could come up with is that hack.

_________________
<Wiccaan> Bah that was supposed to say 'not saying its dead' lol. Fixing >.>
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Mon Nov 08, 2010 3:47 pm    Post subject: Reply with quote

what exactly are you trying to do?
Back to top
View user's profile Send private message
AhMunRa
Grandmaster Cheater Supreme
Reputation: 27

Joined: 06 Aug 2010
Posts: 1117

PostPosted: Mon Nov 08, 2010 4:31 pm    Post subject: Reply with quote

It's a keygen for a crackme. The code works properly, takes a username then derives a key from it.

The bit shifting in the if loop is unnecessary, I was just wondering if there is a prettier way to do the formatting to add the hyphens every 2 bytes. Other than if (x == 2 || x == 4 || x == 6 || x == 8 || x == 10 || x == 12 || x == 14 || x == 16)

_________________
<Wiccaan> Bah that was supposed to say 'not saying its dead' lol. Fixing >.>
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 Nov 08, 2010 4:43 pm    Post subject: Reply with quote

You can check if the number is even rather then a huge if.

Code:
public bool IsEven(int nInput)
{
   return ((nInput & 1) == 0);
}

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
AhMunRa
Grandmaster Cheater Supreme
Reputation: 27

Joined: 06 Aug 2010
Posts: 1117

PostPosted: Tue Nov 09, 2010 10:05 am    Post subject: Reply with quote

Wiccan you are the best. I never woulda thought of that.

Final function working keygen.

C# Solution

Code:

private string GenKey(string user, int len)
{
     arrStr = new int[len];
     string outPut = "";
     int y = 0;
     int prevInt = 0;
     long lval;

     foreach (char c in user)
     {
          arrStr[y] = Convert.ToInt32(c);
          y++;
     }

     for (int x = 0; x < len; x++)
     {
          if (x < 1)
          {
               outPut = String.Format("{0:x2}", ~Convert.ToByte(arrStr[x].ToString()) & (Convert.ToInt32(arrStr[x].ToString()) / 2));
               prevInt = Convert.ToInt32(outPut, 16);
          }
          else
          {
               lval = arrStr[x];
               for (int n = 0; n < prevInt; n++)
               {
                    lval = lval * 2;
               }
               if (lval > 4294967295)
               {
                    lval = lval / 4294967295;
                    if (lval < 57)
                    {
                         lval = 0;
                    }
               }
               long value2 = ((arrStr[x] - prevInt) / 2) & ~Convert.ToInt64(lval);
               prevInt = Convert.ToInt32(String.Format("{0:x2}", value2), 16);

               if ((x & 1) == 0)
               {
                    outPut += String.Format("-{0:x2}", value2);
               }
               else
               {
                    outPut += String.Format("{0:x2}", value2);
               }
          }
     }
     return outPut.ToUpper();
}


Code criticism is welcome.

_________________
<Wiccaan> Bah that was supposed to say 'not saying its dead' lol. Fixing >.>
Back to top
View user's profile Send private message
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