bool java_method_code_parse(FILE *input, java_code *code) { if(!( fread_uint16(input, &(code->max_stack)) && fread_uint16(input, &(code->max_locals)) && fread_uint32(input, &(code->code_length)) )) { return false; } code->bytecode = (uint8_t*)malloc(code->code_length+1); if(!code->bytecode) { return false; } if(fread(code->bytecode, 1, code->code_length, input) != code->code_length) { return false; } code->bytecode[code->code_length] = 0xff; if(!fread_uint16(input, &(code->exception_handlers_count))) { return false; } code->exception_handlers = (java_exception_handler**)malloc(sizeof(java_exception_handler*)*code->exception_handlers_count); if(!code->exception_handlers) { return false; } int i; for(i = 0; i < code->exception_handlers_count; i++) { code->exception_handlers[i] = (java_exception_handler*)malloc(sizeof(java_exception_handler)); if(!code->exception_handlers[i]) { return false; } if(!java_method_code_exception_handler_parse(input, code->exception_handlers[i])) { return false;} } return true; }
bool java_attribute_skip(FILE *input, bool no_index) { uint32_t length = 0; long initial_pos = ftell(input); if(!( ( no_index || (fseek(input, 2, SEEK_CUR) == 0)) && fread_uint32(input, &length) && (fseek(input, length, SEEK_CUR) == 0) )) { fseek(input, initial_pos, SEEK_SET); return false; } return true; }
static void load_tzdata(void) { char *path = str_printf("%r" SEP_S "data" SEP_S "tzdata.dat", fs->fox_home); FileHandle fh = open_fox(path, O_RDONLY, DEFAULT_PERMISSION); int32_t size; char *tzdata_names; int i; if (fh == -1) { fatal_errorf("Cannot load file %q", path); } free(path); tzdata_size = fread_uint32(fh); if (tzdata_size <= 0 || tzdata_size > fs->max_alloc / sizeof(TZData)) { goto ERROR_END; } tzdata = Mem_get(&fg->st_mem, tzdata_size * sizeof(TZData)); for (i = 0; i < tzdata_size; i++) { TZData *p = &tzdata[i]; p->u1.index = fread_uint32(fh); p->u2.index = fread_uint32(fh); } size = fread_uint32(fh); if (size <= 0 || size > fs->max_alloc) { goto ERROR_END; } tzdata_names = fread_buffer(fh, size, &fg->st_mem); size = fread_uint32(fh); if (size <= 0 || size > fs->max_alloc / sizeof(TZDataAlias)) { goto ERROR_END; } tzdata_alias = Mem_get(&fg->st_mem, size * sizeof(TZDataAlias)); for (i = 0; i < size; i++) { TZDataAlias *p = &tzdata_alias[i]; p->tz = NULL; p->index = fread_uint32(fh); } size = fread_uint32(fh); if (size <= 0 || size > fs->max_alloc) { goto ERROR_END; } tzdata_abbr = fread_buffer(fh, size, &fg->st_mem); size = fread_uint32(fh); if (size <= 0 || size > fs->max_alloc) { goto ERROR_END; } tzdata_line = fread_buffer(fh, size * 4, &fg->st_mem); size = fread_uint32(fh); if (size <= 0 || size > fs->max_alloc) { goto ERROR_END; } tzdata_data = fread_buffer(fh, size, &fg->st_mem); for (i = 0; i < tzdata_size; i++) { TZData *p = &tzdata[i]; p->u1.name = tzdata_names + p->u1.index; p->u2.alias = tzdata_alias + p->u2.index; } close_fox(fh); return; ERROR_END: fatal_errorf("Failed to load tzdata"); }