I'm trying to make a packet editor/sniffer/sender for a game, it all works just fine, except I can't send my own packets. I have all the necessary addresses and all that (I know this because if I hard code a packet, it get sent as it should).
But when I use a "Edit control"-box to make dynamic packets at run time, it gets malformed.
I will try to explain the steps and the output at that step:
1. Get string from Edit box, could look something like this "S>0B C8 32 41"
2. Filter my string. Output "0B C8 32 41" or "0BC83241" (depending on what setting)
3. Take that string and convert it to "char *packet = new char[length]", containing the hex!
4. Send the packet through sendPacket(char* buf, Int len).
My problem occur at step 3, when I try to convert the string. The expected output would be:
packet[0] = 0B Or simply B
packet[1] = C8
packet[2] = 32
packet[3] = 41
But I get:
packet[0] = B
packet[1] = FFFFFFC8
packet[2] = 32
packet[3] = 41
Currently I'm using:
Code:
DWORD StringToByteArray(char *str, char *pbyte)
{
DWORD ArraySize = ((strlen(str) + 1) / 3);
char *pEnd = str;
for (DWORD i = 0; i < ArraySize; i++)
{
pbyte[i] = (char) strtol(pEnd, &pEnd, 16);
}
return ArraySize;
}
So my problem is at the convert hex string to char* array stage, mainly, when the hex start with a letter (A,B,C,D,E,F) it get converted to "FFFFFFLX". (where F is F in hex, and L is the letter (A,B,C,D,E,F) and X is whatever comes after the letter in the hex-pair.
I read on the interwebz that char and unsigned char can interpret the hex/int value in two totally different ways example:
Code:
char a=0xa1;
unsigned char b=0xa1;
printf ("a=[%02x], b=[%02x]\n",a,b);
output:
a=[ffffffa1], b=[a1]
So my question (after all this wall of text), is there a way I can force my code to convert the string to C8 instead of FFFFFFC8?
Or is there another way to get the hex-pairs from the string to a char* buf?
Or maybe a better way to get the hex from the Edit-box to a char* array?
I use visual studio 2013, win32project as a DLL.
Thanks in advance, NutellaJunkie.
ps. Sorry if I posted in the wrong section.






