-
April 10th, 2010, 04:52 PM
#1
Very simple question
lets say i open .exe file in hex editor and copy 200 or 300 bytes and want to paste that in some C++ variable
so which type should that variable be?
is this ok:
BYTE myPieceOfCode[300]={
CB 8B E9 A7 64 18 8E 88 E7 C3 29 72 15 5E 56 57
AD 32 61 71 EE 46 7B 04 23 02 3E 4A 21 EA 1E 88
F7 32 56 22 A0 3C 8E F1 A9 3C BA 16 F8 94 3D EC
C9 3B B4 B1 29 2C DE 12 1C 99 69 EF 1E 09 5C DF
A8 79 D2 DB B0 64 60 C7 BF AE 74 40 16 7D 0A C9
3F B3 4E B4 C3 D1 CD 90 91 C2 A3 6E 5F 4D 27 F2
23 BE 1A 1D 4D 49 7F 59 DE FB 9D AC 66 75 4A 65
F9 45 4B E3 5E 0B 89 F5 23 B5 86 A6 1E 70 94 1A
D2 32 9A AC DC DB 05 F1 22 DB 85 3E 8E 44 DA 6C
33 97 65 AA 4A 13 47 DE 19 0C FB D7 B2 A1 48 FB
58 6F 69 AF 76 78 32 A2 F6 DB 68 34 E9 5B EF 3A
D2 64 B4 54 C6 F1 9F 56 74 67 C6 3C 39 E4 6F 2A
82 9E A2 51 57 5F 4D 16 5B CD 0A F0 74 5E 5E B1
};
-
April 10th, 2010, 07:50 PM
#2
-
April 11th, 2010, 04:33 AM
#3
Re: Very simple question
and BYTE can not do?
also do i need to put commas in between like CB, 8B ,E9 ,A7 ,64, 18, 8E, 88 ,E7 ,57 ?
do i need to put 300 commas manually?
and also can i put like this BYTE * myPieceOfCode [] = {CB, 8B ,E9 ,A7 ,64, 18, 8E, 88 ,E7 ,57.....}; ???
whats the difference?
-
April 11th, 2010, 06:59 AM
#4
Re: Very simple question
You can't copy and paste from a binary editor into a C++ variable. What are you really trying to do? Your post doesn't make sense.
-
April 11th, 2010, 07:00 AM
#5
Re: Very simple question
Originally Posted by suncica2222
and BYTE can not do?
also do i need to put commas in between like CB, 8B ,E9 ,A7 ,64, 18, 8E, 88 ,E7 ,57 ?
Your problem is not the type -- the real problem is that you are not aware of hexadecimal constants.
Code:
BYTE myPieceOfCode [] = {0xCB, 0x8B ,0xE9};
Regards,
Paul McKenzie
-
April 11th, 2010, 07:04 AM
#6
Re: Very simple question
Originally Posted by suncica2222
and BYTE can not do?
BYTE is the same as unsigned char
Originally Posted by suncica2222
also do i need to put commas in between like CB, 8B ,E9 ,A7 ,64, 18, 8E, 88 ,E7 ,57 ?
do i need to put 300 commas manually?
... or you could use some text editor...
Originally Posted by suncica2222
... and also can i put like this BYTE * myPieceOfCode [] = {CB, 8B ,E9 ,A7 ,64, 18, 8E, 88 ,E7 ,57.....}; ???
Yes, you can. You also have to insert 0x before each byte...
Originally Posted by suncica2222
... whats the difference?
Between what and what?
Victor Nijegorodov
-
April 11th, 2010, 09:27 AM
#7
Re: Very simple question
Originally Posted by VictorN
Yes, you can. You also have to insert 0x before each byte...
Is the only way to write "0x" 300 times manually or is there some tool?
And when I copy code from hex editor it copies offsets too,then I need to delete them manually,how can I avoid that?
Originally Posted by VictorN
Between what and what?
Between:
1. BYTE myArray[300];
and
2. BYTE * myArray[];
The first needs to be size 300 al the time,and second can be any size?
-
April 11th, 2010, 10:00 AM
#8
Re: Very simple question
Originally Posted by suncica2222
Is the only way to write "0x" 300 times manually or is there some tool?
I prefer to use some text editor (for instance, an IDE editor allows you to use Replace command for a whole file or for selection)
Originally Posted by suncica2222
Between:
1. BYTE myArray[300];
and
2. BYTE * myArray[];
The first needs to be size 300 al the time,and second can be any size?
(1) is OK providing you need no more than 300 bytes
(2) is wrong because you are trying to declare an array of pointers.
The correct one would be:
Code:
BYTE myArray[] = {...};
Victor Nijegorodov
-
April 11th, 2010, 11:26 AM
#9
Re: Very simple question
Originally Posted by suncica2222
Is the only way to write "0x" 300 times manually or is there some tool?
You could write a program to do it for you I guess.....
-
April 11th, 2010, 11:35 AM
#10
Re: Very simple question
Thank you all for help so far!
Originally Posted by VictorN
I prefer to use some text editor (for instance, an IDE editor allows you to use Replace command for a whole file or for selection)
So how would be exactly in MSVC++2008 to copy selection of an .exe and paste it in smoothly with ',' and"0x" {0xAA,0xAA....} as I want to do in this example?
Originally Posted by VictorN
(2) is wrong because you are trying to declare an array of pointers.
The correct one would be:
Code:
BYTE myArray[] = {...};
So if I say
BYTE * myArray;
it is a simple pointer,but could I use this as array (myArray[x]) right there without using operator "new" on it?
-
April 11th, 2010, 11:40 AM
#11
Re: Very simple question
Originally Posted by suncica2222
So how would be exactly in MSVC++2008 to copy selection of an .exe and paste it in smoothly with ',' and"0x" {0xAA,0xAA....} as I want to do in this example?
Menu Edit -> Replace...
Originally Posted by suncica2222
So if I say
BYTE * myArray;
it is a simple pointer,but could I use this as array (myArray[x]) right there without using operator "new" on it?
No!
Victor Nijegorodov
-
April 11th, 2010, 11:46 AM
#12
Re: Very simple question
Originally Posted by suncica2222
So how would be exactly in MSVC++2008 to copy selection of an .exe and paste it in smoothly with ',' and"0x" {0xAA,0xAA....} as I want to do in this example?
What's the problem? Replace every space with ",0x" (remove the quotes).
So if I say
BYTE * myArray;
it is a simple pointer,but could I use this as array (myArray[x]) right there without using operator "new" on it?
Just because you see a "*" doesn't mean "new" is to be used or even mean you have to explicitly declare a pointer.
Code:
void SomeFunction(BYTE *p, int number)
{
}
//...
BYTE whatever[10];
SomeFunction(whatever, 10); //
Hexadecimal constants and arrays/pointers are basic fundamentals of the language. Are you using a C++ book?
Regards,
Paul McKenzie
-
April 11th, 2010, 01:01 PM
#13
Re: Very simple question
Thank you very much,you have been great help!!!
-
April 12th, 2010, 11:39 AM
#14
Re: Very simple question
Most hex editors have an export command that will do all this automatically for you.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|