-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathx86ops.h
More file actions
156 lines (130 loc) · 4.3 KB
/
Copy pathx86ops.h
File metadata and controls
156 lines (130 loc) · 4.3 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*************************** x86 ***************************/
__inline void PushFD() {
DynaLog(" pushfd");
*(x86BlockPtr.ubPtr++) = 0x9C;
}
__inline void PopFD() {
DynaLog(" popfd");
*(x86BlockPtr.ubPtr++) = 0x9D;
}
__inline void Lahf () {
DynaLog(" lahf");
*(x86BlockPtr.ubPtr++) = 0x9F;
}
__inline void Sahf () {
DynaLog(" sahf");
*(x86BlockPtr.ubPtr++) = 0x9E;
}
__inline void SetBranch8b(void * JumpByte, void * Destination) {
/* calculate 32-bit relative offset */
signed int n = (BYTE*)Destination - ((BYTE*)JumpByte + 1);
*(BYTE*)(JumpByte) = (BYTE)n;
}
__inline void SetBranch32b(void * JumpByte, void * Destination) {
*(DWORD*)(JumpByte) = (DWORD)((BYTE*)Destination - (BYTE*)((DWORD*)JumpByte + 1));
}
__inline void MoveConstToVariable (DWORD Const, void * Variable, char * VariableName) {
DynaLog(" mov [%s], 0x%08X", VariableName, Const);
*(x86BlockPtr.uwPtr++) = 0x05C7;
*(x86BlockPtr.udwPtr++) = (DWORD)Variable;
*(x86BlockPtr.udwPtr++) = Const;
}
__inline void CallFunctionDirect(void * FunctAddress, char * FunctName) {
DynaLog(" call %s", FunctName);
*(x86BlockPtr.ubPtr++) = 0xE8;
*(x86BlockPtr.udwPtr++) = (DWORD)FunctAddress-(DWORD)x86BlockPtr.ptr - 4;
}
__inline void AddConstToVariable (DWORD Const, void * Variable, char * VariableName) {
DynaLog(" add [%s], 0x%08X", VariableName, Const);
*(x86BlockPtr.uwPtr++) = 0x0581;
*(x86BlockPtr.udwPtr++) = (DWORD)Variable;
*(x86BlockPtr.udwPtr++) = Const;
}
__inline void SubConst8ToVariable (BYTE Const, void * Variable, char * VariableName) {
DynaLog(" sub [%s], 0x%08X", VariableName, Const);
*(x86BlockPtr.uwPtr++) = 0x2D83;
*(x86BlockPtr.udwPtr++) = (DWORD)Variable;
*(x86BlockPtr.ubPtr++) = Const;
}
__inline void Ret(void) {
DynaLog(" ret");
*(x86BlockPtr.ubPtr++) = 0xC3;
}
__inline void MoveConstToEax(DWORD constant) {
DynaLog(" mov eax, 0%08Xh", constant);
*(x86BlockPtr.ubPtr++) = 0xB8;
*(x86BlockPtr.udwPtr++) = (DWORD)constant;
}
__inline void MoveVariableToEax(void *Variable, char *VariableName) {
DynaLog(" mov eax, [%s]", VariableName);
*(x86BlockPtr.uwPtr++) = 0x058B;
*(x86BlockPtr.udwPtr++) = (DWORD)Variable;
}
__inline void MoveEaxToVariable(void * Variable, char * VariableName) {
DynaLog(" mov dword ptr [%s], eax",VariableName);
*(x86BlockPtr.uwPtr++) = 0x0589;
*(x86BlockPtr.udwPtr++) = (DWORD)Variable;
}
__inline void CompConstToVariable(DWORD Const, void * Variable, char * VariableName) {
DynaLog(" cmp dword ptr [%s], 0x%X",VariableName, Const);
*(x86BlockPtr.uwPtr++) = 0x3D81;
*(x86BlockPtr.udwPtr++) = (DWORD)Variable;
*(x86BlockPtr.udwPtr++) = Const;
}
__inline void CompEaxToVariable(void * Variable, char * VariableName) {
DynaLog(" cmp eax, dword ptr [%s]",VariableName);
*(x86BlockPtr.uwPtr++) = 0x053B;
*(x86BlockPtr.udwPtr++) = (DWORD)Variable;
}
__inline void CompConstToEax(DWORD Const) {
DynaLog(" cmp eax, 0x%08X", Const);
*(x86BlockPtr.uwPtr++) = 0xF881;
*(x86BlockPtr.udwPtr++) = (DWORD)Const;
}
__inline void JeLabel8(char * Label, BYTE Value) {
DynaLog(" je $%s", Label);
*(x86BlockPtr.ubPtr++) = 0x74;
*(x86BlockPtr.ubPtr++) = Value;
}
__inline void JneLabel8(char * Label, BYTE Value) {
DynaLog(" jne $%s", Label);
*(x86BlockPtr.ubPtr++) = 0x75;
*(x86BlockPtr.ubPtr++) = Value;
}
__inline void JlLabel8(char * Label, BYTE Value) {
DynaLog(" jl $%s", Label);
*(x86BlockPtr.ubPtr++) = 0x7C;
*(x86BlockPtr.ubPtr++) = Value;
}
__inline void JgeLabel8(char * Label, BYTE Value) {
DynaLog(" jge $%s", Label);
*(x86BlockPtr.ubPtr++) = 0x7D;
*(x86BlockPtr.ubPtr++) = Value;
}
__inline void JleLabel8(char * Label, BYTE Value) {
DynaLog(" jle $%s", Label);
*(x86BlockPtr.ubPtr++) = 0x7E;
*(x86BlockPtr.ubPtr++) = Value;
}
__inline void JgLabel8(char * Label, BYTE Value) {
DynaLog(" jg $%s", Label);
*(x86BlockPtr.ubPtr++) = 0x7F;
*(x86BlockPtr.ubPtr++) = Value;
}
__inline void JmpLabel8(char * Label, BYTE Value) {
DynaLog(" jmp $%s", Label);
*(x86BlockPtr.ubPtr++) = 0xEB;
*(x86BlockPtr.ubPtr++) = Value;
}
__inline void JumpEax(void) {
DynaLog(" jmp eax");
*(x86BlockPtr.uwPtr++) = 0xe0ff;
}
__inline void JmpIndirectLabel32(char * Label,DWORD location) {
DynaLog(" jmp dword ptr [%s]", Label);
*(x86BlockPtr.uwPtr++) = 0x25ff;
*(x86BlockPtr.udwPtr++) = location;
}
__inline void Int3 () {
*(x86BlockPtr.ubPtr++) = 0xCC;
}