Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions include/Comment.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

#ifndef COMMENT_H_
#define COMMENT_H_

#include "Types.h"
#include "Module.h"

#include <QString>

#include <optional>

struct Comment {
QString comment;
edb::address_t address;
std::optional<Module> module;
};

#endif
3 changes: 3 additions & 0 deletions include/IBreakpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
#define IBREAKPOINT_H_20060720_

#include "Types.h"
#include "Module.h"

#include <QString>
#include <exception>
#include <optional>

class QByteArray;

Expand Down Expand Up @@ -45,6 +47,7 @@ class IBreakpoint {
[[nodiscard]] virtual const uint8_t *originalBytes() const = 0;
[[nodiscard]] virtual size_t size() const = 0;
[[nodiscard]] virtual TypeId type() const = 0;
[[nodiscard]] virtual std::optional<Module> module() const = 0;

public:
virtual bool enable() = 0;
Expand Down
4 changes: 4 additions & 0 deletions include/IPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

class QMenu;
class QAction;
class Module;

class IPlugin {
public:
Expand Down Expand Up @@ -40,6 +41,9 @@ class IPlugin {
// optional, overload this to add a page to the options dialog
[[nodiscard]] virtual QWidget *optionsPage() { return nullptr; }

// optional, overload this to get notified when a library is loaded or unloaded
virtual void libraryEvent(const Module & /*module*/, bool /*loaded*/) {}

public:
[[nodiscard]] virtual QVariantMap saveState() const { return {}; }
virtual void restoreState(const QVariantMap &) {}
Expand Down
14 changes: 13 additions & 1 deletion include/ISymbolManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
#ifndef ISYMBOL_MANAGER_H_20110307_
#define ISYMBOL_MANAGER_H_20110307_

#include "Module.h"
#include "Types.h"

#include <QHash>
#include <QVector>

#include <optional>
#include <vector>

Expand All @@ -17,11 +21,19 @@ class Symbol;
class ISymbolGenerator;

class ISymbolManager {
public:
struct LabelEntry {
QString name;
edb::address_t address;
std::optional<Module> module;
};

public:
virtual ~ISymbolManager() = default;

public:
[[nodiscard]] virtual QHash<edb::address_t, QString> labels() const = 0;
[[nodiscard]] virtual QVector<LabelEntry> labelData() const = 0;
[[nodiscard]] virtual QMap<edb::address_t, QString> labels() const = 0;
[[nodiscard]] virtual QString findAddressName(edb::address_t address, bool prefixed = true) = 0;
[[nodiscard]] virtual QStringList files() const = 0;
[[nodiscard]] virtual std::optional<Symbol> find(const QString &name) const = 0;
Expand Down
7 changes: 1 addition & 6 deletions include/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#define TYPES_H_20071127_

#include "Value.h"

#include <QString>

namespace edb {
Expand All @@ -23,11 +24,5 @@ enum EventStatus {

}

/* Comment Type */
struct Comment {
edb::address_t address;
QString comment;
};

#include "ArchTypes.h"
#endif
5 changes: 5 additions & 0 deletions include/edb.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@

#include "API.h"
#include "IBinary.h"
#include "Module.h"
#include "Status.h"
#include "Types.h"

#include <QMap>
#include <QPointer>
#include <QStringList>
#include <QVector>

#include <memory>
#include <optional>

Expand Down Expand Up @@ -53,6 +56,8 @@ namespace v2 {
EDB_EXPORT std::optional<edb::address_t> get_expression_from_user(const QString &title, const QString &prompt);
EDB_EXPORT std::optional<edb::address_t> eval_expression(const QString &expression);
EDB_EXPORT QString format_bytes(const void *buffer, size_t count);
EDB_EXPORT std::optional<Module> module_for_address(edb::address_t address);
EDB_EXPORT bool compare_module_names(const QString &name1, const QString &name2);

}

Expand Down
3 changes: 2 additions & 1 deletion plugins/Analyzer/Analyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ void set_function_types(IAnalyzer::FunctionMap *results) {
Function &function = it.value();

if (function.empty()) {
qDebug() << "HERE:" << it.key().toString();
qDebug() << "Function at " << function.entryAddress().toHexString() << " is empty, skipping type classification";
continue;
}

Q_ASSERT(!function.empty());
Expand Down
4 changes: 2 additions & 2 deletions plugins/Analyzer/AnalyzerWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,14 @@ void AnalyzerWidget::paintEvent(QPaintEvent * /*event*/) {

const int64_t renderTime = timer.elapsed();
if (renderTime > 8) {
qDebug() << "AnalyzerWidget: Painting took longer than desired: " << renderTime << "ms";
qDebug() << "[AnalyzerWidget]: Painting took longer than desired: " << renderTime << "ms";
}
}

/**
* @brief Handles a click on the overview bar by jumping the disassembly view to the corresponding address.
*
* @param event
* @param event The mouse press event that triggered this function.
*/
void AnalyzerWidget::mousePressEvent(QMouseEvent *event) {

Expand Down
2 changes: 1 addition & 1 deletion plugins/BinaryInfo/ELFXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ ELFXX<ElfHeader>::ELFXX(const std::shared_ptr<IRegion> &region)
for (uint16_t entry = 0; entry < header_.e_phnum; ++entry) {

if (!process->readBytes(phdr_base + (phdr_size * entry), &phdr, sizeof(phdr_type))) {
qDebug() << "Failed to read program header";
qDebug("Failed to read program header");
break;
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/BinaryInfo/symbols.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ bool generate_symbols_internal(QFile &file, std::shared_ptr<QFile> &debugFile, s
return true;
}

qDebug() << "unknown file type";
qDebug("unknown file type");
}

return false;
Expand Down
11 changes: 7 additions & 4 deletions plugins/Bookmarks/BookmarkWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
#include "BookmarksModel.h"
#include "Expression.h"
#include "IBreakpoint.h"
#include "IDebugger.h"
#include "IProcess.h"
#include "edb.h"

#include <QInputDialog>
#include <QMenu>
#include <QMessageBox>
Expand Down Expand Up @@ -175,6 +178,7 @@ void BookmarkWidget::addAddress(edb::address_t address, const QString &type, con
address,
BookmarksModel::bookmarkStringToType(type),
comment,
edb::v2::module_for_address(address),
};

model_->addBookmark(bookmark);
Expand Down Expand Up @@ -277,11 +281,10 @@ void BookmarkWidget::on_tableView_customContextMenuRequested(const QPoint &pos)
/**
* @brief Returns a copy of the current bookmark list.
*
* @return
* @return A QVector of BookmarksModel::Bookmark entries.
*/
QList<BookmarksModel::Bookmark> BookmarkWidget::entries() const {
const QVector<BookmarksModel::Bookmark> &bookmarks = model_->bookmarks();
return bookmarks.toList();
QVector<BookmarksModel::Bookmark> BookmarkWidget::entries() const {
return model_->bookmarks();
}

// This is copied from Debugger::createAction, so really there should either be a class that implements
Expand Down
3 changes: 2 additions & 1 deletion plugins/Bookmarks/BookmarkWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "BookmarksModel.h"
#include "Types.h"
#include "ui_BookmarkWidget.h"

#include <QWidget>

class QModelIndex;
Expand All @@ -32,7 +33,7 @@ public Q_SLOTS:
public:
void shortcut(int index);
void addAddress(edb::address_t address, const QString &type = QString(), const QString &comment = QString());
[[nodiscard]] QList<BookmarksModel::Bookmark> entries() const;
[[nodiscard]] QVector<BookmarksModel::Bookmark> entries() const;

private:
void buttonAddClicked();
Expand Down
64 changes: 58 additions & 6 deletions plugins/Bookmarks/Bookmarks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@

#include "Bookmarks.h"
#include "BookmarkWidget.h"
#include "IDebugger.h"
#include "IProcess.h"
#include "Module.h"
#include "edb.h"

#include <QDockWidget>
#include <QMainWindow>
#include <QMenu>
Expand Down Expand Up @@ -108,12 +112,14 @@ void Bookmarks::addBookmarkMenu() {
QVariantMap Bookmarks::saveState() const {
QVariantMap state;
QVariantList bookmarks;

for (auto &bookmark : bookmarkWidget_->entries()) {

QVariantMap entry;
entry[QStringLiteral("address")] = bookmark.address.toHexString();
entry[QStringLiteral("type")] = BookmarksModel::bookmarkTypeToString(bookmark.type);
entry[QStringLiteral("comment")] = bookmark.comment;
entry[QStringLiteral("module")] = bookmark.module ? bookmark.module->name : QString();
entry[QStringLiteral("offset")] = (bookmark.module) ? (bookmark.address - bookmark.module->baseAddress).toHexString() : QString();

bookmarks.push_back(entry);
}
Expand All @@ -129,17 +135,63 @@ QVariantMap Bookmarks::saveState() const {
*/
void Bookmarks::restoreState(const QVariantMap &state) {

IProcess *process = edb::v1::debugger_core->process();
Q_ASSERT(process);

QSet<Module> modules = process->loadedModules();

QVariantList bookmarks = state[QStringLiteral("bookmarks")].toList();
for (auto &entry : bookmarks) {
auto bookmark = entry.value<QVariantMap>();

auto address = edb::address_t::fromHexString(bookmark[QStringLiteral("address")].toString());
QString type = bookmark[QStringLiteral("type")].toString();
QString comment = bookmark[QStringLiteral("comment")].toString();
QString module_name = bookmark[QStringLiteral("module")].toString();
QString offset_str = bookmark[QStringLiteral("offset")].toString();
QString type = bookmark[QStringLiteral("type")].toString();
QString comment = bookmark[QStringLiteral("comment")].toString();

edb::address_t offset = edb::address_t::fromHexString(offset_str);

// Figure out which module this bookmark belongs to and add it if the module is loaded
auto it = std::find_if(modules.begin(), modules.end(), [&module_name](const Module &module) {
return edb::v2::compare_module_names(module.name, module_name);
});

if (it != modules.end()) {
edb::address_t address = offset + it->baseAddress;
bookmarkWidget_->addAddress(address, type, comment);
continue;
} else {

// If the module is not loaded, store the bookmark entry for later restoration when the module is loaded
BookmarkEntry entry;
entry.type = type;
entry.comment = comment;
entry.module = module_name;
entry.offset = offset_str;
deferredBookmarks_.push_back(entry);
}
}
}

qDebug() << "Restoring bookmark with address: " << address.toHexString();
/**
* @brief Handles library load/unload events to restore bookmarks for newly loaded modules.
*
* @param module The module that was loaded or unloaded.
* @param loaded True if the module was loaded, false if it was unloaded.
*/
void Bookmarks::libraryEvent(const Module &module, bool loaded) {
if (loaded) {
auto it = std::remove_if(deferredBookmarks_.begin(), deferredBookmarks_.end(), [&module, this](const BookmarkEntry &entry) {
if (edb::v2::compare_module_names(entry.module, module.name)) {
edb::address_t offset = edb::address_t::fromHexString(entry.offset);
edb::address_t address = offset + module.baseAddress;
bookmarkWidget_->addAddress(address, entry.type, entry.comment);
return true;
}

bookmarkWidget_->addAddress(address, type, comment);
return false;
});
deferredBookmarks_.erase(it, deferredBookmarks_.end());
}
}

Expand Down
14 changes: 14 additions & 0 deletions plugins/Bookmarks/Bookmarks.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ class Bookmarks : public QObject, public IPlugin {
Q_CLASSINFO("author", "Evan Teran")
Q_CLASSINFO("url", "http://www.codef00.com")

private:
struct BookmarkEntry {
QString type;
QString comment;
QString module;
QString offset;
};

public:
explicit Bookmarks(QObject *parent = nullptr);

Expand All @@ -34,12 +42,18 @@ class Bookmarks : public QObject, public IPlugin {
[[nodiscard]] QVariantMap saveState() const override;
void restoreState(const QVariantMap &) override;

public:
void libraryEvent(const Module &module, bool loaded) override;

private:
void addBookmarkMenu();

private:
QMenu *menu_ = nullptr;
BookmarkWidget *bookmarkWidget_ = nullptr;

// These are the ones not restored yet, but will be restored when the modules are loaded
std::vector<BookmarkEntry> deferredBookmarks_;
};

}
Expand Down
4 changes: 2 additions & 2 deletions plugins/Bookmarks/BookmarksModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ QVariant BookmarksModel::data(const QModelIndex &index, int role) const {
*
* @param r
*/
void BookmarksModel::addBookmark(const Bookmark &r) {
void BookmarksModel::addBookmark(const Bookmark &bookmark) {
beginInsertRows(QModelIndex(), rowCount(), rowCount());
bookmarks_.push_back(r);
bookmarks_.push_back(bookmark);
endInsertRows();
}

Expand Down
Loading