Created
March 9, 2016 14:22
This file contains 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
#!/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