Skip to content

Instantly share code, notes, and snippets.

@moyix
Created March 9, 2016 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moyix/8d0d9996e28b1e433c9e to your computer and use it in GitHub Desktop.
Save moyix/8d0d9996e28b1e433c9e to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import sys
import numpy as np
import struct
f = open(sys.argv[1])
byte_offset = int(sys.argv[2], 0)
ulong_size = struct.unpack("<i", f.read(4))[0]
ulong_fmt = '<u%d' % ulong_size
FMT = "%%0%dx" % (ulong_size*2)
dtype = np.dtype( [ ('caller', ulong_fmt), ('pc', ulong_fmt), ('cr3', ulong_fmt), ('count', '<u8') ] )
data = np.fromfile(f, dtype=dtype)
# Get cumulative sum of the sizes, starting at 0
offsets = np.zeros(data.shape[0]+1,dtype=int)
offsets[1:] = np.cumsum(data['count'])
# Use binary search to find out which tap point that byte
# offest maps to
index = np.searchsorted(offsets, byte_offset, side='right') - 1
row = data[index]
print (FMT + " " + FMT + " " + FMT) % (row['caller'], row['pc'], row['cr3'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment