int main(int argc, char *argv[]) #endif { #ifdef __APPLE__ CFBundleRef mainBundle = CFBundleGetMainBundle(); CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle); char path[PATH_MAX]; if (!CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)path, PATH_MAX)) { // error! std::cerr << "PATH ERROR " << __FILE__ << ": " << __LINE__ << std::endl; } CFRelease(resourcesURL); chdir(path); // cd in psc::Conf::i().init(path); #elif _SHOOTING_CUBES_ANDROID_ app_dummy(); char buf[256] = {0}; getcwd(buf, 256); chdir(app->activity->internalDataPath); LOGI("cwd: %s", buf); unpack_data(app); psc::Conf::i().init("", app->activity->internalDataPath, app->activity->externalDataPath); psc::App::i().init(app).launchOpening2().run(); IrrDevice::i().~IrrDevice(); // manually destruct here, as IrrEx17 example? #else psc::Conf::i().init(""); // doesn't need to find working_path on win32, not sure about linux though std::srand(std::time(0)^std::clock()); // init srand for global rand... //return psc::App::i().init().launchOpening().run(); return psc::App::i().init().launchOpening2().run(); #endif }
/** * * @brief 处理srch命令的函数 * * @param[in] cmd_no 命令号,一个函数可能处理多条命令,可以用命令号来区分 * @param[in] req_head 请求数据的nshead_t* * @param[in] req_buf 请求数据的buffer,本buffer不包含nshead_t * @param[out] res_head 应答数据的nshead_t* * @param[out] res_buf 应答数据的buffer,本buffer不包含nshead_t * @return * 0 : 成功 * -1 : 失败,socket将直接关闭,不给client返回错误信息 **/ STATIC int srch_process(int cmd_no, nshead_t * req_head, ub_buff_t * req_buf, nshead_t * res_head, ub_buff_t * res_buf) { /** *在打NOTICE日志时,请使用 ub_log_pushnotice 加入日志信息 *如果返回值不为0,将导致socket被直接关闭而不给客户返回任何信息 **/ srch_thread_data_t *p_thread_data; if(NULL == req_head || NULL == req_buf || NULL == res_head || NULL == res_buf) { UB_LOG_FATAL("parameter error in srch process."); return -1; } srch_reset_res(req_head, res_head, res_buf); char* req = req_buf->buf; char* res = res_buf->buf; res_head->body_len = 0; int response_buffer_size = ub_server_get_write_size() - sizeof (nshead_t); p_thread_data = (srch_thread_data_t* )ub_server_get_user_data(); if(NULL == p_thread_data) { UB_LOG_FATAL("thead_data null"); return -1; } int post_count = 0; int max_post_count = p_thread_data->max_post_count; u_int64_t* pids = p_thread_data->post_ids; delpost_record_t* records = p_thread_data->records; if (!unpack_data(req, req_head->body_len, post_count, pids, max_post_count)) { UB_LOG_WARNING("unpack mcpack error"); return -1; } int ret = query(post_count, pids, records, g_conf.mask_path, g_conf.index_file, g_conf.mask_file); if (ret < 0) { UB_LOG_WARNING("query[ret=%d] error", ret); return -1; } ret = pack_data(res, response_buffer_size, post_count, records); if (ret < 0) { UB_LOG_WARNING("pack mcpack error"); return -1; } res_head->body_len = ret; return 0; }
void unpack_handled (cBuf *buf, Long *buf_pos, cData *d) { HandledFrob *h=TMALLOC(HandledFrob, 1); h->cclass = read_long(buf, buf_pos); unpack_data (buf, buf_pos, &h->rep); h->handler = read_ident(buf, buf_pos); d->u.instance = (void*) h; }
static int unpack_u32(struct unpack *p, uint32_t *u32) { if (unpack_data(p, u32, 4) == -1) return (-1); *u32 = ntohl(*u32); return (0); }
static int unpack_u16(struct unpack *p, uint16_t *u16) { if (unpack_data(p, u16, 2) == -1) return (-1); *u16 = ntohs(*u16); return (0); }
static void game_init(game_t *p_game) { void *p_buf; memset(p_game, 0, sizeof(game_t)); if ( !(p_buf = (void *)get_resource(SPRITE_FRAMES, SPRITE_FRAMES_SIZE)) ) error_msg("Alloc space for sprite frames\n"); p_game->pp_sprites = unpack_sprite_frames(p_buf, SPRITE_FRAMES_UNPACKED_SIZE, N_FRAMES); vDisposePtr(p_buf); p_game->p_tiles = BG_TILES; p_game->player.sprite.dir = RIGHT; sprite_set_state(&p_game->player.sprite, SPRITE_IDLE); p_game->player.sprite.offset_right = FRAME_BRUCE_FIRST_RIGHT; p_game->player.sprite.p_bounds = bruce_bounding; p_game->player.sprite.p_anims = bruce_anims; if ( !(p_buf = get_resource(BRUCE_MIDI, BRUCE_MIDI_SIZE)) ) error_msg("Alloc space for midi file failed!\n"); if ( !(p_game->p_midi_data = unpack_data(p_buf, BRUCE_MIDI_UNPACKED_SIZE)) ) error_msg("Unpack midi failed!\n"); vDisposePtr(p_buf); store_midifile("bruce.mid", p_game->p_midi_data, BRUCE_MIDI_UNPACKED_SIZE); vDisposePtr(p_game->p_midi_data); play_midifile("bruce.mid"); if ( !(p_buf = (void *)get_resource(TITLE_SCREEN, TITLE_SCREEN_SIZE)) ) error_msg("Alloc space for sprite frames\n"); if ( !(p_game->p_title_screen = (SPRITE*)unpack_data(p_buf, TITLE_SCREEN_UNPACKED_SIZE)) ) error_msg("Unpack title screen failed!\n"); vDisposePtr(p_buf); }
static int unpack_header(struct unpack *p, struct dns_header *h) { if (unpack_data(p, h, HFIXEDSZ) == -1) return (-1); h->flags = ntohs(h->flags); h->qdcount = ntohs(h->qdcount); h->ancount = ntohs(h->ancount); h->nscount = ntohs(h->nscount); h->arcount = ntohs(h->arcount); return (0); }
static cList *unpack_list(cBuf *buf, Long *buf_pos) { Int len, i; cList *list; cData *d; len = read_long(buf, buf_pos); if (len == -1) { list = NULL; } else { list = list_new(len); d = list_empty_spaces(list, len); for (i = 0; i < len; i++) unpack_data(buf, buf_pos, d++); } return list; }
int main(){ char *buffer=pack_data(); unmapall(); unpack_data(buffer); char *out = NULL; //const char *argv[]={"cat","/data/local/tmp/a.txt",NULL}; //out=(char*)exec_bbcmd(argv); //printf("%s",out); //free(out); uint32_t out_len; const char *argv2[]={"ls","/data",NULL}; out=(char*)exec_bbcmd(argv2,&out_len); printf("%s",out); free(out); const char *argv3[]={"ifconfig",NULL}; out=(char*)exec_bbcmd(argv3,&out_len); printf("%s",out); free(out); free(buffer); }
static void unpack_vars(cBuf *buf, Long *buf_pos, Obj *obj) { Int i; obj->vars.size = read_long(buf, buf_pos); obj->vars.blanks = read_long(buf, buf_pos); obj->vars.hashtab = EMALLOC(Int, obj->vars.size); obj->vars.tab = EMALLOC(Var, obj->vars.size); for (i = 0; i < obj->vars.size; i++) { obj->vars.hashtab[i] = read_long(buf, buf_pos); obj->vars.tab[i].name = read_ident(buf, buf_pos); if (obj->vars.tab[i].name != NOT_AN_IDENT) { obj->vars.tab[i].cclass = read_long(buf, buf_pos); unpack_data(buf, buf_pos, &obj->vars.tab[i].val); } obj->vars.tab[i].next = read_long(buf, buf_pos); } }
int Imu::get_imu_data(State& imu_data) { //printf("num_fds: %i \n", num_fds); int a = -10; unsigned char sensor_bytes2[(this->data_size)]; //read in data_size bytes of data from port to the address in memory &sensor_bytes2 //result1 indicates success of reading tcflush(port, TCIFLUSH); int result = read(port, &sensor_bytes2[0], data_size); //track dt between reads timer.update(); //check first and last byte if((sensor_bytes2[0] == 0xbd) && (sensor_bytes2[data_size-1] == 0xff) ) { unpack_data(imu_data, sensor_bytes2); a=1; } else { if (result == -1) printf("get_imu_data: FAILED read from port \n"); printf("\n\n\x1b[31mCHECK BYTES WRONG:FLUSHED PORT\x1b[0m\n\n"); tcflush(port, TCIFLUSH); if(!(sensor_bytes2[0]== 0xbd)) {printf("FIRST BYTE WRONG%04x \x1b[0m\n\n", sensor_bytes2[0]); a=-5;} else if(!(sensor_bytes2[data_size-1] == 0xff)) {printf("LAST BYTE WRONG%04x \x1b[0m\n\n", sensor_bytes2[data_size-1]); a=-6;} else a = -1; } return a; }
END_TEST START_TEST(test_decode_query) { char buf[512]; char *domain; struct query q; struct encoder *enc; size_t len; memset(&q, 0, sizeof(struct query)); memset(&buf, 0, sizeof(buf)); q.id = 0; len = sizeof(query_packet) - 1; enc = get_base32_encoder(); dns_decode(buf, sizeof(buf), &q, QR_QUERY, query_packet, len); domain = strstr(q.name, topdomain); len = sizeof(buf); unpack_data((uint8_t *)buf, len, (uint8_t *)(q.name + 1), (int) (domain - q.name) - 1, enc); fail_unless(strncmp(buf, innerData, strlen(innerData)) == 0, "Did not extract expected host: '%s'", buf); fail_unless(strlen(buf) == strlen(innerData), "Bad host length: %d, expected %d: '%s'", strlen(buf), strlen(innerData), buf); }
//////////////////////////////////////////////////////////////////////////////// // //> Name: GetWavMetaData // // Type: Function // // Description: Finds the meta-data within a .wav file. // // Inputs: Ptr to pathname, current device id, ptr to meta-data struct. // // Outputs: RETCODE // // Notes: none //< //////////////////////////////////////////////////////////////////////////////// RETCODE _reentrant GetWavMetaData(INT PackedPathNameAddress, INT btCurrentDevice, FILE_META_DATA * MetaData) { RETCODE rtn = META_DATA_NOT_FOUND; INT iHandle = NOERROR; // indicates the handle of file opened (or error if failure) DWORD dwNumBytesTemp; // stores 48 bits, number of bytes in file DWORD dwAvgBytesPerSec; // average bytes per second WORD wBufferPacked[ADPCM_READ_BUFFER_SIZE]; // read file (packed bytes) into this buffer BYTE btUnpack[ADPCM_READ_BUFFER_SIZE]; // uppack bytes into this buffer _packed BYTE * pcFilePathName = (_packed BYTE*)PackedPathNameAddress; // Open the file. #ifdef USE_PLAYLIST3 if (g_Rebuild == TRUE) iHandle = FSFastOpen(g_FileKey,READ); else { if(g_CurrentSongFastkey==0) { iHandle = FSFileOpen(pcFilePathName, READ, btCurrentDevice); g_CurrentSongFastkey=FgetFastHandle(iHandle); } else iHandle = FSFastOpen(g_CurrentSongFastkey,READ); //if((iHandle = FSFileOpen(pcFilePathName, READ, btCurrentDevice)) != ERROR) } #endif #ifdef USE_PLAYLIST2 iHandle = FSFileOpen(pcFilePathName, READ, btCurrentDevice); #endif #ifdef USE_PLAYLIST5 g_CurrentFastKey = (g_PL5_PL_queue.pos + g_PL5_Playback.currentplay)->file.lFastKey; iHandle = FSFastOpen(g_CurrentFastKey,READ); #endif if(iHandle!= ERROR) { #ifdef USE_PLAYLIST3 if (g_Rebuild == TRUE) { filegetdate(iHandle,CREATION_DATE,&g_dirdate,&g_dirtime); } #endif // Get the number of bytes in song dwNumBytesTemp = FSFileSize(iHandle); MetaData->dwNumBytes = dwNumBytesTemp; // Clear MetaData members that do not apply MetaData->dwNumFrames = (DWORD)0; MetaData->bVBR = (BOOL)0; MetaData->wBitRate = (WORD)0; // Read from start of file if (FSFileRead(20, iHandle, MEM_SPACE_Y, (INT)(-1), wBufferPacked) != ERROR) //read RIFF header { unpack_data((_packed BYTE *)wBufferPacked, btUnpack,20); if ((btUnpack[0]=='R') && (btUnpack[1]=='I') && (btUnpack[2]=='F') && (btUnpack[3]=='F') && (btUnpack[8]=='W') && (btUnpack[9]=='A') && (btUnpack[10]=='V') && (btUnpack[11]=='E') && (btUnpack[12]=='f') && (btUnpack[13]=='m') && (btUnpack[14]=='t') && (btUnpack[15]==' ')) { // success, header is found dwNumBytesTemp = ((DWORD)btUnpack[16] | ((DWORD)btUnpack[17]<<8) | ((DWORD)btUnpack[18]<<16) | ((DWORD)btUnpack[19]<<24)) - 12; MetaData->iResourceNum = -1; // Set Resource Number to -1 if WAV file type NOT supported. if (FSFileRead(12, iHandle, MEM_SPACE_Y, (INT)(-1), wBufferPacked) != ERROR) // read 'fmt ' chunk { unpack_data((_packed BYTE *)wBufferPacked, btUnpack,12); // Identify the file type with the wformattag (2 bytes) switch(((WORD)btUnpack[0])|((WORD)btUnpack[1]<<8)) { case WAVE_FORMAT_ADPCM: MetaData->iFileType = (INT)MS_ADPCM_TYPE; MetaData->iResourceNum = RSRC_DEC_ADPCM_MOD_CODE; break; case WAVE_FORMAT_IMA_ADPCM: MetaData->iFileType = (INT)IMA_ADPCM_TYPE; MetaData->iResourceNum = RSRC_DEC_ADPCM_MOD_CODE; break; case WAVE_FORMAT_PCM: MetaData->iFileType = (INT)PCM_WAV_TYPE; MetaData->iResourceNum = RSRC_DEC_ADPCM_MOD_CODE; break; default: rtn = META_DATA_FILE_NOT_SUPPORTED; } if (rtn != META_DATA_FILE_NOT_SUPPORTED) { // nchannels next 2 bytes MetaData->wNumChannels = ((WORD)btUnpack[2])|((WORD)btUnpack[3]<<8); // Get nsamplespersec MetaData->wSampRate =((WORD)btUnpack[4])|((WORD)btUnpack[5]<<8)|((WORD)btUnpack[6]<<16); // next byte is 00 // next 4 bytes are navgbytespersec dwAvgBytesPerSec = (DWORD)btUnpack[8] | ((DWORD)btUnpack[9]<<8) | ((DWORD)btUnpack[10]<<16) | ((DWORD)btUnpack[11]<<24); // Calculate the song time while (fseek(iHandle,dwNumBytesTemp,SEEK_CUR) != ERROR) // search 'data' chunk { if (FSFileRead(8, iHandle, MEM_SPACE_Y, (INT)(-1), wBufferPacked) != ERROR) { unpack_data((_packed BYTE *)wBufferPacked, btUnpack,8); dwNumBytesTemp = (DWORD)btUnpack[4] | ((DWORD)btUnpack[5]<<8) | ((DWORD)btUnpack[6]<<16) | ((DWORD)btUnpack[7]<<24); if ((btUnpack[0]=='d') && (btUnpack[1]=='a') && (btUnpack[2]=='t') && (btUnpack[3]=='a')) { // 'data' chunk is found MetaData->iTime = (DWORD) dwNumBytesTemp / (DWORD)dwAvgBytesPerSec; // get wave length in seconds rtn = META_DATA_FOUND; break; } } else break; } } } } } else rtn = META_DATA_FILEREAD_ERROR; #ifdef USE_PLAYLIST3 if (g_Rebuild == TRUE) { if ((Fclose(iHandle)) == ERROR) rtn = META_DATA_FILECLOSE_ERROR; } else #endif { if ((FSFileClose(iHandle)) == ERROR) rtn = META_DATA_FILECLOSE_ERROR; } } else rtn = META_DATA_FILEOPEN_ERROR; #ifdef USE_PLAYLIST3 if (g_Rebuild == TRUE) { if(iHandle) { if ((Fclose(iHandle)) == ERROR) rtn = META_DATA_FILECLOSE_ERROR; } } #endif return(rtn); }
static int unpack_in6addr(struct unpack *p, struct in6_addr *a6) { return (unpack_data(p, a6, 16)); }
static int unpack_inaddr(struct unpack *p, struct in_addr *a) { return (unpack_data(p, a, 4)); }
void unpack_data(cBuf *buf, Long *buf_pos, cData *data) { data->type = read_long(buf, buf_pos); switch (data->type) { case INTEGER: data->u.val = read_long(buf, buf_pos); break; case FLOAT: data->u.fval = read_float(buf, buf_pos); break; case STRING: data->u.str = string_unpack(buf, buf_pos); break; case OBJNUM: data->u.objnum = read_long(buf, buf_pos); break; case LIST: data->u.list = unpack_list(buf, buf_pos); break; case SYMBOL: data->u.symbol = read_ident(buf, buf_pos); break; case T_ERROR: data->u.error = read_ident(buf, buf_pos); break; case FROB: data->u.frob = TMALLOC(cFrob, 1); data->u.frob->cclass = read_long(buf, buf_pos); unpack_data(buf, buf_pos, &data->u.frob->rep); break; case DICT: data->u.dict = unpack_dict(buf, buf_pos); break; case BUFFER: { Int len; len = read_long(buf, buf_pos); data->u.buffer = buffer_new(len); data->u.buffer->len = len; MEMCPY(data->u.buffer->s, &(buf->s[*buf_pos]), len); (*buf_pos) += len; break; } #ifdef USE_PARENT_OBJS case OBJECT: break; #endif default: { INSTANCE_RECORD(data->type, r); r->unpack(buf, buf_pos, data); } } }