3 #include "../../Config.h"
4 #include "RemoteContext.hpp"
6 #include "../../Include/Winheaders.h"
7 #include "../../Include/Macro.h"
8 #include "../Threads/Threads.h"
65 typedef std::map<ptr_t, HookData> mapHook;
66 typedef std::map<ptr_t, ptr_t> mapAddress;
67 typedef std::map<ptr_t, bool> setAddresses;
81 BLACKBONE_API
inline NTSTATUS
Apply( eHookType type, uint64_t ptr, fnCallback newFn,
Thread* pThread =
nullptr )
83 return ApplyP( type, ptr, newFn,
nullptr, pThread );
93 BLACKBONE_API
inline NTSTATUS
AddReturnHook( uint64_t ptr, fnCallback newFn )
95 return AddReturnHookP( ptr, newFn,
nullptr );
111 inline NTSTATUS
Apply( eHookType type, uint64_t ptr,
void(C::* newFn)(
RemoteContext& ctx),
const C& classRef,
Thread* pThread =
nullptr )
113 return ApplyP( type, ptr, brutal_cast<fnCallback>(newFn), &classRef, pThread );
125 inline NTSTATUS
AddReturnHook( uint64_t ptr,
void(C::* newFn)(RemoteContext& ctx),
const C& classRef )
127 return AddReturnHookP( ptr, brutal_cast<fnCallback>(newFn), &classRef );
129 #endif // COMPILER_MSVC
135 BLACKBONE_API
void Remove( uint64_t ptr );
140 BLACKBONE_API
void reset();
153 BLACKBONE_API NTSTATUS ApplyP( eHookType type, uint64_t ptr, fnCallback newFn,
const void* pClass =
nullptr, Thread* pThread =
nullptr );
163 BLACKBONE_API NTSTATUS AddReturnHookP( uint64_t ptr, fnCallback newFn,
const void* pClass =
nullptr );
170 BLACKBONE_API
void Restore(
const HookData &hook, uint64_t ptr );
176 NTSTATUS EnsureDebug();
188 static DWORD __stdcall EventThreadWrap( LPVOID lpParam );
201 DWORD OnDebugEvent(
const DEBUG_EVENT& DebugEv );
208 DWORD OnBreakpoint(
const DEBUG_EVENT& DebugEv );
215 DWORD OnSinglestep(
const DEBUG_EVENT& DebugEv );
223 DWORD OnAccessViolation(
const DEBUG_EVENT& DebugEv );
234 DWORD StackBacktrace( ptr_t ip, ptr_t sp, Thread& thd, std::vector<std::pair<ptr_t, ptr_t>>& results,
int depth = 100 );
236 RemoteHook(
const RemoteHook& ) =
delete;
237 RemoteHook& operator =(
const RemoteHook& ) =
delete;
240 class ProcessMemory& _memory;
241 class ProcessCore& _core;
244 HANDLE _hEventThd = NULL;
245 BOOL _x64Target = FALSE;
247 bool _active =
false;
249 setAddresses _repatch;
250 mapAddress _retHooks;
253 ENUM_OPS( RemoteHook::eHookFlags )
Definition: RemoteHook.h:17
Definition: RemoteHook.h:44
BLACKBONE_API NTSTATUS AddReturnHook(uint64_t ptr, fnCallback newFn)
Hook function return This hook will only work if function is hooked normally
Definition: RemoteHook.h:93
Hook descriptor
Definition: RemoteHook.h:41
Definition: ProcessMemory.h:13
Definition: RemoteHook.h:46
BLACKBONE_API void Remove(uint64_t ptr)
Remove existing hook
Definition: RemoteHook.cpp:177
Remote function context during hook breakpoint.
Definition: RemoteContext.hpp:14
BLACKBONE_API void reset()
Stop debug and remove all hooks
Definition: RemoteHook.cpp:644
Thread management
Definition: Thread.h:91
Definition: AsmHelper32.cpp:6
BLACKBONE_API NTSTATUS Apply(eHookType type, uint64_t ptr, fnCallback newFn, Thread *pThread=nullptr)
Hook specified address
Definition: RemoteHook.h:81