-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathexample.hooks
More file actions
66 lines (56 loc) · 1.7 KB
/
example.hooks
File metadata and controls
66 lines (56 loc) · 1.7 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
# Example API Hooks for Emulator Mode
# Usage: ehook example.hooks
# ehookaddr kernel32!CreateFileA 0x<address>
# CreateFileA - log the filename and return INVALID_HANDLE_VALUE
hook kernel32!CreateFileA:
log "CreateFileA({rcx:str})"
rax = INVALID_HANDLE_VALUE
skip
# CreateFileW - log the address (wide strings need special handling)
hook kernel32!CreateFileW:
log "CreateFileW({rcx:wstr})"
rax = INVALID_HANDLE_VALUE
skip
# VirtualAlloc - allocate memory in the emulator
# rcx = lpAddress (hint), rdx = dwSize, r8 = flAllocationType, r9 = flProtect
hook kernel32!VirtualAlloc:
log "VirtualAlloc(0x{rcx:x}, {rdx:d} bytes, 0x{r8:x}, 0x{r9:x})"
rax = alloc(rdx)
skip
# VirtualFree - free memory
hook kernel32!VirtualFree:
log "VirtualFree(0x{rcx:x})"
free(rcx)
rax = 1
skip
# HeapAlloc - allocate from heap
# rcx = hHeap, rdx = dwFlags, r8 = dwBytes
hook kernel32!HeapAlloc:
log "HeapAlloc(heap=0x{rcx:x}, flags=0x{rdx:x}, size={r8:d})"
rax = alloc(r8)
skip
# HeapFree - free from heap
hook kernel32!HeapFree:
log "HeapFree(heap=0x{rcx:x}, ptr=0x{r8:x})"
free(r8)
rax = 1
skip
# GetProcAddress - log and return NULL (function not found)
hook kernel32!GetProcAddress:
log "GetProcAddress(0x{rcx:x}, {rdx:str})"
rax = NULL
skip
# LoadLibraryA - log and return NULL (library not found)
hook kernel32!LoadLibraryA:
log "LoadLibraryA({rcx:str})"
rax = NULL
skip
# MessageBoxA - log message and return OK (1)
hook user32!MessageBoxA:
log "MessageBoxA(hwnd=0x{rcx:x}, text={rdx:str}, caption={r8:str})"
rax = 1
skip
# ExitProcess - stop the emulator
hook kernel32!ExitProcess:
log "ExitProcess({rcx:d})"
stop