tid_t type_builder_t::get_structure(const qstring name) { tid_t struct_type_id = add_struc(BADADDR, name.c_str()); if (struct_type_id != 0 || struct_type_id != -1) { struc_t * struc = get_struc(struct_type_id); if(struc != NULL) { opinfo_t opinfo; opinfo.tid = struct_type_id; int j = 0; for(std::map<int, struct_filed>::iterator i = structure.begin(); i != structure.end() ; i ++) { VTBL_info_t vtbl; flags_t member_flgs = 0; if(i->second.size == 1) member_flgs = byteflag(); else if (i->second.size == 2) member_flgs = wordflag(); else if (i->second.size == 4) member_flgs = dwrdflag(); else if (i->second.size == 8) member_flgs = qwrdflag(); char field_name[258]; memset(field_name, 0x00, sizeof(field_name)); if((i->second.vftbl != BADADDR) && get_vbtbl_by_ea(i->second.vftbl, vtbl)) { qstring vftbl_name = name; vftbl_name.cat_sprnt("_VTABLE_%X_%p", i->second.offset, i->second.vftbl); tid_t vtbl_str_id = create_vtbl_struct(vtbl.ea_begin, vtbl.ea_end, (char *)vftbl_name.c_str(), 0); if (vtbl_str_id != BADADDR) { sprintf_s(field_name, sizeof(field_name), "vftbl_%d_%p", j, i->second.vftbl); int iRet = add_struc_member(struc, field_name, i->second.offset, member_flgs, NULL, i->second.size); member_t * membr = get_member_by_name(struc, field_name); if (membr != NULL) { tinfo_t new_type = create_typedef((char *)vftbl_name.c_str()); if(new_type.is_correct()) { smt_code_t dd = set_member_tinfo2(struc, membr, 0, make_pointer(new_type), SET_MEMTI_COMPATIBLE); } } } } else { sprintf_s(field_name, sizeof(field_name), "field_%X", i->second.offset); int iRet = add_struc_member(struc, field_name, i->second.offset, member_flgs, NULL, i->second.size); } j ++; } } } return struct_type_id; }
ikptr ikrt_opendir(ikptr dirname, ikpcb* pcb){ DIR* d = opendir((char*)(dirname+off_bytevector_data)); if(d == NULL){ return ik_errno_to_code(); } return(make_pointer((long)d, pcb)); }
char getKey() { char* port_ptr = make_pointer(PORT_ADDR(CONFIG_KEYPAD_OUT_PORT)); volatile char* pin_ptr = make_pointer(CONFIG_KEYPAD_OUT_PORT); char col = 0, row = 0; for(col = 0; col < 4; col++) { add_to_port(PORT_ADDR(CONFIG_KEYPAD_OUT_PORT), 0xf0); subtract_from_port(PORT_ADDR(CONFIG_KEYPAD_OUT_PORT), (1 << col) << 4); _delay_ms(1); row = *(pin_ptr) & 0x0f; if(row != 0x0f) { while((*(pin_ptr) & 0x0f) != 0x0F); break; } } if(col < 4) { row = getRowIndex(row); return keymap[row][col]; } return '\0'; }
static ikptr ffi_to_scheme_value_cast(int n, void* p, ikpcb* pcb) { switch (n & 0xF) { case 1: return void_object; case 2: return u_to_number(*((unsigned char*)p), pcb); case 3: return s_to_number(*((signed char*)p), pcb); case 4: return u_to_number(*((unsigned short*)p), pcb); case 5: return s_to_number(*((signed short*)p), pcb); case 6: return u_to_number(*((unsigned int*)p), pcb); case 7: return s_to_number(*((signed int*)p), pcb); case 8: return u_to_number(*((unsigned long*)p), pcb); case 9: return s_to_number(*((signed long*)p), pcb); case 10: return ull_to_number(*((unsigned long long*)p), pcb); case 11: return sll_to_number(*((signed long long*)p), pcb); case 12: return d_to_number(*((float*)p), pcb); case 13: return d_to_number(*((double*)p), pcb); case 14: return make_pointer((long)*((void**)p), pcb); default: fprintf(stderr, "INVALID ARG %d", n); exit(-1); } }
bool idaapi reconstruct_type(void *ud) { vdui_t &vu = *(vdui_t *)ud; // Determine the ctree item to highlight vu.get_current_item(USE_KEYBOARD); citem_t *highlight = vu.item.is_citem() ? vu.item.e : NULL; // highlight == NULL might happen if one chooses variable at local variables declaration statement if(highlight != NULL) { // the chosen item must be an expression and of 'variable' type if(highlight->is_expr() && (highlight->op == cot_var)) { cexpr_t *highl_expr = (cexpr_t *)highlight; // initialize type rebuilder type_builder_t type_bldr; type_bldr.highl_expr = highl_expr; char highl_expr_name[MAXSTR]; highl_expr->print1(highl_expr_name, MAXSTR, NULL); tag_remove(highl_expr_name, highl_expr_name, 0); type_bldr.expression_to_match.push_back(highl_expr_name); // traverse the ctree structure type_bldr.apply_to(&vu.cfunc->body, NULL); if (type_bldr.structure.size() != 0) { qstring struct_name = "struct_name"; va_list va; va_end(va); // ask a user for the new type name char * type_name = vaskstr(0, struct_name.c_str(), "Enter type name", va); if(type_name != NULL) { // add type to the idb tid_t struct_type_id = type_bldr.get_structure(type_name); if(struct_type_id != 0 || struct_type_id != -1) { // print new type definition tinfo_t new_type = create_typedef(type_name); if(new_type.is_correct()) { qstring type_str; qstring pref = "New type created:\r\n"; if (new_type.print(&type_str, NULL, PRTYPE_DEF | PRTYPE_MULTI)) msg((pref + type_str).c_str()); // update type of the highlighted expression in the decompiler window lvar_t * lvar = vu.item.get_lvar(); vu.set_lvar_type(lvar, make_pointer(new_type)); vu.refresh_ctext(); } } } } else { warning("Failed to reconstruct type, no field references have been found..."); } } } else { msg("Invalid item is choosen"); } return true; }
bool idaapi reconstruct_type(void *ud) { vdui_t &vu = *(vdui_t *)ud; // Determine the ctree item to highlight vu.get_current_item(USE_KEYBOARD); citem_t *highlight = vu.item.is_citem() ? vu.item.e : NULL; // highlight == NULL might happen if one chooses variable at local variables declaration statement if (highlight != NULL) { // the chosen item must be an expression and of 'variable' type if (highlight->is_expr() && (highlight->op == cot_var)) { cexpr_t *highl_expr = (cexpr_t *)highlight; // initialize type rebuilder type_builder_t type_bldr; char highl_expr_name[MAXSTR]; highl_expr->print1(highl_expr_name, sizeof(highl_expr_name), NULL); tag_remove(highl_expr_name, highl_expr_name, sizeof(highl_expr_name)); type_bldr.expression_to_match.push_back(highl_expr_name); // traverse the ctree structure type_bldr.apply_to(&vu.cfunc->body, NULL); // get local var information lvar_t *lvar = vu.item.get_lvar(); if (!type_bldr.structure.empty() && lvar != NULL) { qstring type_name{ "struct_name" }; askqstr(&type_name, "Enter type name:"); if (!type_name.empty()) { tid_t struct_type_id = type_bldr.get_structure(type_name.c_str()); if (struct_type_id != 0 || struct_type_id != -1) { tinfo_t new_type = create_typedef(type_name.c_str()); if (new_type.is_correct()) { qstring type_str; if (new_type.print(&type_str, NULL, PRTYPE_DEF | PRTYPE_MULTI)) { msg("New type created:\r\n%s", type_str.c_str()); logmsg(DEBUG, ("New type created:\r\n%s", type_str.c_str())); lvar_t *lvar = vu.item.get_lvar(); tinfo_t ptype = make_pointer(new_type); vu.set_lvar_type(lvar, ptype); vu.refresh_ctext(); return true; } } } } } else { warning("Failed to reconstruct type, no field references have been found ..."); logmsg(DEBUG, "Failed to reconstruct type, no field references have been found ..."); return false; } } } else { warning("Invalid item is chosen ..."); logmsg(DEBUG, "Invalid item is chosen"); return false; } }
inline ndt::type make_pointer() { return make_pointer(ndt::make_type<Tnative>()); }