void processEntry(WorkSpace *ws, address_t address) { ASSERT(ws); ASSERT(address); // Initialize the queue VectorQueue<Inst *> todo(1024); Inst *inst = getInst(workspace(), address); if(!inst) { cerr << "ERROR: bad function entry at " << address << io::endl; return; } todo.put(inst); // Repeat until there is no more address to explore while(!todo.isEmpty()) { // Get the next instruction Inst *first_inst = todo.get(); if(!first_inst) continue; if(isVerbose()) cerr << "starting from " << first_inst->address() << io::endl; inst = first_inst; // Follow the instruction until a branch address_t next; while(inst && !MARKER(inst)) { if(isVerbose()) { cerr << "process " << inst->address() << " : "; writeBytes(cerr, inst->address(), inst->size()); cerr << ": " << inst << io::endl; } if(inst->isControl()) break; next = inst->topAddress(); inst = getInst(ws, next, inst); } // mark the block if(isVerbose()) cerr << "end found\n"; if(!inst) { cerr << "WARNING: unknown instruction at " << next << io::endl; continue; } bool marker_found = MARKER(inst); MARKER(first_inst) = true; if(marker_found) continue; // Record target and next if(inst->isConditional()) { if(isVerbose()) cerr << "put(" << inst->topAddress() << ")" << io::endl; Inst *ti = getInst(ws, inst->topAddress(), inst); if(!ti) cerr << "ERROR: broken sequence from " << inst->address() << " to " << inst->topAddress() << io::endl; else { FROM(ti).add(first_inst); todo.put(ti); } } if(!inst->isReturn() && !IS_RETURN(inst)) { Inst *target = 0; try { target = inst->target(); if(!target) continue; } catch(ProcessException& e) { cerr << "WARNING: " << e.message() << ": the branched code will not be decoded\n"; } if(target && !NO_CALL(target)) { if(isVerbose()) cerr << "put(" << target->address() << ")\n"; FROM(target).add(first_inst); todo.put(target); } else if(!target) { bool one = false; for(Identifier<Address>::Getter target(inst, BRANCH_TARGET); target; target++) { one = true; Inst *ti = getInst(ws, target, inst); if(!ti) { cerr << "ERROR: broken target from " << inst->address() << " to " << *target << io::endl; continue; } FROM(ti).add(first_inst); todo.put(ti); if(isVerbose()) cerr << "put(" << target << ")\n"; } if(!one) cerr << "WARNING: no target for branch at " << inst->address() << io::endl; } if(inst->isCall() && (!target || !NO_RETURN(target))) { if(isVerbose()) cerr << "put(" << inst->topAddress() << ")\n"; Inst *ti = getInst(ws, inst->topAddress(), inst); if(!ti) { cerr << "ERROR: broken target from " << inst->address() << " to " << *target << io::endl; continue; } FROM(ti).add(first_inst); todo.put(ti); } } } }