CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/external/source/exploits/CVE-2017-13861/liboffsetfinder64/insn.hpp
Views: 11784
1
//
2
// insn.hpp
3
// liboffsetfinder64
4
//
5
// Created by tihmstar on 09.03.18.
6
// Copyright © 2018 tihmstar. All rights reserved.
7
//
8
9
#ifndef insn_hpp
10
#define insn_hpp
11
12
#include "common.h"
13
#include <vector>
14
15
namespace tihmstar{
16
namespace patchfinder64{
17
class insn{
18
public:
19
enum segtype{
20
kText_only,
21
kData_only,
22
kText_and_Data
23
};
24
private:
25
std::pair <loc_t,int> _p;
26
std::vector<text_t> _segments;
27
segtype _segtype;
28
public:
29
insn(segment_t segments, loc_t p = 0, segtype segType = kText_only);
30
insn(const insn &cpy, loc_t p=0);
31
insn &operator++();
32
insn &operator--();
33
insn operator+(int i);
34
insn operator-(int i);
35
insn &operator+=(int i);
36
insn &operator-=(int i);
37
insn &operator=(loc_t p);
38
39
public: //helpers
40
uint64_t pc();
41
uint32_t value();
42
uint64_t doublevalue();
43
44
public: //static type determinition
45
static uint64_t deref(segment_t segments, loc_t p);
46
static bool is_adrp(uint32_t i);
47
static bool is_adr(uint32_t i);
48
static bool is_add(uint32_t i);
49
static bool is_bl(uint32_t i);
50
static bool is_cbz(uint32_t i);
51
static bool is_ret(uint32_t i);
52
static bool is_tbnz(uint32_t i);
53
static bool is_br(uint32_t i);
54
static bool is_ldr(uint32_t i);
55
static bool is_cbnz(uint32_t i);
56
static bool is_movk(uint32_t i);
57
static bool is_orr(uint32_t i);
58
static bool is_and(uint32_t i);
59
static bool is_tbz(uint32_t i);
60
static bool is_ldxr(uint32_t i);
61
static bool is_ldrb(uint32_t i);
62
static bool is_str(uint32_t i);
63
static bool is_stp(uint32_t i);
64
static bool is_movz(uint32_t i);
65
static bool is_bcond(uint32_t i);
66
static bool is_b(uint32_t i);
67
static bool is_nop(uint32_t i);
68
69
public: //type
70
enum type{
71
unknown,
72
adrp,
73
adr,
74
bl,
75
cbz,
76
ret,
77
tbnz,
78
add,
79
br,
80
ldr,
81
cbnz,
82
movk,
83
orr,
84
tbz,
85
ldxr,
86
ldrb,
87
str,
88
stp,
89
movz,
90
bcond,
91
b,
92
nop,
93
and_
94
};
95
enum subtype{
96
st_general,
97
st_register,
98
st_immediate,
99
st_literal
100
};
101
enum supertype{
102
sut_general,
103
sut_branch_imm
104
};
105
enum cond{
106
NE = 000,
107
EG = 000,
108
CS = 001,
109
CC = 001,
110
MI = 010,
111
PL = 010,
112
VS = 011,
113
VC = 011,
114
HI = 100,
115
LS = 100,
116
GE = 101,
117
LT = 101,
118
GT = 110,
119
LE = 110,
120
AL = 111
121
};
122
type type();
123
subtype subtype();
124
supertype supertype();
125
int64_t imm();
126
uint8_t rd();
127
uint8_t rn();
128
uint8_t rt();
129
uint8_t other();
130
public: //cast operators
131
operator void*();
132
operator loc_t();
133
operator enum type();
134
};
135
136
loc_t find_literal_ref(segment_t segemts, loc_t pos, int ignoreTimes = 0);
137
loc_t find_rel_branch_source(insn bdst, bool searchUp, int ignoreTimes=0, int limit = 0);
138
139
};
140
};
141
142
143
#endif /* insn_hpp */
144
145