| 12
 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
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 
 | #include <ntifs.h>#include <ntdef.h>
 #include <ntstatus.h>
 #include <ntddk.h>
 #define SYMBOL L"\\??\\xia0ji2333"
 #define kprintf(format, ...) DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, format, ##__VA_ARGS__)
 
 
 
 NTSTATUS CreateDevice(PDEVICE_OBJECT driver) {
 NTSTATUS status;
 UNICODE_STRING MyDriver;
 PDEVICE_OBJECT device = NULL;
 RtlInitUnicodeString(&MyDriver, L"\\DEVICE\\xia0ji233");
 status = IoCreateDevice(
 driver,
 sizeof(driver->DeviceExtension),
 &MyDriver,
 FILE_DEVICE_UNKNOWN,
 FILE_DEVICE_SECURE_OPEN,
 FALSE,
 &device
 );
 if (status == STATUS_SUCCESS) {
 UNICODE_STRING Sym;
 RtlInitUnicodeString(&Sym, SYMBOL);
 status = IoCreateSymbolicLink(&Sym, &MyDriver);
 if (status == STATUS_SUCCESS) {
 kprintf(("Line %d:xia0ji233: symbol linked success\n"), __LINE__);
 }
 else {
 kprintf(("Line %d:xia0ji233: symbol linked failed status=%x\n"), __LINE__, status);
 }
 }
 else {
 kprintf(("Line %d:xia0ji233: create device fail status=%x\n"), __LINE__, status);
 }
 }
 
 void DeleteDevice(PDRIVER_OBJECT pDriver) {
 kprintf(("Line %d:xia0ji233: start delete device\n"), __LINE__);
 if (pDriver->DeviceObject) {
 UNICODE_STRING Sym;
 RtlInitUnicodeString(&Sym, SYMBOL);
 kprintf(("Line %d:xia0ji233: Delete Symbol\n"), __LINE__);
 IoDeleteSymbolicLink(&Sym);
 kprintf(("Line %d:xia0ji233: Delete Device\n"), __LINE__);
 IoDeleteDevice(pDriver->DeviceObject);
 }
 kprintf(("Line %d:xia0ji233: end delete device\n"), __LINE__);
 }
 
 
 
 char newcode[] = {
 0x48,0xB8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 0xFF,0xE0
 };
 char oldcode[] = {
 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 0x00,0x00,
 };
 
 char *target;
 
 KIRQL WPOFFx64()
 {
 KIRQL irql = KeRaiseIrqlToDpcLevel();
 UINT64 cr0 = __readcr0();
 cr0 &= 0xfffffffffffeffff;
 __writecr0(cr0);
 _disable();
 return irql;
 }
 
 void WPONx64(KIRQL irql)
 {
 UINT64 cr0 = __readcr0();
 cr0 |= 0x10000;
 _enable();
 __writecr0(cr0);
 KeLowerIrql(irql);
 }
 
 NTSTATUS Unhook() {
 KIRQL irql = WPOFFx64();
 for (int i = 0; i < sizeof(newcode); i++) {
 target[i] = oldcode[i];
 }
 WPONx64(irql);
 return STATUS_SUCCESS;
 }
 
 NTSTATUS Hook() {
 KIRQL irql = WPOFFx64();
 for (int i = 0; i < sizeof(newcode); i++) {
 target[i] = newcode[i];
 }
 WPONx64(irql);
 return STATUS_SUCCESS;
 }
 typedef NTSTATUS(*Copy)(PVOID, MM_COPY_ADDRESS, SIZE_T, ULONG, SIZE_T *);
 
 
 
 
 NTSTATUS
 myMmCopyMemory(
 _In_ PVOID TargetAddress,
 _In_ MM_COPY_ADDRESS SourceAddress,
 _In_ SIZE_T NumberOfBytes,
 _In_ ULONG Flags,
 _Out_ PSIZE_T NumberOfBytesTransferred
 ) {
 
 kprintf(("xia0ji233: calls MmCopyMemory(%p,%p,%d,%p,%p)\n"), TargetAddress, SourceAddress, NumberOfBytes, Flags, NumberOfBytesTransferred);
 Unhook();
 Copy func = (Copy)target;
 NTSTATUS s = func(TargetAddress, SourceAddress, NumberOfBytes, Flags, NumberOfBytesTransferred);
 Hook();
 
 return s;
 }
 
 void DriverUnload(PDRIVER_OBJECT pDriver) {
 kprintf(("Line %d:xia0ji233: start unload\n"), __LINE__);
 Unhook();
 DeleteDevice(pDriver);
 }
 
 
 NTSTATUS DriverEntry(
 _In_ PDRIVER_OBJECT DriverObject, _In_ PUNICODE_STRING RegistryPath
 ) {
 DriverObject->DriverUnload = DriverUnload;
 CreateDevice(DriverObject);
 kprintf(("Line %d:xia0ji233: RegistryPath = %S\n"), __LINE__, RegistryPath->Buffer);
 target = MmCopyMemory;
 kprintf(("Line %d:xia0ji233: MmCopyMemory=%p\n"), __LINE__, target);
 
 if (target) {
 for (int i = 0; i < sizeof(oldcode); i++) {
 oldcode[i] = target[i];
 }
 *(UINT64*)(newcode + 2) = myMmCopyMemory;
 Hook();
 }
 else {
 kprintf(("xia0ji233:hahaha"));
 }
 return 0;
 }
 
 |