def packCommand(firmwareFile, fsFile, bodyFile, configFile, device, outDir, defaultVersion='9.99'): mkdirs(outDir) if configFile: config = yaml.safe_load(configFile) datConf = config['dat'] fdatConf = config['fdat'] elif device: devices = getDevices() if device not in devices: raise Exception('Unknown device') config = devices[device] datConf = { 'crypterName': 'gen%d' % config['gen'], 'normalUsbDescriptors': [], 'updaterUsbDescriptors': [], 'isLens': False, } fdatConf = { 'model': config['model'], 'region': config['region'] if 'region' in config else 0, 'version': defaultVersion, 'isAccessory': False, } if not fsFile and bodyFile: print('Packing updater file system') fsFile = open(outDir + '/updater_packed.img', 'w+b') archive.cramfs.writeCramfs([toUnixFile('/bodylib/libupdaterbody.so', bodyFile)], fsFile) if fdatConf: print('Creating firmware image') with open(outDir + '/firmware_packed.fdat', 'w+b') as fdatFile: fdat.writeFdat(fdat.FdatFile( model = fdatConf['model'], region = fdatConf['region'], version = fdatConf['version'], isAccessory = fdatConf['isAccessory'], firmware = firmwareFile if firmwareFile else io.BytesIO(), fs = fsFile if fsFile else io.BytesIO(), ), fdatFile) if datConf: print('Encrypting firmware image') encrypted = fdat.encryptFdat(fdatFile, datConf['crypterName']) with open(outDir + '/firmware_packed.dat', 'w+b') as datFile: dat.writeDat(dat.DatFile( normalUsbDescriptors = datConf['normalUsbDescriptors'], updaterUsbDescriptors = datConf['updaterUsbDescriptors'], isLens = datConf['isLens'], firmwareData = encrypted, ), datFile)
def packCommand(firmwareFile, fsFile, bodyFile, configFile, outDir): mkdirs(outDir) config = yaml.safe_load(configFile) datConf = config['dat'] fdatConf = config['fdat'] if not fsFile and bodyFile: print 'Packing updater file system' fsFile = open(outDir + '/updater_packed.img', 'w+b') archive.cramfs.writeCramfs( [toUnixFile('/bodylib/libupdaterbody.so', bodyFile)], fsFile) if fdatConf: print 'Creating firmware image' with open(outDir + '/firmware_packed.fdat', 'w+b') as fdatFile: fdat.writeFdat( fdat.FdatFile( model=fdatConf['model'], region=fdatConf['region'], version=fdatConf['version'], isAccessory=fdatConf['isAccessory'], firmware=firmwareFile if firmwareFile else io.BytesIO(), fs=fsFile if fsFile else io.BytesIO(), ), fdatFile) if datConf: print 'Encrypting firmware image' encrypted = fdat.encryptFdat(fdatFile, datConf['crypterName']) with open(outDir + '/firmware_packed.dat', 'w+b') as datFile: dat.writeDat( dat.DatFile( normalUsbDescriptors=datConf[ 'normalUsbDescriptors'], updaterUsbDescriptors=datConf[ 'updaterUsbDescriptors'], isLens=datConf['isLens'], firmwareData=encrypted, ), datFile)
path='/bodylib/libupdaterbody.so', size=-1, mtime=0, mode=S_IFREG | 0o775, uid=0, gid=0, contents=f, ) ], fsFile) fdatFile = io.BytesIO() fdat.writeFdat( fdat.FdatFile( model=config['model'], region=config['region'] if 'region' in config else 0, version='9.99', isAccessory=False, firmware=io.BytesIO(), fs=fsFile, ), fdatFile) key = config['arch'] + ('_' + config['key'] if 'key' in config else '') data = fdat.encryptFdat(fdatFile, key).read() dataDict.setdefault(key, {})[name] = data mkdirs(fdatDir) headerSize = 0x30 for key, datas in dataDict.items(): payload = None for name, data in datas.items(): if payload is None: