]> git.siccegge.de Git - frida/frida.git/blobdiff - src/disassembler/llvm/LLVMDisassembler.cxx
Fix startup if no binary is specified on the commandline
[frida/frida.git] / src / disassembler / llvm / LLVMDisassembler.cxx
index 1f92ab04410624c1a3ede4957234e2ad21cb0671..cf40aaa7ec882fbcd76d09645ca88740a8071231 100644 (file)
@@ -13,6 +13,9 @@ using std::error_code;
  *
  */
 Disassembler * createLLVMDisassembler(const std::string& filename, InformationManager* manager) {
+       if (filename == "")
+               return NULL;
+
        std::unique_ptr<Binary> o;
        o.reset(createBinary(filename).get());
        const Binary * op = o.get();
@@ -316,20 +319,19 @@ void LLVMDisassembler<ELFT>::disassemble() {
        if (binary->isELF()) {
                bool is64bit = (binary->getData()[4] == 0x02);
 
-               uint64_t entry(0);
                for (int i(0); i < (is64bit? 8 : 4); ++i) {
                        if (binary->isLittleEndian()) {
-                               entry |= (unsigned int)((unsigned char)binary->getData()[0x18 + i]) << 8*i;
+                               _entryAddress |= (unsigned int)((unsigned char)binary->getData()[0x18 + i]) << 8*i;
                        } else {
-                               entry = entry << 8;
-                               entry |= (unsigned char)binary->getData()[0x18 + i];
+                               _entryAddress = _entryAddress << 8;
+                               _entryAddress |= (unsigned char)binary->getData()[0x18 + i];
                        }
                }
-               LOG4CXX_DEBUG(logger, "Adding entry at: " << std::hex << entry);
+               LOG4CXX_DEBUG(logger, "Adding entryAddress at: " << std::hex << _entryAddress);
                std::stringstream s;
-               s << "<_start 0x" << std::hex << entry << ">";
+               s << "<_start 0x" << std::hex << _entryAddress << ">";
 
-               disassembleFunctionAt(entry, s.str());
+               disassembleFunctionAt(_entryAddress, s.str());
        }
 
        if (functions.empty()) {
@@ -430,8 +432,9 @@ void LLVMDisassembler<ELFT>::forEachFunction(std::function<void (uint64_t, Funct
 
 template <typename ELFT>
 void LLVMDisassembler<ELFT>::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&,
+                                                                         const std::string&)> fun) {
        SectionRef text_section = sections[".text"];
        uint64_t base_address;
        text_section.getAddress(base_address);
@@ -454,17 +457,24 @@ void LLVMDisassembler<ELFT>::printEachInstruction(uint64_t start, uint64_t end,
                        ref.readBytes(current_address, inst_size, bytes);
 
                        uint64_t jmptarget;
+                       std::string ref("");
+                       IP->printInst(&inst, s, "");
                        if (MIA->evaluateBranch(inst, current_address, inst_size, jmptarget)) {
                                std::stringstream stream;
+                               if (MIA->isCall(inst))
+                                       stream << "function:";
+                               else
+                                       stream << "block:";
+
                                stream << std::hex << (base_address + jmptarget);
-                               IP->printInst(&inst, s, stream.str());
-                       } else
-                               IP->printInst(&inst, s, "");
+                               ref = stream.str();
+                       }
+
 
-                       fun(bytes, inst_size, s.str());
+                       fun(bytes, inst_size, s.str(), ref);
                } else {
                        LOG4CXX_WARN(logger, "Invalid byte at" << std::hex << current_address + base_address);
-                       fun(NULL, 0, "Invalid Byte");
+                       fun(NULL, 0, "Invalid Byte", "");
                        inst_size = 1;
                }