Please show more code.
As defined above, "editbytes" is a character array with four characters ('0', 'x', 'e', '9'), not one character 0xe9;
Also, "0xe9" is a const char *, not a char *, so writing to it gives undefined results, most likely that's what's causing the crash.
I imagine you don't want to do "(char*)jumpto" unless you really want the contents of address "jumpto" what you want is jumpto itself, so do "(char*)(&jumpto)"
I'm not familiar with strcat_s, so I can't tell if the signature is okay, but it looks like you might be reading from addres "4" instead of byteArray.
Finally, this smells like C not C++. There're much better and easier ways of doing this in basic C++.
Anyway, here's an ANSI C example.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
#include <stdio.h>
#include <string.h>
#define ARRAY_SIZE (5)
int main()
{
int i = 0;
int jumpto = 0x12345678;
unsigned char editbytes[ARRAY_SIZE];
editbytes[0] = 0xe9;
memcpy(editbytes + 1, (char*)(&jumpto), ARRAY_SIZE);
/* test */
for (i = 0; i < ARRAY_SIZE; ++i)
printf("%#x ", editbytes[i]);
printf("\n");
return 0;
}
|