VMProfiler  v1.8
vmprofiler is a c++ library which is used to statically analyze VMProtect 2 polymorphic virtual machines. This project is inherited in vmprofiler-qt, vmprofiler-cli, and vmemu.
vmp2.hpp
Go to the documentation of this file.
1 #pragma once
2 #include <transform.hpp>
3 #include <vmhandlers.hpp>
4 #define VMP_MAGIC '2PMV'
5 
6 namespace vmp2
7 {
8  enum class exec_type_t
9  {
10  forward,
11  backward
12  };
13 
14  enum class version_t
15  {
16  invalid,
17  v1 = 0x101,
18  v2 = 0x102,
19  v3 = 0x103
20  };
21 
22  namespace v1
23  {
24  struct file_header
25  {
26  u32 magic; // VMP2
31 
34  };
35 
36  struct entry_t
37  {
41 
42  union
43  {
44  struct
45  {
62  };
63  u64 raw[ 16 ];
64  } regs;
65 
66  union
67  {
68  u64 qword[ 0x28 ];
69  u8 raw[ 0x140 ];
70  } vregs;
71 
72  union
73  {
74  u64 qword[ 0x20 ];
75  u8 raw[ 0x100 ];
76  } vsp;
77  };
78  } // namespace v1
79 
80  namespace v2
81  {
82  struct file_header
83  {
84  u32 magic; // VMP2
87 
92 
95 
98  };
99 
100  struct entry_t
101  {
105 
106  union
107  {
108  struct
109  {
126  };
127  u64 raw[ 16 ];
128  } regs;
129 
130  union
131  {
132  u64 qword[ 0x28 ];
133  u8 raw[ 0x140 ];
134  } vregs;
135 
136  union
137  {
138  u64 qword[ 0x20 ];
139  u8 raw[ 0x100 ];
140  } vsp;
141  };
142  } // namespace v2
143 } // namespace vmp2
144 
145 namespace vm
146 {
147  namespace instrs
148  {
150  {
152  std::uint8_t opcode; // aka vm handler idx...
153 
154  // can be used to look at values on the stack...
156 
157  struct
158  {
159  bool has_imm;
160  struct
161  {
162  std::uint8_t imm_size; // size in bits...
163  union
164  {
165  std::int64_t s;
166  std::uint64_t u;
167  };
168  } imm;
170  };
171 
172  enum class jcc_type
173  {
174  none,
175  branching,
176  absolute
177  };
178 
179  struct jcc_data
180  {
181  bool has_jcc;
183  std::uintptr_t block_addr[ 2 ];
184  };
185 
187  {
188  std::uintptr_t vip_begin;
190  std::vector< virt_instr_t > vinstrs;
191  };
192  } // namespace instrs
193 } // namespace vm
194 
195 namespace vmp2
196 {
197  namespace v3
198  {
199  struct file_header
200  {
201  u32 magic; // VMP2
204 
208 
211 
214  };
215 
217  {
218  std::uintptr_t vip_begin;
219  std::uintptr_t next_block_offset;
221 
222  // serialized from std::vector<virt_instr_t>...
223  std::uint32_t vinstr_count;
225  };
226  } // namespace v3
227 } // namespace vmp2
mnemonic_t
vm handler mnemonic... so you dont need to compare strings!
Definition: vmprofiles.hpp:13
jcc_type
Definition: vmp2.hpp:173
Definition: calc_jmp.hpp:6
Definition: vmp2.hpp:7
version_t
Definition: vmp2.hpp:15
exec_type_t
Definition: vmp2.hpp:9
Definition: vmp2.hpp:187
std::vector< virt_instr_t > vinstrs
Definition: vmp2.hpp:190
jcc_data jcc
Definition: vmp2.hpp:189
std::uintptr_t vip_begin
Definition: vmp2.hpp:188
Definition: vmp2.hpp:180
jcc_type type
Definition: vmp2.hpp:182
std::uintptr_t block_addr[2]
Definition: vmp2.hpp:183
bool has_jcc
Definition: vmp2.hpp:181
Definition: vmp2.hpp:150
std::uint64_t u
Definition: vmp2.hpp:166
std::uint8_t imm_size
Definition: vmp2.hpp:162
struct vm::instrs::virt_instr_t::@10::@11 imm
std::int64_t s
Definition: vmp2.hpp:165
vmp2::v2::entry_t trace_data
Definition: vmp2.hpp:155
struct vm::instrs::virt_instr_t::@10 operand
vm::handler::mnemonic_t mnemonic_t
Definition: vmp2.hpp:151
bool has_imm
Definition: vmp2.hpp:159
std::uint8_t opcode
Definition: vmp2.hpp:152
Definition: vmp2.hpp:37
u64 rdi
Definition: vmp2.hpp:55
u64 r11
Definition: vmp2.hpp:50
u64 qword[0x28]
Definition: vmp2.hpp:68
u64 raw[16]
Definition: vmp2.hpp:63
u64 r8
Definition: vmp2.hpp:53
union vmp2::v1::entry_t::@2 vsp
u64 rdx
Definition: vmp2.hpp:57
u8 handler_idx
Definition: vmp2.hpp:38
u64 r14
Definition: vmp2.hpp:47
u64 r9
Definition: vmp2.hpp:52
u64 rbp
Definition: vmp2.hpp:54
u64 r10
Definition: vmp2.hpp:51
u64 rsi
Definition: vmp2.hpp:56
u64 r15
Definition: vmp2.hpp:46
u64 rflags
Definition: vmp2.hpp:61
u64 r12
Definition: vmp2.hpp:49
union vmp2::v1::entry_t::@0 regs
u64 r13
Definition: vmp2.hpp:48
u64 rbx
Definition: vmp2.hpp:59
u64 rcx
Definition: vmp2.hpp:58
union vmp2::v1::entry_t::@1 vregs
u64 rax
Definition: vmp2.hpp:60
u64 vip
Definition: vmp2.hpp:40
u64 decrypt_key
Definition: vmp2.hpp:39
Definition: vmp2.hpp:25
u32 magic
Definition: vmp2.hpp:26
u64 module_base
Definition: vmp2.hpp:28
exec_type_t advancement
Definition: vmp2.hpp:29
version_t version
Definition: vmp2.hpp:30
u32 entry_offset
Definition: vmp2.hpp:33
u32 entry_count
Definition: vmp2.hpp:32
u64 epoch_time
Definition: vmp2.hpp:27
Definition: vmp2.hpp:101
u8 handler_idx
Definition: vmp2.hpp:102
u64 r9
Definition: vmp2.hpp:116
u64 rsi
Definition: vmp2.hpp:120
u64 raw[16]
Definition: vmp2.hpp:127
union vmp2::v2::entry_t::@7 vsp
u64 r10
Definition: vmp2.hpp:115
u64 rax
Definition: vmp2.hpp:124
u64 r14
Definition: vmp2.hpp:111
union vmp2::v2::entry_t::@5 regs
u64 rdx
Definition: vmp2.hpp:121
u64 rflags
Definition: vmp2.hpp:125
u64 r8
Definition: vmp2.hpp:117
u64 r11
Definition: vmp2.hpp:114
u64 rdi
Definition: vmp2.hpp:119
u64 decrypt_key
Definition: vmp2.hpp:103
u64 r12
Definition: vmp2.hpp:113
u64 r13
Definition: vmp2.hpp:112
u64 r15
Definition: vmp2.hpp:110
u64 rbp
Definition: vmp2.hpp:118
u64 rbx
Definition: vmp2.hpp:123
u64 qword[0x28]
Definition: vmp2.hpp:132
u64 rcx
Definition: vmp2.hpp:122
u64 vip
Definition: vmp2.hpp:104
union vmp2::v2::entry_t::@6 vregs
Definition: vmp2.hpp:83
version_t version
Definition: vmp2.hpp:86
u32 module_offset
Definition: vmp2.hpp:93
u32 entry_count
Definition: vmp2.hpp:96
u64 epoch_time
Definition: vmp2.hpp:85
u32 entry_offset
Definition: vmp2.hpp:97
u64 module_base
Definition: vmp2.hpp:88
u64 image_base
Definition: vmp2.hpp:89
exec_type_t advancement
Definition: vmp2.hpp:91
u32 module_size
Definition: vmp2.hpp:94
u32 magic
Definition: vmp2.hpp:84
u64 vm_entry_rva
Definition: vmp2.hpp:90
Definition: vmp2.hpp:217
vm::instrs::jcc_data jcc
Definition: vmp2.hpp:220
vm::instrs::virt_instr_t vinstr[]
Definition: vmp2.hpp:224
std::uintptr_t next_block_offset
Definition: vmp2.hpp:219
std::uintptr_t vip_begin
Definition: vmp2.hpp:218
std::uint32_t vinstr_count
Definition: vmp2.hpp:223
Definition: vmp2.hpp:200
u32 code_block_count
Definition: vmp2.hpp:213
u32 magic
Definition: vmp2.hpp:201
u32 code_block_offset
Definition: vmp2.hpp:212
u32 module_offset
Definition: vmp2.hpp:209
u64 module_base
Definition: vmp2.hpp:205
u32 module_size
Definition: vmp2.hpp:210
u64 image_base
Definition: vmp2.hpp:206
version_t version
Definition: vmp2.hpp:203
u64 epoch_time
Definition: vmp2.hpp:202
u64 vm_entry_rva
Definition: vmp2.hpp:207
unsigned long long u64
Definition: vmutils.hpp:15
unsigned int u32
Definition: vmutils.hpp:14
unsigned char u8
Definition: vmutils.hpp:12