| View previous topic :: View next topic |
| Author |
Message |
AhMunRa Grandmaster Cheater Supreme
Reputation: 27
Joined: 06 Aug 2010 Posts: 1117
|
Posted: Thu Nov 04, 2010 10:53 am Post subject: ASM Instruction Question |
|
|
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 |
|
 |
tombana Master Cheater
Reputation: 2
Joined: 14 Jun 2007 Posts: 456 Location: The Netherlands
|
Posted: Thu Nov 04, 2010 11:14 am Post subject: |
|
|
| The NOT instruction will invert all bits.
|
|
| Back to top |
|
 |
AhMunRa Grandmaster Cheater Supreme
Reputation: 27
Joined: 06 Aug 2010 Posts: 1117
|
Posted: Thu Nov 04, 2010 11:29 am Post subject: |
|
|
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 |
|
 |
AtheistCrusader Grandmaster Cheater
Reputation: 6
Joined: 23 Sep 2006 Posts: 681
|
Posted: Thu Nov 04, 2010 1:07 pm Post subject: |
|
|
Go over each one
15-x=inverted
15-2 = 13, in hex is D
|
|
| Back to top |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Fri Nov 05, 2010 2:25 am Post subject: |
|
|
| 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 |
|
 |
AhMunRa Grandmaster Cheater Supreme
Reputation: 27
Joined: 06 Aug 2010 Posts: 1117
|
Posted: Fri Nov 05, 2010 8:05 am Post subject: |
|
|
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 |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Sat Nov 06, 2010 7:57 am Post subject: |
|
|
| 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 |
|
 |
AhMunRa Grandmaster Cheater Supreme
Reputation: 27
Joined: 06 Aug 2010 Posts: 1117
|
Posted: Mon Nov 08, 2010 12:00 pm Post subject: |
|
|
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 |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Mon Nov 08, 2010 12:20 pm Post subject: |
|
|
they are the same thing.
72 is 0x48
0x48 is 72
|
|
| Back to top |
|
 |
AhMunRa Grandmaster Cheater Supreme
Reputation: 27
Joined: 06 Aug 2010 Posts: 1117
|
Posted: Mon Nov 08, 2010 3:13 pm Post subject: |
|
|
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 |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Mon Nov 08, 2010 3:47 pm Post subject: |
|
|
| what exactly are you trying to do?
|
|
| Back to top |
|
 |
AhMunRa Grandmaster Cheater Supreme
Reputation: 27
Joined: 06 Aug 2010 Posts: 1117
|
Posted: Mon Nov 08, 2010 4:31 pm Post subject: |
|
|
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 |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Mon Nov 08, 2010 4:43 pm Post subject: |
|
|
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 |
|
 |
AhMunRa Grandmaster Cheater Supreme
Reputation: 27
Joined: 06 Aug 2010 Posts: 1117
|
Posted: Tue Nov 09, 2010 10:05 am Post subject: |
|
|
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 |
|
 |
|