2019-07-15 12:08:44 +00:00
|
|
|
#ifndef DECOMPILER_H
|
|
|
|
#define DECOMPILER_H
|
|
|
|
|
|
|
|
#include "CutterCommon.h"
|
|
|
|
|
|
|
|
#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;
|
|
|
|
|
|
|
|
QString getId() const { return id; }
|
|
|
|
QString getName() const { return name; }
|
|
|
|
|
2019-08-27 15:27:39 +00:00
|
|
|
virtual AnnotatedCode decompileAt(RVA addr) =0;
|
2019-07-15 12:08:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class R2DecDecompiler: public Decompiler
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit R2DecDecompiler(QObject *parent = nullptr);
|
2019-08-27 15:27:39 +00:00
|
|
|
AnnotatedCode decompileAt(RVA addr) override;
|
2019-07-15 12:08:44 +00:00
|
|
|
|
|
|
|
static bool isAvailable();
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif //DECOMPILER_H
|