[kernel-team] 08/47: Add script for decompressing vmlinuz

debian-kernel at lists.debian.org debian-kernel at lists.debian.org
Mon Dec 21 00:30:44 UTC 2015


This is an automated email from the git hooks/post-receive script.

benh pushed a commit to branch master
in repository kernel-team.

commit b9ae0ab3de863320328725569927100b362ec28f
Author: Ben Hutchings <benh at debian.org>
Date:   Fri Apr 15 01:53:14 2011 +0000

    Add script for decompressing vmlinuz
    
    svn path=/people/benh/; revision=17223
---
 scripts/benh/zcat-linux-image | 74 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 74 insertions(+)

diff --git a/scripts/benh/zcat-linux-image b/scripts/benh/zcat-linux-image
new file mode 100755
index 0000000..c152e9d
--- /dev/null
+++ b/scripts/benh/zcat-linux-image
@@ -0,0 +1,74 @@
+#!/usr/bin/python
+
+# Copyright 2010 Ben Hutchings
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+import os, struct, zlib
+
+def zcat_vmlinuz(f):
+    f.seek(0, 0)
+    head = f.read(65536)
+
+    try:
+        # Look for gzip-deflate header
+        off = head.index('\x1f\x8b\x08')
+    except ValueError:
+        pass
+    else:
+        return gzcat(f, head, off)
+
+    # Look for likely lzma header
+    off = head.index('\x00\x00\x00\x02\xff\xff\xff\xff\xff\xff\xff\xff') - 1
+    return lzcat(f, head, off)
+
+def gzcat(f, head, off):
+    # 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)
+
+    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)))
+
+    sys.stdout.write(image)
+    sys.stdout.flush()
+
+def lzcat(f, head, off):
+    os.dup2(f.fileno(), 0)
+    f.close()
+    os.lseek(0, off, os.SEEK_SET)
+    os.execvp('lzcat', ['lzcat', '-t'])
+
+if __name__ == '__main__':
+    import sys
+    zcat_vmlinuz(open(sys.argv[1], 'rb'))

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/kernel/kernel-team.git



More information about the Kernel-svn-changes mailing list