-
Notifications
You must be signed in to change notification settings - Fork 8
/
instruction_operand.hpp
72 lines (52 loc) · 1.23 KB
/
instruction_operand.hpp
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
#pragma once
// STD
#include <map>
#include <vector>
#include <tuple>
// x86
#include "instruction_opcode.hpp"
namespace x86
{
class operand
{
public:
operand(std::vector<std::uint8_t> operand) : m_operand(operand) {}
template <class T, size_t N>
operand(T(&operand)[N]) : m_operand(operand) {}
operand() : m_operand() {}
std::vector<std::uint8_t>& buffer();
template <typename T>
T get(size_t index)
{
if (index + sizeof(T) > this->buffer().size())
{
throw std::exception("Operand size mismatch");
}
return *reinterpret_cast<T*>(this->buffer().data() + index);
}
private:
template <typename T>
T get_dynamic(size_t& index)
{
const T value = get<T>(index);
index += sizeof(T);
return value;
}
public:
template <typename ... T>
std::tuple<T...> get_multiple(size_t index)
{
return std::make_tuple(get_dynamic<T>(index)...);
}
struct operand_info
{
//operand_info(bool new_modrm, std::uint8_t new_size) : modrm(new_modrm), size(new_size) {}
bool modrm;
std::uint8_t size;
};
using operand_map_t = std::map<std::uint32_t, x86::operand::operand_info>;
const static operand_map_t info;
private:
std::vector<std::uint8_t> m_operand;
};
}