HyperDbg Debugger
Loading...
Searching...
No Matches
AddressCheck.h File Reference

Header files for address checks. More...

Go to the source code of this file.

Functions

BOOLEAN CheckAddressCanonicality (UINT64 VAddr, PBOOLEAN IsKernelAddress)
 Checks if the address is canonical based on x86 processor's virtual address width or not.
 

Detailed Description

Header files for address checks.

Author
Sina Karvandi (sina@.nosp@m.hype.nosp@m.rdbg..nosp@m.org)
Version
0.2
Date
2023-04-27

Function Documentation

◆ CheckAddressCanonicality()

BOOLEAN CheckAddressCanonicality ( UINT64 VAddr,
PBOOLEAN IsKernelAddress )

Checks if the address is canonical based on x86 processor's virtual address width or not.

Parameters
VAddrvirtual address to check
IsKernelAddressFilled to show whether the address is a kernel address or user-address

IsKernelAddress wouldn't check for page attributes, it just checks the address convention in Windows

Returns
BOOLEAN
67{
68 UINT64 Addr = (UINT64)VAddr;
69 UINT64 MaxVirtualAddrLowHalf, MinVirtualAddressHighHalf;
70
71 //
72 // Get processor's address width for VA
73 //
75
76 //
77 // get max address in lower-half canonical addr space
78 // e.g. if width is 48, then 0x00007FFF_FFFFFFFF
79 //
80 MaxVirtualAddrLowHalf = ((UINT64)1ull << (AddrWidth - 1)) - 1;
81
82 //
83 // get min address in higher-half canonical addr space
84 // e.g., if width is 48, then 0xFFFF8000_00000000
85 //
86 MinVirtualAddressHighHalf = ~MaxVirtualAddrLowHalf;
87
88 //
89 // Check to see if the address in a canonical address
90 //
91 if ((Addr > MaxVirtualAddrLowHalf) && (Addr < MinVirtualAddressHighHalf))
92 {
93 *IsKernelAddress = FALSE;
94 return FALSE;
95 }
96
97 //
98 // Set whether it's a kernel address or not
99 //
100 if (MinVirtualAddressHighHalf < Addr)
101 {
102 *IsKernelAddress = TRUE;
103 }
104 else
105 {
106 *IsKernelAddress = FALSE;
107 }
108
109 return TRUE;
110}
#define TRUE
Definition BasicTypes.h:55
#define FALSE
Definition BasicTypes.h:54
unsigned __int64 UINT64
Definition BasicTypes.h:21
unsigned int UINT32
Definition BasicTypes.h:48
COMPATIBILITY_CHECKS_STATUS g_CompatibilityCheck
Different attributes and compatibility checks of the current processor.
Definition GlobalVariables.h:26
UINT32 VirtualAddressWidth
Definition CompatibilityChecks.h:30