23 #define _DYNDATA_PRIVATE
26 #define INIT_SCAN(scan, bytes, length, address, scanLength, displacement) \
28 ((scan)->Initialized = TRUE), \
29 ((scan)->Scanned = FALSE), \
30 ((scan)->Bytes = (bytes)), \
31 ((scan)->Length = (length)), \
32 ((scan)->StartAddress = (address)), \
33 ((scan)->ScanLength = (scanLength)), \
34 ((scan)->Displacement = (displacement)), \
35 ((scan)->ProcedureAddress = NULL), \
38 #define C_2sTo4(x) ((unsigned int)(signed short)(x))
47 NTSTATUS KphpX86DataInitialization(
60 #pragma alloc_text(PAGE, KphDynamicDataInitialization)
61 #pragma alloc_text(PAGE, KphReadDynamicDataParameters)
62 #pragma alloc_text(PAGE, KphpLoadDynamicConfiguration)
64 #pragma alloc_text(PAGE, KphpX86DataInitialization)
66 #pragma alloc_text(PAGE, KphpAmd64DataInitialization)
75 static UCHAR PspTerminateProcess51Bytes[] =
77 0x8b, 0xff, 0x55, 0x8b, 0xec, 0x56, 0x64, 0xa1,
78 0x24, 0x01, 0x00, 0x00, 0x8b, 0x75, 0x08, 0x3b
80 static UCHAR PspTerminateProcess52Bytes[] =
82 0x8b, 0xff, 0x55, 0x8b, 0xec, 0x56, 0x8b, 0x75,
83 0x08, 0x57, 0x8d, 0xbe, 0x40, 0x02, 0x00, 0x00
85 static UCHAR PsTerminateProcess60Bytes[] =
87 0x8b, 0xff, 0x55, 0x8b, 0xec, 0x53, 0x56, 0x57,
88 0x33, 0xd2, 0x6a, 0x08, 0x42, 0x5e, 0x8d, 0xb9
90 static UCHAR PsTerminateProcess61Bytes[] =
92 0x8b, 0xff, 0x55, 0x8b, 0xec, 0x51, 0x51, 0x53,
93 0x56, 0x64, 0x8b, 0x35, 0x24, 0x01, 0x00, 0x00,
94 0x66, 0xff, 0x8e, 0x84, 0x00, 0x00, 0x00, 0x57,
99 static UCHAR PsTerminateProcess62Bytes[] =
101 0x8b, 0xff, 0x55, 0x8b, 0xec, 0x51, 0x53, 0x64,
102 0x8b, 0x1d, 0x24, 0x01, 0x00, 0x00, 0x56, 0x8d,
103 0xb3, 0x3c, 0x01, 0x00, 0x00, 0x66, 0xff, 0x0e
105 static UCHAR PsTerminateProcess63Bytes[] =
107 0x8b, 0xff, 0x55, 0x8b, 0xec, 0x83, 0xe4, 0xf8,
108 0x56, 0x64, 0x8b, 0x35, 0x24, 0x01, 0x00, 0x00,
109 0x57, 0x66, 0xff, 0x8e, 0x3c, 0x01, 0x00, 0x00
113 static UCHAR PspTerminateThreadByPointer51Bytes[] =
115 0x8b, 0xff, 0x55, 0x8b, 0xec, 0x83, 0xec, 0x0c,
116 0x83, 0x4d, 0xf8, 0xff, 0x56, 0x57, 0x8b, 0x7d
118 static UCHAR PspTerminateThreadByPointer52Bytes[] =
120 0x8b, 0xff, 0x55, 0x8b, 0xec, 0x53, 0x56, 0x57,
121 0x8b, 0x7d, 0x08, 0x8d, 0xb7, 0x40, 0x02, 0x00
123 static UCHAR PspTerminateThreadByPointer60Bytes[] =
125 0x8b, 0xff, 0x55, 0x8b, 0xec, 0x83, 0xe4, 0xf8,
126 0x51, 0x53, 0x56, 0x8b, 0x75, 0x08, 0x57, 0x8d,
127 0xbe, 0x60, 0x02, 0x00, 0x00, 0xf6, 0x07, 0x40
129 static UCHAR PspTerminateThreadByPointer61Bytes[] =
131 0x8b, 0xff, 0x55, 0x8b, 0xec, 0x83, 0xe4, 0xf8,
132 0x51, 0x53, 0x56, 0x8b, 0x75, 0x08, 0x57, 0x8d,
133 0xbe, 0x80, 0x02, 0x00, 0x00, 0xf6, 0x07, 0x40
135 static UCHAR PspTerminateThreadByPointer62Bytes[] =
137 0x8b, 0xff, 0x55, 0x8b, 0xec, 0x8d, 0x87, 0x68,
138 0x02, 0x00, 0x00, 0xf6, 0x00, 0x20, 0x53, 0x8a
140 static UCHAR PspTerminateThreadByPointer63Bytes[] =
142 0x8b, 0xff, 0x55, 0x8b, 0xec, 0x53, 0x56, 0x8b,
143 0xf1, 0x8b, 0xda, 0x57, 0x8d, 0xbe, 0xb8, 0x03
152 NTSTATUS status = STATUS_SUCCESS;
169 KphpX86DataInitialization();
179 __in_opt HANDLE KeyHandle
190 return STATUS_UNSUCCESSFUL;
203 if (status != STATUS_BUFFER_OVERFLOW && status != STATUS_BUFFER_TOO_SMALL)
206 return STATUS_UNSUCCESSFUL;
209 info = ExAllocatePoolWithTag(PagedPool, resultLength,
'ThpK');
212 return STATUS_INSUFFICIENT_RESOURCES;
225 if (info->
Type == REG_BINARY)
228 status = STATUS_OBJECT_TYPE_MISMATCH;
231 dprintf(
"Unable to load dynamic configuration: 0x%x\n", status);
234 ExFreePoolWithTag(info,
'ThpK');
253 return STATUS_INVALID_PARAMETER;
255 return STATUS_INVALID_PARAMETER;
257 return STATUS_INVALID_PARAMETER;
259 return STATUS_INVALID_PARAMETER;
265 package = &config->Packages[i];
286 return STATUS_SUCCESS;
290 return STATUS_NOT_FOUND;
295 static NTSTATUS KphpX86DataInitialization(
299 ULONG majorVersion, minorVersion, servicePack, buildNumber;
307 dprintf(
"Windows %d.%d, SP%d.%d, build %d\n",
308 majorVersion, minorVersion, servicePack,
313 if (majorVersion == 5 && minorVersion == 1)
316 ULONG scanLength = 0x100000;
321 if (servicePack == 0)
323 return STATUS_NOT_SUPPORTED;
325 else if (servicePack == 1)
327 return STATUS_NOT_SUPPORTED;
329 else if (servicePack == 2)
332 else if (servicePack == 3)
337 return STATUS_NOT_SUPPORTED;
340 KphDynEpObjectTable = 0xc4;
341 KphDynEpRundownProtect = 0x80;
343 KphDynOtIndex = 0x4c;
352 PspTerminateProcess51Bytes,
353 sizeof(PspTerminateProcess51Bytes),
354 searchOffset, scanLength, 0
358 PspTerminateThreadByPointer51Bytes,
359 sizeof(PspTerminateThreadByPointer51Bytes),
360 searchOffset, scanLength, 0
364 dprintf(
"Initialized version-specific data for Windows XP SP%d\n", servicePack);
367 else if (majorVersion == 5 && minorVersion == 2)
370 ULONG scanLength = 0x100000;
374 if (servicePack == 0)
377 else if (servicePack == 1)
380 else if (servicePack == 2)
385 return STATUS_NOT_SUPPORTED;
388 KphDynEpObjectTable = 0xd4;
389 KphDynEpRundownProtect = 0x90;
391 KphDynOtIndex = 0x4c;
400 PspTerminateProcess52Bytes,
401 sizeof(PspTerminateProcess52Bytes),
402 searchOffset - 0x50000, scanLength, 0
406 PspTerminateThreadByPointer52Bytes,
407 sizeof(PspTerminateThreadByPointer52Bytes),
408 searchOffset - 0x20000, scanLength, 0
412 dprintf(
"Initialized version-specific data for Windows Server 2003 SP%d\n", servicePack);
415 else if (majorVersion == 6 && minorVersion == 0)
418 ULONG scanLength = 0x100000;
422 if (servicePack == 0)
425 KphDynOtIndex = 0x4c;
427 else if (servicePack == 1)
430 KphDynOtIndex = 0x14;
432 else if (servicePack == 2)
435 KphDynOtIndex = 0x14;
439 return STATUS_NOT_SUPPORTED;
443 KphDynEpObjectTable = 0xdc;
444 KphDynEpRundownProtect = 0x98;
445 KphDynEreGuidEntry = 0x8;
451 PsTerminateProcess60Bytes,
452 sizeof(PsTerminateProcess60Bytes),
453 searchOffset, scanLength, 0
457 PspTerminateThreadByPointer60Bytes,
458 sizeof(PspTerminateThreadByPointer60Bytes),
459 searchOffset - 0x50000, scanLength, 0
463 dprintf(
"Initialized version-specific data for Windows Vista SP%d/Windows Server 2008\n", servicePack);
466 else if (majorVersion == 6 && minorVersion == 1)
473 if (servicePack == 0)
476 else if (servicePack == 1)
481 return STATUS_NOT_SUPPORTED;
485 KphDynEpObjectTable = 0xf4;
486 KphDynEpRundownProtect = 0xb0;
487 KphDynEreGuidEntry = 0x8;
489 KphDynOtIndex = 0x14;
495 PsTerminateProcess61Bytes,
496 sizeof(PsTerminateProcess61Bytes),
497 searchOffset1, 0xa000, 0
505 PspTerminateThreadByPointer61Bytes,
506 sizeof(PspTerminateThreadByPointer61Bytes),
507 searchOffset2, 0x1a000, 0
511 dprintf(
"Initialized version-specific data for Windows 7 SP%d\n", servicePack);
514 else if (majorVersion == 6 && minorVersion == 2)
517 ULONG_PTR searchOffset2 = searchOffset1;
521 if (servicePack == 0)
526 return STATUS_NOT_SUPPORTED;
530 KphDynEpObjectTable = 0x150;
531 KphDynEpRundownProtect = 0xb0;
532 KphDynEreGuidEntry = 0x8;
534 KphDynOtIndex = 0x14;
540 PsTerminateProcess62Bytes,
541 sizeof(PsTerminateProcess62Bytes),
542 searchOffset1, 0x8000, 0
550 PspTerminateThreadByPointer62Bytes,
551 sizeof(PspTerminateThreadByPointer62Bytes),
552 searchOffset2, 0x8000, 0
556 dprintf(
"Initialized version-specific data for Windows 8 SP%d\n", servicePack);
559 else if (majorVersion == 6 && minorVersion == 3)
562 ULONG_PTR searchOffset2 = searchOffset1;
566 if (servicePack == 0)
571 return STATUS_NOT_SUPPORTED;
575 KphDynEpObjectTable = 0x150;
576 KphDynEpRundownProtect = 0xb0;
578 KphDynOtIndex = 0x14;
584 PsTerminateProcess63Bytes,
585 sizeof(PsTerminateProcess63Bytes),
586 searchOffset1, 0x8000, 0
594 PspTerminateThreadByPointer63Bytes,
595 sizeof(PspTerminateThreadByPointer63Bytes),
596 searchOffset2, 0x8000, 0
600 dprintf(
"Initialized version-specific data for Windows 8.1 SP%d\n", servicePack);
602 else if (majorVersion == 6 && minorVersion > 3 || majorVersion > 6)
605 return STATUS_NOT_SUPPORTED;
609 return STATUS_NOT_SUPPORTED;
612 return STATUS_SUCCESS;
621 ULONG majorVersion, minorVersion, servicePack, buildNumber;
629 dprintf(
"Windows %d.%d, SP%d.%d, build %d\n",
630 majorVersion, minorVersion, servicePack,
635 if (majorVersion == 5 && minorVersion == 1)
639 if (servicePack == 0)
641 return STATUS_NOT_SUPPORTED;
643 else if (servicePack == 1)
645 return STATUS_NOT_SUPPORTED;
647 else if (servicePack == 2)
650 else if (servicePack == 3)
655 return STATUS_NOT_SUPPORTED;
659 else if (majorVersion == 5 && minorVersion == 2)
663 if (servicePack == 0)
666 else if (servicePack == 1)
669 else if (servicePack == 2)
674 return STATUS_NOT_SUPPORTED;
678 else if (majorVersion == 6 && minorVersion == 0)
682 if (servicePack == 0)
685 else if (servicePack == 1)
688 else if (servicePack == 2)
693 return STATUS_NOT_SUPPORTED;
697 else if (majorVersion == 6 && minorVersion == 1)
701 if (servicePack == 0)
704 else if (servicePack == 1)
709 return STATUS_NOT_SUPPORTED;
713 else if (majorVersion == 6 && minorVersion == 2)
717 if (servicePack == 0)
722 return STATUS_NOT_SUPPORTED;
726 else if (majorVersion == 6 && minorVersion == 3)
730 if (servicePack == 0)
735 return STATUS_NOT_SUPPORTED;
738 else if (majorVersion == 6 && minorVersion > 3 || majorVersion > 6)
741 return STATUS_NOT_SUPPORTED;
745 return STATUS_NOT_SUPPORTED;
748 return STATUS_SUCCESS;
759 ULONG_PTR endAddress;
762 if (!ProcedureScan->Initialized)
767 if (!ProcedureScan->Scanned)
769 bytes = ProcedureScan->Bytes;
770 length = ProcedureScan->Length;
771 endAddress = ProcedureScan->StartAddress + ProcedureScan->ScanLength;
776 for (address = ProcedureScan->StartAddress; address < endAddress; address++)
778 if (RtlCompareMemory((PVOID)address, bytes, length) == length)
780 ProcedureScan->ProcedureAddress = (PVOID)(address + ProcedureScan->Displacement);
787 ProcedureScan->ProcedureAddress = NULL;
790 ProcedureScan->Scanned =
TRUE;
793 return ProcedureScan->ProcedureAddress;