Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion extract-symvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)

Expand Down