Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
gmh5225 committed Nov 15, 2023
1 parent 74d51d8 commit 7736b65
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions test/testdrv1/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <libwindrv/libwindrv.h>

#include <intrin.h>

DECLSPEC_NOINLINE
EXTERN_C
VOID
Expand Down Expand Up @@ -53,6 +55,39 @@ KCETBSOD()
#endif
}

DECLSPEC_NOINLINE
EXTERN_C
void
InitPageTable()
{
#ifndef _ARM64_
PHYSICAL_ADDRESS PA = {0};
ULONG64 CurCr3 = (ULONG64)PAGE_ALIGN(__readcr3());
PA.QuadPart = CurCr3;
PVOID MapAddress = MmGetVirtualForPhysical(PA);
if (MapAddress)
{
for (int i = 0; i < 512; i++)
{
if ((*(PULONG64)((ULONG64)MapAddress + i * 8) & 0x0000fffffffff000) == (CurCr3 & 0x0000fffffffff000))
{
ULONG64 SelfMapIndex = i;
ULONG64 PteBase = (ULONG64)(0xffff000000000000 + (SelfMapIndex << 39));
ULONG64 PdeBase = PteBase + (SelfMapIndex << 30);
ULONG64 PpeBase = PdeBase + (SelfMapIndex << 21);
ULONG64 PxeBase = PpeBase + (SelfMapIndex << 12);
printf("SelfMapIndex=%d\n", SelfMapIndex);
printf("PteBase=%p\n", PteBase);
printf("PdeBase=%p\n", PdeBase);
printf("PpeBase=%p\n", PpeBase);
printf("PxeBase=%p\n", PxeBase);
break;
}
}
}
#endif
}

EXTERN_C
NTSTATUS
LibWinDrvDriverEntry(__in DRIVER_OBJECT *DriverObject, __in UNICODE_STRING *RegistryPath)
Expand All @@ -70,6 +105,7 @@ LibWinDrvDriverEntry(__in DRIVER_OBJECT *DriverObject, __in UNICODE_STRING *Regi
printf("hello world2\n");*/
// KCETBSOD();
main2();
InitPageTable();

return STATUS_SUCCESS;
}

0 comments on commit 7736b65

Please sign in to comment.