Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 14 additions & 2 deletions src/common/R2GhidraCmdDecompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ R2GhidraCmdDecompiler::R2GhidraCmdDecompiler(QObject *parent)
: Decompiler("pdg", "pdg", parent)
{
task = nullptr;
this->cache = new QHash<QString, RCodeMeta*>();
}

bool R2GhidraCmdDecompiler::isAvailable()
Expand All @@ -28,8 +29,16 @@ void R2GhidraCmdDecompiler::decompileAt(RVA addr)
if (task) {
return;
}
task = new R2Task("pdgj @ " + QString::number(addr));
connect(task, &R2Task::finished, this, [this]() {
QString k = QString::number(addr);
bool is_cached = this->cache->contains (k);
task = new R2Task(is_cached? "?e": "pdgj @ " + k);
connect(task, &R2Task::finished, this, [this, addr, k, is_cached]() {
if (is_cached) {
RCodeMeta *code = r_codemeta_clone (this->cache->value(k));
delete task;
emit finished(code);
return;
}
QJsonObject json = task->getResultJson().object();
delete task;
task = nullptr;
Expand Down Expand Up @@ -65,6 +74,9 @@ void R2GhidraCmdDecompiler::decompileAt(RVA addr)
}
std::string tmp = codeString.toStdString();
code->code = strdup(tmp.c_str());
if (!is_cached) {
this->cache->insert(k, r_codemeta_clone (code));
}
emit finished(code);
});
task->startTask();
Expand Down
2 changes: 1 addition & 1 deletion src/common/R2GhidraCmdDecompiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ class R2GhidraCmdDecompiler: public Decompiler

private:
R2Task *task;
QHash<QString, RCodeMeta*> *cache;

public:
explicit R2GhidraCmdDecompiler(QObject *parent = nullptr);
void decompileAt(RVA addr) override;

bool isRunning() override { return task != nullptr; }

static bool isAvailable();
Expand Down