from crypto.aes import AESdecryptCBC from util import read_file, write_file from util.ramdiskclient import RamdiskToolClient import M2Crypto import struct import hashlib import os import sys def decryptGID(data): try: client = RamdiskToolClient.get() except: return None r = client.aesGID(data) if r and r.has_key("data"): return r.data.data return None def decryptPseudoGID(data): pseudogid = "5F650295E1FFFC97CE77ABD49DD955B3".decode("hex") return AESdecryptCBC(data, pseudogid, padding=False) def dword(s,i): return struct.unpack(" 16 and data.startswith("complzss"): return "kernel" if len(data) > 0x800 and data[0x400:0x400+2] == "H+": return "ramdisk" if len(data) > 0x300 and data[0x280:0x285] == "iBoot": return "bootloader"; if data.find("serial-number") != -1: return "devicetree" if data.startswith("iBootIm"): return "bootlogo" def getRawData(self): return self.sections["DATA"][:self.datalen] def decryptData(self, key=None, iv=None): if not self.sections.has_key("KBAG"): return self.getRawData() if not key or not iv: if not self.decryptKBAG(): return key = self.key iv = self.iv data = AESdecryptCBC(self.sections["DATA"], key, iv) x = self.isValidDecryptedData(data) if not x: print >> sys.stderr, "%s : Decrypted data seems invalid" % self.shortname print >> sys.stderr, data[:50].encode("hex") return False print "%s : decrypted OK (%s)" % (self.shortname, x) return data[:self.datalen] if __name__ == "__main__": img3 = Img3(sys.argv[1]) img3.sigcheck()