| 43 | } |
| 44 | |
| 45 | NTSTATUS nullhook::hook_handler(PVOID called_param) |
| 46 | { |
| 47 | NULL_MEMORY* instructions = (NULL_MEMORY*)called_param; |
| 48 | |
| 49 | if (instructions->req_base == TRUE) |
| 50 | { |
| 51 | ANSI_STRING AS; |
| 52 | UNICODE_STRING ModuleName; |
| 53 | |
| 54 | RtlInitAnsiString(&AS, instructions->module_name); |
| 55 | RtlAnsiStringToUnicodeString(&ModuleName, &AS, TRUE); |
| 56 | |
| 57 | PEPROCESS process; |
| 58 | PsLookupProcessByProcessId((HANDLE)instructions->pid, &process); |
| 59 | ULONG64 base_address64 = NULL; |
| 60 | base_address64 = get_module_base_x64(process, ModuleName); |
| 61 | instructions->base_address = base_address64; |
| 62 | RtlFreeUnicodeString(&ModuleName); |
| 63 | } |
| 64 | |
| 65 | else if (instructions->write == TRUE) |
| 66 | { |
| 67 | if (instructions->address < 0x7FFFFFFFFFFF && instructions->address > 0) |
| 68 | { |
| 69 | PVOID kernelBuff = ExAllocatePool(NonPagedPool, instructions->size); |
| 70 | |
| 71 | if (!kernelBuff) |
| 72 | { |
| 73 | return STATUS_UNSUCCESSFUL; |
| 74 | } |
| 75 | |
| 76 | if (!memcpy(kernelBuff, instructions->buffer_address, instructions->size)) |
| 77 | { |
| 78 | return STATUS_UNSUCCESSFUL; |
| 79 | } |
| 80 | |
| 81 | PEPROCESS process; |
| 82 | PsLookupProcessByProcessId((HANDLE)instructions->pid, &process); |
| 83 | write_kernel_memory((HANDLE)instructions->pid, instructions->address, kernelBuff, instructions->size); |
| 84 | ExFreePool(kernelBuff); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | else if (instructions->read == TRUE) |
| 89 | { |
| 90 | if (instructions->address < 0x7FFFFFFFFFFF && instructions->address > 0) |
| 91 | { |
| 92 | read_kernel_memory((HANDLE)instructions->pid, instructions->address, instructions->output, instructions->size); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | else if (instructions->draw_box == TRUE) |
| 97 | { |
| 98 | HDC hdc = NtUserGetDC(NULL); |
| 99 | if (!hdc) |
| 100 | return STATUS_UNSUCCESSFUL; |
| 101 | |
| 102 | HBRUSH brush = NtGdiCreateSolidBrush(RGB(instructions->r, instructions->g, instructions->b), NULL); |
nothing calls this directly
no test coverage detected