from construct import RepeatUntil from construct.core import Struct, Union from construct.macros import * from crypto.aes import AESdecryptCBC from crypto.aeswrap import AESUnwrap from zipfile import crc32 import struct Dkey = 0x446B6579 EMF = 0x454D4621 BAG1 = 0x42414731 DONE = 0x444f4e45 #locker sentinel #**** = 0x2A2A2A2A #wildcard for erase #MAGIC (kL) | LEN (2bytes) | TAG (4) | DATA (LEN) Locker = Struct("Locker", String("magic",2), ULInt16("length"), Union("tag", ULInt32("int"), String("tag",4)) , String("data", lambda ctx: ctx["length"]) ) Lockers = RepeatUntil(lambda obj, ctx: obj.tag.int == DONE, Locker) def xor_strings(s, key): res = "" for i in xrange(len(s)): res += chr(ord(s[i]) ^ ord(key[i%len(key)])) return res def check_effaceable_header(plog): z = xor_strings(plog[:16], plog[16:32]) if z[:4] != "ecaF": return False plog_generation = struct.unpack("