Skip to content

Instantly share code, notes, and snippets.

@segrax
Last active August 29, 2015 14:16
Show Gist options
  • Save segrax/168b8e106f0f20bd69ee to your computer and use it in GitHub Desktop.
Save segrax/168b8e106f0f20bd69ee to your computer and use it in GitHub Desktop.
Calculating Indexs from a virtual address
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);
@segrax
Copy link
Author

segrax commented Mar 29, 2015

@segrax
Copy link
Author

segrax commented Mar 29, 2015

> 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