Fix issues bad lock state

This commit is contained in:
Bjoern Kerler 2023-07-12 11:41:03 +02:00
parent 81694c4aae
commit 47232848e8
3 changed files with 14 additions and 16 deletions

View file

@ -188,9 +188,9 @@ class legacyext(metaclass=LogBase):
return False, "Unknown lockstate or no lockstate"
if not sc_org.parse(seccfg_data):
return False, "Device has is either already unlocked or algo is unknown. Aborting."
writedata = sc_org.create(lockflag=lockflag)
if writedata is None:
return False, "Error on creating seccfg, bad lock state"
ret, writedata = sc_org.create(lockflag=lockflag)
if ret is False:
return False, writedata
if self.legacy.writeflash(addr=partition.sector * self.mtk.daloader.daconfig.pagesize,
length=len(writedata),
filename=None, wdata=writedata, parttype="user", display=True):

View file

@ -80,11 +80,9 @@ class seccfgV4(metaclass=LogBase):
def create(self, lockflag: str = "unlock"):
if lockflag == "lock" and self.lock_state == 1:
self.error("Device is already locked")
return None
return False, "Device is already locked"
elif lockflag == "unlock" and self.lock_state == 3:
self.error("Device is already unlocked")
return None
return False, "Device is already unlocked"
if lockflag == "unlock":
self.lock_state = 3
self.critical_lock_state = 1
@ -104,7 +102,7 @@ class seccfgV4(metaclass=LogBase):
data = seccfg_data + enc_hash
while len(data) % 0x200 != 0:
data += b"\x00"
return bytearray(data)
return True, bytearray(data)
class SECCFG_STATUS:
@ -244,13 +242,13 @@ class seccfgV3(metaclass=LogBase):
seccfg_attr_new = SECCFG_ATTR.ATTR_DEFAULT
if lockflag == "lock" and self.seccfg_attr != SECCFG_ATTR.ATTR_UNLOCK:
return False, ("Can't find lock state, current (%#x)" % self.seccfg_attr)
return False, "Can't find lock state, current (%#x)" % self.seccfg_attr
elif lockflag == "unlock" and self.seccfg_attr != SECCFG_ATTR.ATTR_DEFAULT \
and self.seccfg_attr != SECCFG_ATTR.ATTR_MP_DEFAULT \
and self.seccfg_attr != SECCFG_ATTR.ATTR_CUSTOM \
and self.seccfg_attr != SECCFG_ATTR.ATTR_VERIFIED \
and self.seccfg_attr != SECCFG_ATTR.ATTR_LOCK:
return False, ("Can't find unlock state, current (%#x)" % self.seccfg_attr)
return False, "Can't find unlock state, current (%#x)" % self.seccfg_attr
data = bytearray()
wf = BytesIO(data)
@ -280,14 +278,14 @@ class seccfgV3(metaclass=LogBase):
elif self.hwtype == "V3":
data = self.hwc.sej.sej_sec_cfg_hw_V3(data, True)
else:
return None
return False, "Unknown error"
wf.write(data)
wf.write(int.to_bytes(self.endflag, 4, 'little'))
data = bytearray(wf.getbuffer())
while len(data) % 0x200 != 0:
data += b"\x00"
return bytearray(data)
return True, bytearray(data)
if __name__ == "__main__":
with open("seccfg.bin","rb") as rf:
@ -300,5 +298,5 @@ if __name__ == "__main__":
sej_base = None
v3=seccfgV3(hwc,mtk)
v3.parse(data)
newdata=v3.create("lock")
ret, newdata=v3.create("lock")
print(newdata.hex())

View file

@ -531,9 +531,9 @@ class xflashext(metaclass=LogBase):
return False, "Unknown lockstate or no lockstate"
if not sc_org.parse(seccfg_data):
return False, "Device has is either already unlocked or algo is unknown. Aborting."
writedata = sc_org.create(lockflag=lockflag)
if writedata is None:
return False, "Error on creating seccfg, bad lock state"
ret, writedata = sc_org.create(lockflag=lockflag)
if ret is False:
return False, writedata
if self.xflash.writeflash(addr=partition.sector * self.mtk.daloader.daconfig.pagesize,
length=len(writedata),
filename=None, wdata=writedata, parttype="user", display=True):