vine_blocks_t * asmir_asmprogram_to_vine(asm_program_t *prog) { vector<vine_block_t *> *res = new vector<vine_block_t *>(); // eww, references *res = generate_vex_ir(prog); generate_vine_ir(prog, *res); return res; }
vine_blocks_t *instmap_translate_address_range(instmap_t *insts, address_t start, address_t end) { translate_init(); vx_FreeAll(); vector<Instruction *> foo; vine_blocks_t *ret = new vine_blocks_t; for(address_t i = start; i <= end; i++){ if(insts->imap.find(i) == insts->imap.end()) continue; foo.push_back(insts->imap.find(i)->second); } vector<vine_block_t *> blocks = generate_vex_ir(insts->prog, foo); blocks = generate_vine_ir(insts->prog, blocks); for(unsigned i = 0; i < blocks.size(); i++){ vine_block_t *block = blocks.at(i); assert(block); if(block->inst == NULL) continue; /* This is broken as it removes the jumps from the end of repz instructions. Just because control flow eventually goes on to the following instruction doesn't mean that jump is at the end. It should simply be checking that the jump is to the following instruction since we know where that is. // If the statement isn't control flow, and not the last // remove the dummy jumps to the next block that vex inserts bfd_vma target; int ctype = get_control_transfer_type(block->inst, &target); Stmt *s; switch(ctype){ case INST_CONT: s = block->vine_ir->back(); if(s->stmt_type == JMP){ block->vine_ir->pop_back(); } break; default: break; } */ } ret->insert(ret->end(), blocks.begin(), blocks.end()); for(vector<vine_block_t *>::iterator it = ret->begin(); it != ret->end(); it++){ vine_block_t *block = *it; block->vex_ir = NULL; // this isn't available. } return ret; }
// moved from ir_program.cpp vine_block_t* asm_addr_to_ir(asm_program_t *p, address_t addr) { translate_init(); asm_function_t *f = get_nearest_function(p, addr); assert(f); assert(f->instmap.find(addr) != f->instmap.end()); Instruction *inst = f->instmap.find(addr)->second; vector<Instruction *> instrs; instrs.push_back(inst); vector<vine_block_t *> vine_blocks = generate_vex_ir(p, instrs); vine_blocks = generate_vine_ir(p, vine_blocks); vx_FreeAll(); assert(vine_blocks.size() == 1); return vine_blocks[0]; }
vine_block_t *instmap_translate_address(instmap_t *insts, address_t addr) { translate_init(); vx_FreeAll(); vector<Instruction *> foo; assert(insts->imap.find(addr) != insts->imap.end()); foo.push_back(insts->imap.find(addr)->second); vector<vine_block_t *> blocks = generate_vex_ir(insts->prog, foo); blocks = generate_vine_ir(insts->prog, blocks); assert(blocks.size() == 1); vine_block_t *block = *(blocks.begin()); block->vex_ir = NULL; vx_FreeAll(); return block; }
// moved from ir_program.cpp bap_block_t* asmir_addr_to_bap(asm_program_t *p, address_t addr, address_t *next) { // Set longjmp to handle possible VEX errors jmp_buf_set = 1; if (setjmp(vex_error) != 0) { /* There was an exception */ jmp_buf_set = 0; cerr << "There was an exception in asmir_addr_to_bap" << endl; return NULL; } translate_init(); bap_block_t * bap_block = generate_vex_ir(p, addr); generate_bap_ir_block(p, bap_block); if (next) *next = addr + asmir_get_instr_length(p, addr); return bap_block; }