def unpackCommand(file, outDir): """Extracts the firmware image from the updater executable, unpacks it and extracts it to the specified directory""" print "Reading installer binary" exeFile = pe.readExe(file.read()) print "Decompressing installer data" zipFile = zip.readZip(zip.findZip(exeFile["_winzip_"].tobytes())) print "Reading .dat file" datFile = dat.readDat(zipFile[dat.findDat(zipFile.keys())]) print "Decoding firmware image" firmwareData = fdat.decryptFdat(datFile["FDAT"].tobytes()) print "Extracting updater image" writeFile(outDir, "updater.img", firmwareData.getImg()) print "Decompressing .tar file" tarFile = tar.readTar(firmwareData.getTar()) print "Extracting files" for path, data in tarFile.iteritems(): if not re.search("^\d{4}_([^/]+)_sum/\\1\.sum$", path): if path.startswith("0700_part_image/dev/nflash") and lzpt.isLzpt(data): print "Decompressing file system image " + os.path.basename(path) data = lzpt.readLzpt(data) writeFile(outDir, path, data) print "Done"
def unpackInstaller(exeFile, datFile): print('Extracting installer binary') exeSectors = pe.readExe(exeFile) zipFile = exeSectors['_winzip_'] zippedFiles = dict((file.path, file) for file in zip.readZip(zipFile)) zippedDatFile = zippedFiles[dat.findDat(zippedFiles.keys())] shutil.copyfileobj(zippedDatFile.contents, datFile) return zippedDatFile.mtime
def unpackInstaller(exeFile, datFile): print('Extracting installer binary') exeSectors = pe.readExe(exeFile) if '_winzip_' in exeSectors: zipFile = exeSectors['_winzip_'] zippedFiles = dict((file.path, file) for file in zip.readZip(zipFile)) zippedDatFile = zippedFiles[dat.findDat(zippedFiles.keys())] else: last = next(reversed(exeSectors.values())) lzhFile = FilePart(exeFile, last.offset + last.size) if not lzh.isLzh(lzhFile): raise Exception('Unknown exe file') zippedDatFile = lzh.readLzh(lzhFile) shutil.copyfileobj(zippedDatFile.contents, datFile) return zippedDatFile.mtime