Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question#include <winsock2.h> #pragma comment(lib, "ws2_32.lib") #define TAILLETAMPON 1024 int main() { //On crée nos variables SOCKET mon_socket; SOCKADDR_IN sin; int mtampon = 4; //On initialise Winsock WSADATA WSAData; WSAStartup(MAKEWORD(2,0), &WSAData); //On défini nos paramètres sin.sin_addr.s_addr = inet_addr("ip_serveur"); sin.sin_family = AF_INET; sin.sin_port = htons(port_serveur); //On crée le socket ! mon_socket = socket(AF_INET,SOCK_STREAM,0); bind(mon_socket, (SOCKADDR *)&sin, sizeof(sin)); //On connecte notre socket connect(mon_socket, (SOCKADDR *)&sin, sizeof(sin)); int i; for (i=0 ; i < TAILLETAMPON ; i+=1) { char tampon[i]; recv(mon_socket, tampon, sizeof(tampon),0); printf("%d \n", tampon); } }
signed short Pak_SwitchEncryptionOff_150 (pak_t *pak, unsigned long seed) { // the 1.50 protocol cryptography uses extensively the standard C random number generator, // which is a VERY BAD idea, since its implementation may differ from system to system !!! char stack1[10]; char stack2[10]; unsigned char a; unsigned char c; char *edi; char *ebp; int index; unsigned int algo; signed short checksum; // initialize the system's pseudo-random number generator from the seed given in the datagram // (they apparently swapped the bytes in an attempt to confuse the reverse-engineerers) srand ( (int) (((unsigned char *) &seed)[0] << 24) | (int) (((unsigned char *) &seed)[3] << 16) | (int) (((unsigned char *) &seed)[1] << 8) | (int) (((unsigned char *) &seed)[2])); // now generate the crypto tables for the given datagram length // stack sequences for (index = 0; index < 10; index++) { stack1[index] = (char) rand (); stack2[index] = (char) rand (); } // xor table for (index = 0; index < pak->data_size; index++) { cryptotables_150.xor[index] = (unsigned char) stack2[rand () % 10]; cryptotables_150.xor[index] *= (unsigned char) stack1[rand () % 10]; cryptotables_150.xor[index] += rand (); } // offset & algo tables for (index = 0; index < pak->data_size; index++) { cryptotables_150.offsets[index] = rand () % pak->data_size; if (cryptotables_150.offsets[index] == (unsigned int) index) cryptotables_150.offsets[index] = (index == 0 ? 1 : 0); cryptotables_150.algo[index] = rand () % 21; } // cryptographic tables are generated, now apply the algorithm for (index = pak->data_size - 1; index >= 0; index--) { algo = cryptotables_150.algo[index]; ebp = &pak->data[cryptotables_150.offsets[index]]; edi = &pak->data[index]; a = *ebp; c = *edi; if (algo 0) { *edi ((a ^ c) & 0x0F) ^ c; *ebp = ((a ^ c) & 0x0F) ^ a; } else if (algo 1) { *edi ((a ^ c) & 0x0F) ^ c; *ebp = (a >> 4) | (c << 4); } else if (algo 2) { *edi (c >> 4) | (c << 4); *ebp = (a >> 4) | (a << 4); } else if (algo 3) { *edi (a >> 4) | (c << 4); *ebp = ((a ^ c) & 0x0F) ^ c; } else if (algo 4) { *edi (a & 0x0F) | (c << 4); *ebp = (a & 0xF0) | (c >> 4); } else if (algo 5) { *edi (c & 0xF0) | (a >> 4); *ebp = (a << 4) | (c & 0x0F); } else if (algo 6) { *edi (a >> 4) | (c << 4); *ebp = (a << 4) | (c >> 4); } else if (algo 7) { *edi (c & 0xF0) | (a >> 4); *ebp = (a & 0x0F) | (c << 4); } else if (algo 8) { *edi (a & 0x0F) | (c << 4); *ebp = (c & 0xF0) | (a >> 4); } else if (algo 9) { *edi (a & 0xF0) | (c >> 4); *ebp = (a & 0x0F) | (c << 4); } else if (algo 10) { *edi (a << 4) | (c & 0x0F); *ebp = (a & 0xF0) | (c >> 4); } else if (algo 11) { *edi (a << 4) | (c >> 4); *ebp = ((a ^ c) & 0x0F) ^ a; } else if (algo 12) { *edi (a >> 4) | (a << 4); *ebp = (c >> 4) | (c << 4); } else if (algo 13) { *edi a; *ebp = c; } else if (algo 14) { *edi (a & 0xF0) | (c >> 4); *ebp = (a << 4) | (c & 0x0F); } else if (algo 15) { *edi ((a ^ c) & 0x0F) ^ a; *ebp = ((a ^ c) & 0x0F) ^ c; } else if (algo 16) { *edi a; *ebp = (c >> 4) | (c << 4); } else if (algo 17) { *edi (a << 4) | (c & 0x0F); *ebp = (c & 0xF0) | (a >> 4); } else if (algo 18) { *edi (a << 4) | (c >> 4); *ebp = (a >> 4) | (c << 4); } else if (algo 19) { *edi (a >> 4) | (a << 4); *ebp = c; } else if (algo 20) { *edi ((a ^ c) & 0x0F) ^ a; *ebp = (a << 4) | (c >> 4); } } // and finally, quadruple-XOR the data out for (index = pak->data_size - 1; index >= 0; index--) { if (index <= pak->data_size - 4) { pak->data[index + 0] ^= (cryptotables_150.xor[index] & 0x000000FF); // we can XOR 4 bytes in a row pak->data[index + 1] ^= (cryptotables_150.xor[index] & 0x0000FF00) >> 8; pak->data[index + 2] ^= (cryptotables_150.xor[index] & 0x00FF0000) >> 16; pak->data[index + 3] ^= (cryptotables_150.xor[index] & 0xFF000000) >> 24; } else if (index == pak->data_size - 3) { pak->data[index + 0] ^= (cryptotables_150.xor[index] & 0x0000FF); // we can XOR 3 bytes in a row pak->data[index + 1] ^= (cryptotables_150.xor[index] & 0x00FF00) >> 8; pak->data[index + 2] ^= (cryptotables_150.xor[index] & 0xFF0000) >> 16; } else if (index == pak->data_size - 2) { pak->data[index + 0] ^= (cryptotables_150.xor[index] & 0x00FF); // we can XOR 2 bytes in a row pak->data[index + 1] ^= (cryptotables_150.xor[index] & 0xFF00) >> 8; } else if (index == pak->data_size - 1) pak->data[index] ^= (cryptotables_150.xor[index] & 0xFF); // end of stream } // in the 1.50 protocol, the checksum info is at the trailing end of the pak. checksum = *(unsigned short *) &pak->data[pak->data_size - 2]; // so get it from there... pak->data_size -= 2; // ...and correct the data size return (checksum); // finished, pak is decrypted }
void Pak_ToggleEncryption_125 (pak_t *pak, unsigned short first_seed) { // this function toggles Vircom's encryption on/off on the pak data. Note that the checksum // must be computed on the decrypted data, so it has to be done before calling this function. unsigned short seed; unsigned long index; seed = first_seed; // for each byte of data... for (index = 0; index < pak->data_size; index++) { seed = seed * 145 + 1; // apply an infinite suite to seed pak->data[index] ^= (char) seed; // use it to mask the data (XOR) } return; // finished }
void Pak_ToggleEncryption_125 (pak_t *pak, unsigned short first_seed) { // this function toggles Vircom's encryption on/off on the pak data. Note that the checksum // must be computed on the decrypted data, so it has to be done before calling this function. unsigned short seed; unsigned long index; seed = first_seed; // for each byte of data... for (index = 0; index < pak->data_size; index++) { seed = seed * 145 + 1; // apply an infinite suite to seed pak->data[index] ^= (char) seed; // use it to mask the data (XOR) } return; // finished }