-
Notifications
You must be signed in to change notification settings - Fork 2
/
wrapper.h
75 lines (56 loc) · 1.84 KB
/
wrapper.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#ifndef WRAPPER_INCLUDED
#define WRAPPER_INCLUDED
#include <cinttypes>
#include <string>
#include <set>
#include <iostream>
#include <fstream>
#include <memory>
using namespace std;
#include <capstone/capstone.h>
class OneStepDisasm
{
private:
csh _handle;
cs_insn *_insn;
uint64_t _startaddr; //startaddr for physical address
uint64_t _v_addr; //and v_addr for virtual
size_t _lifetime; //max value of jumps to be explored
int _mode; //32 or 64
string _filename;
ifstream _codefile;
shared_ptr<uint8_t> _code_begin; //code keeper
const uint8_t* _code_current; //pointer to current instruction
size_t _codesize;
//so this pretty much copies the capstone struct, but with strings and without bytes representation
struct instruction
{
friend OneStepDisasm;
//this thing tells if the disassemblation is over && no more instructions can be accessed
const bool empty;
const unsigned int id;
const uint64_t address;
const string mnemonic;
const string operands;
//details (not all)
const set<uint8_t> groups; //the fuck, this should be an enum. Why-why those ceeshniki
instruction(const instruction&);
instruction();
private:
instruction(unsigned int cid, uint64_t caddress, const char* cmnemonic, const char* cop_str, cs_detail* details);
instruction(bool cempty = true); //only applicable if cempty == true. Throws std::runtime_error
};
public:
OneStepDisasm(string filename, int mode, uint64_t startaddr, uint64_t _v_addr); //throws std::runtime_error
OneStepDisasm(const OneStepDisasm&);
~OneStepDisasm();
//a function that disassembles and returns the next instruction
instruction next();
//return previously disassembled instruction
instruction current() const;
//a simple getter
int get_mode() const;
//a function that clones on given virtual address
OneStepDisasm clone_at(const uint64_t &addr);
};
#endif