2019-07-15 12:08:44 +00:00
|
|
|
#ifndef DECOMPILER_H
|
|
|
|
#define DECOMPILER_H
|
|
|
|
|
|
|
|
#include "CutterCommon.h"
|
2019-08-28 17:01:12 +00:00
|
|
|
#include "R2Task.h"
|
2019-07-15 12:08:44 +00:00
|
|
|
|
|
|
|
#include <QString>
|
|
|
|
#include <QObject>
|
|
|
|
|
2019-08-27 15:27:39 +00:00
|
|
|
struct CodeAnnotation
|
|
|
|
{
|
|
|
|
size_t start;
|
|
|
|
size_t end;
|
|
|
|
|
|
|
|
enum class Type { Offset };
|
|
|
|
Type type;
|
|
|
|
|
|
|
|
union
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
ut64 offset;
|
|
|
|
} offset;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-07-15 12:08:44 +00:00
|
|
|
/**
|
|
|
|
* Describes the result of a Decompilation Process with optional metadata
|
|
|
|
*/
|
2019-08-27 15:27:39 +00:00
|
|
|
struct AnnotatedCode
|
|
|
|
{
|
2019-07-15 12:08:44 +00:00
|
|
|
/**
|
2019-08-27 15:27:39 +00:00
|
|
|
* The entire decompiled code
|
2019-07-15 12:08:44 +00:00
|
|
|
*/
|
2019-08-27 15:27:39 +00:00
|
|
|
QString code;
|
2019-07-15 12:08:44 +00:00
|
|
|
|
2019-08-27 15:27:39 +00:00
|
|
|
QList<CodeAnnotation> annotations;
|
2019-07-15 12:08:44 +00:00
|
|
|
|
2019-08-27 15:27:39 +00:00
|
|
|
ut64 OffsetForPosition(size_t pos) const;
|
|
|
|
size_t PositionForOffset(ut64 offset) const;
|
2019-07-15 12:08:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements a decompiler that can be registered using CutterCore::registerDecompiler()
|
|
|
|
*/
|
|
|
|
class Decompiler: public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private:
|
|
|
|
const QString id;
|
|
|
|
const QString name;
|
|
|
|
|
|
|
|
public:
|
|
|
|
Decompiler(const QString &id, const QString &name, QObject *parent = nullptr);
|
|
|
|
virtual ~Decompiler() = default;
|
|
|
|
|
2019-08-28 17:01:12 +00:00
|
|
|
QString getId() const { return id; }
|
|
|
|
QString getName() const { return name; }
|
|
|
|
virtual bool isRunning() { return false; }
|
|
|
|
virtual bool isCancelable() { return false; }
|
2019-07-15 12:08:44 +00:00
|
|
|
|
2019-08-28 17:01:12 +00:00
|
|
|
virtual void decompileAt(RVA addr) =0;
|
|
|
|
virtual void cancel() {}
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void finished(AnnotatedCode code);
|
2019-07-15 12:08:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class R2DecDecompiler: public Decompiler
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
2019-08-28 17:01:12 +00:00
|
|
|
private:
|
|
|
|
R2Task *task;
|
|
|
|
|
2019-07-15 12:08:44 +00:00
|
|
|
public:
|
|
|
|
explicit R2DecDecompiler(QObject *parent = nullptr);
|
2019-08-28 17:01:12 +00:00
|
|
|
void decompileAt(RVA addr) override;
|
|
|
|
|
|
|
|
bool isRunning() override { return task != nullptr; }
|
2019-07-15 12:08:44 +00:00
|
|
|
|
|
|
|
static bool isAvailable();
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif //DECOMPILER_H
|