From f47dd6b106b9ba1d6363277b47cdec2ac0448f6c Mon Sep 17 00:00:00 2001 From: Christoph Egger Date: Tue, 3 Jun 2014 13:57:23 +0200 Subject: [PATCH] Move to table widget -- looks nicer and matches better --- src/disassembler/Disassembler.hxx | 3 +- src/disassembler/llvm/LLVMDisassembler.cxx | 12 ++--- src/disassembler/llvm/LLVMDisassembler.hxx | 3 +- src/gui/Mainwindow.cxx | 4 +- src/gui/widgets/BasicBlockWidget.hxx | 55 ++++++++++++++++++---- 5 files changed, 55 insertions(+), 22 deletions(-) diff --git a/src/disassembler/Disassembler.hxx b/src/disassembler/Disassembler.hxx index 7bd3cdc..a618ae5 100644 --- a/src/disassembler/Disassembler.hxx +++ b/src/disassembler/Disassembler.hxx @@ -18,7 +18,8 @@ public: virtual BasicBlock * getBasicBlock(uint64_t address) = 0; virtual void forEachFunction(std::function callback) = 0; - virtual void printEachInstruction(uint64_t start, uint64_t end, std::function fun) = 0; + virtual void printEachInstruction(uint64_t start, uint64_t end, + std::function fun) = 0; protected: virtual bool isFunctionCall(uint64_t address) = 0; virtual bool isJump(uint64_t address) = 0; diff --git a/src/disassembler/llvm/LLVMDisassembler.cxx b/src/disassembler/llvm/LLVMDisassembler.cxx index 6e76c91..a194d21 100644 --- a/src/disassembler/llvm/LLVMDisassembler.cxx +++ b/src/disassembler/llvm/LLVMDisassembler.cxx @@ -283,7 +283,8 @@ void LLVMDisassembler::forEachFunction(std::function }); } -void LLVMDisassembler::printEachInstruction(uint64_t start, uint64_t end, std::function fun) { +void LLVMDisassembler::printEachInstruction(uint64_t start, uint64_t end, + std::function 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; } diff --git a/src/disassembler/llvm/LLVMDisassembler.hxx b/src/disassembler/llvm/LLVMDisassembler.hxx index 8c93a45..52a7443 100644 --- a/src/disassembler/llvm/LLVMDisassembler.hxx +++ b/src/disassembler/llvm/LLVMDisassembler.hxx @@ -24,7 +24,8 @@ public: uint64_t entryAddress(); void forEachFunction(std::function callback); - void printEachInstruction(uint64_t start, uint64_t end, std::function fun); + void printEachInstruction(uint64_t start, uint64_t end, + std::function fun); BasicBlock * getBasicBlock(uint64_t address) { return blocks[address]; diff --git a/src/gui/Mainwindow.cxx b/src/gui/Mainwindow.cxx index 1c8ae0b..7d90820 100644 --- a/src/gui/Mainwindow.cxx +++ b/src/gui/Mainwindow.cxx @@ -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) diff --git a/src/gui/widgets/BasicBlockWidget.hxx b/src/gui/widgets/BasicBlockWidget.hxx index 7f4a0a3..98d3e63 100644 --- a/src/gui/widgets/BasicBlockWidget.hxx +++ b/src/gui/widgets/BasicBlockWidget.hxx @@ -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; }; -- 2.39.5