ďťż

Ładny brzuch

Witam.

Próbuję napisać program który będzie obsługiwał protokół gg, ale stanąłem na punkcie logowania się do sieci. Nie mogę się zalogować. Dane są na 100% poprawnie wpisywane. Opieram się na tym opisie - http://toxygen.net/libgadu/protocol/

Kod wygląda tak

#include <iostream> #include <cstring> #include <cerrno> #include <unistd.h> #include <netdb.h> #include <sys/types.h> #include <sys/socket.h> #include <arpa/inet.h> #include <netinet/in.h> #include <openssl/sha.h> using namespace std; #define GG_PACKED __attribute__ ((packed)) #define GG_WELCOME 0x0001 #define GG_LOGIN80 0x0031 #define GG_LOGIN80_OK 0x0035 #define GG_LOGIN80_FAILED 0x0043 #define GG_LIST_EMPTY 0x0012 struct gg_header { int type; /* typ */ int length; /* dl. reszty */ }GG_PACKED; struct gg_welcome { int seed; /* ziarno */ }GG_PACKED; struct gg_login80 { int uin; char language[2]; /* "pl" */ char hash_type; /* 0x02 */ char hash[64]; int status; /* 0x0002 */ int flags; int features; /*0x00000007 */ int local_ip; /*0*/ short local_port; /*0*/ int external_ip; /*0*/ short external_port; /*0*/ char image_size; char unknown1; /* 0x64 */ int version_len; /* 0x23 */ char version[36]; /* Gadu-Gadu Client build 10.0.0.10450 */ int description_size; char description[32]; }GG_PACKED; /*struct gg_login80_ok { int unknown1; }GG_PACKED; struct gg_login80_failed { int unknown1; }GG_PACKED;*/ char *gg_sha_hash(const char *password, unsigned int seed) { SHA_CTX ctx; static char result[20]; memset(result, '\0', sizeof(result)); SHA_Init(&ctx); SHA_Update(&ctx, password, strlen(password)); SHA_Update(&ctx, &seed, sizeof(seed)); SHA_Final((unsigned char *)result, &ctx); return result; } void clear(struct gg_header *pHead) { pHead->type = 0; pHead->length = 0; } int main(int argc, char *argv[]) { int sock = 0; int numer = jakis_tam_nr; const char *pass = "haslo"; struct sockaddr_in server; struct gg_header header; struct gg_welcome welcome; struct gg_login80 login; /*struct gg_login80_ok lok; struct gg_login80_failed lfailed;*/ server.sin_family = AF_INET; server.sin_port = htons((u_short)8074); server.sin_addr.s_addr = inet_addr("91.214.237.16"); memset(&(server.sin_zero), '\0', 8); if((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1) { cout<<"socket()\r\n"; cout.flush(); fprintf(stderr, "%s\r\n", strerror(errno)); return -1; } cout<<"ip: "<<server.sin_addr.s_addr<<"\r\n"; cout<<"port: "<<server.sin_port<<"\r\n"; cout.flush(); if(connect(sock, (struct sockaddr *)&server, sizeof(struct sockaddr)) == -1) { cout<<"connect()\r\n"; cout.flush(); fprintf(stderr, "%s\r\n", strerror(errno)); return -1; } clear(&header); if(recv(sock, (char *)&header, sizeof(header), 0) > 0) { if(recv(sock, (char *)&welcome, header.length, 0) > 0) { cout<<"header type: "<<header.type<<"\r\n"; cout<<"seed: "<<welcome.seed<<"\r\n"; cout.flush(); } else { cout<<"recv seed 2\r\n"; cout.flush(); } } clear(&header); login.uin = numer; sprintf(login.language, "pl"); login.hash_type = 0x02; sprintf(login.hash, gg_sha_hash(pass, welcome.seed)); for(unsigned int i = sizeof(login.hash); i > strlen(login.hash); i--) { login.hash[i] = '\0'; } printf("%s %d %d\r\n", login.hash, sizeof(login.hash), strlen(login.hash)); login.status = 0x0002; login.flags = 0; login.features = 0x00000367; login.local_ip = 0; login.local_port = 0; login.external_ip = 0; login.external_port = 0; login.image_size = 64; login.unknown1 = 0x64; login.version_len = 0x23; sprintf(login.version, "Gadu-Gadu Client build 10.0.0.10450"); login.description_size = 0; login.description[0] = '\0'; header.type = GG_LOGIN80; header.length = sizeof(login); if(send(sock, (char *)&header, sizeof(header), 0) > 0) { if(send(sock, (char *)&login, sizeof(login), 0) > 0) { clear(&header); if(recv(sock, (char *)&header, sizeof(header), 0) > 0) { if(header.type == GG_LOGIN80_OK) { cout<<"login ok\r\n"; cout.flush(); } else if(header.type == GG_LOGIN80_FAILED) { cout<<"login failed\r\n"; cout.flush(); } else if(header.type == 0x000b) { cout<<"gg disconnect\r\n"; cout.flush(); } else { cout<<"wtf?!\r\n"; cout.flush(); } } cout<<"header type: "<<header.type<<"\r\n"; cout.flush(); } } close(sock); return 0; }

Problem jest taki, że cały czas w odpowiedzi od serwera dostaję 0x0043 czyli błędne logowanie, zamiast 0x0035 czyli logowanie poprawne. Może ktoś pomóc ?:)

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • zsf.htw.pl
  •