Merge pull request #224 from luk1337/patch-3

Unbreak 900E memorydump
This commit is contained in:
Bjoern Kerler 2022-01-27 22:07:03 +01:00 committed by GitHub
commit 0ea910eb73
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 40 deletions

34
edl
View file

@ -295,8 +295,8 @@ class main(metaclass=LogBase):
if mode == "sahara": if mode == "sahara":
cmd = conninfo["cmd"] cmd = conninfo["cmd"]
data = conninfo["data"] data = conninfo["data"]
if cmd == cmd_t.SAHARA_END_TRANSFER: if cmd == cmd_t.SAHARA_HELLO_REQ:
if data.status == sahara_mode_t.SAHARA_MODE_MEMORY_DEBUG: if data.mode == sahara_mode_t.SAHARA_MODE_MEMORY_DEBUG:
if args["memorydump"]: if args["memorydump"]:
time.sleep(0.5) time.sleep(0.5)
print("Device is in memory dump mode, dumping memory") print("Device is in memory dump mode, dumping memory")
@ -325,24 +325,18 @@ class main(metaclass=LogBase):
print("Error, couldn't find suitable enprg/nprg loader :(") print("Error, couldn't find suitable enprg/nprg loader :(")
self.exit() self.exit()
else: else:
self.error("Device is in an unknown sahara state, rebooting...") sahara_info = self.sahara.cmd_info()
self.sahara.cmd_reset() if sahara_info is not None:
data = self.cdc.read(timeout=None) resp = self.sahara.connect()
self.debug(hexlify(data).decode('utf-8')) mode = resp["mode"]
self.exit() if "data" in resp:
elif cmd == cmd_t.SAHARA_HELLO_REQ: data = resp["data"]
sahara_info = self.sahara.cmd_info() if mode == "sahara":
if sahara_info is not None: mode = self.sahara.upload_loader()
resp = self.sahara.connect() else:
mode = resp["mode"] print("Error on sahara handshake, resetting.")
if "data" in resp: self.sahara.cmd_reset()
data = resp["data"] sys.exit(1)
if mode == "sahara":
mode = self.sahara.upload_loader()
else:
print("Error on sahara handshake, resetting.")
self.sahara.cmd_reset()
sys.exit(1)
if mode == "error": if mode == "error":
print("Connection detected, quiting.") print("Connection detected, quiting.")
sys.exit(1) sys.exit(1)

View file

