Skip to content

Commit bf05fd4

Browse files
committed
WIP: cache decompiler output
1 parent face9ca commit bf05fd4

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/common/R2GhidraCmdDecompiler.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ R2GhidraCmdDecompiler::R2GhidraCmdDecompiler(QObject *parent)
1616
: Decompiler("pdg", "pdg", parent)
1717
{
1818
task = nullptr;
19+
this->cache = new QHash<QString, RCodeMeta*>();
1920
}
2021

2122
bool R2GhidraCmdDecompiler::isAvailable()
@@ -28,8 +29,16 @@ void R2GhidraCmdDecompiler::decompileAt(RVA addr)
2829
if (task) {
2930
return;
3031
}
31-
task = new R2Task("pdgj @ " + QString::number(addr));
32-
connect(task, &R2Task::finished, this, [this]() {
32+
QString k = QString::number(addr);
33+
bool is_cached = false; // this->cache->contains (k);
34+
task = new R2Task(is_cached? "?e": "pdgj @ " + k);
35+
connect(task, &R2Task::finished, this, [this, addr, k, is_cached]() {
36+
if (is_cached) {
37+
RCodeMeta *code = r_codemeta_clone (this->cache->value(k));
38+
delete task;
39+
emit finished(code);
40+
return;
41+
}
3342
QJsonObject json = task->getResultJson().object();
3443
delete task;
3544
task = nullptr;
@@ -65,6 +74,9 @@ void R2GhidraCmdDecompiler::decompileAt(RVA addr)
6574
}
6675
std::string tmp = codeString.toStdString();
6776
code->code = strdup(tmp.c_str());
77+
if (!is_cached) {
78+
// this->cache->insert(k, r_codemeta_clone (code));
79+
}
6880
emit finished(code);
6981
});
7082
task->startTask();

src/common/R2GhidraCmdDecompiler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ class R2GhidraCmdDecompiler: public Decompiler
1414

1515
private:
1616
R2Task *task;
17+
QHash<QString, RCodeMeta*> *cache;
1718

1819
public:
1920
explicit R2GhidraCmdDecompiler(QObject *parent = nullptr);
2021
void decompileAt(RVA addr) override;
21-
2222
bool isRunning() override { return task != nullptr; }
2323

2424
static bool isAvailable();

0 commit comments

Comments
 (0)