5 #pragma warning(disable : 4100)
6 #include <AsmJit/asmjit.h>
7 #pragma warning(default : 4100)
22 template<
typename... Args>
42 : AsmVariant( noarg, 0, 0 ) { }
44 BLACKBONE_API AsmVariant(
int _imm )
45 : AsmVariant( imm,
sizeof(_imm), static_cast<size_t>(_imm) ) { }
47 BLACKBONE_API AsmVariant(
unsigned long _imm )
48 : AsmVariant( imm,
sizeof(_imm), static_cast<size_t>(_imm) ) { }
50 BLACKBONE_API AsmVariant(
size_t _imm )
51 : AsmVariant( imm,
sizeof(_imm), _imm ) { }
53 BLACKBONE_API AsmVariant(
char* ptr )
54 : AsmVariant( dataPtr, strlen( ptr ) + 1, reinterpret_cast<size_t>(ptr) ) { }
56 BLACKBONE_API AsmVariant(
const char* ptr )
57 : AsmVariant( const_cast<char*>(ptr) ) { }
59 BLACKBONE_API AsmVariant(
wchar_t* ptr )
60 : AsmVariant( dataPtr, (wcslen( ptr ) + 1) *
sizeof(
wchar_t), reinterpret_cast<size_t>(ptr) ) { }
62 BLACKBONE_API AsmVariant(
const wchar_t* ptr )
63 : AsmVariant( const_cast<wchar_t*>(ptr) ) { }
65 BLACKBONE_API AsmVariant(
void* _imm )
66 : AsmVariant( imm,
sizeof(
void*), reinterpret_cast<size_t>(_imm) ) { }
68 BLACKBONE_API AsmVariant(
const void* _imm )
69 : AsmVariant( imm,
sizeof(
void*), reinterpret_cast<size_t>(_imm) ) { }
72 BLACKBONE_API AsmVariant(
long double _imm_fpu )
73 : AsmVariant( (
double)_imm_fpu ) { }
75 BLACKBONE_API AsmVariant(
double _imm_fpu )
77 , size(
sizeof(
double) )
78 , imm_double_val( _imm_fpu )
79 , new_imm_val( 0 ) { }
81 BLACKBONE_API AsmVariant(
float _imm_fpu )
83 , size(
sizeof(
float) )
84 , imm_float_val( _imm_fpu )
85 , new_imm_val( 0 ) { }
87 BLACKBONE_API AsmVariant( asmjit::host::GpReg _reg )
89 , size(
sizeof(
size_t) )
91 , imm_double_val( -1.0 )
92 , new_imm_val( 0 ) { }
95 BLACKBONE_API AsmVariant( asmjit::host::Mem _mem )
97 , size(
sizeof(
size_t) )
99 , imm_double_val( -1.0 ) { }
102 BLACKBONE_API AsmVariant( asmjit::host::Mem* _mem )
104 , size(
sizeof(
size_t) )
106 , imm_double_val( -1.0 )
107 , new_imm_val( 0 ) { }
109 BLACKBONE_API AsmVariant(
const asmjit::host::Mem* _mem )
110 : AsmVariant( const_cast<asmjit::host::Mem*>(_mem) ) { }
112 template <
typename T>
114 : AsmVariant( dataPtr,
sizeof(T), reinterpret_cast<size_t>(ptr) ) { }
116 template <
typename T>
117 AsmVariant(
const T* ptr )
122 const bool isFunction = std::is_function<typename std::remove_pointer<T>::type>::value;
123 typedef typename std::conditional<isFunction, void*, T>::type Type;
125 type = isFunction ? imm : dataPtr;
127 imm_val =
reinterpret_cast<size_t>(ptr);
131 template <
typename T>
132 AsmVariant(
const T* ptr,
size_t size )
133 : AsmVariant( dataPtr, size, reinterpret_cast<size_t>(ptr) ) { }
135 template <
typename T>
137 : AsmVariant( dataPtr,
sizeof(T), reinterpret_cast<size_t>(&val) ) { }
139 template <
typename T>
140 AsmVariant(
const T& val )
141 : AsmVariant( dataPtr,
sizeof(T), reinterpret_cast<size_t>(&val) ) {}
145 #pragma warning(disable : 4127)
146 template <
typename T>
147 AsmVariant( T&& val )
148 : AsmVariant( dataStruct,
sizeof(T), reinterpret_cast<size_t>(&val) )
151 if (
sizeof(T) <=
sizeof(
void*) && !std::is_class<T>::value)
155 memcpy( &imm_val, &val,
sizeof(T) );
159 buf.reset(
new uint8_t[
sizeof(T)] );
160 imm_val =
reinterpret_cast<size_t>(buf.get());
161 memcpy( buf.get(), &val,
sizeof(T) );
164 #pragma warning(default : 4127)
166 BLACKBONE_API AsmVariant( AsmVariant&& other )
168 *
this = std::move( other );
171 BLACKBONE_API AsmVariant(
const AsmVariant& other ) =
default;
172 BLACKBONE_API AsmVariant& operator =(
const AsmVariant& other) =
default;
177 BLACKBONE_API
inline uint32_t getImm_float()
const {
return *(
reinterpret_cast<const uint32_t*
>(&imm_float_val)); }
178 BLACKBONE_API
inline uint64_t getImm_double()
const {
return *(
reinterpret_cast<const uint64_t*
>(&imm_double_val)); }
186 if (type == dataStruct || type == imm_float || type == imm_double || type == structRet)
200 AsmVariant( eType _type,
size_t _size,
size_t val )
204 , new_imm_val( 0 ) { }
210 asmjit::host::GpReg reg_val;
211 asmjit::host::Mem mem_val;
217 double imm_double_val;
224 std::shared_ptr<uint8_t> buf;
Definition: AsmHelper64.h:9
Definition: RemoteExec.h:20
General purpose assembly variable
Definition: AsmVariant.hpp:16
BLACKBONE_API bool reg86Compatible() const
Check if argument can be passed in x86 register
Definition: AsmVariant.hpp:184
Definition: RemoteFunction.hpp:103
32 bit assembler helper
Definition: AsmHelper32.h:11
Definition: AsmHelper32.cpp:6