Created
July 22, 2013 18:45
-
-
Save luca-m/6056429 to your computer and use it in GitHub Desktop.
Quick and dirty script for decompressing a gz stream
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import zlib,sys,os | |
print 'Usage: %s <infile> <offset-addr> <length> <outfile>' % sys.argv[0] | |
if len(sys.argv) < 5: | |
exit(-1) | |
fr = open(sys.argv[1], 'rb') | |
offset = int(sys.argv[2]) | |
length = int(sys.argv[3]) | |
if length == 0: | |
length = os.path.getsize(sys.argv[1]) - offset | |
fr.seek(offset) | |
bytes = fr.read(length) | |
fr.close() | |
try: | |
uncomprr =zlib.decompress(bytes) | |
fw = open(sys.argv[4], 'w') | |
fw.write(uncomprr) | |
fw.close() | |
print "decompressed file segment !" | |
except zlib.error : | |
print 'File segment 0x%x->%s does not contain zlib compressed data' % (offset,length) | |
exit(-1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment