Here is my present C++ code:
char head[]="YMSG\x00\x0B\x00\x00";
char header[10000];
char size[2];
memset(size,0,sizeof(size));
sprintf(size,"\%c\%c",strlen(Pck)/256,strlen(Pck)%256);
memset(header,0,sizeof(header));
memcpy(header,head,sizeof(head));
memcpy(&header[8],&size,2);
memcpy(&header[10],&b,6);
memcpy(&header[16],&key1,4);
memcpy(&header[20],Pck,strlen(Pck));
send(sock,header,strlen(Pck)+20,0);

How would i perform the memcpy and how would i manage to make it copy the chr(0)'s or \x00 someone please help:( I need to know.
Posted on 2005-01-20 19:00:24 by natalic
Why would you want to copy the null character? You already set it to 0.
Posted on 2005-01-20 21:00:45 by roticv
Its part of the protocol thats why...I have no choice but to do it, please help!
Posted on 2005-01-20 22:10:54 by natalic
What Roticv is trying to say is that if you first fill your packet buffer (called 'header') with zero (NULL), you can discard the lines which copy NULL bytes into the buffer, since they'll already be there :)
Add the line memset(&header,0,sizeof(header)); hehehe
Also note that you omitted the & symbol in some lines.. :)
Now what exactly are you asking for help with?

Also just a word of warning - don't use any YMSG login DLL written by "Markus" because they carry nasty code. This guy rips the code from others and re-releases it so just look for the original author.
Posted on 2005-01-20 23:00:48 by Homer
It's ok that he omited the & symbol as using the name of an array is just like using it's address in c/c++, & is only required if you want the address of a specific element.
Posted on 2005-01-21 02:19:19 by QuantumMatrix1024
Would the following code not be better C?


char header[10000];
char head[] = "YMSG\x00\x0B\x00\x00";

unsigned long Pck_length = strlen(Pck);

header[8] = (char)(Pck_length >> 8);
header[9] = (char)(Pck_length);

memcpy(header, head, sizeof(head));
memcpy(header + 10, &b, 6);
memcpy(header + 16, &key1, 4)
memcpy(header + 20, Pck, Pck_length);

// Not needed for the sock send but...
// memset(header + Pck_length + 20, 0, sizeof(header) - (Pck_length + 20));

send(sock, header, Pck_length + 20, 0);


It eliminates the size variable, but if it's needed later try:


size[0] = header[8] = (char)(Pck_length >> 8);
size[1] = header[9] = (char)(Pck_length);


Sorry for posting C code, but it seems that optimising in the "native language" is a better first step than adding inline assembly (especially if the coder doesn't understand it).

Mirno
Posted on 2005-01-21 04:47:17 by Mirno
I want the code in assembly:-s Thats my problem now, I don't want the C/C++ code, and as for markus he is a loser who cant program. But if you could give me an example of how to do this in Assembly it would be great.
Posted on 2005-01-21 05:39:14 by natalic
That's the absolutely worst code I've ever seen, I swear.

You would do this:


push edi
lea edi,Pck
push edi
or ecx,-1
repnz scasb
not ecx
dec ecx
pop edi
lea eax,b
push key1
push dword ptr [eax+2]
push word ptr [eax]
mov eax,ecx
xchg al,ah
push ax
push 0b00h
push 'YMSG'
mov eax,esp
mov edx,sock
push 0
push ecx
push edi
push edx
push 0
push 20
push eax
push edx
call send
call send
add esp,20
pop edi
ret
Posted on 2005-01-21 13:01:48 by Sephiroth3
Thanks, I wrote that code along time ago, i just wanted it converted to Assembly to learn from, I wanna make a chat client in Assembly.
Posted on 2005-01-21 13:49:06 by natalic
I learned a lot from doing just that - good luck, and help is available :)
Posted on 2005-01-29 02:14:49 by Homer