| View previous topic :: View next topic |
| Author |
Message |
sumone4life Cheater
Reputation: 0
Joined: 26 Feb 2007 Posts: 27
|
Posted: Thu Mar 15, 2007 11:02 pm Post subject: Hex and Byte |
|
|
Im working on making a trainer for a game in C++ using the 'WriteProcessMemory' command. Now i need to convert the hex or decimal value into a byte array and despite searching on google i still dont know how to do it.
So lets say i have the decimal value of 1885627762. Which in hex is 70646572. How do i then go converting this to a byte array?
_________________
-amen |
|
| Back to top |
|
 |
the_undead Expert Cheater
Reputation: 1
Joined: 12 Nov 2006 Posts: 235 Location: Johannesburg, South Africa
|
Posted: Fri Mar 16, 2007 2:06 am Post subject: |
|
|
| Code: | | DWORD NewVal[] = {0x90, 0x90, 0x90}; |
etc...
| Code: | | WriteProcessMemory(ProcessHandle, BaseAddress, &NewVal, Sizeof(NewVal), ptrtobyteswritten) | or something along those lines.
_________________
|
|
| Back to top |
|
 |
Robotex Master Cheater
Reputation: 0
Joined: 05 Sep 2006 Posts: 378 Location: The pizza country!
|
Posted: Fri Mar 16, 2007 7:37 am Post subject: |
|
|
try BYTE MyByte = (BYTE) 0x1234ABCD
_________________
ASM/C++ Coder
Project Speranza lead developer |
|
| Back to top |
|
 |
appalsap Moderator
Reputation: 0
Joined: 27 Apr 2006 Posts: 6753 Location: Pakistan
|
Posted: Fri Mar 16, 2007 7:44 am Post subject: |
|
|
Robotex, You need to make an array of bytes, regular byte cannot hold that much.
| Code: |
DWORD oldval = 1885627762; BYTE bb[50];
ZeroMemory(&bb, sizeof(bb));
itoa(oldval, bb, 16);
|
p.s in most cases if you're using a reinterpret cast, you're doing something wrong
_________________
|
|
| Back to top |
|
 |
sumone4life Cheater
Reputation: 0
Joined: 26 Feb 2007 Posts: 27
|
Posted: Fri Mar 16, 2007 12:15 pm Post subject: |
|
|
appalsap...are you saying thats how to convert a hex or decimal value into a byte array?
If not that thats what i need, im not really understanding the code you posted so if that is correct could you explain it?
EDIT: nevermind i got it. I had forgotten that the bytes were in reverse order.
So for anyone looking at this wondering what the is going on heres a little tutorial on converting between decimal, hex and a byte array
if i have the value 123456789
the hex value would be: 75BCD15 (easy enough correct?)
A byte represents 2 hex digits so the byte array for that hex value would be: {0x15, 0xCD, 0x5B, 0x07, 0x00}
So all you have to do is think backwards... hope this helped anyone who was wondering about byte arrays.
Cheers!
_________________
-amen |
|
| Back to top |
|
 |
appalsap Moderator
Reputation: 0
Joined: 27 Apr 2006 Posts: 6753 Location: Pakistan
|
Posted: Fri Mar 16, 2007 1:01 pm Post subject: |
|
|
I made it more "visual" for you (compile and run to see):
| Code: |
#include <stdio.h>
#include <windows.h>
#define freshbyte(x) BYTE x[50]; memset(&x,0,sizeof(x))
int main(int argc, char *argv[])
{
DWORD oldval = 1885627762, i, len;
freshbyte(bb);
printf("DWORD notbyte = 0x%x\n", oldval);
itoa(oldval, bb, 16); len = strlen(bb);
printf("BYTE newbyte[%d] = {0x%c%c", len, bb[0], bb[1]);
for (i=2; bb[i]; i+=2)
printf(", 0x%c%c", bb[i], bb[i+1]);
printf("};");
getch();
return 0;
}
|
If you want to do that with your own byte array just modify it slightly (remove the 0x visuals, and use sprintf or wsprintf). I don't know how 'thinking backwards' is relevant here, you asked how to convert a "number" to a byte array, in the programming section which implies you want to know how to do it programmatically (turns out you didn't, should have gtfo)
_________________
Last edited by appalsap on Fri Mar 16, 2007 1:55 pm; edited 1 time in total |
|
| Back to top |
|
 |
sumone4life Cheater
Reputation: 0
Joined: 26 Feb 2007 Posts: 27
|
Posted: Fri Mar 16, 2007 1:15 pm Post subject: |
|
|
I asked how to convert a hex value to a byte array... i didnt say anything about DWORD...
Hex is just backwards of a byte array correct?
_________________
-amen |
|
| Back to top |
|
 |
appalsap Moderator
Reputation: 0
Joined: 27 Apr 2006 Posts: 6753 Location: Pakistan
|
Posted: Fri Mar 16, 2007 1:55 pm Post subject: |
|
|
no, it isn't.
_________________
|
|
| Back to top |
|
 |
sumone4life Cheater
Reputation: 0
Joined: 26 Feb 2007 Posts: 27
|
Posted: Fri Mar 16, 2007 5:14 pm Post subject: |
|
|
what do you mean it isnt. 1 i read it on a website that the byte array was reverse of the hex value.... so if you have
HEX: 75BCD15
the byte array would be : {0x15, 0xCD, 0x5B, 0x07, 0x00}
which is reverse of the hex value. Granted it not completely reverse, but the set of 2 hex values go in reverse...
so the last set of the hex value is 15 so the first value for the byte array is 0x15
the second to last set in the hex value is CD so the 2nd value in the byte array is 0xCD
and so on... so it is reverse just in sets of 2, not completely reverse is what i meant
_________________
-amen |
|
| Back to top |
|
 |
appalsap Moderator
Reputation: 0
Joined: 27 Apr 2006 Posts: 6753 Location: Pakistan
|
Posted: Fri Mar 16, 2007 5:42 pm Post subject: |
|
|
That's WRONG, and thats not what hex MEANS, hexidecimal is the base 16 numbering system, extending 0-10 to 0-F! No reversing involved!
_________________
|
|
| Back to top |
|
 |
sumone4life Cheater
Reputation: 0
Joined: 26 Feb 2007 Posts: 27
|
Posted: Fri Mar 16, 2007 7:51 pm Post subject: |
|
|
yes but a BYTE is 2 digits of a hexidecimal value. Im not saying that to convert to hex you have to reverse the number im saying to go from HEX to a BYTE ARRAY you have to reverse the hex value in sets of too like my examples above. im not saying anything about converting to hex.
_________________
-amen |
|
| Back to top |
|
 |
jasondavies Cheater
Reputation: 0
Joined: 11 Jan 2009 Posts: 33 Location: Some Guys A** WHOLE!!!
|
Posted: Thu Oct 01, 2009 1:13 am Post subject: |
|
|
what is this crap
_________________
Don't Post Dump Post's Or Else
I Warned You!!!!! |
|
| Back to top |
|
 |
|