diff --git a/extract-symvers.py b/extract-symvers.py index 6776c14..c155836 100644 --- a/extract-symvers.py +++ b/extract-symvers.py @@ -4,6 +4,7 @@ import struct import sys import StringIO +from subprocess import Popen, PIPE from optparse import OptionParser # gzip.GzipFile is being unhelpful trying to read another gzip @@ -46,6 +47,11 @@ def __init__(self, file, base, endian, ptr_size): # contain what looks like a gzip header much later. if index != -1 and float(index) / len(kernel) < 0.01: kernel = gzip.GzipFile(fileobj=StringIO.StringIO(kernel[index:])).read() + else: + index = kernel.rfind(b'\xfd\x37\x7a\x58\x5a\x00') # XZ marker + if index != -1 and float(index) / len(kernel) < 0.1: + p = Popen("xz -dc", shell=True, stdin=PIPE, stderr=PIPE, stdout=PIPE) + kernel = p.communicate(input=StringIO.StringIO(kernel[index:]).read())[0] self.kernel = kernel self.size = len(self.kernel) self.base = base @@ -91,14 +97,16 @@ def scan_symsearch(self): raise ScanFailException() off += 4 symsearch[EXPORT_TYPE[i]] = ptrs - + # print "Offset = %x" % (offset) return symsearch except ScanFailException: pass + # print "Offset = %x" % (offset) offset += self.ptr_bytes def symbols(self): symsearch = self.scan_symsearch() + # print symsearch for t, s in symsearch.items(): crc_off = s['crcs'] - self.base for offset in range(s['start'] - self.base, s['stop'] - self.base, self.ptr_bytes * 2): @@ -132,6 +140,7 @@ def main(): exit(1) kernel = KernelImage(args[0], int(options.base, 16), options.endian, int(options.bits)) + # print "Got the Kernel" for s, crc, t in kernel.symbols(): print "0x%08x\t%s\tvmlinux\t%s" % (crc, s, t)