def decompress_fs(data, path, test = False): """Decompress filesystem""" lzofsdatalen = unpack('>L', data[4:8])[0] if draytools.verbose: print 'Compressed FS length: %d [0x%08X]' % (lzofsdatalen, lzofsdatalen) # stupid assumption of raw FS length. Seems OK for now fsdatalen = 0x800000 fs_raw = pydelzo.decompress('\xF0' + pack(">L", fsdatalen) \ + data[0x08:0x08 + lzofsdatalen]) cfs = draytools.fs(fs_raw, test, draytools.verbose) return (lzofsdatalen, cfs.save_all(path))
def decompress_cfg(data): """Decompress a config file""" modelstr = "V" + format(unpack(">H", draytools.get_modelid(data))[0],"04X") if draytools.verbose and draytools.modelprint: print 'Model is :\t' + modelstr else: draytools.modelprint = True rawcfgsize = 0x00100000 lzocfgsize = unpack(">L", data[0x24:0x28])[0] raw = data[:0x2D] + '\x00' + data[0x2E:0x100] \ + pydelzo.decompress('\xF0' + pack(">L",rawcfgsize) \ + data[0x100:0x100+lzocfgsize]) return raw
def decompress_cfg(data): """Decompress a config file""" modelstr = "V" + format( unpack(">H", draytools.get_modelid(data))[0], "04X") if draytools.verbose and draytools.modelprint: print 'Model is :\t' + modelstr else: draytools.modelprint = True rawcfgsize = 0x00100000 lzocfgsize = unpack(">L", data[0x24:0x28])[0] raw = data[:0x2D] + '\x00' + data[0x2E:0x100] \ + pydelzo.decompress('\xF0' + pack(">L",rawcfgsize) \ + data[0x100:0x100+lzocfgsize]) return raw
def save_file(self,i): """Extract file #i from current FS""" fname = self.get_fname(i) # compressed file data offset in FS block ds = self.get_offset(i) # size of compressed file fs = self.get_fsize(i) # compressed file data fdata = self.cdata[ds : ds+fs] # create all subdirs along the path if they don't exist pp = fname.split('\\') pp = [self.path] + pp ppp = os.sep.join(pp[:-1]) if len(pp) > 1: if not os.path.exists(ppp) and not self.test: os.makedirs(ppp) nfname = os.sep.join(pp) # size of uncompressed file rawfs = -1 if not self.test: ff = file(nfname,'wb') # perform extraction, some file types are not compressed if fs>0: if pp[-1].split('.')[-1].lower() \ in ['gif','jpg','cgi','cab','txt','jar']: rawfdata = fdata else: try: rawfdata = pydelzo.decompress('\xF0' \ + pack(">L",fs*64)+fdata) except LZO_ERROR as lze: print '[ERR]:\tFile "'+ fname \ + '" is damaged or uncompressed [' \ + str(lze) \ + '], RAW DATA WRITTEN' rawfdata = fdata else: rawfdata = '' rawfs = len(rawfdata) if not self.test: ff.write(rawfdata) ff.close() # print some debug info for each file if self.echo: print '%08X "' % ds + fname + '" %08X' % fs \ + ' %08X' % rawfs return (fs, rawfs)
def save_file(self,i): """Extract file #i from current FS""" fname = self.get_fname(i) # compressed file data offset in FS block ds = self.get_offset(i) # size of compressed file fs = self.get_fsize(i) # compressed file data fdata = self.cdata[ds : ds+fs] # create all subdirs along the path if they don't exist pp = fname.split('\\') pp = [self.path] + pp ppp = os.sep.join(pp[:-1]) if len(pp) > 1: if not os.path.exists(ppp) and not self.test: os.makedirs(ppp) nfname = os.sep.join(pp) # size of uncompressed file rawfs = -1 if not self.test: ff = file(nfname,'wb') # perform extraction, some file types are not compressed if fs > 0: if pp[-1].split('.')[-1].lower() \ in ['gif','jpg','cgi','cab','txt','jar']: rawfdata = fdata else: try: rawfdata = pydelzo.decompress('\xF0' \ + pack(">L",fs*64)+fdata) except LZO_ERROR as lze: print '[ERR]:\tFile "'+ fname \ + '" is damaged or uncompressed [' \ + str(lze) \ + '], RAW DATA WRITTEN' rawfdata = fdata else: rawfdata = '' rawfs = len(rawfdata) if not self.test: ff.write(rawfdata) ff.close() # print some debug info for each file if self.echo: print '%08X "' % ds + fname + '" %08X' % fs \ + ' %08X' % rawfs return (fs, rawfs)
def decompress_firmware(data): """Decompress firmware""" flen = len(data) sigstart = data.find('\xA5\xA5\xA5\x5A\xA5\x5A') # Try an alternative signature if sigstart <= 0: sigstart = data.find('\x5A\x5A\xA5\x5A\xA5\x5A') # Compressed FW block found, now decompress if sigstart > 0: if draytools.verbose: print 'Signature found at [0x%08X]' % sigstart lzosizestart = sigstart + 6 lzostart = lzosizestart + 4 lzosize = unpack('>L', data[lzosizestart:lzostart])[0] return data[0x100:sigstart+2] \ + pydelzo.decompress('\xF0' + pack(">L",0x1000000) \ + data[lzostart:lzostart+lzosize]) else: print '[ERR]:\tCompressed FW signature not found!' raise Exception('Compressed FW signature not found') return ''
def decompress_firmware(data): """Decompress firmware""" flen = len(data) sigstart = data.find('\xA5\xA5\xA5\x5A\xA5\x5A') # Try an alternative signature if sigstart <= 0: sigstart = data.find('\x5A\x5A\xA5\x5A\xA5\x5A') # Compressed FW block found, now decompress if sigstart > 0: if draytools.verbose: print 'Signature found at [0x%08X]' % sigstart lzosizestart = sigstart + 6 lzostart = lzosizestart + 4 lzosize = unpack('>L', data[lzosizestart:lzostart])[0] return data[0x100:sigstart+2] \ + pydelzo.decompress('\xF0' + pack(">L",0x1000000) \ + data[lzostart:lzostart+lzosize]) else: print '[ERR]:\tCompressed FW signature not found!' raise Exception('Compressed FW signature not found') return ''