mirror of
https://github.com/bkerler/mtkclient.git
synced 2024-11-14 19:25:05 -05:00
Revert "Update mtkclient, prepare for rpmb key gen"
This reverts commit 4b499ad20e
.
This commit is contained in:
parent
4b499ad20e
commit
e546bf2a83
11 changed files with 86 additions and 99 deletions
BIN
gpt.bin
BIN
gpt.bin
Binary file not shown.
|
@ -1 +0,0 @@
|
|||
{"hwcode": "0x766", "meid": "3313f9a2fdd912fe3d210b354764f547", "socid": "ba6c2e8fb889665a8e9b09df6c379daaa3f2121f91cc03cb099d619104e3cc5f", "cid": "150100524331344d42128d9ecc359329", "rpmbkey": "ae6ba679ee75938c678674a9d5828a7defcd3bc3163d87fd2191360f0abe10dc", "rpmb2key": "088f4ee86cf3f0c97c6b9a7c440abaef", "fdekey": "9d06c2c729757d029703ae14d5676c4a", "kmkey": "53ad4fd48f42bda3a8d2eec6e8c9907fe9eeb5c364b2e4f5a2565ebc2da2a20d", "provkey": "00000000000000000000000000000000"}
|
|
@ -1160,7 +1160,7 @@ class dxcc(metaclass=LogBase):
|
|||
pdesc[5] = 0
|
||||
self.sasi_sb_adddescsequence(pdesc)
|
||||
dstaddr = self.da_payload_addr - 0x300
|
||||
self.SB_HalWaitDescCompletion()
|
||||
self.SB_HalWaitDescCompletion(dstaddr)
|
||||
# data=self.read32(0x200D90)
|
||||
self.tzcc_clk(0)
|
||||
return platkey, provkey
|
||||
|
@ -1205,13 +1205,13 @@ class dxcc(metaclass=LogBase):
|
|||
dmaMode = dmaMode
|
||||
self.writemem(inputSramAddr, DataIn[:bufferlen])
|
||||
if self.SBROM_AesCmacDriver(aesKeyType, pInternalKey, inputSramAddr, dmaMode, bufferlen, sramAddr):
|
||||
return sramAddr
|
||||
return pInternalKey
|
||||
return 0
|
||||
|
||||
def SB_HalInit(self):
|
||||
return self.SB_HalClearInterruptBit()
|
||||
|
||||
def SB_HalWaitDescCompletion(self, destptr=0):
|
||||
def SB_HalWaitDescCompletion(self, destptr):
|
||||
data = []
|
||||
self.SB_HalClearInterruptBit()
|
||||
val = self.sasi_paldmamap(0)
|
||||
|
@ -1236,7 +1236,7 @@ class dxcc(metaclass=LogBase):
|
|||
else:
|
||||
return 0xF6000001
|
||||
|
||||
def SBROM_AesCmacDriver(self, aesKeyType, pInternalKey, pDataIn, dmaMode, blockSize, pDataOut):
|
||||
def SBROM_AesCmacDriver(self, aesKeyType, pInternalKey, pDataIn, dmaMode, blockSize, pCMacResult):
|
||||
ivSramAddr = 0
|
||||
if aesKeyType == HwCryptoKey.ROOT_KEY:
|
||||
if self.read32(self.dxcc_base + self.DX_HOST_SEP_HOST_GPR4) & 2 != 0:
|
||||
|
@ -1289,14 +1289,14 @@ class dxcc(metaclass=LogBase):
|
|||
xdesc = hw_desc_set_setup_mode(xdesc, SetupOp.SETUP_WRITE_STATE0) # desc[4]=0x8001C00
|
||||
xdesc = hw_desc_set_flow_mode(xdesc, FlowMode.S_AES_to_DOUT) # desc[4]=0x8001C26
|
||||
if dmaMode == DmaMode.DMA_SRAM:
|
||||
xdesc = hw_desc_set_dout_sram(xdesc, pDataOut, AES_BLOCK_SIZE_IN_BYTES)
|
||||
xdesc = hw_desc_set_dout_sram(xdesc, pInternalKey, AES_BLOCK_SIZE_IN_BYTES)
|
||||
else:
|
||||
xdesc = hw_desc_set_dout_dlli(xdesc, pDataOut, AES_BLOCK_SIZE_IN_BYTES, SB_AXI_ID,
|
||||
xdesc = hw_desc_set_dout_dlli(xdesc, pInternalKey, AES_BLOCK_SIZE_IN_BYTES, SB_AXI_ID,
|
||||
0) # desc[2]=0x200E08, desc[3]=0x42
|
||||
# xdesc = hw_desc_set_din_sram(xdesc, 0, 0)
|
||||
xdesc = hw_desc_set_din_nodma(xdesc, 0, 0)
|
||||
self.sasi_sb_adddescsequence(xdesc)
|
||||
return self.SB_HalWaitDescCompletion() == 0
|
||||
return self.SB_HalWaitDescCompletion(pCMacResult) == 0
|
||||
|
||||
def mtee_decrypt(self, data):
|
||||
key = bytes.fromhex("B936C14D95A99585073E5607784A51F7444B60D6BFD6110F76D004CCB7E1950E")
|
||||
|
@ -1352,7 +1352,7 @@ class dxcc(metaclass=LogBase):
|
|||
self.sasi_sb_adddescsequence(tdesc)
|
||||
|
||||
def sbrom_cryptoupdate(self, inputptr, outputptr, blockSize, islastblock, cryptodrivermode, waitforcrypto):
|
||||
if waitforcrypto != 2 or self.SB_HalWaitDescCompletion() == 0:
|
||||
if waitforcrypto != 2 or self.SB_HalWaitDescCompletion(self.dxcc_base) == 0:
|
||||
if islastblock == 1 and (cryptodrivermode & 0xFFFFFFFD) == 0:
|
||||
# 0=0
|
||||
# 1=0
|
||||
|
@ -1373,7 +1373,7 @@ class dxcc(metaclass=LogBase):
|
|||
udesc = hw_desc_set_flow_mode(udesc, FlowMode.DIN_HASH)
|
||||
self.sasi_sb_adddescsequence(udesc)
|
||||
if (waitforcrypto == 2 and not islastblock) or waitforcrypto == 3:
|
||||
self.SB_HalWaitDescCompletion()
|
||||
self.SB_HalWaitDescCompletion(self.dxcc_base)
|
||||
elif waitforcrypto == 0:
|
||||
return 0
|
||||
else:
|
||||
|
@ -1394,7 +1394,7 @@ class dxcc(metaclass=LogBase):
|
|||
# 4 = 0x80C082B
|
||||
# 5 = outputptr>>32<<16
|
||||
self.sasi_sb_adddescsequence(fdesc)
|
||||
return self.SB_HalWaitDescCompletion()
|
||||
return self.SB_HalWaitDescCompletion(self.dxcc_base)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
@ -4,7 +4,7 @@ from mtkclient.config.payloads import pathconfig
|
|||
from mtkclient.Library.error import ErrorHandler
|
||||
from mtkclient.Library.hwcrypto import crypto_setup, hwcrypto
|
||||
from mtkclient.Library.utils import LogBase, progress, logsetup, find_binary
|
||||
from mtkclient.Library.settings import hwparam
|
||||
from mtkclient.Library.settings import writesetting, loadsetting
|
||||
from mtkclient.Library.seccfg import seccfg
|
||||
from binascii import hexlify
|
||||
import hashlib
|
||||
|
@ -24,7 +24,6 @@ class legacyext(metaclass=LogBase):
|
|||
self.error = self.__logger.error
|
||||
self.warning = self.__logger.warning
|
||||
self.mtk = mtk
|
||||
self.hwparam = hwparam(mtk.config.meid)
|
||||
self.loglevel = loglevel
|
||||
self.__logger = self.__logger
|
||||
self.eh = ErrorHandler()
|
||||
|
@ -173,8 +172,8 @@ class legacyext(metaclass=LogBase):
|
|||
def generate_keys(self):
|
||||
hwc = self.cryptosetup()
|
||||
meid = b""
|
||||
meidv = self.hwparam.loadsetting("meid")
|
||||
socidv = self.hwparam.loadsetting("socid")
|
||||
meidv = loadsetting("meid")
|
||||
socidv = loadsetting("socid")
|
||||
if meidv is not None:
|
||||
meid = bytes.fromhex(meidv)
|
||||
self.info("MEID : " + meidv)
|
||||
|
@ -182,7 +181,7 @@ class legacyext(metaclass=LogBase):
|
|||
try:
|
||||
if self.config.chipconfig.meid_addr is not None:
|
||||
meid = b"".join([pack("<I", val) for val in self.readmem(self.config.chipconfig.meid_addr, 4)])
|
||||
self.hwparam.writesetting("meid", hexlify(meid).decode('utf-8'))
|
||||
writesetting("meid", hexlify(meid).decode('utf-8'))
|
||||
self.info("MEID : " + hexlify(meid).decode('utf-8'))
|
||||
except Exception as err:
|
||||
pass
|
||||
|
@ -193,7 +192,7 @@ class legacyext(metaclass=LogBase):
|
|||
try:
|
||||
if self.config.chipconfig.socid_addr is not None:
|
||||
socid = b"".join([pack("<I",val) for val in self.readmem(self.config.chipconfig.socid_addr,8)])
|
||||
self.hwparam.writesetting("socid", hexlify(socid).decode('utf-8'))
|
||||
writesetting("socid", hexlify(socid).decode('utf-8'))
|
||||
self.info("SOCID : " + hexlify(socid).decode('utf-8'))
|
||||
except Exception as err:
|
||||
pass
|
||||
|
@ -212,20 +211,20 @@ class legacyext(metaclass=LogBase):
|
|||
#self.info("Platkey : " + hexlify(platkey).decode('utf-8'))
|
||||
if rpmbkey is not None:
|
||||
self.info("RPMB : " + hexlify(rpmbkey).decode('utf-8'))
|
||||
self.hwparam.writesetting("rpmbkey",hexlify(rpmbkey).decode('utf-8'))
|
||||
writesetting("rpmbkey",hexlify(rpmbkey).decode('utf-8'))
|
||||
if rpmb2key is not None:
|
||||
self.info("RPMB2 : " + hexlify(rpmb2key).decode('utf-8'))
|
||||
self.hwparam.writesetting("rpmb2key",hexlify(rpmb2key).decode('utf-8'))
|
||||
writesetting("rpmb2key",hexlify(rpmb2key).decode('utf-8'))
|
||||
if fdekey is not None:
|
||||
self.info("FDE : " + hexlify(fdekey).decode('utf-8'))
|
||||
self.hwparam.writesetting("fdekey",hexlify(fdekey).decode('utf-8'))
|
||||
writesetting("fdekey",hexlify(fdekey).decode('utf-8'))
|
||||
if ikey is not None:
|
||||
self.info("iTrustee : " + hexlify(ikey).decode('utf-8'))
|
||||
self.hwparam.writesetting("kmkey", hexlify(ikey).decode('utf-8'))
|
||||
writesetting("kmkey", hexlify(ikey).decode('utf-8'))
|
||||
if self.config.chipconfig.prov_addr:
|
||||
provkey = self.custom_read(self.config.chipconfig.prov_addr, 16)
|
||||
self.info("PROV : " + hexlify(provkey).decode('utf-8'))
|
||||
self.hwparam.writesetting("provkey", hexlify(provkey).decode('utf-8'))
|
||||
writesetting("provkey", hexlify(provkey).decode('utf-8'))
|
||||
"""
|
||||
hrid = self.xflash.get_hrid()
|
||||
if hrid is not None:
|
||||
|
@ -241,7 +240,7 @@ class legacyext(metaclass=LogBase):
|
|||
self.setotp(hwc)
|
||||
rpmbkey = hwc.aes_hwcrypt(mode="rpmb", data=meid, btype="sej")
|
||||
self.info("RPMB : " + hexlify(rpmbkey).decode('utf-8'))
|
||||
self.hwparam.writesetting("rpmbkey", hexlify(rpmbkey).decode('utf-8'))
|
||||
writesetting("rpmbkey", hexlify(rpmbkey).decode('utf-8'))
|
||||
else:
|
||||
self.info("SEJ Mode: No meid found. Are you in brom mode ?")
|
||||
return True
|
||||
|
|
|
@ -10,6 +10,7 @@ from struct import unpack, pack
|
|||
from binascii import hexlify
|
||||
from mtkclient.Library.utils import LogBase, logsetup
|
||||
from mtkclient.Library.error import ErrorHandler
|
||||
from mtkclient.Library.settings import writesetting
|
||||
|
||||
class META(metaclass=LogBase):
|
||||
class Mode(Enum):
|
||||
|
|
|
@ -13,7 +13,7 @@ from mtkclient.Library.error import ErrorHandler
|
|||
from mtkclient.Library.daconfig import DaStorage, EMMC_PartitionType
|
||||
from mtkclient.Library.partition import Partition
|
||||
from mtkclient.config.payloads import pathconfig
|
||||
from mtkclient.Library.settings import hwparam
|
||||
from mtkclient.Library.settings import writesetting
|
||||
from mtkclient.Library.legacy_ext import legacyext
|
||||
|
||||
class norinfo:
|
||||
|
@ -149,11 +149,10 @@ class emmcinfo:
|
|||
m_emmc_cid = None
|
||||
m_emmc_fwver = None
|
||||
|
||||
def __init__(self, hwparam: hwparam, data = None):
|
||||
def __init__(self, data = None):
|
||||
if data is None:
|
||||
return
|
||||
sh = structhelper(data)
|
||||
self.hwparam = hwparam
|
||||
self.m_emmc_ret = sh.dword(True)
|
||||
self.m_emmc_boot1_size = sh.qword(True)
|
||||
self.m_emmc_boot2_size = sh.qword(True)
|
||||
|
@ -175,8 +174,7 @@ class emmcinfo:
|
|||
res += f"m_emmc_ua_size = {hex(self.m_emmc_ua_size)}\n"
|
||||
cid = pack("<QQ", self.m_emmc_cid[0], self.m_emmc_cid[1])
|
||||
res += f"m_emmc_cid = {hexlify(cid).decode('utf-8')}\n"
|
||||
if self.hwparam is not None:
|
||||
self.hwparam.writesetting("cid", hexlify(cid).decode('utf-8'))
|
||||
writesetting("cid", hexlify(cid).decode('utf-8'))
|
||||
res += f"m_emmc_fwver = {hexlify(self.m_emmc_fwver).decode('utf-8')}\n"
|
||||
return res
|
||||
|
||||
|
@ -186,11 +184,10 @@ class sdcinfo:
|
|||
m_sdmmc_ua_size = None
|
||||
m_sdmmc_cid = None
|
||||
|
||||
def __init__(self, hwparam:hwparam, data = None):
|
||||
def __init__(self, data = None):
|
||||
if data is None:
|
||||
return
|
||||
sh = structhelper(data)
|
||||
self.hwparam = hwparam
|
||||
self.m_sdmmc_info = sh.dword(True)
|
||||
self.m_sdmmc_ua_size = sh.qword(True)
|
||||
self.m_sdmmc_cid = sh.qwords(2, True)
|
||||
|
@ -199,8 +196,7 @@ class sdcinfo:
|
|||
print(f"m_sdmmc_info = {hex(self.m_sdmmc_info)}")
|
||||
print(f"m_sdmmc_ua_size = {hex(self.m_sdmmc_ua_size)}")
|
||||
cid = pack("<QQ", self.m_sdmmc_cid[0], self.m_sdmmc_cid[1])
|
||||
if self.hwparam is not None:
|
||||
self.hwparam.writesetting("cid", hexlify(cid).decode('utf-8'))
|
||||
writesetting("cid", hexlify(cid).decode('utf-8'))
|
||||
print(f"m_sdmmc_cid = {hexlify(cid).decode('utf-8')}")
|
||||
|
||||
|
||||
|
@ -680,7 +676,6 @@ class DALegacy(metaclass=LogBase):
|
|||
self.pathconfig = pathconfig()
|
||||
self.patch = False
|
||||
self.generatekeys = self.mtk.config.generatekeys
|
||||
self.hwparam = hwparam(self.mtk.config.meid)
|
||||
if self.generatekeys:
|
||||
self.patch = True
|
||||
self.lft = legacyext(self.mtk, self, loglevel)
|
||||
|
@ -954,8 +949,8 @@ class DALegacy(metaclass=LogBase):
|
|||
m_nand_dev_code = unpack(">" + str(nandcount) + "H", nc)
|
||||
self.nand.m_nand_flash_dev_code = m_nand_dev_code
|
||||
self.nand.info2 = nandinfo2(self.usbread(9))
|
||||
self.emmc = emmcinfo(self.hwparam,self.usbread(0x5C))
|
||||
self.sdc = sdcinfo(self.hwparam,self.usbread(0x1C))
|
||||
self.emmc = emmcinfo(self.usbread(0x5C))
|
||||
self.sdc = sdcinfo(self.usbread(0x1C))
|
||||
self.flashconfig = configinfo(self.usbread(0x26))
|
||||
pi = passinfo(self.usbread(0xA))
|
||||
if pi.ack == 0x5A:
|
||||
|
|
|
@ -13,7 +13,7 @@ from mtkclient.Library.mtk_daxflash import DAXFlash
|
|||
from mtkclient.config.brom_config import damodes
|
||||
from mtkclient.Library.xflash_ext import xflashext
|
||||
from mtkclient.Library.legacy_ext import legacyext
|
||||
from mtkclient.Library.settings import hwparam
|
||||
|
||||
|
||||
class DAloader(metaclass=LogBase):
|
||||
def __init__(self, mtk, loglevel=logging.INFO):
|
||||
|
@ -31,7 +31,6 @@ class DAloader(metaclass=LogBase):
|
|||
self.rword = self.mtk.port.rword
|
||||
self.daconfig = DAconfig(mtk=self.mtk, loader=self.mtk.config.loader,
|
||||
preloader=self.mtk.config.preloader, loglevel=loglevel)
|
||||
self.hwparam = hwparam(mtk.config.meid)
|
||||
self.xft = None
|
||||
self.lft = None
|
||||
self.da = None
|
||||
|
@ -106,8 +105,8 @@ class DAloader(metaclass=LogBase):
|
|||
self.daconfig.flashsize = config["flashsize"]
|
||||
self.da.nor = norinfo()
|
||||
self.da.nand = nandinfo64()
|
||||
self.da.emmc = emmcinfo(self.hwparam)
|
||||
self.da.sdc = sdcinfo(self.hwparam)
|
||||
self.da.emmc = emmcinfo()
|
||||
self.da.sdc = sdcinfo()
|
||||
self.lft=legacyext(self.mtk, self.da, self.loglevel)
|
||||
self.da.emmc.m_emmc_ua_size = config["m_emmc_ua_size"]
|
||||
self.da.emmc.m_emmc_boot1_size = config["m_emmc_boot1_size"]
|
||||
|
|
|
@ -7,7 +7,7 @@ import os
|
|||
import hashlib
|
||||
from binascii import hexlify
|
||||
from struct import pack, unpack
|
||||
from mtkclient.Library.settings import hwparam
|
||||
from mtkclient.Library.settings import writesetting
|
||||
from mtkclient.Library.utils import LogBase, progress, logsetup
|
||||
from mtkclient.Library.error import ErrorHandler
|
||||
from mtkclient.Library.daconfig import EMMC_PartitionType, UFS_PartitionType, DaStorage
|
||||
|
@ -153,7 +153,6 @@ class DAXFlash(metaclass=LogBase):
|
|||
self.partition = Partition(self.mtk, self.readflash, self.read_pmt, loglevel)
|
||||
self.progress = progress(self.daconfig.pagesize)
|
||||
self.pathconfig = pathconfig()
|
||||
self.hwparam = hwparam(self.mtk.config.meid)
|
||||
self.patch = False
|
||||
self.generatekeys = self.mtk.config.generatekeys
|
||||
if self.generatekeys:
|
||||
|
@ -560,7 +559,7 @@ class DAXFlash(metaclass=LogBase):
|
|||
except:
|
||||
pass
|
||||
self.info(f"EMMC CID: {hexlify(emmc.cid).decode('utf-8')}")
|
||||
self.hwparam.writesetting("cid", hexlify(emmc.cid).decode('utf-8'))
|
||||
writesetting("cid", hexlify(emmc.cid).decode('utf-8'))
|
||||
self.info(f"EMMC Boot1 Size: {hex(emmc.boot1_size)}")
|
||||
self.info(f"EMMC Boot2 Size: {hex(emmc.boot2_size)}")
|
||||
self.info(f"EMMC GP1 Size: {hex(emmc.gp1_size)}")
|
||||
|
@ -664,7 +663,7 @@ class DAXFlash(metaclass=LogBase):
|
|||
except:
|
||||
pass
|
||||
self.info(f"UFS CID: {hexlify(ufs.cid).decode('utf-8')}")
|
||||
self.hwparam.writesetting("cid", hexlify(ufs.cid).decode('utf-8'))
|
||||
writesetting("cid", hexlify(ufs.cid).decode('utf-8'))
|
||||
self.info(f"UFS LU0 Size: {hex(ufs.lu0_size)}")
|
||||
self.info(f"UFS LU1 Size: {hex(ufs.lu1_size)}")
|
||||
self.info(f"UFS LU2 Size: {hex(ufs.lu2_size)}")
|
||||
|
@ -1107,7 +1106,7 @@ class DAXFlash(metaclass=LogBase):
|
|||
# if self.get_da_stor_life_check() == 0x0:
|
||||
cid = self.get_chip_id()
|
||||
self.info("DA-CODE : 0x%X", (cid.hw_code << 4) + (cid.hw_code >> 4))
|
||||
self.hwparam.writesetting("hwcode", hex(self.config.hwcode))
|
||||
writesetting("hwcode", hex(self.config.hwcode))
|
||||
|
||||
daextdata = self.xft.patch()
|
||||
if daextdata is not None:
|
||||
|
|
|
@ -9,7 +9,7 @@ from struct import unpack, pack
|
|||
from binascii import hexlify
|
||||
from mtkclient.Library.utils import LogBase, logsetup
|
||||
from mtkclient.Library.error import ErrorHandler
|
||||
from mtkclient.Library.settings import hwparam
|
||||
from mtkclient.Library.settings import writesetting
|
||||
|
||||
def calc_xflash_checksum(data):
|
||||
checksum = 0
|
||||
|
@ -124,7 +124,6 @@ class Preloader(metaclass=LogBase):
|
|||
self.usbwrite = self.mtk.port.usbwrite
|
||||
self.echo = self.mtk.port.echo
|
||||
self.sendcmd = self.mtk.port.mtk_cmd
|
||||
self.hwparam = None
|
||||
|
||||
def init(self, maxtries=None, display=True):
|
||||
if os.path.exists(".state"):
|
||||
|
@ -132,6 +131,17 @@ class Preloader(metaclass=LogBase):
|
|||
os.remove(".state")
|
||||
except:
|
||||
pass
|
||||
settings=os.path.join("logs","hwparam.json")
|
||||
if os.path.exists(settings):
|
||||
try:
|
||||
os.remove(settings)
|
||||
except:
|
||||
pass
|
||||
if os.path.exists("logs"):
|
||||
try:
|
||||
shutil.rmtree("logs")
|
||||
except:
|
||||
pass
|
||||
readsocid=self.config.readsocid
|
||||
skipwdt = self.config.skipwdt
|
||||
|
||||
|
@ -180,6 +190,7 @@ class Preloader(metaclass=LogBase):
|
|||
self.setreg_disablewatchdogtimer(self.config.hwcode) # D4
|
||||
if self.display:
|
||||
self.info("HW code:\t\t\t" + hex(self.config.hwcode))
|
||||
writesetting("hwcode",hex(self.config.hwcode))
|
||||
self.config.target_config = self.get_target_config(self.display)
|
||||
self.info("Get Target info")
|
||||
self.get_blver()
|
||||
|
@ -196,19 +207,16 @@ class Preloader(metaclass=LogBase):
|
|||
self.info("\tHW subcode:\t\t" + hex(self.config.hwsubcode))
|
||||
self.info("\tHW Ver:\t\t\t" + hex(self.config.hwver))
|
||||
self.info("\tSW Ver:\t\t\t" + hex(self.config.swver))
|
||||
self.config.meid = self.get_meid()
|
||||
if len(self.config.meid) >= 16:
|
||||
self.hwparam = hwparam(hexlify(self.config.meid).decode('utf-8'))
|
||||
self.hwparam.writesetting("meid",hexlify(self.config.meid).decode('utf-8'))
|
||||
self.hwparam.writesetting("hwcode",hex(self.config.hwcode))
|
||||
if self.config.meid != b"":
|
||||
meid = self.get_meid()
|
||||
if len(meid) >= 16:
|
||||
writesetting("meid", hexlify(meid).decode('utf-8'))
|
||||
if meid != b"":
|
||||
if self.display:
|
||||
self.info("ME_ID:\t\t\t" + hexlify(self.config.meid).decode('utf-8').upper())
|
||||
self.info("ME_ID:\t\t\t" + hexlify(meid).decode('utf-8').upper())
|
||||
if readsocid or self.config.chipconfig.socid_addr:
|
||||
socid = self.get_socid()
|
||||
if len(socid) >= 16:
|
||||
if self.hwparam is not None:
|
||||
self.hwparam.writesetting("socid", hexlify(socid).decode('utf-8'))
|
||||
writesetting("socid", hexlify(socid).decode('utf-8'))
|
||||
if self.display:
|
||||
if socid != b"":
|
||||
self.info("SOC_ID:\t\t\t" + hexlify(socid).decode('utf-8').upper())
|
||||
|
|
|
@ -1,37 +1,25 @@
|
|||
import json
|
||||
import os.path
|
||||
from binascii import hexlify
|
||||
|
||||
class hwparam:
|
||||
paramsetting = None
|
||||
hwcode = None
|
||||
logpath = "logs"
|
||||
paramfile = os.path.join(logpath, "hwparam.json")
|
||||
logpath = "logs"
|
||||
paramfile = os.path.join(logpath, "hwparam.json")
|
||||
|
||||
def __init__(self, meid:str):
|
||||
if isinstance(meid,bytearray) or isinstance(meid,bytes):
|
||||
meid=hexlify(meid).decode('utf-8')
|
||||
if meid is None:
|
||||
self.paramsetting = None
|
||||
if os.path.exists(self.paramfile):
|
||||
self.paramsetting = json.loads(open(self.paramfile, "r").read())
|
||||
if "meid" in self.paramsetting:
|
||||
if meid!=self.paramsetting["meid"]:
|
||||
self.paramsetting = {}
|
||||
def loadsetting(key):
|
||||
if os.path.exists(paramfile):
|
||||
paramsetting = json.loads(open(paramfile, "r").read())
|
||||
if key in paramsetting:
|
||||
return paramsetting[key]
|
||||
return None
|
||||
|
||||
def loadsetting(self,key:str):
|
||||
if self.paramsetting is not None:
|
||||
if key in self.paramsetting:
|
||||
return self.paramsetting[key]
|
||||
return None
|
||||
|
||||
def writesetting(self, key:str,value:str):
|
||||
if self.paramsetting is not None:
|
||||
self.paramsetting[key]=value
|
||||
self.write_json()
|
||||
|
||||
def write_json(self):
|
||||
if self.paramsetting is not None:
|
||||
if not os.path.exists(self.logpath):
|
||||
os.mkdir(self.logpath)
|
||||
open(self.paramfile, "w").write(json.dumps(self.paramsetting))
|
||||
def writesetting(key:str,value:str):
|
||||
try:
|
||||
paramsetting={}
|
||||
if not os.path.exists(logpath):
|
||||
os.mkdir(logpath)
|
||||
if os.path.exists(paramfile):
|
||||
paramsetting=json.loads(open(paramfile,"r").read())
|
||||
paramsetting[key]=value
|
||||
open(paramfile,"w").write(json.dumps(paramsetting))
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
|
|
|
@ -5,7 +5,7 @@ from mtkclient.config.payloads import pathconfig
|
|||
from mtkclient.Library.error import ErrorHandler
|
||||
from mtkclient.Library.hwcrypto import crypto_setup, hwcrypto
|
||||
from mtkclient.Library.utils import LogBase, progress, logsetup, find_binary
|
||||
from mtkclient.Library.settings import hwparam
|
||||
from mtkclient.Library.settings import writesetting, loadsetting
|
||||
from mtkclient.Library.seccfg import seccfg
|
||||
from binascii import hexlify
|
||||
import hashlib
|
||||
|
@ -61,7 +61,6 @@ class xflashext(metaclass=LogBase):
|
|||
self.send_devctrl = self.xflash.send_devctrl
|
||||
self.xread = self.xflash.xread
|
||||
self.status = self.xflash.status
|
||||
self.hwparam = hwparam(self.mtk.config.meid)
|
||||
self.da2 = None
|
||||
self.da2address = None
|
||||
|
||||
|
@ -498,8 +497,8 @@ class xflashext(metaclass=LogBase):
|
|||
def generate_keys(self):
|
||||
hwc = self.cryptosetup()
|
||||
meid = b""
|
||||
meidv = self.hwparam.loadsetting("meid")
|
||||
socidv = self.hwparam.loadsetting("socid")
|
||||
meidv = loadsetting("meid")
|
||||
socidv = loadsetting("socid")
|
||||
if meidv is not None:
|
||||
meid = bytes.fromhex(meidv)
|
||||
self.info("MEID : " + meidv)
|
||||
|
@ -507,7 +506,7 @@ class xflashext(metaclass=LogBase):
|
|||
try:
|
||||
if self.config.chipconfig.meid_addr is not None:
|
||||
meid = b"".join([pack("<I", val) for val in self.readmem(self.config.chipconfig.meid_addr, 4)])
|
||||
self.hwparam.writesetting("meid", hexlify(meid).decode('utf-8'))
|
||||
writesetting("meid", hexlify(meid).decode('utf-8'))
|
||||
self.info("MEID : " + hexlify(meid).decode('utf-8'))
|
||||
except Exception as err:
|
||||
pass
|
||||
|
@ -518,7 +517,7 @@ class xflashext(metaclass=LogBase):
|
|||
try:
|
||||
if self.config.chipconfig.socid_addr is not None:
|
||||
socid = b"".join([pack("<I", val) for val in self.readmem(self.config.chipconfig.socid_addr, 8)])
|
||||
self.hwparam.writesetting("socid", hexlify(socid).decode('utf-8'))
|
||||
writesetting("socid", hexlify(socid).decode('utf-8'))
|
||||
self.info("SOCID : " + hexlify(socid).decode('utf-8'))
|
||||
except Exception as err:
|
||||
pass
|
||||
|
@ -539,20 +538,20 @@ class xflashext(metaclass=LogBase):
|
|||
# self.info("Platkey : " + hexlify(platkey).decode('utf-8'))
|
||||
if rpmbkey is not None:
|
||||
self.info("RPMB : " + hexlify(rpmbkey).decode('utf-8'))
|
||||
self.hwparam.writesetting("rpmbkey", hexlify(rpmbkey).decode('utf-8'))
|
||||
writesetting("rpmbkey", hexlify(rpmbkey).decode('utf-8'))
|
||||
if rpmb2key is not None:
|
||||
self.info("RPMB2 : " + hexlify(rpmb2key).decode('utf-8'))
|
||||
self.hwparam.writesetting("rpmb2key", hexlify(rpmb2key).decode('utf-8'))
|
||||
writesetting("rpmb2key", hexlify(rpmb2key).decode('utf-8'))
|
||||
if fdekey is not None:
|
||||
self.info("FDE : " + hexlify(fdekey).decode('utf-8'))
|
||||
self.hwparam.writesetting("fdekey", hexlify(fdekey).decode('utf-8'))
|
||||
writesetting("fdekey", hexlify(fdekey).decode('utf-8'))
|
||||
if ikey is not None:
|
||||
self.info("iTrustee : " + hexlify(ikey).decode('utf-8'))
|
||||
self.hwparam.writesetting("kmkey", hexlify(ikey).decode('utf-8'))
|
||||
writesetting("kmkey", hexlify(ikey).decode('utf-8'))
|
||||
if self.config.chipconfig.prov_addr:
|
||||
provkey = self.custom_read(self.config.chipconfig.prov_addr, 16)
|
||||
self.info("PROV : " + hexlify(provkey).decode('utf-8'))
|
||||
self.hwparam.writesetting("provkey", hexlify(provkey).decode('utf-8'))
|
||||
writesetting("provkey", hexlify(provkey).decode('utf-8'))
|
||||
"""
|
||||
hrid = self.xflash.get_hrid()
|
||||
if hrid is not None:
|
||||
|
@ -568,7 +567,7 @@ class xflashext(metaclass=LogBase):
|
|||
self.setotp(hwc)
|
||||
rpmbkey = hwc.aes_hwcrypt(mode="rpmb", data=meid, btype="sej")
|
||||
self.info("RPMB : " + hexlify(rpmbkey).decode('utf-8'))
|
||||
self.hwparam.writesetting("rpmbkey", hexlify(rpmbkey).decode('utf-8'))
|
||||
writesetting("rpmbkey", hexlify(rpmbkey).decode('utf-8'))
|
||||
else:
|
||||
self.info("SEJ Mode: No meid found. Are you in brom mode ?")
|
||||
return True
|
||||
|
|
Loading…
Reference in a new issue