def _build_storage(self): mapping = [ (1, 'MSCompressed', (LZXCOMPRESS_GUID, )), (2, 'EbEncryptDS', (LZXCOMPRESS_GUID, DESENCRYPT_GUID)), (3, 'EbEncryptOnlyDS', (DESENCRYPT_GUID, )), ] for secnum, name, transforms in mapping: root = '::DataSpace/Storage/' + name data = self._sections[secnum].getvalue() cdata, sdata, tdata, rdata = '', '', '', '' for guid in transforms: tdata = packguid(guid) + tdata sdata = sdata + pack('<Q', len(data)) if guid == DESENCRYPT_GUID: cdata = MSDES_CONTROL + cdata if not data: continue msdes.deskey(self._bookkey, msdes.EN0) pad = 8 - (len(data) & 0x7) if pad != 8: data = data + ('\0' * pad) data = msdes.des(data) elif guid == LZXCOMPRESS_GUID: cdata = LZXC_CONTROL + cdata if not data: continue unlen = len(data) lzx = Compressor(17) data, rtable = lzx.compress(data, flush=True) rdata = StringIO() rdata.write( pack('<IIIIQQQQ', 3, len(rtable), 8, 0x28, unlen, len(data), 0x8000, 0)) for uncomp, comp in rtable[:-1]: rdata.write(pack('<Q', comp)) rdata = rdata.getvalue() self._add_file(root + '/Content', data) self._add_file(root + '/ControlData', cdata) self._add_file(root + '/SpanInfo', sdata) self._add_file(root + '/Transform/List', tdata) troot = root + '/Transform' for guid in transforms: dname = self._djoin(troot, guid, 'InstanceData') self._add_folder(dname) if guid == LZXCOMPRESS_GUID: dname += '/ResetTable' self._add_file(dname, rdata)
def _build_storage(self): mapping = [(1, 'MSCompressed', (LZXCOMPRESS_GUID,)), (2, 'EbEncryptDS', (LZXCOMPRESS_GUID, DESENCRYPT_GUID)), (3, 'EbEncryptOnlyDS', (DESENCRYPT_GUID,)),] for secnum, name, transforms in mapping: root = '::DataSpace/Storage/' + name data = self._sections[secnum].getvalue() cdata, sdata, tdata, rdata = '', '', '', '' for guid in transforms: tdata = packguid(guid) + tdata sdata = sdata + pack('<Q', len(data)) if guid == DESENCRYPT_GUID: cdata = MSDES_CONTROL + cdata if not data: continue msdes.deskey(self._bookkey, msdes.EN0) pad = 8 - (len(data) & 0x7) if pad != 8: data = data + ('\0' * pad) data = msdes.des(data) elif guid == LZXCOMPRESS_GUID: cdata = LZXC_CONTROL + cdata if not data: continue unlen = len(data) lzx = Compressor(17) data, rtable = lzx.compress(data, flush=True) rdata = StringIO() rdata.write(pack('<IIIIQQQQ', 3, len(rtable), 8, 0x28, unlen, len(data), 0x8000, 0)) for uncomp, comp in rtable[:-1]: rdata.write(pack('<Q', comp)) rdata = rdata.getvalue() self._add_file(root + '/Content', data) self._add_file(root + '/ControlData', cdata) self._add_file(root + '/SpanInfo', sdata) self._add_file(root + '/Transform/List', tdata) troot = root + '/Transform' for guid in transforms: dname = self._djoin(troot, guid, 'InstanceData') self._add_folder(dname) if guid == LZXCOMPRESS_GUID: dname += '/ResetTable' self._add_file(dname, rdata)