@ -431,34 +431,34 @@ class sahara(metaclass=LogBase):
if os.path.exists("memory"): if os.path.exists("memory"):
rmrf("memory") rmrf("memory")
os.mkdir("memory") os.mkdir("memory")
cmd, pkt = self.get_rsp() res = self.get_rsp()
if cmd["cmd"] == cmd_t.SAHARA_MEMORY_DEBUG or cmd["cmd"] == cmd_t.SAHARA_64BIT_MEMORY_DEBUG: if res["cmd"] == cmd_t.SAHARA_MEMORY_DEBUG or res["cmd"] == cmd_t.SAHARA_64BIT_MEMORY_DEBUG:
memory_table_addr = pkt["memory_table_addr"] memory_table_addr = res["data"].memory_table_addr
memory_table_length = pkt["memory_table_length"] memory_table_length = res["data"].memory_table_length
if self.bit64: if self.bit64:
pktsize = 8 + 8 + 8 + 20 + 20 pktsize = 8 + 8 + 8 + 20 + 20
if memory_table_length % pktsize == 0: if memory_table_length % pktsize == 0:
if memory_table_length != 0: if memory_table_length != 0:
print( print(
f"Reading 64-Bit partition from {hex(memory_table_addr)} with length of " + f"Reading 64-Bit partition from {hex(memory_table_addr)} with length of " +
"{hex(memory_table_length)}") f"{hex(memory_table_length)}")
ptbldata = self.read_memory(memory_table_addr, memory_table_length) ptbldata = self.read_memory(memory_table_addr, memory_table_length)
num_entries = len(ptbldata) // pktsize num_entries = len(ptbldata) // pktsize
partitions = [] partitions = []
for id_entry in range(0, num_entries): for id_entry in range(0, num_entries):
pd = self.ch.parttbl_64bit(ptbldata[id_entry * pktsize:(id_entry * pktsize) + pktsize]) pd = self.ch.parttbl_64bit(ptbldata[id_entry * pktsize:(id_entry * pktsize) + pktsize])
desc = pd["desc"].replace(b"\x00", b"").decode('utf-8') desc = pd.desc.replace(b"\x00", b"").decode('utf-8')
filename = pd["filename"].replace(b"\x00", b"").decode('utf-8') filename = pd.filename.replace(b"\x00", b"").decode('utf-8')
if dump_partitions and filename not in dump_partitions: if dump_partitions and filename not in dump_partitions:
continue continue
mem_base = pd["mem_base"] mem_base = pd.mem_base
save_pref = pd["save_pref"] save_pref = pd.save_pref
length = pd["length"] length = pd.length
partitions.append(dict(desc=desc, filename=filename, mem_base=mem_base, length=length, partitions.append(dict(desc=desc, filename=filename, mem_base=mem_base, length=length,
save_pref=save_pref)) save_pref=save_pref))
print( print(
f"{filename}({desc}): Offset {hex(mem_base)}, Length {hex(length)}, " + f"{filename}({desc}): Offset {hex(mem_base)}, Length {hex(length)}, " +
"SavePref {hex(save_pref)}") f"SavePref {hex(save_pref)}")
self.dump_partitions(partitions) self.dump_partitions(partitions)
return True return True
@ -475,13 +475,13 @@ class sahara(metaclass=LogBase):
partitions = [] partitions = []
for id_entry in range(0, num_entries): for id_entry in range(0, num_entries):
pd = self.parttbl(ptbldata[id_entry * pktsize:(id_entry * pktsize) + pktsize]) pd = self.parttbl(ptbldata[id_entry * pktsize:(id_entry * pktsize) + pktsize])
desc = pd["desc"].replace(b"\x00", b"").decode('utf-8') desc = pd.desc.replace(b"\x00", b"").decode('utf-8')
filename = pd["filename"].replace(b"\x00", b"").decode('utf-8') filename = pd.filename.replace(b"\x00", b"").decode('utf-8')
if dump_partitions and filename not in dump_partitions: if dump_partitions and filename not in dump_partitions:
continue continue
mem_base = pd["mem_base"] mem_base = pd.mem_base
save_pref = pd["save_pref"] save_pref = pd.save_pref
length = pd["length"] length = pd.length
partitions.append(dict(desc=desc, filename=filename, mem_base=mem_base, length=length, partitions.append(dict(desc=desc, filename=filename, mem_base=mem_base, length=length,
save_pref=save_pref)) save_pref=save_pref))
print(f"{filename}({desc}): Offset {hex(mem_base)}, " + print(f"{filename}({desc}): Offset {hex(mem_base)}, " +
@ -489,8 +489,8 @@ class sahara(metaclass=LogBase):
self.dump_partitions(partitions) self.dump_partitions(partitions)
return True return True
elif "status" in pkt: elif res["data"].status:
self.error(self.get_error_desc(pkt["status"])) self.error(self.get_error_desc(res["data"].status))
return False return False
return False return False

View file

@ -303,7 +303,7 @@ class CommandHandler:
class req: class req:
save_pref = st.dword() save_pref = st.dword()
msm_base = st.dword() mem_base = st.dword()
length = st.dword() length = st.dword()
desc = st.string(20) desc = st.string(20)
filename = st.string(20) filename = st.string(20)
@ -317,7 +317,7 @@ class CommandHandler:
class req: class req:
save_pref = st.qword() save_pref = st.qword()
msm_base = st.qword() mem_base = st.qword()
length = st.qword() length = st.qword()
desc = st.string(20) desc = st.string(20)
filename = st.string(20) filename = st.string(20)