void prot_login_verify( struct qqclient* qq ) { qqpacket* p = packetmgr_new_send( qq, QQ_CMD_LOGIN_VERIFY ); if( !p ) return; bytebuffer *buf = p->buf; bytebuffer *verify_data; NEW( verify_data, sizeof(bytebuffer) ); if( !verify_data ) { packetmgr_del_packet( &qq->packetmgr, p ); return; } verify_data->size = PACKET_SIZE; put_int( verify_data, rand2() ); //random?? put_word( verify_data, 0x0001 ); put_int( verify_data, qq->number ); put_data( verify_data, qq->data.version_spec, sizeof(qq->data.version_spec) ); put_byte( verify_data, 00 ); put_word( verify_data, 00 ); //0x0001 什么来的? put_data( verify_data, qq->md5_pass1, 16 ); put_int( verify_data, qq->server_time ); verify_data->pos += 13; put_int( verify_data, qq->server_ip ); put_int( verify_data, 0 ); put_int( verify_data, 0 ); put_word( verify_data, 0x0010 ); put_data( verify_data, qq->data.verify_key1, 0x10 ); put_data( verify_data, qq->data.verify_key2, 0x10 ); // put_word( buf, 0x00CA ); //sub cmd?? put_word( buf, 0x0001 ); put_data( buf, qq->data.locale, sizeof(qq->data.locale) ); put_data( buf, qq->data.version_spec, sizeof(qq->data.version_spec) ); put_word( buf, qq->data.token_c.len ); put_data( buf, qq->data.token_c.data, qq->data.token_c.len ); if( verify_data->pos != 104 ) { DBG("wrong pos!!!"); } int out_len = 120; uchar encrypted[120+10]; qqencrypt( verify_data->data, verify_data->pos, qq->md5_pass2, encrypted, &out_len ); put_word( buf, out_len ); put_data( buf, encrypted, out_len ); put_word( buf, 0x0000 ); put_word( buf, 0x018B ); put_byte( buf, 0x2E ); //length of the following info static uchar unknown6[] = {0xE9,0xC4,0xD6,0x5C,0x4D,0x9D, 0xA0,0x17,0xE5,0x24,0x6B,0x55,0x57,0xD3,0xAB,0xF1 }; static uchar unknown7[] = {0xCB,0x8D,0xA4,0xE2,0x61,0xC2, 0xDD,0x27,0x39,0xEC,0x8A,0xCA,0xA6,0x98,0xF8,0x9B }; randkey( unknown6 ); randkey( unknown7 ); put_byte( buf, 0x01 ); put_int( buf, rand2() ); // put_int( buf, 0x0741E9748 ); put_word( buf, sizeof(unknown6) ); put_data( buf, unknown6, sizeof(unknown6) ); put_byte( buf, 0x02 ); put_int( buf, rand2() ); // put_int( buf, 0x8BED382E ); put_word( buf, sizeof(unknown7) ); put_data( buf, unknown7, sizeof(unknown7) ); buf->pos += 0x015C; //395 zeros? 348 DEL( verify_data ); post_packet( qq, p, RANDOM_KEY ); }
static void read_buffer(void) { char line[LINE_BUFFER_SIZE]; unsigned int ptr, current, *last; init_hash(); ptr = 0; while (fgetl(line, sizeof(line), fpInput)) { char LM_Buf[8]; if (LM) { if (strlen(line) > 7) { strncpy(LM_Buf, &line[7], 7); LM_Buf[7] = 0; upcase(LM_Buf); ++totLines; } else *LM_Buf = 0; line[7] = 0; upcase(line); } else if (cut_len) line[cut_len] = 0; ++totLines; last = &buffer.hash[line_hash(line)]; #if ARCH_LITTLE_ENDIAN && !ARCH_INT_GT_32 current = *last; #else current = get_int(last); #endif while (current != ENTRY_END_HASH) { if (!strcmp(line, &buffer.data[current + 4])) break; last = (unsigned int *)&buffer.data[current]; current = get_int(last); } if (current != ENTRY_END_HASH) { if (LM && *LM_Buf) goto DoExtraLM; continue; } put_int(last, ptr); put_data(ptr, ENTRY_END_HASH); ptr += 4; strcpy(&buffer.data[ptr], line); ptr += strlen(line) + 1; if (ptr > vUNIQUE_BUFFER_SIZE - sizeof(line) - 8) break; DoExtraLM:; if (LM && *LM_Buf) { last = &buffer.hash[line_hash(LM_Buf)]; #if ARCH_LITTLE_ENDIAN && !ARCH_INT_GT_32 current = *last; #else current = get_int(last); #endif while (current != ENTRY_END_HASH) { if (!strcmp(LM_Buf, &buffer.data[current + 4])) break; last = (unsigned int *)&buffer.data[current]; current = get_int(last); } if (current != ENTRY_END_HASH) continue; put_int(last, ptr); put_data(ptr, ENTRY_END_HASH); ptr += 4; strcpy(&buffer.data[ptr], LM_Buf); ptr += strlen(LM_Buf) + 1; if (ptr > vUNIQUE_BUFFER_SIZE - sizeof(line) - 8) break; } } if (ferror(fpInput)) pexit("fgets"); put_data(ptr, ENTRY_END_LIST); }
int dist_prec(atmos_data_struct *atmos, dist_prcp_struct *prcp, soil_con_struct *soil_con, veg_con_struct *veg_con, lake_con_struct *lake_con, dmy_struct *dmy, global_param_struct *global_param, filep_struct *filep, out_data_file_struct *out_data_files, out_data_struct *out_data, save_data_struct *save_data, int rec, int cellnum, char NEWCELL, char LASTREC, char *init_STILL_STORM, int *init_DRY_TIME) { /********************************************************************** dist_prec Keith Cherkauer October 9, 1997 This subroutine calls the solution routines for a single grid cell for one time step. It also controls the distribution of precipitation and reassembles grid cell data for output. The fractional coverage of precipitation over an area or grid cell, mu, is estimated using the equation from Fan et. al. (1996). The coefficient, 0.6, was selected for the Arkansas - Red River Basin and was found using precipitation records on a 100km x 100km area. It may not be applicable to all regions, please check the reference References: Modifications: 11-30-98 Added counter to assure that a storm has been stopped for at least one day, before allowing the model to average soil moisture when a new precipitation event arrives. KAC 03-05-01 Fixed error in which distributed precipitation accounting variables (DRY_TIME, STILL_STORM, ANY_SNOW) were used within the vegetation loop, but did not store separate values for each vegetation type. KAC 03-12-03 Modifed to add AboveTreeLine to soil_con_struct so that the model can make use of the computed treeline. KAC 03-27-03 Modified calculation of DRY_TIME. Originally the check to see if a new storm was warranted checked if DRY_TIME was greater than 24/dt. However, DRY_TIME is incremented by dt, so it was checking hours against time steps. The division by dt has been removed, so a new storm starts if the cell has been drying for a full 24 hours. RS & KAC 04-10-03 Modified to store STILL_STORM and DRY_TIME in the model statefile, so that full conditions will be preserved. KAC 01-Nov-04 Added support for state files containing SPATIAL_FROST and LAKE_MODEL state variables. TJB 02-Feb-05 Modified to save state file at the end of the final timestep of the date indicated by STATEYEAR, STATEMONTH, and STATEDAY in the global parameter file. TJB 2005-Mar-24 Modified parameter list of put_data() to accomodate support for ALMA variables. TJB 2006-Sep-23 Implemented flexible output configuration; uses new out_data, out_data_files, and save_data structures. TJB 2006-Oct-16 Merged infiles and outfiles structs into filep_struct. TJB 2006-Nov-07 Removed LAKE_MODEL option. TJB 2007-Apr-04 Modified to handle grid cell errors by returning to the main subroutine, rather than ending the simulation. GCT/KAC 2008-Oct-23 Modified call to put_data() to store ErrorFlag. TJB 2009-Mar-03 Modified routine to store put_data() error in ErrorFlag2 and return a single ERROR value if an error occurs. KAC via TJB 2009-Jun-19 Added T flag to indicate whether TFALLBACK occurred. TJB 2009-Sep-28 Added logic for initial (pre-simulation) call to put_data.TJB **********************************************************************/ extern option_struct options; extern veg_lib_struct *veg_lib; #if LINK_DEBUG extern debug_struct debug; #endif static char STILL_STORM[MAX_VEG]; static int DRY_TIME[MAX_VEG]; char ANY_SNOW[MAX_VEG]; int veg, i; int month; int ErrorFlag, ErrorFlag2; double Wdmax; double NEW_MU; /************************************************** If rec < 0, initialize the storage terms for water and energy balances **************************************************/ if (rec < 0) { ErrorFlag2 = put_data(prcp, atmos, soil_con, veg_con, lake_con, out_data_files, out_data, save_data, &dmy[0], rec); if ( ErrorFlag2 == ERROR ) ErrorFlag = ERROR; return (0); } /************************************************** If rec >= 0, proceed with simulation **************************************************/ // check if state file has been used to initialize storm tracking if ( init_DRY_TIME >= 0 ) { // initialize storm tracking for ( veg = 0; veg <= veg_con[0].vegetat_type_num; veg++ ) { DRY_TIME[veg] = init_DRY_TIME[veg]; STILL_STORM[veg] = init_STILL_STORM[veg]; } } if(options.DIST_PRCP) { /******************************************* Controls Distributed Precipitation Model *******************************************/ NEW_MU = 1.0 - exp(-options.PREC_EXPT*atmos->prec[NR]); for ( veg = 0; veg <= veg_con[0].vegetat_type_num; veg++ ) { ANY_SNOW[veg] = FALSE; for ( i = 0; i < options.SNOW_BAND; i++ ) /* Check for snow on ground or falling */ if ( prcp->snow[veg][i].swq > 0 || prcp->snow[veg][i].snow_canopy > 0. ) ANY_SNOW[veg] = TRUE; if ( ANY_SNOW[veg] || atmos->snowflag[NR] ) { /* If snow present, mu must be set to 1. */ NEW_MU = 1.; if ( rec == 0 ) { /* Set model variables if first time step */ prcp->mu[veg] = NEW_MU; if ( atmos->prec[NR] > 0 ) STILL_STORM[veg] = TRUE; else STILL_STORM[veg] = FALSE; DRY_TIME[veg] = 0; } ANY_SNOW[veg] = TRUE; } else { if ( rec == 0 ) { if ( atmos->prec[NR] == 0 ) { /* If first time step has no rain, than set mu to 1. */ prcp->mu[veg] = 1.; NEW_MU = 1.; STILL_STORM[veg] = TRUE; DRY_TIME[veg] = 24; } else { /* If first time step has rain, then set mu based on intensity */ prcp->mu[veg] = NEW_MU; STILL_STORM[veg] = TRUE; DRY_TIME[veg] = 0; } } else if(atmos->prec[NR] == 0 && DRY_TIME[veg] >= 24.) { /* Check if storm has ended */ NEW_MU = prcp->mu[veg]; STILL_STORM[veg] = FALSE; DRY_TIME[veg] = 0; } else if ( atmos->prec[NR] == 0 ) { /* May be pause in storm, keep track of pause length */ NEW_MU = prcp->mu[veg]; DRY_TIME[veg] += global_param->dt; } } if ( !STILL_STORM[veg] && (atmos->prec[NR] > STORM_THRES || ANY_SNOW[veg] ) ) { /** Average soil moisture before a new storm **/ ErrorFlag = initialize_new_storm(prcp->cell,prcp->veg_var, veg,veg_con[0].vegetat_type_num,rec, prcp->mu[veg],NEW_MU); if ( ErrorFlag == ERROR ) return ( ERROR ); STILL_STORM[veg] = TRUE; prcp->mu[veg] = NEW_MU; } else if ( NEW_MU != prcp->mu[veg] && STILL_STORM[veg] ) { /** Redistribute soil moisture during the storm if mu changes **/ if ( dmy[rec].day == 1 && dmy[rec].hour == 0 ) { month = dmy[rec].month - 2; if ( month < 0 ) month = 11; } else month = dmy[rec].month - 1; if (veg < veg_con[0].vegetat_type_num) Wdmax = veg_lib[veg_con[veg].veg_class].Wdmax[month]; else Wdmax = 0; redistribute_during_storm(prcp->cell, prcp->veg_var, veg, veg_con[0].vegetat_type_num, rec, Wdmax, prcp->mu[veg], NEW_MU, soil_con->max_moist); prcp->mu[veg] = NEW_MU; } } /** Solve model time step **/ ErrorFlag = full_energy(NEWCELL, cellnum, rec, atmos, prcp, dmy, global_param, lake_con, soil_con, veg_con); } else { /************************************************** Controls Grid Cell Averaged Precipitation Model **************************************************/ ErrorFlag = full_energy(NEWCELL, cellnum, rec, atmos, prcp, dmy, global_param, lake_con, soil_con, veg_con); } /************************************************** Write cell average values for current time step **************************************************/ ErrorFlag2 = put_data(prcp, atmos, soil_con, veg_con, lake_con, out_data_files, out_data, save_data, &dmy[rec], rec); if ( ErrorFlag2 == ERROR ) ErrorFlag = ERROR; /************************************ Save model state at assigned date (after the final time step of the assigned date) ************************************/ if ( filep->statefile != NULL && ( dmy[rec].year == global_param->stateyear && dmy[rec].month == global_param->statemonth && dmy[rec].day == global_param->stateday && ( rec+1 == global_param->nrecs || dmy[rec+1].day != global_param->stateday ) ) ) write_model_state(prcp, global_param, veg_con[0].vegetat_type_num, soil_con->gridcel, filep, soil_con, STILL_STORM, DRY_TIME, *lake_con); return ( ErrorFlag ); }
savestate(string file) { stream str; str = stropen(file, "a"); /* open state output file */ fseek(str, 0L, 0); /* rewind stream to origin */ put_string(str, "program", getargv0()); put_string(str, "version", getparam("VERSION")); put_string(str, "headline", headline); /* save control parameters */ put_data(str, "freq", RealType, &freq, 0); put_data(str, "tol", RealType, &tol, 0); put_data(str, "eps", RealType, &eps, 0); put_data(str, "fcells", RealType, &fcells, 0); put_string(str, "options", options); put_data(str, "tstop", RealType, &tstop, 0); put_data(str, "freqout", RealType, &freqout, 0); put_data(str, "minor_freqout", RealType, &minor_freqout, 0); put_data(str, "tnow", RealType, &tnow, 0); /* save state variables */ put_data(str, "tout", RealType, &tout, 0); put_data(str, "minor_tout", RealType, &minor_tout, 0); put_data(str, "nstep", IntType, &nstep, 0); put_data(str, "rmin", RealType, rmin, NDIM, 0); put_data(str, "rsize", RealType, &rsize, 0); put_data(str, "nbody", IntType, &nbody, 0); put_data(str, "bodytab", AnyType, bodytab, nbody, sizeof(body), 0); strclose(str); }
/* ------------------infinite loop to handle client requests------------ */ int command_loop() { reply smesg; char repstr[1024]; int filefd; for(;;) { if (get_command(sconn, &smesg) <= 0 ) { return 0; } switch(smesg.code) { case USER : strncpy(username,smesg.text,127); sprintf(repstr, "331 Password required for %s.\n", username); send_request(sconn, repstr, strlen(repstr)); break; case PASS : if (check_user(username, smesg.text)) { sprintf(repstr, "230 User %s logged in.\n", username); send_request(sconn, repstr, strlen(repstr)); status = LOGGED_IN; } else { sprintf(repstr, "530 login failed.\n"); send_request(sconn, repstr, strlen(repstr)); } break; case PORT : if (!loggedin()) break; get_data_connection_info(smesg.text, cip, &cport); sprintf(repstr, "200 port command succesfull.\n"); send_request(sconn, repstr, strlen(repstr)); break; case LIST : if (!loggedin()) break; if (open_sock_connection(cip, cport, &data_conn) < 0) { sprintf(repstr, "425 Can't build data connection: Connection refused.\n"); send_request(sconn, repstr, strlen(repstr)); close_conn(data_conn); break; } sprintf(repstr, "150 Opening data connection.\n"); send_request(sconn, repstr, strlen(repstr)); put_local_ls(data_conn.sock, smesg.text); sprintf(repstr, "226 Transfer complete.\n"); send_request(sconn, repstr, strlen(repstr)); close_conn(data_conn); break; case RETR : if (!loggedin()) break; if ( (filefd = open(smesg.text, O_RDONLY, 0)) < 0) { sprintf(repstr, "550 %s\n",strerror(errno)); send_request(sconn, repstr, strlen(repstr)); break; } if (open_sock_connection(cip, cport, &data_conn) < 0) { sprintf(repstr, "425 Can't build data connection: Connection refused.\n"); send_request(sconn, repstr, strlen(repstr)); close_conn(data_conn); break; } sprintf(repstr, "150 Opening data connection.\n"); send_request(sconn, repstr, strlen(repstr)); put_data(data_conn, filefd); sprintf(repstr, "226 Transfer complete.\n"); send_request(sconn, repstr, strlen(repstr)); close_conn(data_conn); close(filefd); break; case STOR : if (!loggedin()) break; if ( (filefd = open(smesg.text, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR)) < 0) { sprintf(repstr, "550 %s\n",strerror(errno)); send_request(sconn, repstr, strlen(repstr)); break; } if (open_sock_connection(cip, cport, &data_conn) < 0) { sprintf(repstr, "425 Can't build data connection : Connection refused.\n"); send_request(sconn, repstr, strlen(repstr)); close_conn(data_conn); break; } sprintf(repstr, "150 Opening data connection.\n"); send_request(sconn, repstr, strlen(repstr)); get_data(data_conn, filefd); sprintf(repstr, "226 Transfer complete.\n"); send_request(sconn, repstr, strlen(repstr)); close_conn(data_conn); close(filefd); break; case QUIT : sprintf(repstr, "221 GoodBye.\n"); send_request(sconn, repstr, strlen(repstr)); exit(0); break; default : strcpy(repstr, "500 command not understood\n"); send_request(sconn, repstr, strlen(repstr)); break; } }
/* output the resources into a .o file */ void output_res_o_file( DLLSPEC *spec ) { unsigned int i; char *res_file = NULL; int fd; struct strarray *args; if (!spec->nb_resources) fatal_error( "--resources mode needs at least one resource file as input\n" ); if (!output_file_name) fatal_error( "No output file name specified\n" ); qsort( spec->resources, spec->nb_resources, sizeof(*spec->resources), cmp_res ); remove_duplicate_resources( spec ); byte_swapped = 0; init_output_buffer(); put_dword( 0 ); /* ResSize */ put_dword( 32 ); /* HeaderSize */ put_word( 0xffff ); /* ResType */ put_word( 0x0000 ); put_word( 0xffff ); /* ResName */ put_word( 0x0000 ); put_dword( 0 ); /* DataVersion */ put_word( 0 ); /* Memory options */ put_word( 0 ); /* Language */ put_dword( 0 ); /* Version */ put_dword( 0 ); /* Characteristics */ for (i = 0; i < spec->nb_resources; i++) { unsigned int header_size = get_resource_header_size( &spec->resources[i] ); put_dword( spec->resources[i].data_size ); put_dword( (header_size + 3) & ~3 ); put_string( &spec->resources[i].type ); put_string( &spec->resources[i].name ); align_output( 4 ); put_dword( 0 ); put_word( spec->resources[i].mem_options ); put_word( spec->resources[i].lang ); put_dword( spec->resources[i].version ); put_dword( 0 ); put_data( spec->resources[i].data, spec->resources[i].data_size ); align_output( 4 ); } /* if the output file name is a .res too, don't run the results through windres */ if (strendswith( output_file_name, ".res")) { flush_output_buffer(); return; } res_file = get_temp_file_name( output_file_name, ".res" ); if ((fd = open( res_file, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0600 )) == -1) fatal_error( "Cannot create %s\n", res_file ); if (write( fd, output_buffer, output_buffer_pos ) != output_buffer_pos) fatal_error( "Error writing to %s\n", res_file ); close( fd ); free( output_buffer ); args = strarray_init(); strarray_add( args, find_tool( "windres", NULL ), "-i", res_file, "-o", output_file_name, NULL ); spawn( args ); strarray_free( args ); output_file_name = NULL; /* so we don't try to assemble it */ }
static int run_test (int, char**) { MyIos<char, std::char_traits<char> > nio; MyStreambuf<char, std::char_traits<char> > nsb; nio.rdbuf (&nsb); #ifndef _RWSTD_NO_WCHAR_T MyIos<wchar_t, std::char_traits<wchar_t> > wio; MyStreambuf<wchar_t, std::char_traits<wchar_t> > wsb; wio.rdbuf (&wsb); #endif // _RWSTD_NO_WCHAR_T // find all installed locales for which setlocale(LC_ALL) succeeds const char* const locale_list = rw_opt_locales ? rw_opt_locales : rw_locales (_RWSTD_LC_ALL); const std::size_t maxinx = RW_COUNT_OF (locales); for (const char *name = locale_list; *name; name += std::strlen (name) + 1) { const std::size_t inx = nlocales; locales [inx] = name; // fill in the value and results for this locale MyNumData& data = my_num_data [nlocales]; data.locale_name_ = name; try { const std::locale loc (data.locale_name_); data.value_ = nlocales & 1 ? -1 * nlocales : nlocales; data.type_ = MyNumData::PutId (nlocales % MyNumData::put_max); // format data into buffers const std::num_put<char> &np = std::use_facet<std::num_put<char> >(loc); nio.imbue (loc); nsb.pubsetp (data.ncs_, RW_COUNT_OF (data.ncs_)); put_data (data, np, std::ostreambuf_iterator<char>(&nsb), nio, ' ', '\0'); rw_fatal (!nio.fail (), __FILE__, __LINE__, "num_put<char>::put(...) failed for locale(%#s)", data.locale_name_); #ifndef _RWSTD_NO_WCHAR_T const std::num_put<wchar_t> &wp = std::use_facet<std::num_put<wchar_t> >(loc); wio.imbue (loc); wsb.pubsetp (data.wcs_, RW_COUNT_OF (data.wcs_)); put_data (data, wp, std::ostreambuf_iterator<wchar_t>(&wsb), wio, L' ', L'\0'); rw_fatal (!wio.fail (), __FILE__, __LINE__, "num_put<wchar_t>::put(...) failed for locale(%#s)", data.locale_name_); #endif // _RWSTD_NO_WCHAR_T if (opt_shared_locale) data.locale_ = loc; nlocales += 1; } catch (...) { rw_warn (!rw_opt_locales, 0, __LINE__, "failed to create locale(%#s)", name); } if (nlocales == maxinx || nlocales == std::size_t (opt_nlocales)) break; } // avoid divide by zero in thread if there are no locales to test rw_fatal (nlocales != 0, 0, __LINE__, "failed to create one or more usable locales!"); rw_info (0, 0, 0, "testing std::num_put<charT> with %d thread%{?}s%{;}, " "%d iteration%{?}s%{;} each, in %zu locales { %{ .*A@} }", opt_nthreads, 1 != opt_nthreads, opt_nloops, 1 != opt_nloops, nlocales, int (nlocales), "%#s", locales); rw_info (0, 0, 0, "exercising std::num_put<char>"); test_char = true; test_wchar = false; // create and start a pool of threads and wait for them to finish int result = rw_thread_pool (0, std::size_t (opt_nthreads), 0, thread_func, 0); rw_error (result == 0, 0, __LINE__, "rw_thread_pool(0, %d, 0, %{#f}, 0) failed", opt_nthreads, thread_func); #ifndef _RWSTD_NO_WCHAR_T rw_info (0, 0, 0, "exercising std::num_put<wchar_t>"); test_char = false; test_wchar = true; // start a pool of threads to exercise wstring thread safety result = rw_thread_pool (0, std::size_t (opt_nthreads), 0, thread_func, 0); rw_error (result == 0, 0, __LINE__, "rw_thread_pool(0, %d, 0, %{#f}, 0) failed", opt_nthreads, thread_func); // exercise both the char and the wchar_t specializations // at the same time rw_info (0, 0, 0, "exercising both std::num_put<char> and std::num_put<wchar_t>"); test_char = true; test_wchar = true; // start a pool of threads to exercise wstring thread safety result = rw_thread_pool (0, std::size_t (opt_nthreads), 0, thread_func, 0); rw_error (result == 0, 0, __LINE__, "rw_thread_pool(0, %d, 0, %{#f}, 0) failed", opt_nthreads, thread_func); #endif // _RWSTD_NO_WCHAR_T return result; }
Error StreamPeerBuffer::put_partial_data(const uint8_t *p_data, int p_bytes, int &r_sent) { r_sent = p_bytes; return put_data(p_data, p_bytes); }
void add_to_commasep(strbuf *buf, const char *data) { if (buf->len > 0) put_byte(buf, ','); put_data(buf, data, strlen(data)); }
void StreamPeer::put_8(int8_t p_val) { put_data((const uint8_t *)&p_val, 1); }
void StreamPeer::put_utf8_string(const String &p_string) { CharString cs = p_string.utf8(); put_u32(cs.length()); put_data((const uint8_t *)cs.get_data(), cs.length()); }
//encypt data int post_packet( struct qqclient* qq, qqpacket* p, int key_type ) { bytebuffer* buf = p->buf; unsigned char* encrypted; int head_len = qq->network==TCP || qq->network==PROXY_HTTP ? 24 : 22; static uchar unknown_packet_flags[] = {0x02,0x00,0x00,0x00,0x01,0x01,0x01,0x00,0x00,0x64,0x70}; if( qq->log_packet ){ if( p->command == QQ_CMD_QUN_CMD ) DBG("[%d] send packet cmd: %x subcmd: %x seq: %x", qq->number, p->command, (int)p->buf->data[0], p->seqno ); else DBG("[%d] send packet cmd: %x seq: %x", qq->number, p->command, p->seqno ); hex_dump( buf->data, buf->pos ); } switch( key_type )//use this key to enrypt data { case NO_KEY: { if( buf->pos+head_len+1 <= buf->size ){ memmove( buf->data+head_len, buf->data, buf->pos ); buf->pos += head_len; } break; } case RANDOM_KEY: { int out_len = PACKET_SIZE; NEW( encrypted, PACKET_SIZE, unsigned char ); if( !encrypted ) { DBG("Error: encrypted not allocated."); return -1; } qqencrypt( buf->data, buf->pos, p->key, encrypted, &out_len ); //for tcp if( p->command == QQ_CMD_LOGIN_SEND_INFO || p->command == QQ_CMD_LOGIN_GET_INFO || p->command == QQ_CMD_LOGIN_GET_LIST || p->command == QQ_CMD_LOGIN_A4 ){ if( out_len+head_len+1+(2+qq->data.login_info_magic.len) <= buf->size ){ *(ushort*)(buf->data+head_len) = htons( qq->data.login_info_magic.len ); memcpy( buf->data+head_len+2, qq->data.login_info_magic.data, qq->data.login_info_magic.len ); memcpy( buf->data+qq->data.login_info_magic.len+head_len+2, encrypted, out_len ); buf->pos = out_len+qq->data.login_info_magic.len+head_len+2; }else{ DBG("encrypted data is too large to store in the packet."); } }else{ if( out_len+16+head_len+1 <= buf->size ){ memcpy( buf->data+head_len, p->key, 16 ); memcpy( buf->data+16+head_len, encrypted, out_len ); buf->pos = out_len+16+head_len; }else{ DBG("encrypted data is too large to store in the packet."); } } DEL( encrypted ); break; } case SESSION_KEY: { int out_len = PACKET_SIZE; NEW( encrypted, PACKET_SIZE, unsigned char ); if( !encrypted ) { DBG("Error: encrypted not allocated."); return -2; } qqencrypt( buf->data, buf->pos, qq->data.session_key, encrypted, &out_len ); //for tcp if( out_len+head_len+1 <= buf->size ){ memcpy( buf->data+head_len, encrypted, out_len ); buf->pos = out_len+head_len; }else{ DBG("encrypted data is too large to store in the packet."); } DEL( encrypted ); break; } } //end the packet put_byte( buf, p->tail ); buf->len = buf->pos; buf->pos = 0; //basic information if( qq->network == TCP || qq->network==PROXY_HTTP ) put_word( buf, buf->len ); put_byte( buf, p->head ); put_word( buf, p->version ); put_word( buf, p->command ); put_word( buf, p->seqno ); put_int( buf, qq->number ); put_data( buf, unknown_packet_flags, 11 ); p->key_type = key_type; return packetmgr_put( qq, p ); }
/******************************************************************* * output_fake_module * * Build a fake binary module from a spec file. */ void output_fake_module( DLLSPEC *spec ) { static const unsigned char dll_code_section[] = { 0x31, 0xc0, /* xor %eax,%eax */ 0xc2, 0x0c, 0x00 }; /* ret $12 */ static const unsigned char exe_code_section[] = { 0xb8, 0x01, 0x00, 0x00, 0x00, /* movl $1,%eax */ 0xc2, 0x04, 0x00 }; /* ret $4 */ static const char fakedll_signature[] = "Wine placeholder DLL"; const unsigned int page_size = get_page_size(); const unsigned int section_align = page_size; const unsigned int file_align = 0x200; const unsigned int reloc_size = 8; const unsigned int lfanew = (0x40 + sizeof(fakedll_signature) + 15) & ~15; const unsigned int nb_sections = 2 + (spec->nb_resources != 0); const unsigned int text_size = (spec->characteristics & IMAGE_FILE_DLL) ? sizeof(dll_code_section) : sizeof(exe_code_section); unsigned char *resources; unsigned int resources_size; unsigned int image_size = 3 * section_align; resolve_imports( spec ); output_bin_resources( spec, 3 * section_align ); resources = output_buffer; resources_size = output_buffer_pos; if (resources_size) image_size += (resources_size + section_align - 1) & ~(section_align - 1); init_output_buffer(); put_word( 0x5a4d ); /* e_magic */ put_word( 0x40 ); /* e_cblp */ put_word( 0x01 ); /* e_cp */ put_word( 0 ); /* e_crlc */ put_word( lfanew / 16 ); /* e_cparhdr */ put_word( 0x0000 ); /* e_minalloc */ put_word( 0xffff ); /* e_maxalloc */ put_word( 0x0000 ); /* e_ss */ put_word( 0x00b8 ); /* e_sp */ put_word( 0 ); /* e_csum */ put_word( 0 ); /* e_ip */ put_word( 0 ); /* e_cs */ put_word( lfanew ); /* e_lfarlc */ put_word( 0 ); /* e_ovno */ put_dword( 0 ); /* e_res */ put_dword( 0 ); put_word( 0 ); /* e_oemid */ put_word( 0 ); /* e_oeminfo */ put_dword( 0 ); /* e_res2 */ put_dword( 0 ); put_dword( 0 ); put_dword( 0 ); put_dword( 0 ); put_dword( lfanew ); put_data( fakedll_signature, sizeof(fakedll_signature) ); align_output( 16 ); put_dword( 0x4550 ); /* Signature */ switch(target_cpu) { case CPU_x86: put_word( IMAGE_FILE_MACHINE_I386 ); break; case CPU_x86_64: put_word( IMAGE_FILE_MACHINE_AMD64 ); break; case CPU_POWERPC: put_word( IMAGE_FILE_MACHINE_POWERPC ); break; case CPU_ARM: put_word( IMAGE_FILE_MACHINE_ARMNT ); break; case CPU_ARM64: put_word( IMAGE_FILE_MACHINE_ARM64 ); break; } put_word( nb_sections ); /* NumberOfSections */ put_dword( 0 ); /* TimeDateStamp */ put_dword( 0 ); /* PointerToSymbolTable */ put_dword( 0 ); /* NumberOfSymbols */ put_word( get_ptr_size() == 8 ? IMAGE_SIZEOF_NT_OPTIONAL64_HEADER : IMAGE_SIZEOF_NT_OPTIONAL32_HEADER ); /* SizeOfOptionalHeader */ put_word( spec->characteristics ); /* Characteristics */ put_word( get_ptr_size() == 8 ? IMAGE_NT_OPTIONAL_HDR64_MAGIC : IMAGE_NT_OPTIONAL_HDR32_MAGIC ); /* Magic */ put_byte( 0 ); /* MajorLinkerVersion */ put_byte( 0 ); /* MinorLinkerVersion */ put_dword( text_size ); /* SizeOfCode */ put_dword( 0 ); /* SizeOfInitializedData */ put_dword( 0 ); /* SizeOfUninitializedData */ put_dword( section_align ); /* AddressOfEntryPoint */ put_dword( section_align ); /* BaseOfCode */ if (get_ptr_size() == 4) put_dword( 0 ); /* BaseOfData */ put_pword( 0x10000000 ); /* ImageBase */ put_dword( section_align ); /* SectionAlignment */ put_dword( file_align ); /* FileAlignment */ put_word( 1 ); /* MajorOperatingSystemVersion */ put_word( 0 ); /* MinorOperatingSystemVersion */ put_word( 0 ); /* MajorImageVersion */ put_word( 0 ); /* MinorImageVersion */ put_word( spec->subsystem_major ); /* MajorSubsystemVersion */ put_word( spec->subsystem_minor ); /* MinorSubsystemVersion */ put_dword( 0 ); /* Win32VersionValue */ put_dword( image_size ); /* SizeOfImage */ put_dword( file_align ); /* SizeOfHeaders */ put_dword( 0 ); /* CheckSum */ put_word( spec->subsystem ); /* Subsystem */ put_word( spec->dll_characteristics ); /* DllCharacteristics */ put_pword( (spec->stack_size ? spec->stack_size : 1024) * 1024 ); /* SizeOfStackReserve */ put_pword( page_size ); /* SizeOfStackCommit */ put_pword( (spec->heap_size ? spec->heap_size : 1024) * 1024 ); /* SizeOfHeapReserve */ put_pword( page_size ); /* SizeOfHeapCommit */ put_dword( 0 ); /* LoaderFlags */ put_dword( 16 ); /* NumberOfRvaAndSizes */ put_dword( 0 ); put_dword( 0 ); /* DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT] */ put_dword( 0 ); put_dword( 0 ); /* DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT] */ if (resources_size) /* DataDirectory[IMAGE_DIRECTORY_ENTRY_RESOURCE] */ { put_dword( 3 * section_align ); put_dword( resources_size ); } else { put_dword( 0 ); put_dword( 0 ); } put_dword( 0 ); put_dword( 0 ); /* DataDirectory[IMAGE_DIRECTORY_ENTRY_EXCEPTION] */ put_dword( 0 ); put_dword( 0 ); /* DataDirectory[IMAGE_DIRECTORY_ENTRY_SECURITY] */ put_dword( 2 * section_align ); /* DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC] */ put_dword( reloc_size ); put_dword( 0 ); put_dword( 0 ); /* DataDirectory[IMAGE_DIRECTORY_ENTRY_DEBUG] */ put_dword( 0 ); put_dword( 0 ); /* DataDirectory[IMAGE_DIRECTORY_ENTRY_COPYRIGHT] */ put_dword( 0 ); put_dword( 0 ); /* DataDirectory[IMAGE_DIRECTORY_ENTRY_GLOBALPTR] */ put_dword( 0 ); put_dword( 0 ); /* DataDirectory[IMAGE_DIRECTORY_ENTRY_TLS] */ put_dword( 0 ); put_dword( 0 ); /* DataDirectory[IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG] */ put_dword( 0 ); put_dword( 0 ); /* DataDirectory[IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT] */ put_dword( 0 ); put_dword( 0 ); /* DataDirectory[IMAGE_DIRECTORY_ENTRY_IAT] */ put_dword( 0 ); put_dword( 0 ); /* DataDirectory[IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT] */ put_dword( 0 ); put_dword( 0 ); /* DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR] */ put_dword( 0 ); put_dword( 0 ); /* DataDirectory[15] */ /* .text section */ put_data( ".text\0\0", 8 ); /* Name */ put_dword( section_align ); /* VirtualSize */ put_dword( section_align ); /* VirtualAddress */ put_dword( text_size ); /* SizeOfRawData */ put_dword( file_align ); /* PointerToRawData */ put_dword( 0 ); /* PointerToRelocations */ put_dword( 0 ); /* PointerToLinenumbers */ put_word( 0 ); /* NumberOfRelocations */ put_word( 0 ); /* NumberOfLinenumbers */ put_dword( 0x60000020 /* CNT_CODE|MEM_EXECUTE|MEM_READ */ ); /* Characteristics */ /* .reloc section */ put_data( ".reloc\0", 8 ); /* Name */ put_dword( section_align ); /* VirtualSize */ put_dword( 2 * section_align );/* VirtualAddress */ put_dword( reloc_size ); /* SizeOfRawData */ put_dword( 2 * file_align ); /* PointerToRawData */ put_dword( 0 ); /* PointerToRelocations */ put_dword( 0 ); /* PointerToLinenumbers */ put_word( 0 ); /* NumberOfRelocations */ put_word( 0 ); /* NumberOfLinenumbers */ put_dword( 0x42000040 /* CNT_INITIALIZED_DATA|MEM_DISCARDABLE|MEM_READ */ ); /* Characteristics */ /* .rsrc section */ if (resources_size) { put_data( ".rsrc\0\0", 8 ); /* Name */ put_dword( (resources_size + section_align - 1) & ~(section_align - 1) ); /* VirtualSize */ put_dword( 3 * section_align );/* VirtualAddress */ put_dword( resources_size ); /* SizeOfRawData */ put_dword( 3 * file_align ); /* PointerToRawData */ put_dword( 0 ); /* PointerToRelocations */ put_dword( 0 ); /* PointerToLinenumbers */ put_word( 0 ); /* NumberOfRelocations */ put_word( 0 ); /* NumberOfLinenumbers */ put_dword( 0x40000040 /* CNT_INITIALIZED_DATA|MEM_READ */ ); /* Characteristics */ } /* .text contents */ align_output( file_align ); if (spec->characteristics & IMAGE_FILE_DLL) put_data( dll_code_section, sizeof(dll_code_section) ); else put_data( exe_code_section, sizeof(exe_code_section) ); /* .reloc contents */ align_output( file_align ); put_dword( 0 ); /* VirtualAddress */ put_dword( 0 ); /* SizeOfBlock */ /* .rsrc contents */ if (resources_size) { align_output( file_align ); put_data( resources, resources_size ); } flush_output_buffer(); }
void put_image_data(struct data_entry *entry, struct image_data *data) { if (data->ops->dtor) data->ops->dtor(data); put_data(entry, &data->up); }
void prot_login_send_info( struct qqclient* qq ) { static uchar unknown5[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00 }; static uchar unknown6[] = {0xE9,0xC4,0xD6,0x5C,0x4D,0x9D, 0xA0,0x17,0xE5,0x24,0x6B,0x55,0x57,0xD3,0xAB,0xF1 }; static uchar unknown7[] = {0xCB,0x8D,0xA4,0xE2,0x61,0xC2, 0xDD,0x27,0x39,0xEC,0x8A,0xCA,0xA6,0x98,0xF8,0x9B }; qqpacket* p = packetmgr_new_send( qq, QQ_CMD_LOGIN_SEND_INFO ); if( !p ) return; bytebuffer *buf = p->buf; //prepare sth. randkey( unknown6 ); randkey( unknown7 ); put_word( buf, 0x0001 ); put_data( buf, qq->data.version_spec, sizeof(qq->data.version_spec) ); put_int( buf, qq->data.login_info_unknown2 ); put_int( buf, qq->server_time ); put_int( buf, qq->client_ip ); put_int( buf, 00000000 ); put_word( buf, qq->data.login_info_large.len ); put_data( buf, qq->data.login_info_large.data, qq->data.login_info_large.len ); buf->pos += 35; put_data( buf, qq->data.exe_hash, sizeof(qq->data.exe_hash) ); put_byte( buf, rand2() ); //unknown important byte put_byte( buf, qq->mode ); put_data( buf, unknown5, sizeof(unknown5) ); put_data( buf, qq->data.server_data, sizeof(qq->data.server_data) ); put_data( buf, qq->data.locale, sizeof(qq->data.locale) ); buf->pos += 16; //16 zeros put_word( buf, qq->data.token_c.len ); put_data( buf, qq->data.token_c.data, qq->data.token_c.len ); put_int( buf, 0x00000007 ); put_int( buf, 0x00000000 ); put_int( buf, 0x08041801 ); put_byte( buf, 0x40 ); //length of the following put_byte( buf, 0x01 ); put_int( buf, rand2() ); // put_int( buf, 0x0741E9748 ); put_word( buf, sizeof(unknown6) ); put_data( buf, unknown6, sizeof(unknown6) ); put_data( buf, unknown5, sizeof(unknown5) ); put_data( buf, qq->data.server_data, sizeof(qq->data.server_data) ); put_byte( buf, 0x02 ); put_int( buf, rand2() ); // put_int( buf, 0x8BED382E ); put_word( buf, sizeof(unknown7) ); put_data( buf, unknown7, sizeof(unknown7) ); buf->pos += 249; //all zeros memcpy( p->key, qq->data.login_info_key1, sizeof(qq->data.login_info_key1) ); post_packet( qq, p, RANDOM_KEY ); }
static void* thread_func (void*) { char ncs [MyNumData::BufferSize]; MyIos<char, std::char_traits<char> > nio; MyStreambuf<char, std::char_traits<char> > nsb; nio.rdbuf (&nsb); #ifndef _RWSTD_NO_WCHAR_T wchar_t wcs [MyNumData::BufferSize]; MyIos<wchar_t, std::char_traits<wchar_t> > wio; MyStreambuf<wchar_t, std::char_traits<wchar_t> > wsb; wio.rdbuf (&wsb); #endif // _RWSTD_NO_WCHAR_T for (int i = 0; i != opt_nloops; ++i) { // fill in the value and results for this locale const MyNumData& data = my_num_data [i % nlocales]; // construct a named locale and imbue it in the ios object // so that the locale is used not only by the num_put facet const std::locale loc = opt_shared_locale ? data.locale_ : std::locale (data.locale_name_); if (test_char) { // exercise the narrow char specialization of the facet const std::num_put<char> &np = std::use_facet<std::num_put<char> >(loc); nio.imbue (loc); nsb.pubsetp (ncs, RW_COUNT_OF (ncs)); put_data (data, np, std::ostreambuf_iterator<char>(&nsb), nio, ' ', '\0'); RW_ASSERT (!nio.fail ()); RW_ASSERT (!rw_strncmp (ncs, data.ncs_)); } // both specializations may be tested at the same time if (test_wchar) { // exercise the wide char specialization of the facet #ifndef _RWSTD_NO_WCHAR_T const std::num_put<wchar_t> &wp = std::use_facet<std::num_put<wchar_t> >(loc); wio.imbue (loc); wsb.pubsetp (wcs, RW_COUNT_OF (wcs)); put_data (data, wp, std::ostreambuf_iterator<wchar_t>(&wsb), wio, L' ', L'\0'); RW_ASSERT (!wio.fail ()); RW_ASSERT (!rw_strncmp (wcs, data.wcs_)); #endif // _RWSTD_NO_WCHAR_T } } return 0; }
int main() { pid_t child; unsigned long long orig_eax, eax; unsigned long long params[3]; int insyscall = 0; int status; struct user_regs_struct regs; child = fork(); if(child == 0) { ptrace(PTRACE_TRACEME, 0, NULL, NULL); execl("/bin/ls", "ls", NULL); } else { while(1) { wait(&status); if(WIFEXITED(status)) break; unsigned long offset = offsetof(struct user_regs_struct, orig_rax); orig_eax = ptrace(PTRACE_PEEKUSER, child, offset, NULL); if (orig_eax < 0) perror("erron"); //printf("The child made asystem call %ld\n", orig_eax); //ptrace(PTRACE_CONT, child, NULL, NULL); if(orig_eax == SYS_write) { if(insyscall == 0) { /* Syscall entry */ insyscall = 1; //ptrace(PTRACE_GETREGS, child, NULL, ®s); //printf("Write called with %llu, %llu, %llu\n", regs.rdi, regs.rsi, regs.rdx); unsigned long offset = offsetof(struct user_regs_struct, rdi); params[0] = ptrace(PTRACE_PEEKUSER, child, offset, NULL); offset = offsetof(struct user_regs_struct, rsi); params[1] = ptrace(PTRACE_PEEKUSER, child, offset, NULL); offset = offsetof(struct user_regs_struct, rdx); params[2] = ptrace(PTRACE_PEEKUSER, child, offset, NULL); char *str = malloc(params[2]); get_data(child, params[1], params[2], str); printf("Write called with %llu, %llu, %llu\n", params[0], params[1], params[2]); printf("write contens:%s", str); reverse(str); put_data(child, params[1], params[2], str); } else { /* Syscall exit */ unsigned long offset = offsetof(struct user_regs_struct, rax); eax = ptrace(PTRACE_PEEKUSER, child, offset, NULL); printf("Write returned with %llu\n", eax); insyscall = 0; } } ptrace(PTRACE_SYSCALL, child, NULL, NULL); }
/* output the resource definitions in binary format */ void output_bin_resources( DLLSPEC *spec, unsigned int start_rva ) { int k, nb_id_types; unsigned int i, n, data_offset; struct res_tree *tree; struct res_type *type; struct res_name *name; const struct resource *res; if (!spec->nb_resources) return; tree = build_resource_tree( spec, &data_offset ); init_output_buffer(); /* output the resource directories */ for (i = nb_id_types = 0, type = tree->types; i < tree->nb_types; i++, type++) if (!type->type->str) nb_id_types++; output_bin_res_dir( tree->nb_types - nb_id_types, nb_id_types ); /* dump the type directory */ for (i = 0, type = tree->types; i < tree->nb_types; i++, type++) { put_dword( type->name_offset ); put_dword( type->dir_offset | 0x80000000 ); } /* dump the names and languages directories */ for (i = 0, type = tree->types; i < tree->nb_types; i++, type++) { output_bin_res_dir( type->nb_names - type->nb_id_names, type->nb_id_names ); for (n = 0, name = type->names; n < type->nb_names; n++, name++) { put_dword( name->name_offset ); put_dword( name->dir_offset | 0x80000000 ); } for (n = 0, name = type->names; n < type->nb_names; n++, name++) { output_bin_res_dir( 0, name->nb_languages ); for (k = 0, res = name->res; k < name->nb_languages; k++, res++) { put_dword( res->lang ); put_dword( res->data_offset ); } } } /* dump the resource data entries */ for (i = 0, res = spec->resources; i < spec->nb_resources; i++, res++) { put_dword( data_offset + start_rva ); put_dword( (res->data_size + 3) & ~3 ); put_dword( 0 ); put_dword( 0 ); data_offset += (res->data_size + 3) & ~3; } /* dump the name strings */ for (i = 0, type = tree->types; i < tree->nb_types; i++, type++) { if (type->type->str) output_bin_string( type->type->str ); for (n = 0, name = type->names; n < type->nb_names; n++, name++) if (name->name->str) output_bin_string( name->name->str ); } /* resource data */ align_output( 4 ); for (i = 0, res = spec->resources; i < spec->nb_resources; i++, res++) { put_data( res->data, res->data_size ); align_output( 4 ); } free_resource_tree( tree ); }