5 #include <capstone/capstone.h>
8 #include "decompilerbase.h"
11 #define BINLEX_EXPORT __declspec(dllexport)
16 #define DECOMPILER_MAX_SECTIONS 256
17 #define SHA256_PRINTABLE_SIZE 65
19 #define DECOMPILER_VISITED_QUEUED 0
20 #define DECOMPILER_VISITED_ANALYZED 1
22 #define DECOMPILER_GPU_MODE_CUDA 0
23 #define DECOMPILER_GPU_MODE_OPENCL 1
25 typedef enum DECOMPILER_OPERAND_TYPE {
26 DECOMPILER_OPERAND_TYPE_BLOCK = 0,
27 DECOMPILER_OPERAND_TYPE_FUNCTION = 1,
28 DECOMPILER_OPERAND_TYPE_UNSET = 2
29 } DECOMPILER_OPERAND_TYPE;
31 using json = nlohmann::json;
36 typedef struct worker {
61 uint invalid_instructions;
62 uint cyclomatic_complexity;
63 uint average_instructions_per_block;
66 char bytes_sha256[SHA256_PRINTABLE_SIZE];
67 char trait_sha256[SHA256_PRINTABLE_SIZE];
73 vector<struct Trait> traits;
76 set<uint64_t> coverage;
77 map<uint64_t, uint> addresses;
78 map<uint64_t, int> visited;
79 queue<uint64_t> discovered;
83 struct Section sections[DECOMPILER_MAX_SECTIONS];
91 BINLEX_EXPORT
bool Setup(cs_arch architecture, cs_mode mode_type);
118 BINLEX_EXPORT
static void CollectOperands(cs_insn* insn,
int operand_type,
struct Section *sections, uint index);
125 BINLEX_EXPORT
static uint
CollectInsn(cs_insn* insn,
struct Section *sections, uint index);
133 BINLEX_EXPORT
void LinearDisassemble(
void* data,
size_t data_size,
size_t offset, uint index);
141 BINLEX_EXPORT
void Decompile(
void* data,
size_t data_size,
size_t offset, uint index);
151 BINLEX_EXPORT
void FreeTraits(uint index);
157 BINLEX_EXPORT
static bool IsNopInsn(cs_insn *ins);
169 BINLEX_EXPORT
static bool IsTrapInsn(cs_insn *ins);
175 BINLEX_EXPORT
static bool IsPrivInsn(cs_insn *ins);
181 BINLEX_EXPORT
static bool IsEndInsn(cs_insn *insn);
193 BINLEX_EXPORT
static uint64_t
MaxAddress(set<uint64_t> coverage);
199 BINLEX_EXPORT
static bool IsFunction(map<uint64_t, uint> &addresses, uint64_t address);
205 BINLEX_EXPORT
static bool IsBlock(map<uint64_t, uint> &addresses, uint64_t address);
211 BINLEX_EXPORT
static bool IsVisited(map<uint64_t, int> &visited, uint64_t address);
217 BINLEX_EXPORT
bool IsAddress(map<uint64_t, uint> &addresses, uint64_t address, uint index);
229 BINLEX_EXPORT
static string WildcardInsn(cs_insn *insn);
246 BINLEX_EXPORT
static void * TraitWorker(
void *args);
247 BINLEX_EXPORT
static void * FinalizeTrait(
struct Trait &trait);
248 BINLEX_EXPORT
void AppendQueue(set<uint64_t> &addresses, uint operand_type, uint index);
static BINLEX_EXPORT uint CollectInsn(cs_insn *insn, struct Section *sections, uint index)
BINLEX_EXPORT bool Setup(cs_arch architecture, cs_mode mode_type)
static BINLEX_EXPORT bool IsBlock(map< uint64_t, uint > &addresses, uint64_t address)
static BINLEX_EXPORT bool IsPrivInsn(cs_insn *ins)
Definition: decompiler.h:69
BINLEX_EXPORT bool IsAddress(map< uint64_t, uint > &addresses, uint64_t address, uint index)
static BINLEX_EXPORT bool IsEndInsn(cs_insn *insn)
static BINLEX_EXPORT bool IsWildcardInsn(cs_insn *insn)
static BINLEX_EXPORT uint64_t MaxAddress(set< uint64_t > coverage)
BINLEX_EXPORT void Decompile(void *data, size_t data_size, size_t offset, uint index)
static BINLEX_EXPORT void AddDiscoveredBlock(uint64_t address, struct Section *sections, uint index)
static BINLEX_EXPORT void CollectOperands(cs_insn *insn, int operand_type, struct Section *sections, uint index)
Definition: decompiler.h:34
Definition: decompiler.h:50
vector< json > GetTraits()
BINLEX_EXPORT void SetInstructions(bool instructions, uint index)
static BINLEX_EXPORT bool IsSemanticNopInsn(cs_insn *ins)
static BINLEX_EXPORT uint IsConditionalInsn(cs_insn *insn)
Definition: decompilerbase.h:12
static BINLEX_EXPORT bool IsFunction(map< uint64_t, uint > &addresses, uint64_t address)
BINLEX_EXPORT void * CreateTraitsForSection(uint index)
BINLEX_EXPORT json GetTrait(struct Trait &trait)
static BINLEX_EXPORT bool IsTrapInsn(cs_insn *ins)
BINLEX_EXPORT void LinearDisassemble(void *data, size_t data_size, size_t offset, uint index)
static BINLEX_EXPORT bool IsVisited(map< uint64_t, int > &visited, uint64_t address)
static BINLEX_EXPORT bool IsNopInsn(cs_insn *ins)
static BINLEX_EXPORT void ClearTrait(struct Trait *trait)
static BINLEX_EXPORT string WildcardInsn(cs_insn *insn)
static BINLEX_EXPORT void AppendTrait(struct Trait *trait, struct Section *sections, uint index)