Last active
August 29, 2015 14:16
-
-
Save segrax/168b8e106f0f20bd69ee to your computer and use it in GitHub Desktop.
Calculating Indexs from a virtual address
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PML4 Directory Ptr Page Directory Page Table Page Offset | |
x-xxxx-xxxx x-xxxx-xxxx x-xxxx-xxxx x-xxxx-xxxx XXXX-XXXX-XXXX | |
$address = 0xFF8000000000; | |
$pml4 = ($address & 0xFF8000000000) >> 39; | |
$pdp = ($address & 0x7FC0000000) >> 30; | |
$pd = ($address & 0x3FE00000) >> 21; | |
$pt = ($address & 0x1FF000) >> 12; | |
$offset = ($address & 0xFFF); |
Author
segrax
commented
Mar 10, 2015
> 39;
$pdp = ($address & 0x7fc0000000) >> 30;
$pd = ($address & 0x3fe00000) >> 21;
$pt = ($address & 0x1FF000) >> 12;
$offset = ($address & 0xFFF);
echo "Address: 0x".dechex($address)."\n\n";
echo "Page Offset:0x" . dechex($offset)."\n\n";
echo "PML4 Index: $pml4\n";
echo "PDP Index: $pdp\n";
echo "PD Index: $pd\n";
echo "PT Index: $pt\n";
> 39) & 0x1FF;
}
function GetPageDirectoryPointer_Index( $pVirtual ) {
return ($pVirtual >> 30) & 0x1FF;
}
function GetPageDirectory_Index( $pVirtual ) {
return ($pVirtual >> 21) & 0x1FF;
}
function getPageDirectoryTable_Index( $pVirtual ) {
return ($pVirtual >> 12) & 0x1FF;
}
function GetPageTableEntryForAddress( $pVirtual ) {
```
$PML4 = GetPageMapLevel4_Index( $pVirtual );
$PDP = GetPageDirectoryPointer_Index( $pVirtual );
$PD = GetPageDirectory_Index( $pVirtual );
$PT = GetpageDirectoryTable_Index( $pVirtual );
$Address = 0xFFFFFF8000000000 + (0x40000000 * $PDP) + (0x200000 * $PD) + (0x1000 * $PT);
return $Address;
```
}
echo "0x" . dechex( GetPageTableEntryForAddress( 0x2000 ) ) . "\n";
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment