int http_simple_client_encode(obfs *self, char **pencryptdata, int datalength, size_t* capacity) { char *encryptdata = *pencryptdata; http_simple_local_data *local = (http_simple_local_data*)self->l_data; if (local->has_sent_header) { return datalength; } char hostport[128]; int head_size = self->server.head_len + (xorshift128plus() & 0x3F); int outlength; char * out_buffer = (char*)malloc(datalength + 2048); if (head_size > datalength) head_size = datalength; http_simple_encode_head(local, encryptdata, head_size); if (self->server.param && strlen(self->server.param) == 0) self->server.param = NULL; if (self->server.port == 80) sprintf(hostport, "%s", (self->server.param ? self->server.param : self->server.host)); else sprintf(hostport, "%s:%d", (self->server.param ? self->server.param : self->server.host), self->server.port); sprintf(out_buffer, "GET /%s HTTP/1.1\r\n" "Host: %s\r\n" "User-Agent: %s\r\n" "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n" "Accept-Language: en-US,en;q=0.8\r\n" "Accept-Encoding: gzip, deflate\r\n" "DNT: 1\r\n" "Connection: keep-alive\r\n" "\r\n", local->encode_buffer, hostport, "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0" ); outlength = strlen(out_buffer); memmove(out_buffer + outlength, encryptdata + head_size, datalength - head_size); outlength += datalength - head_size; local->has_sent_header = 1; if (*capacity < outlength) { *pencryptdata = (char*)realloc(*pencryptdata, *capacity = outlength * 2); encryptdata = *pencryptdata; } memmove(encryptdata, out_buffer, outlength); free(out_buffer); if (local->encode_buffer != NULL) { free(local->encode_buffer); local->encode_buffer = NULL; } return outlength; }
int http_simple_client_encode(obfs *self, char **pencryptdata, int datalength, size_t* capacity) { char *encryptdata = *pencryptdata; http_simple_local_data *local = (http_simple_local_data*)self->l_data; if (local->has_sent_header) { return datalength; } char hosts[1024]; char * phost[128]; int host_num = 0; int pos; char hostport[128]; int head_size = self->server.head_len + (xorshift128plus() & 0x3F); int outlength; char * out_buffer = (char*)malloc(datalength + 2048); char * body_buffer = NULL; if (head_size > datalength) head_size = datalength; http_simple_encode_head(local, encryptdata, head_size); if (self->server.param && strlen(self->server.param) == 0) self->server.param = NULL; strncpy(hosts, self->server.param ? self->server.param : self->server.host, sizeof hosts); phost[host_num++] = hosts; for (pos = 0; hosts[pos]; ++pos) { if (hosts[pos] == ',') { phost[host_num++] = &hosts[pos + 1]; hosts[pos] = 0; } else if (hosts[pos] == '#') { char * body_pointer = &hosts[pos + 1]; char * p; int trans_char = 0; p = body_buffer = (char*)malloc(2048); for ( ; *body_pointer; ++body_pointer) { if (*body_pointer == '\\') { trans_char = 1; continue; } if (trans_char) { if (*body_pointer == '\\' ) { *p = '\\'; } else if (*body_pointer == 'n' ) { *p = '\r'; *++p = '\n'; } else { *p = '\\'; *p = *body_pointer; } trans_char = 0; } else { *p = *body_pointer; } ++p; } hosts[pos] = 0; break; } } host_num = xorshift128plus() % host_num; if (self->server.port == 80) sprintf(hostport, "%s", phost[host_num]); else sprintf(hostport, "%s:%d", phost[host_num], self->server.port); if (body_buffer) { sprintf(out_buffer, "GET /%s HTTP/1.1\r\n" "Host: %s\r\n" "%s\r\n\r\n", local->encode_buffer, hostport, body_buffer); } else { sprintf(out_buffer, "GET /%s HTTP/1.1\r\n" "Host: %s\r\n" "User-Agent: %s\r\n" "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n" "Accept-Language: en-US,en;q=0.8\r\n" "Accept-Encoding: gzip, deflate\r\n" "DNT: 1\r\n" "Connection: keep-alive\r\n" "\r\n", local->encode_buffer, hostport, g_useragent[g_useragent_index] ); } outlength = strlen(out_buffer); memmove(out_buffer + outlength, encryptdata + head_size, datalength - head_size); outlength += datalength - head_size; local->has_sent_header = 1; if (*capacity < outlength) { *pencryptdata = (char*)realloc(*pencryptdata, *capacity = outlength * 2); encryptdata = *pencryptdata; } memmove(encryptdata, out_buffer, outlength); free(out_buffer); if (body_buffer != NULL) free(body_buffer); if (local->encode_buffer != NULL) { free(local->encode_buffer); local->encode_buffer = NULL; } return outlength; }