3 #include "../Include/Winheaders.h"
4 #include "../Include/Types.h"
5 #include "../Include/Macro.h"
6 #include "../../BlackBoneDrv/BlackBoneDef.h"
11 ENUM_OPS( KMmapFlags );
16 typedef std::map < std::pair<ptr_t, uint32_t>, ptr_t > mapMemoryMap;
21 ptr_t targetSharedPage;
41 BLACKBONE_API ~DriverControl();
43 BLACKBONE_API
static DriverControl& Instance();
50 BLACKBONE_API NTSTATUS
EnsureLoaded(
const std::wstring& path = L
"" );
57 BLACKBONE_API NTSTATUS
Reload( std::wstring path = L
"" );
63 BLACKBONE_API NTSTATUS
Unload();
71 BLACKBONE_API NTSTATUS
DisableDEP( DWORD pid );
88 BLACKBONE_API NTSTATUS
PromoteHandle( DWORD pid, HANDLE handle, DWORD access );
99 BLACKBONE_API NTSTATUS
AllocateMem( DWORD pid, ptr_t& base, ptr_t& size, DWORD type, DWORD protection,
bool physical =
false );
109 BLACKBONE_API NTSTATUS
FreeMem( DWORD pid, ptr_t base, ptr_t size, DWORD type );
119 BLACKBONE_API NTSTATUS
ReadMem( DWORD pid, ptr_t base, ptr_t size, PVOID buffer );
129 BLACKBONE_API NTSTATUS
WriteMem( DWORD pid, ptr_t base, ptr_t size, PVOID buffer );
139 BLACKBONE_API NTSTATUS
ProtectMem( DWORD pid, ptr_t base, ptr_t size, DWORD protection );
149 BLACKBONE_API NTSTATUS
MapMemory( DWORD pid,
const std::wstring& pipeName,
bool mapSections,
MapMemoryResult& result );
178 BLACKBONE_API NTSTATUS
UnmapMemoryRegion( DWORD pid, ptr_t base, uint32_t size );
194 const std::wstring& path,
196 uint32_t initRVA = 0,
197 const std::wstring& initArg = L
"",
199 bool erasePE =
false,
212 BLACKBONE_API NTSTATUS
MmapDll(
214 const std::wstring& path,
216 uint32_t initRVA = 0,
217 const std::wstring& initArg = L
""
231 BLACKBONE_API NTSTATUS
MmapDll(
237 uint32_t initRVA = 0,
238 const std::wstring& initArg = L
""
246 BLACKBONE_API NTSTATUS
MMapDriver(
const std::wstring& path );
255 BLACKBONE_API NTSTATUS
ConcealVAD( DWORD pid, ptr_t base, uint32_t size );
268 BLACKBONE_API
inline bool loaded()
const {
return _hDriver != INVALID_HANDLE_VALUE; }
269 BLACKBONE_API
inline NTSTATUS status()
const {
return _loadStatus; }
272 DriverControl(
const DriverControl& ) =
delete;
273 DriverControl& operator = (
const DriverControl&) =
delete;
281 NTSTATUS LoadDriver(
const std::wstring& svcName,
const std::wstring& path );
288 NTSTATUS UnloadDriver(
const std::wstring& svcName );
296 LSTATUS PrepareDriverRegEntry(
const std::wstring& svcName,
const std::wstring& path );
298 HANDLE _hDriver = INVALID_HANDLE_VALUE;
299 NTSTATUS _loadStatus = STATUS_NOT_FOUND;
303 inline DriverControl& Driver() {
return DriverControl::Instance(); }
BLACKBONE_API NTSTATUS UnmapMemoryRegion(DWORD pid, ptr_t base, uint32_t size)
Unmap single memory region If unmapped region size is smaller than the size specified during map...
Definition: DriverControl.cpp:243
BLACKBONE_API NTSTATUS UnlinkHandleTable(DWORD pid)
Unlink process handle table from HandleListHead
Definition: DriverControl.cpp:678
BLACKBONE_API bool loaded() const
Check if driver is loaded
Definition: DriverControl.h:268
BLACKBONE_API NTSTATUS Unload()
Unload driver
Definition: DriverControl.cpp:120
BLACKBONE_API NTSTATUS MMapDriver(const std::wstring &path)
Manually map another system driver into system space
Definition: DriverControl.cpp:625
BLACKBONE_API NTSTATUS ProtectProcess(DWORD pid, bool enable)
Change process protection flag
Definition: DriverControl.cpp:290
BLACKBONE_API NTSTATUS MapMemoryRegion(DWORD pid, ptr_t base, uint32_t size, MapMemoryRegionResult &result)
Maps single memory region into current process
Definition: DriverControl.cpp:185
BLACKBONE_API NTSTATUS MmapDll(DWORD pid, const std::wstring &path, KMmapFlags flags, uint32_t initRVA=0, const std::wstring &initArg=L"")
Manually map PE image
Definition: DriverControl.cpp:541
BLACKBONE_API NTSTATUS AllocateMem(DWORD pid, ptr_t &base, ptr_t &size, DWORD type, DWORD protection, bool physical=false)
Allocate virtual memory
Definition: DriverControl.cpp:340
BLACKBONE_API NTSTATUS InjectDll(DWORD pid, const std::wstring &path, InjectType itype, uint32_t initRVA=0, const std::wstring &initArg=L"", bool unlink=false, bool erasePE=false, bool wait=true)
Inject DLL into arbitrary process
Definition: DriverControl.cpp:499
BLACKBONE_API NTSTATUS EnsureLoaded(const std::wstring &path=L"")
Try to load driver if it isn't loaded
Definition: DriverControl.cpp:41
BLACKBONE_API NTSTATUS Reload(std::wstring path=L"")
Reload driver
Definition: DriverControl.cpp:67
BLACKBONE_API NTSTATUS PromoteHandle(DWORD pid, HANDLE handle, DWORD access)
Change handle access rights
Definition: DriverControl.cpp:312
BLACKBONE_API NTSTATUS ConcealVAD(DWORD pid, ptr_t base, uint32_t size)
Make VAD region appear as PAGE_NO_ACESS to NtQueryVirtualMemory
Definition: DriverControl.cpp:654
Definition: DriverControl.h:18
BLACKBONE_API NTSTATUS UnmapMemory(DWORD pid)
Unmap memory of the target process from current
Definition: DriverControl.cpp:218
BLACKBONE_API NTSTATUS FreeMem(DWORD pid, ptr_t base, ptr_t size, DWORD type)
Free virtual memory
Definition: DriverControl.cpp:378
BLACKBONE_API NTSTATUS ReadMem(DWORD pid, ptr_t base, ptr_t size, PVOID buffer)
Read process memory
Definition: DriverControl.cpp:409
BLACKBONE_API NTSTATUS WriteMem(DWORD pid, ptr_t base, ptr_t size, PVOID buffer)
Write process memory
Definition: DriverControl.cpp:438
BLACKBONE_API NTSTATUS ProtectMem(DWORD pid, ptr_t base, ptr_t size, DWORD protection)
Change memory protection
Definition: DriverControl.cpp:467
Definition: DriverControl.h:37
BLACKBONE_API NTSTATUS DisableDEP(DWORD pid)
Disable DEP for process Has no effect on native x64 processes
Definition: DriverControl.cpp:269
Definition: AsmHelper32.cpp:6
Definition: DriverControl.h:27
BLACKBONE_API NTSTATUS MapMemory(DWORD pid, const std::wstring &pipeName, bool mapSections, MapMemoryResult &result)
Maps target process memory into current process
Definition: DriverControl.cpp:140