text_section.getAddress(base_address);
text_section.getSize(size);
- if (address < base_address ||
+ if (address < base_address ||
address >= base_address + size) {
return NULL;
}
LLVMBasicBlock * block = new LLVMBasicBlock(function->getStartAddress(), this);
remaining_blocks.push(block);
blocks.insert(std::make_pair(block->getStartAddress(), block));
+ function->addBasicBlock(block);
while (remaining_blocks.size()) {
LLVMBasicBlock * current_block = remaining_blocks.top();
if (blocks.find(jmptarget) == blocks.end()) {
LLVMBasicBlock * block = new LLVMBasicBlock(jmptarget, this);
blocks.insert(std::make_pair(block->getStartAddress(), block));
+ function->addBasicBlock(block);
remaining_blocks.push(block);
}
if (MIA->isConditionalBranch(inst)) {
if (blocks.find(jmptarget) == blocks.end()) {
LLVMBasicBlock * block = new LLVMBasicBlock(jmptarget, this);
blocks.insert(std::make_pair(block->getStartAddress(), block));
+ function->addBasicBlock(block);
remaining_blocks.push(block);
}
}
current_address += inst_size;
}
}
+ splitBlocks(function);
LOG4CXX_DEBUG(logger, "Finished function " << function->getName());
manager->signal_new_function(function);
}
LOG4CXX_INFO(logger, "No Symbols found, starting at the beginning of the text segment");
disassembleFunctionAt(text_entry);
}
-
- splitBlocks();
}
-void LLVMDisassembler::splitBlocks() {
+void LLVMDisassembler::splitBlocks(LLVMFunction* function) {
SectionRef text_section = sections[".text"];
StringRef bytes;
text_section.getContents(bytes);
StringRefMemoryObject ref(bytes);
// Split blocks where jumps are going inside the block
- for (auto it = blocks.begin(); it != blocks.end(); ++it) {
- LLVMBasicBlock * current_block = it->second;
+ for (auto it = function->blocks().begin();
+ it != function->blocks().end();
+ ++it) {
+ BasicBlock * current_block = it->second;
uint64_t inst_size;
uint64_t base_address;
text_section.getAddress(base_address);
if(llvm::MCDisassembler::Success ==
DisAsm->getInstruction(inst, inst_size, ref, current_address, nulls(), nulls())) {
+ // See if some other block starts here
auto other = blocks.find(current_address + inst_size + base_address);
+ // Special case, other block starts here but we are at the end anyway
if (other != blocks.end()) {
uint64_t endaddress = current_address + inst_size + base_address;
if (endaddress != current_block->getEndAddress()) {
}
void LLVMDisassembler::printEachInstruction(uint64_t start, uint64_t end,
- std::function<void (uint8_t*, size_t, const std::string&)> fun) {
+ std::function<void (uint8_t*, size_t,
+ const std::string&)> fun) {
SectionRef text_section = sections[".text"];
uint64_t base_address;
text_section.getAddress(base_address);