-
Notifications
You must be signed in to change notification settings - Fork 256
Expand file tree
/
Copy pathDecompileItRpcStub.cpp
More file actions
137 lines (117 loc) · 2.61 KB
/
DecompileItRpcStub.cpp
File metadata and controls
137 lines (117 loc) · 2.61 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include "RpcDecompileIt.h"
#include <conio.h>
PVOID
DecompileItRpcAlloc(
_In_ size_t Size
)
{
return malloc(Size);
}
void
DecompileItRpcFree(
_In_ PVOID pMem
)
{
free(pMem);
}
void
DecompileItRpcPrint(
_In_ PVOID Context,
_In_ const char *pText
)
{
UNREFERENCED_PARAMETER(Context);
printf(pText);
}
void
DecompileItRpcDebug(
_In_ const char *pFunction,
_In_ ULONG Line,
_In_ const char *pFormat,
...
)
{
va_list Arg;
UNREFERENCED_PARAMETER(pFunction);
UNREFERENCED_PARAMETER(Line);
va_start(Arg, pFormat);
_vcprintf(pFormat, Arg);
}
bool
DecompileItRpcGetInterfaceName(
_In_ GUID *pIfId,
_Out_ UCHAR *pName,
_Out_ ULONG NameLength
)
{
HKEY hKey = NULL;
ULONG DataLength;
UCHAR SubKeyName[MAX_PATH];
RPC_CSTR pUuidString = NULL;
BOOL bResult = FALSE;
if (UuidToStringA(pIfId, &pUuidString) != RPC_S_OK) goto End;
sprintf_s((char*) SubKeyName, sizeof(SubKeyName), "Interface\\{%s}", pUuidString);
if (RegOpenKeyExA(HKEY_CLASSES_ROOT, (LPCSTR)SubKeyName, 0, KEY_READ, &hKey) != ERROR_SUCCESS) goto End;
DataLength = NameLength;
if (RegQueryValueExA(hKey, NULL, NULL, NULL, pName, &DataLength) != ERROR_SUCCESS) goto End;
bResult = TRUE;
End:
if (hKey != NULL) RegCloseKey(hKey);
if (pUuidString != NULL) RpcStringFreeA(&pUuidString);
return (bResult);
}
bool __fastcall
DecompileItRpcGetProcessData(
_In_ RpcModuleInfo_T *Context,
_In_ RVA_T Rva,
_Out_ VOID* pBuffer,
_Out_ UINT BufferLength
)
{
HANDLE hTargetProcess = INVALID_HANDLE_VALUE;
BOOL bResult = FALSE;
VOID* pAddress = NULL;
RpcModuleInfo_T *DecompileContext = (RpcModuleInfo_T *)Context;
if ((Context == NULL) || (DecompileContext->Pid == 0))
{
goto End;
}
hTargetProcess = OpenProcess(
PROCESS_VM_READ | PROCESS_QUERY_INFORMATION,
FALSE,
DecompileContext->Pid
);
if (hTargetProcess == INVALID_HANDLE_VALUE)
{
goto End;
}
pAddress = (VOID*)(DecompileContext->pModuleBase + Rva);
bResult = ReadProcessMemory(
hTargetProcess,
pAddress,
pBuffer,
BufferLength,
NULL
);
End:
if (hTargetProcess != INVALID_HANDLE_VALUE)
{
CloseHandle(hTargetProcess);
}
return (bResult);
}
void
DecompileItInitRpcViewStub
(
_Inout_ RpcViewHelper_T *RpcViewStub,
_In_ PVOID Context
)
{
RpcViewStub->pContext = &Context;
RpcViewStub->RpcAlloc = (RpcAllocFn_T) &DecompileItRpcAlloc;
RpcViewStub->RpcFree = (RpcFreeFn_T) &DecompileItRpcFree;
RpcViewStub->RpcGetProcessData = (RpcGetProcessDataFn_T)&DecompileItRpcGetProcessData;
RpcViewStub->RpcPrint = &DecompileItRpcPrint;
RpcViewStub->RpcDebug = &DecompileItRpcDebug;
RpcViewStub->RpcGetInterfaceName = (RpcGetInterfaceNameFn_T)&DecompileItRpcGetInterfaceName;
}