1#!/usr/bin/python3 2 3import re 4import sys 5 6def main(): 7 if len(sys.argv) != 3: 8 print("Missing arguments: ./radv_check_va.py <bo_history> <64-bit VA>") 9 sys.exit(1) 10 11 bo_history = str(sys.argv[1]) 12 va = int(sys.argv[2], 16) 13 14 va_found = False 15 with open(bo_history) as f: 16 for line in f: 17 p = re.compile('timestamp=(.*), VA=(.*)-(.*), destroyed=(.*), is_virtual=(.*)') 18 mapped_p = re.compile('timestamp=(.*), VA=(.*)-(.*), mapped_to=(.*)') 19 m = p.match(line) 20 mapped_m = mapped_p.match(line) 21 if m: 22 va_start = int(m.group(2), 16) 23 va_end = int(m.group(3), 16) 24 mapped_va = 0 25 elif mapped_m: 26 va_start = int(mapped_m.group(2), 16) 27 va_end = int(mapped_m.group(3), 16) 28 mapped_va = int(mapped_m.group(4), 16) 29 else: 30 continue 31 32 # Check if the given VA was ever valid and print info. 33 if va >= va_start and va < va_end: 34 print("VA found: %s" % line, end='') 35 if mapped_m: 36 effective_va = (va - va_start) + mapped_va 37 if mapped_va == 0: 38 effective_va = 0 39 print(" Virtual mapping: %016x -> %016x" % (va, effective_va)) 40 va_found = True 41 if not va_found: 42 print("VA not found!") 43 44if __name__ == '__main__': 45 main() 46