]> git.siccegge.de Git - frida/frida.git/commitdiff
Move to table widget -- looks nicer and matches better
authorChristoph Egger <siccegge@cs.fau.de>
Tue, 3 Jun 2014 11:57:23 +0000 (13:57 +0200)
committerChristoph Egger <siccegge@cs.fau.de>
Tue, 3 Jun 2014 11:57:23 +0000 (13:57 +0200)
src/disassembler/Disassembler.hxx
src/disassembler/llvm/LLVMDisassembler.cxx
src/disassembler/llvm/LLVMDisassembler.hxx
src/gui/Mainwindow.cxx
src/gui/widgets/BasicBlockWidget.hxx

index 7bd3cdc4cfa3da85b34ff7fc66b1a47279a3bf5d..a618ae587e020575b5c6b246194f5d60def4046e 100644 (file)
@@ -18,7 +18,8 @@ public:
        virtual BasicBlock * getBasicBlock(uint64_t address) = 0;
 
        virtual void forEachFunction(std::function<void (uint64_t, Function*)> callback) = 0;
-       virtual void printEachInstruction(uint64_t start, uint64_t end, std::function<void (const std::string&)> fun) = 0;
+       virtual void printEachInstruction(uint64_t start, uint64_t end,
+                                                                         std::function<void (uint8_t*, size_t, const std::string&)> fun) = 0;
 protected:
     virtual bool isFunctionCall(uint64_t address) = 0;
     virtual bool isJump(uint64_t address) = 0;
index 6e76c91bc27c8121f7088460401ae3c20d4faf47..a194d2144d459d407efa769596a2975e72ed0a44 100644 (file)
@@ -283,7 +283,8 @@ void LLVMDisassembler::forEachFunction(std::function<void (uint64_t, Function*)>
                   });
 }
 
-void LLVMDisassembler::printEachInstruction(uint64_t start, uint64_t end, std::function<void (const std::string&)> fun) {
+void LLVMDisassembler::printEachInstruction(uint64_t start, uint64_t end,
+                                                                                       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);
@@ -304,16 +305,11 @@ void LLVMDisassembler::printEachInstruction(uint64_t start, uint64_t end, std::f
 
             uint8_t bytes[inst_size+2];
             ref.readBytes(current_address, inst_size, bytes);
-            for(uint8_t* cur = bytes; cur < bytes + inst_size; ++cur) {
-                s.write_hex(*cur);
-                s << ' ';
-            }
-            s << '\t';
 
             IP->printInst(&inst, s, "");
-                       fun(s.str());
+                       fun(bytes, inst_size, s.str());
         } else {
-                       fun("Invalid Byte");
+                       fun(NULL, 0, "Invalid Byte");
                        inst_size = 1;
                }
 
index 8c93a450610d4f0f2b8925be02fd976b04ceff14..52a744346a41cefa10f176597fbe10e3db2a9aa1 100644 (file)
@@ -24,7 +24,8 @@ public:
        uint64_t entryAddress();
 
        void forEachFunction(std::function<void (uint64_t, Function*)> callback);
-       void printEachInstruction(uint64_t start, uint64_t end, std::function<void (const std::string&)> fun);
+       void printEachInstruction(uint64_t start, uint64_t end,
+                                                         std::function<void (uint8_t*, size_t, const std::string&)> fun);
 
        BasicBlock * getBasicBlock(uint64_t address) {
                return blocks[address];
index 1c8ae0bb2225b49e2132b8cb9dcc188c2c2fcb25..7d90820a9869436323f5236be1891843642affe5 100644 (file)
@@ -79,8 +79,8 @@ namespace {
                widget->moveBy(100*startx, 10*(block->getStartAddress() - starty));
 
                dis->printEachInstruction(block->getStartAddress(), block->getEndAddress(),
-                                                                 [&](const std::string& line) {
-                                                                         widget->addItem(line.c_str());
+                                                                 [&](uint8_t* bytes, size_t byte_count, const std::string& line) {
+                                                                         widget->addItem(bytes, byte_count, line.c_str() + 1);
                                                                  });
 
                if (block->getNextBlock(0) != 0)
index 7f4a0a36dfb791aff828b98e79f60bf741f4f4cf..98d3e6301b266b5d4c51663b08b7e57cd26a9844 100644 (file)
@@ -7,20 +7,55 @@ public:
                : x(-5), y(-20)
                , dx(270), dy(45)
                , name(name) {
-               _widget.setMinimumWidth(_widget.sizeHintForColumn(0) + 10);
+               _widget.setMinimumHeight(_widget.rowHeight(0) + 10);
                _widget.setMaximumHeight(20);
-               dx = _widget.sizeHintForColumn(0) + 20;
+               _widget.setColumnCount(3);
+               _widget.verticalHeader()->hide();
+               _widget.horizontalHeader()->hide();
+               dx = _widget.rowHeight(0) + 20;
                if (dx < 270) dx = 270;
     }
 
-       void addItem(const QString& line) {
-               _widget.addItem(line);
+       void addItem(uint8_t* bytes, size_t num_bytes,
+                                const QString& line) {
+               size_t current_row = _widget.rowCount();
+               int column_width;
+
+               QString bytestring;
+
+               for (size_t i(0); i < num_bytes; ++i) {
+                       const char * hexdigits = "0123456789ABCDEF";
+                       bytestring += hexdigits[(bytes[i] >> 4) & 0xF];
+                       bytestring += hexdigits[bytes[i] & 0xF];
+                       bytestring += ' ';
+               }
+
+               _widget.setRowCount(current_row + 1);
+
+               _widget.setItem(current_row, 0, new QTableWidgetItem(bytestring));
+               _widget.setItem(current_row, 1, new QTableWidgetItem(line));
+               _widget.setItem(current_row, 2, new QTableWidgetItem(""));
                _widget.updateGeometry();
-               _widget.setMinimumWidth(_widget.sizeHintForColumn(0) + 10);
-               _widget.setMinimumHeight(_widget.sizeHintForRow(0) * (1 + _widget.count()));
-               _widget.setMaximumHeight(_widget.sizeHintForRow(0) * (1 + _widget.count()));
-               dy = _widget.sizeHintForRow(0) * (1 + _widget.count()) + 25;
-               dx = _widget.sizeHintForColumn(0) + 20;
+
+               _widget.resizeColumnToContents(0);
+               _widget.resizeColumnToContents(1);
+               _widget.resizeColumnToContents(2);
+
+               _widget.resizeRowToContents(current_row);
+
+               column_width =
+                       _widget.columnWidth(0) +
+                       _widget.columnWidth(1) +
+                       _widget.columnWidth(2) +
+                       2;
+
+               _widget.setMinimumWidth(column_width);
+               _widget.setMinimumHeight(_widget.rowHeight(1) * (_widget.rowCount()) + 2);
+               _widget.setMaximumHeight(_widget.rowHeight(1) * (_widget.rowCount()) + 2);
+
+
+               dy = _widget.rowHeight(0) * (_widget.rowCount()) + 25;
+               dx = column_width + 10;
                if (dx < 270) dx = 270;
        }
 
@@ -42,6 +77,6 @@ public:
     }
 private:
     int x, y, dx, dy;
-    QListWidget _widget;
+    QTableWidget _widget;
        QString name;
 };