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 


Hex and Byte

 
Post new topic   This topic is locked: you cannot edit posts or make replies.    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
sumone4life
Cheater
Reputation: 0

Joined: 26 Feb 2007
Posts: 27

PostPosted: Thu Mar 15, 2007 11:02 pm    Post subject: Hex and Byte Reply with quote

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
View user's profile Send private message AIM Address MSN Messenger
the_undead
Expert Cheater
Reputation: 1

Joined: 12 Nov 2006
Posts: 235
Location: Johannesburg, South Africa

PostPosted: Fri Mar 16, 2007 2:06 am    Post subject: Reply with quote

Code:
DWORD NewVal[] = {0x90, 0x90, 0x90};

etc...
Code:
WriteProcessMemory(ProcessHandle, BaseAddress, &NewVal, Sizeof(NewVal), ptrtobyteswritten)
or something along those lines.
_________________
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Robotex
Master Cheater
Reputation: 0

Joined: 05 Sep 2006
Posts: 378
Location: The pizza country!

PostPosted: Fri Mar 16, 2007 7:37 am    Post subject: Reply with quote

try BYTE MyByte = (BYTE) 0x1234ABCD
_________________

ASM/C++ Coder
Project Speranza lead developer
Back to top
View user's profile Send private message
appalsap
Moderator
Reputation: 0

Joined: 27 Apr 2006
Posts: 6753
Location: Pakistan

PostPosted: Fri Mar 16, 2007 7:44 am    Post subject: Reply with quote

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
View user's profile Send private message
sumone4life
Cheater
Reputation: 0

Joined: 26 Feb 2007
Posts: 27

PostPosted: Fri Mar 16, 2007 12:15 pm    Post subject: Reply with quote

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
View user's profile Send private message AIM Address MSN Messenger
appalsap
Moderator
Reputation: 0

Joined: 27 Apr 2006
Posts: 6753
Location: Pakistan

PostPosted: Fri Mar 16, 2007 1:01 pm    Post subject: Reply with quote

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
View user's profile Send private message
sumone4life
Cheater
Reputation: 0

Joined: 26 Feb 2007
Posts: 27

PostPosted: Fri Mar 16, 2007 1:15 pm    Post subject: Reply with quote

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
View user's profile Send private message AIM Address MSN Messenger
appalsap
Moderator
Reputation: 0

Joined: 27 Apr 2006
Posts: 6753
Location: Pakistan

PostPosted: Fri Mar 16, 2007 1:55 pm    Post subject: Reply with quote

no, it isn't.
_________________
Back to top
View user's profile Send private message
sumone4life
Cheater
Reputation: 0

Joined: 26 Feb 2007
Posts: 27

PostPosted: Fri Mar 16, 2007 5:14 pm    Post subject: Reply with quote

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
View user's profile Send private message AIM Address MSN Messenger
appalsap
Moderator
Reputation: 0

Joined: 27 Apr 2006
Posts: 6753
Location: Pakistan

PostPosted: Fri Mar 16, 2007 5:42 pm    Post subject: Reply with quote

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
View user's profile Send private message
sumone4life
Cheater
Reputation: 0

Joined: 26 Feb 2007
Posts: 27

PostPosted: Fri Mar 16, 2007 7:51 pm    Post subject: Reply with quote

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
View user's profile Send private message AIM Address MSN Messenger
jasondavies
Cheater
Reputation: 0

Joined: 11 Jan 2009
Posts: 33
Location: Some Guys A** WHOLE!!!

PostPosted: Thu Oct 01, 2009 1:13 am    Post subject: Reply with quote

what is this crap
_________________
Don't Post Dump Post's Or Else

I Warned You!!!!!
Back to top
View user's profile Send private message Send e-mail MSN Messenger
Display posts from previous:   
Post new topic   This topic is locked: you cannot edit posts or make replies.    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