From e7797f637dc70d6587bc641117a18c3bc8352a0a Mon Sep 17 00:00:00 2001 From: Mikkel Krautz Date: Sun, 25 Mar 2018 12:35:28 +0200 Subject: [PATCH] tools: add dump-appimage.py tool. unsquashfs can't find the squashfs image embedded in the AppImage from https://dl.mumble.info/murmur-linux-appimage-i386-1.3.0~2498~g80916fd~snapshot.tar.bz2 This tool allowed me to extract it. --- tools/dump-appimage.py | 53 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100755 tools/dump-appimage.py diff --git a/tools/dump-appimage.py b/tools/dump-appimage.py new file mode 100755 index 00000000..71d50da9 --- /dev/null +++ b/tools/dump-appimage.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python +# +# Copyright 2018 The 'mumble-releng' Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that +# can be found in the LICENSE file in the source tree or at +# . + +# Dump a .squashfs file from an .AppImage. +# +# Sometimes, unsquashfs gets confused and can't find +# the superblock. We find it, via 'hsqs' header and +# major version == 4 and copy the squashfs filesystem +# to its own file. + +from __future__ import (unicode_literals, print_function, division) + +import os +import sys + +def usage(): + print('dump-appimage.py ') + print('') + print('Writes resulting .squashfs file to') + print('.squashfs.') + sys.exit(1) + +def main(): + if len(sys.argv) < 2: + usage() + fn = sys.argv[1] + f = open(fn, 'r') + all = f.read() + f.close() + + squashMagic = bytearray((ord('h'), ord('s'), ord('q'), ord('s'))) + squashOffset = 0 + squashMajor = 0 + for i in range(0, len(all)): + if all[i:i+len(squashMagic)] == squashMagic: + squashOffset = i + squashMajor = (ord(all[i+29]) << 8) | ord(all[i+28]) + if squashMajor == 4: + break + + if squashOffset == 0 or squashMajor != 4: + raise Exception('no squashfs image found') + + newf = open(fn + '.squashfs', 'w') + newf.write(all[i:]) + newf.close() + +if __name__ == '__main__': + main()