]> git.siccegge.de Git - frida/frida.git/commitdiff
Pass the InformationManager inside the BasicBlock and Function classes
authorChristoph Egger <Christoph.Egger@fau.de>
Fri, 20 Feb 2015 16:34:23 +0000 (17:34 +0100)
committerChristoph Egger <Christoph.Egger@fau.de>
Fri, 20 Feb 2015 16:34:23 +0000 (17:34 +0100)
All models should know the InformationManager so we can forward changes
to any kind of information to the manager, who then is responsible to
update all stakeholders of this information

src/core/BasicBlock.hxx
src/core/Function.hxx
src/disassembler/llvm/LLVMDisassembler.cxx

index 0a759bf4d85875a2f153e14ba5cd4556d49f8c1b..9018b5b56aa8172d10d66e8f4248aeb9bb87de57 100644 (file)
@@ -6,12 +6,15 @@
 #include <sstream>
 
 class Disassembler;
+class InformationManager;
 
 class BasicBlock {
 public:
-       BasicBlock(uint64_t start_address, Disassembler * disassembler)
+       BasicBlock(uint64_t start_address, Disassembler * disassembler,
+                  InformationManager* manager)
                : start_address(start_address)
-               , disassembler(disassembler) {
+               , disassembler(disassembler)
+               , manager(manager) {
                next_blocks[0] = 0;
                next_blocks[1] = 0;
        }
@@ -52,10 +55,14 @@ public:
                return disassembler;
        }
 
+       InformationManager* getManager() const {
+               return manager;
+       }
 private:
        uint64_t start_address;
        uint64_t end_address;
        Disassembler* disassembler;
+       InformationManager* manager;
        uint64_t next_blocks[2];
 };
 
index 3c8f799543c8d3acb5901951a64cf9bb96246e74..f4fa90e1e429eeaf9928896b454906226ce3e223 100644 (file)
@@ -4,12 +4,15 @@
 #include <map>
 #include "BasicBlock.hxx"
 
+class InformationManager;
+
 class Function {
 public:
-       Function(const std::string& name, uint64_t start_address)
+       Function(const std::string& name, uint64_t start_address,
+                InformationManager* manager)
                : name(name)
-               , start_address(start_address) {
-       }
+               , start_address(start_address)
+               ,manager(manager) {}
 
        uint64_t getStartAddress() const {
                return start_address;
@@ -19,6 +22,10 @@ public:
                return name;
        }
 
+       InformationManager* getManager() const {
+               return manager;
+       }
+
        void addBasicBlock(BasicBlock* block) {
                _blocks.insert(std::make_pair(block->getStartAddress(), block));
        }
@@ -29,6 +36,7 @@ public:
 private:
        std::string name;
        uint64_t start_address;
+       InformationManager * manager;
        std::map<uint64_t, BasicBlock*> _blocks;
 };
 
index 1d4f2dff725064ecb64dd6cfd7a8d6c0de68d766..b6f8dae75ae2d6cc33b2586bc2b45df68b899eec 100644 (file)
@@ -192,9 +192,9 @@ Function* LLVMDisassembler<ELFT>::disassembleFunctionAt(uint64_t address, const
        if (name == "") {
                std::stringstream s;
                s << "<Unnamed 0x" << std::hex << address << ">";
-               function = new Function(s.str(), address);
+               function = new Function(s.str(), address, manager);
        } else {
-               function = new Function(name, address);
+               function = new Function(name, address, manager);
        }
        functions.insert(std::make_pair(address, function));
 
@@ -213,7 +213,7 @@ void LLVMDisassembler<ELFT>::disassembleFunction(Function* function) {
 
        LOG4CXX_DEBUG(logger, "Handling function " << function->getName());
 
-       BasicBlock * block = new BasicBlock(function->getStartAddress(), this);
+       BasicBlock * block = new BasicBlock(function->getStartAddress(), this, manager);
        remaining_blocks.push(block);
        blocks.insert(std::make_pair(block->getStartAddress(), block));
        function->addBasicBlock(block);
@@ -247,7 +247,7 @@ void LLVMDisassembler<ELFT>::disassembleFunction(Function* function) {
                                                } else {
                                                        current_block->setNextBlock(0, jmptarget);
                                                        if (blocks.find(jmptarget) == blocks.end()) {
-                                                               BasicBlock * block = new BasicBlock(jmptarget, this);
+                                                               BasicBlock * block = new BasicBlock(jmptarget, this, manager);
                                                                blocks.insert(std::make_pair(block->getStartAddress(), block));
                                                                function->addBasicBlock(block);
                                                                remaining_blocks.push(block);
@@ -259,7 +259,7 @@ void LLVMDisassembler<ELFT>::disassembleFunction(Function* function) {
                                                                jmptarget = base_address + current_address + inst_size;
                                                                current_block->setNextBlock(1, jmptarget);
                                                                if (blocks.find(jmptarget) == blocks.end()) {
-                                                                       BasicBlock * block = new BasicBlock(jmptarget, this);
+                                                                       BasicBlock * block = new BasicBlock(jmptarget, this, manager);
                                                                        blocks.insert(std::make_pair(block->getStartAddress(), block));
                                                                        function->addBasicBlock(block);
                                                                        remaining_blocks.push(block);
@@ -310,7 +310,7 @@ void LLVMDisassembler<ELFT>::disassemble() {
                        continue;
 
                if (!x->second.getAddress(result)) {
-                       Function * fun = new Function(x->first, result);
+                       Function * fun = new Function(x->first, result, manager);
                        remaining_functions.push_back(fun);
                        functions.insert(std::make_pair(result, fun));
                        LOG4CXX_DEBUG(logger, "Disasembling " << x->first);