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; highl_expr->print1(type_bldr.highl_expr_name, MAXSTR, NULL); tag_remove(type_bldr.highl_expr_name, type_bldr.highl_expr_name, 0); // traverse the ctree structure type_bldr.apply_to(&vu.cfunc->body, NULL); tid_t struct_type_id = type_bldr.get_structure(NULL); if(struct_type_id != 0 || struct_type_id != -1) { qstring struct_name; struct_name = get_struc_name(struct_type_id); va_list va; va_end(va); char * type_name = vaskstr(0, struct_name.c_str(), "Enter type name", va); if(type_name != NULL) { set_struc_name(struct_type_id, type_name); // get the structure description char buffr[MAXSTR*10]; type_bldr.get_structure(type_name, buffr, sizeof(buffr)); msg("%s", buffr); } } } } else { msg("Invalid item is choosen"); } return true; }
bool idaapi extract_all_ctrees(void *ud) { // default prefix to display in the dialog qstring default_prefix = "crypto_"; va_list va; va_end(va); char * crypto_prefix = vaskstr(0, default_prefix.c_str(), "Enter prefix of crypto function names", va); if((crypto_prefix != NULL) && (strlen(crypto_prefix) > 0)) { qstring qcrypt_prefix = crypto_prefix; dump_funcs_ctree(NULL, qcrypt_prefix); } else { warning("Incorrect prefix!!"); } 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; 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; }