updated readme and doxygen file...

merge-requests/11/head
_xeroxz 3 years ago
parent 64a139ffca
commit 97cb3f11c7

@ -4,6 +4,118 @@
</div> </div>
</div> </div>
# VMProfiler - Library To Profile VMProtect 2 Virtual Machines ### VMProfiler - Library To Profile VMProtect 2 Virtual Machines
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. This is the base project for all other VMProtect 2 projects inside of this group on githacks. 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. This is the base project for all other VMProtect 2 projects inside of this group on githacks.
### Credit & Contributors
* [VTIL](https://github.com/vtil-project/VTIL-Core) - Virtual-machine Translation Intermediate Language
* [Zydis](https://github.com/zyantific/zydis) - Fast and lightweight x86/x86-64 disassembler library
* [irql0](https://github.com/irql0) - helped with the first version of vm handler pattern matching
### Basic Usage - Creating a vm::ctx_t Object
The `vm::ctx_t` class is a small container-like class which is simply used to contain all information for a given vm entry. This class contains the following useful information:
* all vm handlers for a given vm entry
* the linear virtual address of the module base in memory
* the image base address
* the image size in virtual memory
* which way VIP advances (exec_type)
* vm entry relative virtual address
* vm entry deobfuscated and flattened
* calc jmp deobfuscated and flattened
All of the above information is generated by executing the `vm::ctx_t::init` member function. Below is a C++ example of how to create a `vm::ctx_t` object.
```cpp
const auto module_base = reinterpret_cast< std::uintptr_t >(
LoadLibraryExA( parser.get< std::string >( "bin" ).c_str(),
NULL, DONT_RESOLVE_DLL_REFERENCES ) );
const auto vm_entry_rva = std::strtoull( parser.get< std::string >( "vmentry" ).c_str(), nullptr, 16 );
const auto image_base = umtils->image_base( parser.get< std::string >( "bin" ).c_str() );
const auto image_size = NT_HEADER( module_base )->OptionalHeader.SizeOfImage;
vm::ctx_t vmctx( module_base, image_base, image_size, vm_entry_rva );
if ( !vmctx.init() )
{
std::printf( "[!] failed to init vm::ctx_t... make sure all cli arguments are correct!\n" );
return -1;
}
```
### Using vm::ctx_t Object
Once you have instantiated `vm::ctx_t` and called `vm::ctx_t::init` with success, you now can directly access the data members of `vm::ctx_t`. Most importantly, `vm::ctx_t::calc_jmp`, `vm::ctx_t::vm_entry`, and `vm::ctx_t::vm_handlers`. An example usage of this data could be dumping the native x86_64 instructions which make up `vm::ctx_t::vm_entry`. Example c++ code for this is displayed below.
```cpp
std::puts( "======================== [vm entry] ========================\n" );
vm::util::print( vmctx.vm_entry );
```
***Output***
```
======================== [vm entry] ========================
> 0x00007FF7911A822C push 0xFFFFFFFF890001FA
> 0x00007FF7911A7FC9 push 0x45D3BF1F
> 0x00007FF7911A48E4 push r13
> 0x00007FF7911A4690 push rsi
> 0x00007FF7911A4E53 push r14
> 0x00007FF7911A74FB push rcx
> 0x00007FF7911A607C push rsp
> 0x00007FF7911A4926 pushfq
> 0x00007FF7911A4DC2 push rbp
> 0x00007FF7911A5C8C push r12
> 0x00007FF7911A52AC push r10
> 0x00007FF7911A51A5 push r9
> 0x00007FF7911A5189 push rdx
> 0x00007FF7911A7D5F push r8
> 0x00007FF7911A4505 push rdi
> 0x00007FF7911A4745 push r11
> 0x00007FF7911A478B push rax
> 0x00007FF7911A7A53 push rbx
> 0x00007FF7911A500D push r15
> 0x00007FF7911A6030 push [0x00007FF7911A7912]
> 0x00007FF7911A593A mov rax, 0x7FF6511A0000
> 0x00007FF7911A5955 mov r13, rax
> 0x00007FF7911A595F test dl, al
> 0x00007FF7911A5965 push rax
> 0x00007FF7911A5969 btr si, bx
> 0x00007FF7911A596F mov esi, [rsp+0xA0]
> 0x00007FF7911A5979 not esi
> 0x00007FF7911A5985 neg esi
> 0x00007FF7911A598D ror esi, 0x1A
> 0x00007FF7911A599E mov rbp, rsp
> 0x00007FF7911A59A8 sub rsp, 0x140
> 0x00007FF7911A59B5 and rsp, 0xFFFFFFFFFFFFFFF0
> 0x00007FF7911A59BE inc ax
> 0x00007FF7911A59C1 mov rdi, rsp
> 0x00007FF7911A59C7 bsr r12, rax
> 0x00007FF7911A59CB lea r12, [0x00007FF7911A6473]
> 0x00007FF7911A59DF mov rax, 0x100000000
> 0x00007FF7911A59EC add rsi, rax
> 0x00007FF7911A59F3 mov rbx, rsi
> 0x00007FF7911A59FA add rsi, [rbp]
> 0x00007FF7911A5A03 rcr dl, cl
> 0x00007FF7911A5A05 mov al, [rsi]
> 0x00007FF7911A5A0A xor al, bl
> 0x00007FF7911A5A11 neg al
> 0x00007FF7911A5A19 rol al, 0x05
> 0x00007FF7911A5A26 inc al
> 0x00007FF7911A5A2F xor bl, al
> 0x00007FF7911A5A34 movzx rax, al
> 0x00007FF7911A5A41 mov rdx, [r12+rax*8]
> 0x00007FF7911A5A49 xor rdx, 0x7F3D2149
> 0x00007FF7911A5507 inc rsi
> 0x00007FF7911A7951 add rdx, r13
> 0x00007FF7911A7954 jmp rdx
```
### License & Copyright
Copyright (c) 2021 _xeroxz, Independent Researcher @back.engineering
Licensed under the MIT License

@ -68,9 +68,110 @@ $(function() {
<div class="title">VMProfiler Documentation</div> </div> <div class="title">VMProfiler Documentation</div> </div>
</div><!--header--> </div><!--header-->
<div class="contents"> <div class="contents">
<div class="textblock"><p><a class="anchor" id="md_D__vmprofiler_qt_dependencies_vmprofiler_README"></a> </p><div align="center"> <div> <img src="https://githacks.org/uploads/-/system/project/avatar/374/icon-5.png" alt="" class="inline"/> </div> </div><h1><a class="anchor" id="autotoc_md0"></a> <div class="textblock"><p><a class="anchor" id="md_D__vmprofiler_qt_dependencies_vmprofiler_README"></a> </p><div align="center"> <div> <img src="https://githacks.org/uploads/-/system/project/avatar/374/icon-5.png" alt="" class="inline"/> </div> </div><h3><a class="anchor" id="autotoc_md0"></a>
VMProfiler - Library To Profile VMProtect 2 Virtual Machines</h1> VMProfiler - Library To Profile VMProtect 2 Virtual Machines</h3>
<p>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. This is the base project for all other VMProtect 2 projects inside of this group on githacks.</p> <p>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. This is the base project for all other VMProtect 2 projects inside of this group on githacks.</p>
<h3><a class="anchor" id="autotoc_md1"></a>
Credit &amp; Contributors</h3>
<ul>
<li><a href="https://github.com/vtil-project/VTIL-Core">VTIL</a> - Virtual-machine Translation Intermediate Language</li>
<li><a href="https://github.com/zyantific/zydis">Zydis</a> - Fast and lightweight x86/x86-64 disassembler library</li>
<li><a href="https://github.com/irql0">irql0</a> - helped with the first version of vm handler pattern matching</li>
</ul>
<h3><a class="anchor" id="autotoc_md2"></a>
Basic Usage - Creating a vm::ctx_t Object</h3>
<p>The <code><a class="el" href="classvm_1_1ctx__t.html" title="vm::ctx_t class is used to auto generate vm_entry, calc_jmp, and other per-vm entry information....">vm::ctx_t</a></code> class is a small container-like class which is simply used to contain all information for a given vm entry. This class contains the following useful information:</p>
<ul>
<li>all vm handlers for a given vm entry</li>
<li>the linear virtual address of the module base in memory</li>
<li>the image base address</li>
<li>the image size in virtual memory</li>
<li>which way VIP advances (exec_type)</li>
<li>vm entry relative virtual address</li>
<li>vm entry deobfuscated and flattened</li>
<li>calc jmp deobfuscated and flattened</li>
</ul>
<p>All of the above information is generated by executing the <code><a class="el" href="classvm_1_1ctx__t.html#a7f24e3ed32d1cca86c296dd8dae4b6d2" title="init all per-vm entry data such as vm_entry, calc_jmp, and vm handlers...">vm::ctx_t::init</a></code> member function. Below is a C++ example of how to create a <code><a class="el" href="classvm_1_1ctx__t.html" title="vm::ctx_t class is used to auto generate vm_entry, calc_jmp, and other per-vm entry information....">vm::ctx_t</a></code> object.</p>
<div class="fragment"><div class="line"><span class="keyword">const</span> <span class="keyword">auto</span> module_base = <span class="keyword">reinterpret_cast&lt;</span> std::uintptr_t <span class="keyword">&gt;</span>(</div>
<div class="line"> LoadLibraryExA( parser.get&lt; std::string &gt;( <span class="stringliteral">&quot;bin&quot;</span> ).c_str(),</div>
<div class="line"> NULL, DONT_RESOLVE_DLL_REFERENCES ) );</div>
<div class="line"> </div>
<div class="line"><span class="keyword">const</span> <span class="keyword">auto</span> vm_entry_rva = std::strtoull( parser.get&lt; std::string &gt;( <span class="stringliteral">&quot;vmentry&quot;</span> ).c_str(), <span class="keyword">nullptr</span>, 16 );</div>
<div class="line"><span class="keyword">const</span> <span class="keyword">auto</span> image_base = umtils-&gt;image_base( parser.get&lt; std::string &gt;( <span class="stringliteral">&quot;bin&quot;</span> ).c_str() );</div>
<div class="line"><span class="keyword">const</span> <span class="keyword">auto</span> image_size = NT_HEADER( module_base )-&gt;OptionalHeader.SizeOfImage;</div>
<div class="line"><a class="code" href="classvm_1_1ctx__t.html">vm::ctx_t</a> vmctx( module_base, image_base, image_size, vm_entry_rva );</div>
<div class="line"> </div>
<div class="line"><span class="keywordflow">if</span> ( !vmctx.init() )</div>
<div class="line">{</div>
<div class="line"> std::printf( <span class="stringliteral">&quot;[!] failed to init vm::ctx_t... make sure all cli arguments are correct!\n&quot;</span> );</div>
<div class="line"> <span class="keywordflow">return</span> -1;</div>
<div class="line">}</div>
<div class="ttc" id="aclassvm_1_1ctx__t_html"><div class="ttname"><a href="classvm_1_1ctx__t.html">vm::ctx_t</a></div><div class="ttdoc">vm::ctx_t class is used to auto generate vm_entry, calc_jmp, and other per-vm entry information....</div><div class="ttdef"><b>Definition:</b> vmctx.hpp:13</div></div>
</div><!-- fragment --><h3><a class="anchor" id="autotoc_md3"></a>
Using vm::ctx_t Object</h3>
<p>Once you have instantiated <code><a class="el" href="classvm_1_1ctx__t.html" title="vm::ctx_t class is used to auto generate vm_entry, calc_jmp, and other per-vm entry information....">vm::ctx_t</a></code> and called <code><a class="el" href="classvm_1_1ctx__t.html#a7f24e3ed32d1cca86c296dd8dae4b6d2" title="init all per-vm entry data such as vm_entry, calc_jmp, and vm handlers...">vm::ctx_t::init</a></code> with success, you now can directly access the data members of <code><a class="el" href="classvm_1_1ctx__t.html" title="vm::ctx_t class is used to auto generate vm_entry, calc_jmp, and other per-vm entry information....">vm::ctx_t</a></code>. Most importantly, <code><a class="el" href="classvm_1_1ctx__t.html#aed0dfa1748035f48bda0f59f76643d8d">vm::ctx_t::calc_jmp</a></code>, <code><a class="el" href="classvm_1_1ctx__t.html#a40f0524813578bcddf9ded1e74443793">vm::ctx_t::vm_entry</a></code>, and <code><a class="el" href="classvm_1_1ctx__t.html#a0fa31b5bd78861dbd2c5cf04af81aa4d" title="all the vm handlers for the given vm entry...">vm::ctx_t::vm_handlers</a></code>. An example usage of this data could be dumping the native x86_64 instructions which make up <code><a class="el" href="classvm_1_1ctx__t.html#a40f0524813578bcddf9ded1e74443793">vm::ctx_t::vm_entry</a></code>. Example c++ code for this is displayed below.</p>
<div class="fragment"><div class="line">std::puts( <span class="stringliteral">&quot;======================== [vm entry] ========================\n&quot;</span> );</div>
<div class="line"><a class="code" href="namespacevm_1_1util.html#abcfe75a7d22f907a6187579373679204">vm::util::print</a>( vmctx.vm_entry );</div>
<div class="ttc" id="anamespacevm_1_1util_html_abcfe75a7d22f907a6187579373679204"><div class="ttname"><a href="namespacevm_1_1util.html#abcfe75a7d22f907a6187579373679204">vm::util::print</a></div><div class="ttdeci">void print(zydis_routine_t &amp;routine)</div><div class="ttdoc">prints a disassembly view of a routine...</div><div class="ttdef"><b>Definition:</b> vmutils.cpp:69</div></div>
</div><!-- fragment --><p><em><b>Output</b></em></p>
<div class="fragment"><div class="line">======================== [vm entry] ========================</div>
<div class="line">&gt; 0x00007FF7911A822C push 0xFFFFFFFF890001FA</div>
<div class="line">&gt; 0x00007FF7911A7FC9 push 0x45D3BF1F</div>
<div class="line">&gt; 0x00007FF7911A48E4 push r13</div>
<div class="line">&gt; 0x00007FF7911A4690 push rsi</div>
<div class="line">&gt; 0x00007FF7911A4E53 push r14</div>
<div class="line">&gt; 0x00007FF7911A74FB push rcx</div>
<div class="line">&gt; 0x00007FF7911A607C push rsp</div>
<div class="line">&gt; 0x00007FF7911A4926 pushfq</div>
<div class="line">&gt; 0x00007FF7911A4DC2 push rbp</div>
<div class="line">&gt; 0x00007FF7911A5C8C push r12</div>
<div class="line">&gt; 0x00007FF7911A52AC push r10</div>
<div class="line">&gt; 0x00007FF7911A51A5 push r9</div>
<div class="line">&gt; 0x00007FF7911A5189 push rdx</div>
<div class="line">&gt; 0x00007FF7911A7D5F push r8</div>
<div class="line">&gt; 0x00007FF7911A4505 push rdi</div>
<div class="line">&gt; 0x00007FF7911A4745 push r11</div>
<div class="line">&gt; 0x00007FF7911A478B push rax</div>
<div class="line">&gt; 0x00007FF7911A7A53 push rbx</div>
<div class="line">&gt; 0x00007FF7911A500D push r15</div>
<div class="line">&gt; 0x00007FF7911A6030 push [0x00007FF7911A7912]</div>
<div class="line">&gt; 0x00007FF7911A593A mov rax, 0x7FF6511A0000</div>
<div class="line">&gt; 0x00007FF7911A5955 mov r13, rax</div>
<div class="line">&gt; 0x00007FF7911A595F test dl, al</div>
<div class="line">&gt; 0x00007FF7911A5965 push rax</div>
<div class="line">&gt; 0x00007FF7911A5969 btr si, bx</div>
<div class="line">&gt; 0x00007FF7911A596F mov esi, [rsp+0xA0]</div>
<div class="line">&gt; 0x00007FF7911A5979 not esi</div>
<div class="line">&gt; 0x00007FF7911A5985 neg esi</div>
<div class="line">&gt; 0x00007FF7911A598D ror esi, 0x1A</div>
<div class="line">&gt; 0x00007FF7911A599E mov rbp, rsp</div>
<div class="line">&gt; 0x00007FF7911A59A8 sub rsp, 0x140</div>
<div class="line">&gt; 0x00007FF7911A59B5 and rsp, 0xFFFFFFFFFFFFFFF0</div>
<div class="line">&gt; 0x00007FF7911A59BE inc ax</div>
<div class="line">&gt; 0x00007FF7911A59C1 mov rdi, rsp</div>
<div class="line">&gt; 0x00007FF7911A59C7 bsr r12, rax</div>
<div class="line">&gt; 0x00007FF7911A59CB lea r12, [0x00007FF7911A6473]</div>
<div class="line">&gt; 0x00007FF7911A59DF mov rax, 0x100000000</div>
<div class="line">&gt; 0x00007FF7911A59EC add rsi, rax</div>
<div class="line">&gt; 0x00007FF7911A59F3 mov rbx, rsi</div>
<div class="line">&gt; 0x00007FF7911A59FA add rsi, [rbp]</div>
<div class="line">&gt; 0x00007FF7911A5A03 rcr dl, cl</div>
<div class="line">&gt; 0x00007FF7911A5A05 mov al, [rsi]</div>
<div class="line">&gt; 0x00007FF7911A5A0A xor al, bl</div>
<div class="line">&gt; 0x00007FF7911A5A11 neg al</div>
<div class="line">&gt; 0x00007FF7911A5A19 rol al, 0x05</div>
<div class="line">&gt; 0x00007FF7911A5A26 inc al</div>
<div class="line">&gt; 0x00007FF7911A5A2F xor bl, al</div>
<div class="line">&gt; 0x00007FF7911A5A34 movzx rax, al</div>
<div class="line">&gt; 0x00007FF7911A5A41 mov rdx, [r12+rax*8]</div>
<div class="line">&gt; 0x00007FF7911A5A49 xor rdx, 0x7F3D2149</div>
<div class="line">&gt; 0x00007FF7911A5507 inc rsi</div>
<div class="line">&gt; 0x00007FF7911A7951 add rdx, r13</div>
<div class="line">&gt; 0x00007FF7911A7954 jmp rdx</div>
</div><!-- fragment --><h3><a class="anchor" id="autotoc_md4"></a>
License &amp; Copyright</h3>
<p>Copyright (c) 2021 _xeroxz, Independent Researcher @back.engineering</p>
<p>Licensed under the MIT License </p>
</div></div><!-- PageDoc --> </div></div><!-- PageDoc -->
</div><!-- contents --> </div><!-- contents -->
<!-- start footer part --> <!-- start footer part -->

Loading…
Cancel
Save