-
Notifications
You must be signed in to change notification settings - Fork 106
/
tools.h
93 lines (81 loc) · 1.96 KB
/
tools.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#pragma once
#define SYSCALL_INDEX( a ) ( *( PULONG )( ( PUCHAR )a + 1 ) )
inline void AllocateUnicodeString( PUNICODE_STRING us, USHORT Size )
{
if ( !us )
return;
__try
{
us->Length = 0;
us->MaximumLength = 0;
us->Buffer = PWSTR( ExAllocatePoolWithTag( NonPagedPool, Size, TAG ) );
if ( us->Buffer )
{
us->Length = 0;
us->MaximumLength = Size;
}
}
__except ( EXCEPTION_EXECUTE_HANDLER ) { }
}
inline void FreeUnicodeString( PUNICODE_STRING us )
{
if ( !us )
return;
__try
{
if ( us->MaximumLength > 0 && us->Buffer )
ExFreePoolWithTag( us->Buffer, TAG );
us->Length = 0;
us->MaximumLength = 0;
}
__except ( EXCEPTION_EXECUTE_HANDLER ) { }
}
namespace masterhide
{
namespace utils
{
extern KIRQL WPOFF();
extern void WPON( KIRQL Irql );
extern const PUCHAR FindCodeCave( PUCHAR Code, ULONG ulCodeSize, size_t CaveLength );
}
};
namespace masterhide
{
namespace tools
{
//
// Tools
//
extern ULONG64 FindPatternKM( const char* szModuleName, const char* szsection, const char* bmask, const char* szmask );
extern bool GetProcessName( HANDLE PID, PUNICODE_STRING wsProcessName );
extern bool GetProcessNameByPEPROCESS( PEPROCESS Process, PUNICODE_STRING ProcessImageName );
extern PVOID GetNtKernelBase();
extern PVOID GetModuleBase( const char* szModule );
extern PEPROCESS FindPEPROCESSById( PWCH wsName );
inline void SwapEndianness( PCHAR ptr, size_t size )
{
struct u16
{
UCHAR high;
UCHAR low;
};
for ( u16* pStruct = ( u16* )ptr; pStruct < ( u16* )ptr + size / 2; pStruct++ )
{
auto tmp = pStruct->low;
pStruct->low = pStruct->high;
pStruct->high = tmp;
}
}
//
// Helpers
//
extern ULONG GetNtSyscall( LPCSTR FunctionName );
extern ULONG GetWin32Syscall( LPCSTR FunctionName );
extern PVOID GetImageTextSection( const ULONG64 uImageBase, ULONG* ulSectionSize );
//
// Misc
//
extern bool DumpMZ( PUCHAR pImageBase );
extern void UnloadImages();
}
}