While we still aren't providing an uncompressed vmlinux image, it is now
possible to extract one from vmlinuz.  The following Python script does
the job; give it the filename of the compressed image followed by the
filename for the uncompressed image.

Ben.

#!/usr/bin/python

import struct, zlib

def vmlinuz_to_image(f):
    # We can't use gzip.GzipFile because that complains if there is
    # trailing data, which is the case for ELFBoot kernel images.
    # Use zlib directly.
    zo = zlib.decompressobj(-15)

    # Look for gzip-deflate header and find end of it
    f.seek(0, 0)
    head = f.read(65536)
    off = head.index('\x1f\x8b\x08')
    flags = ord(head[off + 3])
    off += 10                   # fixed header
    if flags & 0x04:            # FEXTRA
        off += 2 + struct.unpack('<H', head[off:off+2])[0]
    if flags & 0x08:            # FNAME
        off = head.index('\0', off) + 1
    if flags & 0x10:            # FCOMMENT
        off = head.index('\0', off) + 1
    if flags & 0x02:            # FHCRC
        off += 2
    assert not (flags & 0xe0)   # reserved

    # Decompress following deflate blocks
    f.seek(off)
    image = zo.decompress(f.read()) + zo.flush()

    # Verify decompressed data against gzip trailer
    assert (struct.unpack('<LL', zo.unused_data[:8]) ==
            (zlib.crc32(image) & 0xffffffffL, len(image)))

    return image

if __name__ == '__main__':
    import sys
    vmlinuz = open(sys.argv[1], 'rb')
    vmlinux = open(sys.argv[2], 'wb')
    vmlinux.write(vmlinuz_to_image(vmlinuz))
### END ###

-- 
Ben Hutchings
I say we take off; nuke the site from orbit.  It's the only way to be sure.

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to