VMAssembler  v1.2
VMProtect 2 Virtual Instruction Assembler
compiler.h
Go to the documentation of this file.
1 #pragma once
2 #include <Windows.h>
3 #include <algorithm>
4 #include <vmprofiler.hpp>
5 #include <xtils.hpp>
6 
7 #include "parser.h"
8 
9 namespace vm
10 {
14  struct vinstr_data
15  {
19  std::uint8_t vm_handler;
20 
24  std::uint64_t operand;
25 
29  std::uint8_t imm_size;
30  };
31 
35  struct vlabel_data
36  {
40  std::string label_name;
41 
45  std::vector< vinstr_data > vinstrs;
46  };
47 
52  {
56  std::string label_name;
57 
61  std::uintptr_t alloc_rva;
62 
66  std::uintptr_t enc_alloc_rva;
67 
71  std::vector< std::uint8_t > vinstrs;
72  };
73 
77  class compiler_t
78  {
79  public:
84  explicit compiler_t( vm::ctx_t *vmctx );
85 
90  std::vector< vlabel_data > *encode();
91 
97  std::vector< compiled_label_data > encrypt();
98 
99  private:
106  std::uint64_t encrypt_rva( std::uint64_t rva );
107 
111  vm::ctx_t *vmctx;
112 
117  transform::map_t calc_jmp_transforms;
118 
122  std::vector< vlabel_data > virt_labels;
123 
128  std::vector< zydis_decoded_instr_t > encrypt_vinstrs_rva;
129  };
130 } // namespace vm
class containing member functions used to encode and encrypted virtual instructions....
Definition: compiler.h:78
std::vector< compiled_label_data > encrypt()
encrypt virtual instructions from parser::virt_labels
Definition: compiler.cpp:76
compiler_t(vm::ctx_t *vmctx)
default constructor
Definition: compiler.cpp:5
std::vector< vlabel_data > * encode()
encode virtual instructions from parser::virt_labels
Definition: compiler.cpp:53
Definition: test.hpp:6
struct containing compiled virtual instructions (encoded and encrypted) for a given label....
Definition: compiler.h:52
std::string label_name
label name...
Definition: compiler.h:56
std::uintptr_t alloc_rva
relative virtual address from vm_entry to the virtual instructions...
Definition: compiler.h:61
std::vector< std::uint8_t > vinstrs
vector of bytes containing the raw, encrypted virtual instructions...
Definition: compiler.h:71
std::uintptr_t enc_alloc_rva
encrypted relative virtual address from vm_entry to virtual instructions...
Definition: compiler.h:66
struct containing encoded data for a given virtual instruction...
Definition: compiler.h:15
std::uint8_t vm_handler
vm handler index also known as the opcode...
Definition: compiler.h:19
std::uint64_t operand
this field contains the second operand if any...
Definition: compiler.h:24
std::uint8_t imm_size
size in bits of the second operand if any... zero if none...
Definition: compiler.h:29
struct containing all information for a label...
Definition: compiler.h:36
std::string label_name
name of the label...
Definition: compiler.h:40
std::vector< vinstr_data > vinstrs
vector of encoded virtual instructions...
Definition: compiler.h:45