find_package(Qt5Widgets)
find_package(Qt5 CONFIG REQUIRED Widgets Gui)
+find_package(PkgConfig)
+pkg_check_modules(LOG4CXX REQUIRED liblog4cxx)
+
+add_compile_options(${LOG4CXX_CFLAGS})
execute_process(COMMAND llvm-config-3.4 --cflags OUTPUT_VARIABLE LLVM_CFLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND llvm-config-3.4 --ldflags OUTPUT_VARIABLE LLVM_LDFLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
set(CMAKE_CXX_COMPILER "clang++")
-SET(qtlldb_SOURCES src/Binary.cxx src/main.cxx src/gui/Mainwindow.cxx)
-SET(qtlldb_HEADERS src/Binary.hxx src/include.hxx src/Section.hxx src/gui/Mainwindow.h++)
+SET(qtlldb_SOURCES
+ src/Binary.cxx
+ src/main.cxx
+ src/gui/Mainwindow.cxx
+ src/gui/widgets/BasicBlockWidget.cxx
+ src/disassembler/InstructionReader.cxx
+ src/disassembler/Target.cxx
+ src/disassembler/Disassembler.cxx)
+SET(qtlldb_HEADERS
+ src/Binary.hxx
+ src/include.hxx
+ src/Section.hxx
+ src/gui/Mainwindow.hxx
+ src/gui/widgets/BasicBlockWidget.hxx)
ADD_EXECUTABLE(qtlldb ${qtlldb_SOURCES} ${qtlldb_HEADERS_MOC})
-
-set(CMAKE_LD_FLAGS "${LLVM_LDFLAGS}")
-set(CMAKE_LIBS "${LLVM_LIBS}")
-
ADD_DEFINITIONS(${QT_DEFINITIONS})
qt5_use_modules(qtlldb Widgets)
INCLUDE_DIRECTORIES("src")
-TARGET_LINK_LIBRARIES(qtlldb ${QT_LIBRARIES} ${LLVM_LDFLAGS} ${LLVM_LIBS})
+TARGET_LINK_LIBRARIES(qtlldb ${QT_LIBRARIES} ${LLVM_LDFLAGS} ${LLVM_LIBS} ${LOG4CXX_LDFLAGS})
#include "Binary.hxx"
+#include "disassembler/Disassembler.hxx"
+
#include <iostream>
#include <string>
#include <algorithm>
Binary::Binary(const std::string& filename)
: triple("unkown-unknown-unknown")
{
+ ::Disassembler d(filename);
std::string error;
createBinary(filename, binary);
--- /dev/null
+#ifndef INCLUDE__Section_hxx
+#define INCLUDE__Section_hxx
+
+#include "include.hxx"
+
+#include <string>
+#include <vector>
+#include <functional>
+
+using llvm::OwningPtr;
+
+namespace qtlldb {
+ class Section {
+ public:
+ Section() {}
+
+ private:
+
+ };
+}
+#endif
--- /dev/null
+
+
+class BasicBlock {
+public:
+
+private:
+
+};
--- /dev/null
+#include "Disassembler.hxx"
+
+namespace {
+ llvm::OwningPtr<llvm::object::Binary>&
+ constructor_helper(const std::string& filename,
+ llvm::OwningPtr<llvm::object::Binary>& binary) {
+ createBinary(filename, binary);
+ return binary;
+ }
+}
+
+
+Disassembler::Disassembler(const std::string& filename)
+ : _target(constructor_helper(filename, _binary))
+{
+
+}
+
--- /dev/null
+#ifndef INCLUDE__Disassembler_hxx
+#define INCLUDE__Disassembler_hxx
+
+#include "Target.hxx"
+#include "include.hxx"
+
+class Disassembler {
+public:
+ Disassembler(const std::string& filename);
+private:
+ llvm::OwningPtr<llvm::object::Binary> _binary;
+
+ Target _target;
+};
+
+#endif
--- /dev/null
+
+
+class Instruction {
+public:
+private:
+};
--- /dev/null
+#include "InstructionReader.hxx"
+
+InstructionReader::InstructionReader(const Target& target)
+ : _logger(log4cxx::Logger::getLogger("disassembler.Target"))
+ , _target(target)
+{
+ DisAsm.reset(_target.getTarget().createMCDisassembler(_target.getSubTargetInfo()));
+ if (!DisAsm) {
+ LOG4CXX_ERROR(_logger, "error: no disassembler for target " << _target.getTripleName())
+ return;
+ }
+}
+
+void InstructionReader::readInstruction(std::string& data, size_t& offset, Instruction& inst) {
+ llvm::MCInst instr;
+ llvm::StringRefMemoryObject memoryObject(data);
+ uint64_t size;
+
+ if (DisAsm->getInstruction(instr, size, memoryObject, offset,
+ llvm::nulls(), llvm::nulls())) {
+
+ } else {
+ LOG4CXX_WARN(_logger, "warning: invalid instruction encoding");
+ if (size == 0)
+ size = 1; // skip illegible bytes
+ }
+}
--- /dev/null
+#include "include.hxx"
+#include "Instruction.hxx"
+#include "Target.hxx"
+
+#include <string>
+
+#include <log4cxx/logger.h>
+
+
+class InstructionReader {
+public:
+ InstructionReader(const Target& target);
+ void readInstruction(std::string& data, size_t& offset, Instruction& inst);
+private:
+ log4cxx::LoggerPtr _logger;
+ const Target& _target;
+ llvm::OwningPtr<llvm::MCDisassembler> DisAsm;
+};
--- /dev/null
+#include "Target.hxx"
+#include "include.hxx"
+
+#include <string>
+
+Target:: Target(const llvm::OwningPtr<llvm::object::Binary>& binary)
+ : _logger(log4cxx::Logger::getLogger("disassembler.Target"))
+ , triple("unknown-unknown-unknown")
+{
+ std::string error;
+ llvm::object::ObjectFile * o = llvm::dyn_cast<llvm::object::ObjectFile>(binary.get());
+
+ triple.setArch(llvm::Triple::ArchType(o->getArch()));
+ std::string tripleName(triple.getTriple());
+ LOG4CXX_INFO(_logger, "Detected triple " << tripleName);
+
+ target = llvm::TargetRegistry::lookupTarget("", triple, error);
+ if (!target) {
+ LOG4CXX_ERROR(_logger, "Couldn't create Target: " << error);
+ return;
+ }
+ LOG4CXX_INFO(_logger, "Target: " << target->getName());
+
+ STI.reset(target->createMCSubtargetInfo(tripleName, "", ""));
+ if (!STI) {
+ LOG4CXX_ERROR(_logger, "No subtarget for target " << tripleName);
+ return;
+ }
+}
--- /dev/null
+#ifndef INCLUDE__Target_hxx
+#define INCLUDE__Target_hxx
+
+#include <log4cxx/logger.h>
+
+#include "include.hxx"
+
+class Target {
+public:
+ Target(const llvm::OwningPtr<llvm::object::Binary>& binary);
+
+ const llvm::Target& getTarget() const {
+ return *target;
+ }
+
+ const llvm::MCSubtargetInfo& getSubTargetInfo() const {
+ return *STI;
+ }
+
+ std::string getTripleName() const {
+ return triple.getTriple();
+ }
+private:
+ log4cxx::LoggerPtr _logger;
+ llvm::Triple triple;
+
+ const llvm::Target * target;
+ llvm::OwningPtr<const llvm::MCSubtargetInfo> STI;
+};
+
+#endif
#include "Mainwindow.hxx"
+#include "widgets/BasicBlockWidget.hxx"
+#include "qt.hxx"
#include <iostream>
#include <sstream>
#include <QtGui>
-#include <QAction>
-#include <QMenuBar>
-#include <QMenu>
-#include <QDockWidget>
-#include <QMessageBox>
-#include <QFileDialog>
-#include <QTableWidget>
-#include <QHeaderView>
-#include <QGraphicsScene>
-#include <QGraphicsItem>
-#include <QGraphicsView>
-
-namespace {
-
-}
Mainwindow::Mainwindow()
{
// CFG
QGraphicsScene * scene = new QGraphicsScene;
- QGraphicsRectItem *rect = scene->addRect(QRectF(0, 0, 100, 100));
- rect->setFlag(QGraphicsItem::ItemIsMovable);
+
+ BasicBlockWidget * s1 = new BasicBlockWidget;
+ scene->addItem(s1);
+ s1->setFlag(QGraphicsItem::ItemIsMovable, true);
+
+ BasicBlockWidget * s2 = new BasicBlockWidget;
+ scene->addItem(s2);
+ s2->setFlag(QGraphicsItem::ItemIsMovable, true);
+ s2->moveBy(-200, 350);
+
+ BasicBlockWidget * s3 = new BasicBlockWidget;
+ scene->addItem(s3);
+ s3->setFlag(QGraphicsItem::ItemIsMovable, true);
+ s3->moveBy(100, 350);
+
+ BasicBlockWidget * s4 = new BasicBlockWidget;
+ scene->addItem(s4);
+ s4->setFlag(QGraphicsItem::ItemIsMovable, true);
+ s4->moveBy(400, 350);
+
+
QGraphicsView * view = new QGraphicsView(scene);
w->addTab(view, "CFG");
--- /dev/null
+#include <QAction>
+#include <QDockWidget>
+#include <QFileDialog>
+#include <QGraphicsItem>
+#include <QGraphicsProxyWidget>
+#include <QGraphicsScene>
+#include <QGraphicsView>
+#include <QGroupBox>
+#include <QHeaderView>
+#include <QListWidget>
+#include <QMenu>
+#include <QMenuBar>
+#include <QMessageBox>
+#include <QPainter>
+#include <QTableWidget>
+#include <QVBoxLayout>
--- /dev/null
+#include "gui/qt.hxx"
+
+class BasicBlockWidget : public QGraphicsItem
+{
+public:
+ BasicBlockWidget() {
+ x = -5;
+ y = -20;
+ dx = 250;
+ dy = 270;
+ _widget.addItem("THIS");
+ _widget.addItem("IS");
+ _widget.addItem("A");
+ _widget.addItem("TEST");
+ }
+
+ QRectF boundingRect() const
+ {
+ qreal penWidth = 1;
+ return QRectF(x - penWidth / 2, y - penWidth / 2,
+ dx + penWidth, dy + penWidth);
+ }
+
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
+ QWidget *widget)
+ {
+ painter->fillRect(x, y, dx, dy, QColor(0xcc, 0xcc, 0xff, 0xff));
+ painter->setPen(QColor(0x00, 0x00, 0xff, 0xff));
+ painter->drawRect(x, y, dx, dy);
+ painter->drawText(0, -5, "BLOCK");
+ _widget.render(painter);
+ }
+private:
+ int x, y, dx, dy;
+ QListWidget _widget;
+};
#include <QApplication>
#include <QTextEdit>
+#include "log4cxx/logger.h"
+#include "log4cxx/basicconfigurator.h"
+
#include "Binary.hxx"
#include "gui/Mainwindow.hxx"
int main(int argc, char** argv)
{
+ log4cxx::BasicConfigurator::configure();
+ log4cxx::LoggerPtr _logger(log4cxx::Logger::getLogger("main"));
+ LOG4CXX_DEBUG(_logger, "Initializing LLVM");
llvm::InitializeAllTargetInfos();
llvm::InitializeAllTargetMCs();
llvm::InitializeAllAsmParsers();