3 #include "../../Include/Winheaders.h"
4 #include "../ProcessMemory.h"
5 #include "../ProcessCore.h"
6 #include "../Threads/Thread.h"
7 #include "../../Include/Macro.h"
19 ptr_t frame_ptr, BOOL x64,
int wordSize )
24 , _wordSize( wordSize )
25 , _frame_ptr( frame_ptr != 0 ? frame_ptr : ctx.Rsp )
29 BLACKBONE_API ~RemoteContext()
55 _memory.
Read( _frame_ptr, _wordSize, &val );
67 return (_memory.
Write( _frame_ptr, _wordSize, &val ) == STATUS_SUCCESS);
77 memcpy( &_ctx.Rax, &val, _wordSize );
87 SET_BIT( val, (_wordSize * 8 - 1) );
101 RESET_BIT( val, (_wordSize * 8 - 1) );
116 BLACKBONE_API DWORD64
getArg(
int index )
132 return _memory.
Read<DWORD64>( _ctx.Rsp + 0x30 + (index - 4 ) * _wordSize );
138 _memory.
Read( _ctx.Rsp + 4 + index * _wordSize, _wordSize, &val );
151 BLACKBONE_API
bool setArg(
int index, DWORD64 val )
174 return (_memory.
Write( _ctx.Rsp + 0x30 + (index - 4) * _wordSize, val ) == STATUS_SUCCESS);
181 return (_memory.
Write( _ctx.Rsp + 4 + index * _wordSize, _wordSize, &val ) == STATUS_SUCCESS);
198 offset = FIELD_OFFSET(
_TEB64, LastErrorValue );
203 offset = FIELD_OFFSET(
_TEB32, LastErrorValue );
207 return _memory.
Read<DWORD>( pteb + offset );
224 offset = FIELD_OFFSET(
_TEB64, LastErrorValue );
229 offset = FIELD_OFFSET(
_TEB32, LastErrorValue );
233 return _memory.
Write( pteb + offset, newError );
245 auto pteb = _thd.
teb( (
_TEB64*)
nullptr );
259 auto pteb = _thd.
teb( (
_TEB64*)
nullptr );
262 if (_memory.
Write( pteb + FIELD_OFFSET(
_NT_TIB_T<DWORD64>, ArbitraryUserPointer ), context ) == STATUS_SUCCESS)
271 RemoteContext(
const RemoteContext& ) =
delete;
272 RemoteContext& operator = (
const RemoteContext& ) =
delete;
279 BOOL _x64Target = FALSE;
281 ptr_t _frame_ptr = 0;
BLACKBONE_API ptr_t getUserContext()
Get arbitrary thread data
Definition: RemoteContext.hpp:243
BLACKBONE_API Thread & getThread()
Get current process thread where exception occurred
Definition: RemoteContext.hpp:43
BLACKBONE_API ptr_t hookReturn()
Raise exception on function return
Definition: RemoteContext.hpp:84
BLACKBONE_API DWORD lastError(DWORD newError)
Set last thread error code
Definition: RemoteContext.hpp:216
BLACKBONE_API NTSTATUS Read(ptr_t dwAddress, size_t dwSize, PVOID pResult, bool handleHoles=false)
Read data
Definition: ProcessMemory.cpp:81
Definition: NativeStructures.h:71
BLACKBONE_API bool setArg(int index, DWORD64 val)
Set argument value. For x86 function works only with stack arguments. For x64 only integer arguments ...
Definition: RemoteContext.hpp:151
Definition: NativeStructures.h:44
BLACKBONE_API bool setUserContext(ptr_t context)
Set arbitrary thread data
Definition: RemoteContext.hpp:257
Definition: ProcessMemory.h:13
BLACKBONE_API const ptr_t returnAddress() const
Definition: RemoteContext.hpp:52
BLACKBONE_API NTSTATUS Write(ptr_t pAddress, size_t dwSize, const void *pData)
Write data
Definition: ProcessMemory.cpp:131
Remote function context during hook breakpoint.
Definition: RemoteContext.hpp:15
BLACKBONE_API bool returnAddress(ptr_t val) const
Set return address of current frame
Definition: RemoteContext.hpp:65
BLACKBONE_API DWORD64 getArg(int index)
Get argument value. Argument index is 0 based. For x86 function works only with stack arguments For x...
Definition: RemoteContext.hpp:116
BLACKBONE_API ptr_t teb(_TEB32 *pteb=nullptr) const
Get WOW64 TEB
Definition: Thread.cpp:41
BLACKBONE_API DWORD lastError()
Get last thread error code
Definition: RemoteContext.hpp:190
Thread management
Definition: Thread.h:44
Definition: NativeStructures.h:442
Definition: AsmHelper32.cpp:6
BLACKBONE_API void setReturnValue(ptr_t val) const
Set new integer return value. Has no effect on FPU. Has effect only if called in return callback ...
Definition: RemoteContext.hpp:75
BLACKBONE_API ptr_t unhookReturn()
Remove exception on return
Definition: RemoteContext.hpp:98