Advertisement
Neo-Craft

Memory Virtual address parsing

May 23rd, 2018
394
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.98 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5. )
  6.  
  7. func VAtoOffsets(va uint64) {
  8.     phy_offset := va & 0xFFF
  9.     pt_index := (va >> 12) & 0x1FF
  10.     pde_index := (va >> (12 + 9)) & 0x1FF
  11.     pdpt_index := (va >> (12 + 9 + 9)) & 0x1FF
  12.     pml4_index := (va >> (12 + 9 + 9 + 9)) & 0x1FF
  13.    
  14.     fmt.Printf("PML4 Index: %03x\n", pml4_index)
  15.     fmt.Printf("PDPT Index: %03x\n", pdpt_index)
  16.     fmt.Printf("PDE Index: %03x\n", pde_index)
  17.     fmt.Printf("PT Index: %03x\n", pt_index)
  18.     fmt.Printf("Page offset: %03x\n", phy_offset)
  19.      
  20. }
  21.  
  22. func OffsetsToVA(phy_offset, pt_index, pde_index, pdpt_index, pml4_index uint64) {
  23.     var va uint64
  24.    
  25.     va = pml4_index << (12 + 9 + 9 + 9)
  26.     va = va | pdpt_index << (12 + 9 + 9)
  27.     va = va | pde_index << (12 + 9)
  28.     va = va | pt_index << 12
  29.     va = va | phy_offset
  30.    
  31.     if ((va & 0x800000000000) == 0x800000000000) {
  32.         va |= 0xFFFF000000000000
  33.     }
  34.    
  35.     fmt.Printf("Virtual Address: %x\n", va)
  36. }
  37.  
  38. func main() {
  39.     VAtoOffsets(0xffff804020100000)
  40.     OffsetsToVA(0, 0x100, 0x100, 0x100, 0x100)
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement