void print_vine_ir(asm_program_t *prog, vector<vine_block_t *> vblocks ) { unsigned int i, j; for ( i = 0; i < vblocks.size(); i++ ) { vine_block_t *block = vblocks.at(i); assert(block); vector<Stmt *> *inner = block->vine_ir; // cout << "Vine Block " << i << endl; cout << " {" << endl; // declvis vis; // vis.compute(inner); // print_decls(vis.decls); // cout << " "; ostringstream os; ostream_insn(prog, block->inst, os); cout << " // " << os.str() << endl; vector<VarDecl *> globals = get_reg_decls(); map<string,reg_t> context; for(vector<VarDecl *>::const_iterator gi = globals.begin(); gi != globals.end(); gi++){ VarDecl *vd = *gi; context.insert(pair<string, reg_t>(vd->name, vd->typ)); } for ( j = 0; j < inner->size(); j++ ) { #ifdef TYPECHECKING try { if (typecheck_stmt(&context, inner->at(j)) < 0) { cout <<"Type error found at:" <<endl; } } catch (TypeError &e) { cout <<"Type Error: " << e.what() <<endl; cout <<"Found at:" <<endl; } #endif Stmt *s = inner->at(j); cout << " " << s->tostring(); // if(s->stmt_type == LABEL) // cout << endl; // else // cout << ";" << endl; cout << endl; } cout << " }" << endl; } }
void print_merged_ir( vector<Stmt *> ir ) { unsigned int i; for ( i = 0; i < ir.size(); i++ ) { Stmt *stmt = ir.at(i); assert(stmt); cout << stmt->ir_address << "\t\t" << stmt->tostring() << endl; } }
void print_globals(){ vector<VarDecl *> globals = get_reg_decls(); for(vector<VarDecl *>::const_iterator it = globals.begin(); it != globals.end(); it++){ VarDecl *s = *it; cout << s->tostring() << endl; } cout << "var mem:reg8_t[reg32_t];" << endl; vector<Stmt *> helpers = gen_eflags_helpers(); for(vector<Stmt *>::const_iterator it = helpers.begin(); it != helpers.end(); it++){ Stmt *s = *it; cout << s->tostring() << endl; } }
void CReilFromBilTranslator::process_bil(reil_raw_t *raw_info, bap_block_t *block) { int size = block->bap_ir->size(); reset_state(block); if (raw_info) { current_raw_info = raw_info; } log_write(LOG_BIL, "BAP {"); for (int i = 0; i < size; i++) { // enumerate BIL statements Stmt *s = block->bap_ir->at(i); log_write(LOG_BIL, " %s", s->tostring().c_str()); } if (is_unknown_insn(block)) { log_write(LOG_BIL, " // %.8llx was not translated", raw_info->addr); // add metainformation about unknown instruction into the code process_unknown_insn(); goto _end; } for (int i = 0; i < size; i++) { current_stmt = i; // enumerate BIL statements Stmt *s = block->bap_ir->at(i); uint64_t inst_flags = IOPT_ASM_END; for (int n = i + 1; n < size; n++) { // check for last IR instruction Stmt *s_next = block->bap_ir->at(n); if (s_next->stmt_type == MOVE || s_next->stmt_type == CJMP || s_next->stmt_type == JMP) { inst_flags = 0; break; } } if (i < size - 1) { Stmt *s_next = block->bap_ir->at(i + 1); // check for the special statement that following current if (s_next->stmt_type == SPECIAL) { Special *special = (Special *)s_next; // translate special statement to the REIL instruction options inst_flags |= convert_special(special); } } // convert statement to REIL code process_bil_stmt(s, inst_flags); } if (inst_count == 0) { // add I_NONE process_empty_insn(); } _end: if (inst_handler) { vector<reil_inst_t *>::iterator it; // enumerate translated instructions for (it = translated_insts.begin(); it != translated_insts.end(); ++it) { reil_inst_t *reil_inst = *it; // check for JCC with label if (reil_inst->op == I_JCC && reil_inst->c.type == A_LOC && strlen(reil_inst->c.name) > 0) { vector<BAP_LABEL *>::iterator it_l; bool label_found = false; // find label by name for (it_l = translated_labels.begin(); it_l != translated_labels.end(); ++it_l) { BAP_LABEL *label = *it_l; if (!strcmp(reil_inst->c.name, label->first.c_str())) { reil_inst->c.val = label->second.first; reil_inst->c.inum = label->second.second; memset(reil_inst->c.name, 0, MAX_REG_NAME_LEN); label_found = true; break; } } reil_assert(label_found, "unresolved label"); } } // enumerate translated instructions for (it = translated_insts.begin(); it != translated_insts.end(); ++it) { reil_inst_t *reil_inst = *it; // call user-specified REIL instruction handler inst_handler(reil_inst, inst_handler_context); } } log_write(LOG_BIL, "}"); // cleanup reset_state(NULL); return; }
void CReilFromBilTranslator::process_bil(reil_raw_t *raw_info, bap_block_t *block) { int size = block->bap_ir->size(); reset_state(block); if (raw_info) { current_raw_info = raw_info; } log_write(LOG_BIL, "BAP {"); for (int i = 0; i < size; i++) { // enumerate BIL statements Stmt *s = block->bap_ir->at(i); log_write(LOG_BIL, " %s", s->tostring().c_str()); } if (is_unknown_insn(block)) { log_write(LOG_BIL, " // %.8llx was not translated", raw_info->addr); // add metainformation about unknown instruction into the code process_unknown_insn(); goto _end; } for (int i = 0; i < size; i++) { current_stmt = i; // enumerate BIL statements Stmt *s = block->bap_ir->at(i); uint64_t inst_flags = IOPT_ASM_END; for (int n = i + 1; n < size; n++) { // check for last IR instruction Stmt *s_next = block->bap_ir->at(n); if (s_next->stmt_type == MOVE || s_next->stmt_type == CJMP || s_next->stmt_type == JMP) { inst_flags = 0; break; } } if (i < size - 1) { // check for the special statement that following current Stmt *s_next = block->bap_ir->at(i + 1); if (s_next->stmt_type == SPECIAL) { Special *special = (Special *)s_next; // translate special statement to the REIL instruction options inst_flags |= convert_special(special); } } // convert statement to REIL code process_bil_stmt(s, inst_flags); } if (inst_count == 0) { // add I_NONE process_empty_insn(); } _end: log_write(LOG_BIL, "}"); return; }