BlackBone
Windows memory hacking library
 All Classes Functions
AsmStack.hpp
1 #pragma once
2 
3 #pragma warning(disable : 4100)
4 #include "AsmJit/AsmJit.h"
5 #pragma warning(default : 4100)
6 #include "../Include/Macro.h"
7 
8 #include <stdint.h>
9 
10 namespace blackbone
11 {
12 
14 {
15 public:
16  BLACKBONE_API AsmStackAllocator( intptr_t baseval = 0x28 )
17  : disp_ofst( sizeof(size_t) )
18  {
19 #ifdef USE64
20  disp_ofst = baseval;
21 #else
22  UNREFERENCED_PARAMETER( baseval );
23 #endif
24  }
25 
31  BLACKBONE_API asmjit::host::Mem AllocVar( intptr_t size )
32  {
33  // Align on word length
34  size = Align( size, sizeof(size_t) );
35 
36 #ifdef USE64
37  auto val = asmjit::host::Mem( asmjit::host::zsp, static_cast<int32_t>(disp_ofst), static_cast<int32_t>(size) );
38 #else
39  auto val = asmjit::host::Mem( asmjit::host::zbp, -disp_ofst - size, size );
40 #endif
41  disp_ofst += size;
42  return val;
43  }
44 
52  BLACKBONE_API bool AllocArray( asmjit::host::Mem arr[], int count, intptr_t size )
53  {
54  for (int i = 0; i < count; i++)
55  {
56 #ifdef USE64
57  arr[i] = asmjit::host::Mem( asmjit::host::zsp, static_cast<int32_t>(disp_ofst), static_cast<int32_t>(size) );
58 #else
59  arr[i] = asmjit::host::Mem( asmjit::host::zbp, -disp_ofst - size, size );
60 #endif
61  disp_ofst += size;
62  }
63 
64  return true;
65  }
66 
71  BLACKBONE_API inline intptr_t getTotalSize() const { return disp_ofst; };
72 
73 private:
74  intptr_t disp_ofst; // Next variable stack offset
75 };
76 
77 //
78 // Helpers
79 //
80 #define ALLOC_STACK_VAR(worker, name, type) asmjit::host::Mem name( worker.AllocVar( sizeof(type) ) );
81 #define ALLOC_STACK_VAR_S(worker, name, size) asmjit::host::Mem name( worker.AllocVar( size ) );
82 
83 #define ALLOC_STACK_ARRAY(worker, name, type, count) \
84  asmjit::host::Mem name[count]; \
85  worker.AllocArray( name, count, sizeof(type) );
86 
87 }
Definition: AsmStack.hpp:13
BLACKBONE_API asmjit::host::Mem AllocVar(intptr_t size)
Allocate stack variable
Definition: AsmStack.hpp:31
BLACKBONE_API bool AllocArray(asmjit::host::Mem arr[], int count, intptr_t size)
Allocate array of stack variables
Definition: AsmStack.hpp:52
BLACKBONE_API intptr_t getTotalSize() const
Get total size of all stack variables
Definition: AsmStack.hpp:71
Definition: AsmHelper32.cpp:6