]> git.siccegge.de Git - frida/frida.git/commitdiff
Implement InformationManager / Comment and ChangeCommentEvent
authorChristoph Egger <Christoph.Egger@fau.de>
Fri, 20 Mar 2015 11:55:09 +0000 (12:55 +0100)
committerChristoph Egger <Christoph.Egger@fau.de>
Fri, 20 Mar 2015 12:18:56 +0000 (13:18 +0100)
Comments can now be passed through the InformationManager who will
properly emit events

src/core/Comment.cxx
src/core/Comment.hxx
src/core/InformationManager.cxx
src/core/InformationManager.hxx
src/core/events/ChangeCommentEvent.hxx [new file with mode: 0644]
src/disassembler/Instruction.hxx

index 0cb804c84ab35dc3397ddbc836014fe2a3f90574..d6fedfbf00331b7c026342e693d9219fe6e21b4f 100644 (file)
@@ -1,5 +1,7 @@
 #include "Comment.hxx"
 #include "Function.hxx"
+#include "InformationManager.hxx"
+#include "events/ChangeCommentEvent.hxx"
 
 Comment::Comment(uint64_t address, InformationManager* manager)
        : address(address)
@@ -12,9 +14,15 @@ Comment::Comment(uint64_t address, Function* location, InformationManager* manag
        , manager(manager) {}
 
 void Comment::setText(const std::string& text) {
+       ChangeCommentEvent event(address, location, this);
        this->text = text;
+       manager->dispatch(&event);
 }
 
 uint64_t Comment::getAddress() {
        return address;
 }
+
+Function* Comment::getLocation() {
+       return location;
+}
index b07f13ae1a81c8310ae3ab93104ff933529d9f0c..98febe41392380150900cdbd4cfeed6e340022a8 100644 (file)
@@ -12,6 +12,7 @@ public:
 
        void setText(const std::string& text);
        uint64_t getAddress();
+       Function* getLocation();
 private:
        Comment(uint64_t address, InformationManager* manager);
        Comment(uint64_t address, Function* location, InformationManager* manager);
index e1571892349336ab5d0cc94f1d64104d64428d68..8834a7a39f479b49a0d9b9dad115eaf7269d33cc 100644 (file)
@@ -5,6 +5,7 @@
 #include "core/BasicBlock.hxx"
 #include "core/Comment.hxx"
 #include "core/events/NewFunctionEvent.hxx"
+#include "core/events/ChangeCommentEvent.hxx"
 
 #include "gui/qt.hxx"
 #include <quazip/quazip.h>
@@ -160,6 +161,22 @@ std::map<uint64_t, BasicBlock*>::const_iterator InformationManager::endBasicBloc
        return blocks.end();
 }
 
+/* *********************************
+ * Accessors for the Comments map
+ */
+std::pair<
+       std::multimap<uint64_t, Comment*>::const_iterator,
+       std::multimap<uint64_t, Comment*>::const_iterator>
+InformationManager::getComments(uint64_t address) {
+       return comments.equal_range(address);
+}
+
+std::multimap<uint64_t, Comment*>::const_iterator InformationManager::beginComments() {
+       return comments.begin();
+}
+std::multimap<uint64_t, Comment*>::const_iterator InformationManager::endComments() {
+       return comments.end();
+}
 
 /* *********************************
  * Accessors for the Interpreter map
@@ -210,7 +227,7 @@ Comment* InformationManager::newGlobalComment(uint64_t address) {
 }
 
 Comment* InformationManager::newLocalComment(uint64_t address, Function* f) {
-       Comment* comment = new Comment(address, this);
+       Comment* comment = new Comment(address, f, this);
        comments.insert(std::make_pair(address, comment));
        return comment;
 }
@@ -228,7 +245,10 @@ void InformationManager::finishFunction(Function* fun) {
 void InformationManager::finishBasicBlock(BasicBlock*) {
 }
 
-void InformationManager::finnishComment(Comment* c) {
+void InformationManager::finishComment(Comment* c) {
+       LOG4CXX_DEBUG(logger, "Finishing comment " << c->getAddress());
+       ChangeCommentEvent event(c->getAddress(), c->getLocation(), c);
+       dispatch(&event);
 }
 
 void InformationManager::deleteFunction(Function* f) {
index bb37a1e9a69ee9965b82a031b4e8d7bb9853d3f8..3407113e3324bd14c573a844780ed66926f01557 100644 (file)
@@ -72,12 +72,19 @@ public:
        std::map<uint64_t, BasicBlock*>::const_iterator beginBasicBlocks();
        std::map<uint64_t, BasicBlock*>::const_iterator endBasicBlocks();
 
+       std::pair<
+               std::multimap<uint64_t, Comment*>::const_iterator,
+               std::multimap<uint64_t, Comment*>::const_iterator>
+       getComments(uint64_t address);
+       bool hasComments() const {return ! comments.empty();}
+       std::multimap<uint64_t,Comment*>::const_iterator beginComments();
+       std::multimap<uint64_t,Comment*>::const_iterator endComments();
+
        Interpreter* getInterpreter(const std::string& name);
        bool hasInterpreters() const {return interpreters.size() != 0;}
        std::map<std::string, Interpreter*>::const_iterator beginInterpreters();
        std::map<std::string, Interpreter*>::const_iterator endInterpreters();
 
-
        /* Protocoll:
         *
         * Users may allocate new Data containers with the new*()
@@ -104,7 +111,7 @@ public:
        Comment* newLocalComment(uint64_t address, Function* f);
        void finishFunction(Function* f);
        void finishBasicBlock(BasicBlock* b);
-       void finnishComment(Comment* c);
+       void finishComment(Comment* c);
        void deleteFunction(Function* f);
        void deleteBasicBlock(BasicBlock* b);
        void deleteComment(Comment* c);
diff --git a/src/core/events/ChangeCommentEvent.hxx b/src/core/events/ChangeCommentEvent.hxx
new file mode 100644 (file)
index 0000000..de8d5c3
--- /dev/null
@@ -0,0 +1,21 @@
+#ifndef INCLUDE__ChangeCommentEvent_hxx_
+#define INCLUDE__ChangeCommentEvent_hxx_
+
+#include <string>
+
+class Comment;
+class Function;
+
+class ChangeCommentEvent {
+public:
+       ChangeCommentEvent(uint64_t address, Function* function, Comment* comment)
+               : address(address), function(function), comment(comment) {}
+       ChangeCommentEvent(uint64_t address, Comment* comment)
+               : address(address), function(NULL), comment(comment) {}
+
+       uint64_t address;
+       Function* function;
+       Comment* comment;
+};
+
+#endif /* INCLUDE__ChangeCommentEvent_hxx_ */
index e79b24f38408ded9dfe060699914014a6810d3fb..5a74e22afe1bcfaf9779e9311fd74b28b3dad639 100644 (file)
@@ -5,6 +5,8 @@
 #include <cstdint>
 #include <string>
 
+class Comment;
+
 class Instruction {
 public:
        Instruction(uint64_t address, const std::string& text, const std::vector<uint8_t>& bytes, const std::string& reference)
@@ -13,11 +15,13 @@ public:
        const std::string& getText() const {return text;}
        const std::vector<uint8_t>& getBytes() const {return bytes;}
        const std::string& getReference() const {return reference;}
+       std::vector<Comment*>& comments() {return _comments;}
 private:
        uint64_t address;
        std::string text;
        std::vector<uint8_t> bytes;
        std::string reference;
+       std::vector<Comment*> _comments;
 };
 
 #endif /* INCLUDE__Instruction_hxx_ */