Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools: add dump-appimage.py tool. #77

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
53 changes: 53 additions & 0 deletions tools/dump-appimage.py
Original file line number Diff line number Diff line change
@@ -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
# <http://mumble.info/mumble-releng/LICENSE>.

# 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 <appimage-fn>')
print('')
print('Writes resulting .squashfs file to')
print('<appimage-fn>.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()