forked from kevoreilly/capemon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhook_clr.c
56 lines (52 loc) · 1.77 KB
/
hook_clr.c
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
#include <stdio.h>
#include "hooking.h"
#include "log.h"
#include "pipe.h"
#include "misc.h"
#include "CAPE\CAPE.h"
#include "CAPE\Debugger.h"
#include "CAPE\YaraHarness.h"
//#define DEBUG_COMMENTS
extern void DebugOutput(_In_ LPCTSTR lpOutputString, ...);
extern BOOL BreakpointCallback(PBREAKPOINTINFO pBreakpointInfo, struct _EXCEPTION_POINTERS* ExceptionInfo);
extern BOOL SetInitialBreakpoints(PVOID ImageBase);
lookup_t g_dotnet_jit;
HOOKDEF(int, WINAPI, compileMethod,
PVOID this,
PVOID compHnd,
PVOID methodInfo,
unsigned int flags,
uint8_t** entryAddress,
uint32_t* nativeSizeOfCode
)
{
int ret = Old_compileMethod(this, compHnd, methodInfo, flags, entryAddress, nativeSizeOfCode);
if (ret == 0) {
PVOID AllocationBase = GetAllocationBase(*entryAddress);
if (AllocationBase && !lookup_get(&g_dotnet_jit, (ULONG_PTR)AllocationBase, 0)) {
if (g_config.procdump && g_config.yarascan)
DebugOutput(".NET JIT native cache at 0x%p: scans and dumps active.\n", AllocationBase);
else if (g_config.procdump)
DebugOutput(".NET JIT native cache at 0x%p: dumps active.\n", AllocationBase);
else if (g_config.yarascan)
DebugOutput(".NET JIT native cache at 0x%p: scans active.\n", AllocationBase);
lookup_add(&g_dotnet_jit, (ULONG_PTR)AllocationBase, 0);
}
if (g_config.yarascan)
{
#ifdef DEBUG_COMMENTS
YaraScan(*entryAddress, *nativeSizeOfCode);
#else
SilentYaraScan(*entryAddress, *nativeSizeOfCode);
#endif
}
if (g_config.break_on_jit) {
unsigned int Register;
if (SetNextAvailableBreakpoint(GetCurrentThreadId(), &Register, 0, *entryAddress, BP_EXEC, 1, BreakpointCallback))
DebugOutput("compileMethod: set JIT native breakpoint.\n");
else
DebugOutput("compileMethod: failed to set JIT native breakpoint.\n");
}
}
return ret;
}