BlackBone
Windows memory hacking library
 All Classes Functions
AsmHelperBase.h
1 #pragma once
2 
3 #include "AsmVariant.hpp"
4 #include "AsmStack.hpp"
5 #include "../Include/Macro.h"
6 
7 #include <initializer_list>
8 #include <vector>
9 
10 namespace blackbone
11 {
12  //
13  // Function calling convention
14  //
15  enum eCalligConvention
16  {
17  cc_cdecl, // cdecl
18  cc_stdcall, // stdcall
19  cc_thiscall, // thiscall
20  cc_fastcall // fastcall
21  };
22 
23  //
24  // Function return type
25  // Do not change numeric values!
26  //
27  enum eReturnType
28  {
29  rt_int32 = 4, // 32bit value
30  rt_int64 = 8, // 64bit value
31  rt_float = 1, // float value
32  rt_double = 2, // double value
33  rt_struct = 3, // structure returned by value
34  };
35 
36  // Argument pass method
37  enum eArgType
38  {
39  at_ecx = 0, // In ecx
40  at_edx = 1, // In edx
41  at_stack = 2, // On stack
42  };
43 
44 
49  {
50  public:
51  BLACKBONE_API AsmHelperBase() : _assembler( &_runtime ) { }
52  virtual ~AsmHelperBase() { }
53 
54  virtual void GenPrologue( bool switchMode = false ) = 0;
55  virtual void GenEpilogue( bool switchMode = false, int retSize = -1) = 0;
56  virtual void GenCall( const AsmVariant&, const std::vector<AsmVariant>& args, eCalligConvention cc = cc_stdcall ) = 0;
57  virtual void ExitThreadWithStatus( size_t pExitThread, size_t resultPtr ) = 0;
58  virtual void SaveRetValAndSignalEvent( size_t pSetEvent, size_t ResultPtr, size_t EventPtr, size_t errPtr, eReturnType rtype = rt_int32 ) = 0;
59  virtual void SetTebPtr() = 0;
60  virtual void EnableX64CallStack( bool state ) = 0;
61 
65  BLACKBONE_API void SwitchTo86()
66  {
67  asmjit::Label l = _assembler.newLabel();
68 
69  _assembler.call( l ); _assembler.bind( l );
70  _assembler.mov( asmjit::host::dword_ptr( asmjit::host::esp, 4 ), 0x23 );
71  _assembler.add( asmjit::host::dword_ptr( asmjit::host::esp ), 0xD );
72  _assembler.db( 0xCB ); // retf
73  }
74 
78  BLACKBONE_API void SwitchTo64()
79  {
80  asmjit::Label l = _assembler.newLabel();
81 
82  _assembler.push( 0x33 );
83  _assembler.call( l ); _assembler.bind( l );
84  //_assembler.add( asmjit::host::dword_ptr( asmjit::host::esp ), 5 );
85  _assembler.dd( '\x83\x04\x24\x05' );
86  _assembler.db( 0xCB ); // retf
87  }
88 
89  BLACKBONE_API inline asmjit::X86Assembler* assembler() { return &_assembler; }
90  BLACKBONE_API inline asmjit::X86Assembler* operator ->() { return &_assembler; }
91 
92  private:
93  AsmHelperBase( const AsmHelperBase& ) = delete;
94  AsmHelperBase& operator =(const AsmHelperBase&) = delete;
95 
96  protected:
97  asmjit::JitRuntime _runtime;
98  asmjit::X86Assembler _assembler;
99  };
100 }
BLACKBONE_API void SwitchTo64()
Switch processor into x64 mode (long mode)
Definition: AsmHelperBase.h:78
General purpose assembly variable
Definition: AsmVariant.hpp:16
Assembly generation helper
Definition: AsmHelperBase.h:48
BLACKBONE_API void SwitchTo86()
Switch processor into WOW64 emulation mode
Definition: AsmHelperBase.h:65
Definition: AsmHelper32.cpp:6