Minor bugfixes, beautify

This commit is contained in:
info@revskills.de 2024-05-12 11:54:51 +02:00
parent 491f930424
commit 8e46df657c
9 changed files with 39 additions and 6 deletions

2
.gitignore vendored
View file

@ -1,6 +1,8 @@
__pycache__ __pycache__
# Compiled python modules. # Compiled python modules.
*.pyc *.pyc
.idea
DA_*.bin
# Setuptools distribution folder. # Setuptools distribution folder.
/dist/ /dist/

View file

@ -653,9 +653,11 @@ class DA_handler(metaclass=LogBase):
partitionname = args.partitionname partitionname = args.partitionname
parttype = args.parttype parttype = args.parttype
filename = args.filename filename = args.filename
self.mtk.config.hwparam_path = os.path.dirname(filename)
self.da_read(partitionname=partitionname, parttype=parttype, filename=filename) self.da_read(partitionname=partitionname, parttype=parttype, filename=filename)
elif cmd == "rl": elif cmd == "rl":
directory = args.directory directory = args.directory
self.mtk.config.hwparam_path = directory
parttype = args.parttype parttype = args.parttype
if args.skip: if args.skip:
skip = args.skip.split(",") skip = args.skip.split(",")
@ -664,12 +666,14 @@ class DA_handler(metaclass=LogBase):
self.da_rl(directory=directory, parttype=parttype, skip=skip) self.da_rl(directory=directory, parttype=parttype, skip=skip)
elif cmd == "rf": elif cmd == "rf":
filename = args.filename filename = args.filename
self.mtk.config.hwparam_path = os.path.dirname(filename)
parttype = args.parttype parttype = args.parttype
self.da_rf(filename=filename, parttype=parttype) self.da_rf(filename=filename, parttype=parttype)
elif cmd == "rs": elif cmd == "rs":
start = getint(args.startsector) start = getint(args.startsector)
sectors = getint(args.sectors) sectors = getint(args.sectors)
filename = args.filename filename = args.filename
self.mtk.config.hwparam_path = os.path.dirname(filename)
parttype = args.parttype parttype = args.parttype
if self.da_rs(start=start, sectors=sectors, filename=filename, parttype=parttype): if self.da_rs(start=start, sectors=sectors, filename=filename, parttype=parttype):
print(f"Dumped sector {str(start)} with sector count {str(sectors)} as {filename}.") print(f"Dumped sector {str(start)} with sector count {str(sectors)} as {filename}.")
@ -679,6 +683,7 @@ class DA_handler(metaclass=LogBase):
start = getint(args.offset) start = getint(args.offset)
length = getint(args.length) length = getint(args.length)
filename = args.filename filename = args.filename
self.mtk.config.hwparam_path = os.path.dirname(filename)
parttype = args.parttype parttype = args.parttype
if self.da_ro(start=start, length=length, filename=filename, parttype=parttype): if self.da_ro(start=start, length=length, filename=filename, parttype=parttype):
print(f"Dumped offset {hex(start)} with length {hex(length)} as {filename}.") print(f"Dumped offset {hex(start)} with length {hex(length)} as {filename}.")
@ -804,6 +809,7 @@ class DA_handler(metaclass=LogBase):
data = args.data data = args.data
self.da_poke(addr=addr, data=data, filename=filename) self.da_poke(addr=addr, data=data, filename=filename)
elif subcmd == "generatekeys": elif subcmd == "generatekeys":
self.mtk.config.hwparam_path = "."
mtk.daloader.keys() mtk.daloader.keys()
elif subcmd == "dumpbrom": elif subcmd == "dumpbrom":
filename = f"brom_{hex(mtk.daloader.config.hwcode)[2:]}.bin" filename = f"brom_{hex(mtk.daloader.config.hwcode)[2:]}.bin"

View file

@ -210,7 +210,7 @@ class DAloader(metaclass=LogBase):
self.flashmode = damodes.XFLASH self.flashmode = damodes.XFLASH
if self.mtk.config.chipconfig.damode == damodes.XFLASH: if self.mtk.config.chipconfig.damode == damodes.XFLASH:
self.flashmode = damodes.XFLASH self.flashmode = damodes.XFLASH
elif self.mtk.config.chipconfig.damode == damodes.XML: elif self.mtk.config.chipconfig.damode == damodes.XML or self.daconfig.da_loader.v6:
self.flashmode = damodes.XML self.flashmode = damodes.XML
if self.flashmode == damodes.XFLASH: if self.flashmode == damodes.XFLASH:
self.da = DAXFlash(self.mtk, self.daconfig, self.loglevel) self.da = DAXFlash(self.mtk, self.daconfig, self.loglevel)

View file

@ -35,6 +35,20 @@ class XMLCmd(metaclass=LogBase):
cmd = self.create_cmd("NOTIFY-INIT-HW") cmd = self.create_cmd("NOTIFY-INIT-HW")
return cmd return cmd
def cmd_security_set_flash_policy(self,host_offset: int = 0x8000000,
length: int = 0x100000):
"""
<?xml version="1.0" encoding="utf-8"?><da><version>1.0</version><command>CMD:SECURITY-SET-FLASH-POLICY</command><arg>
<source_file>MEM://0x8000000:0x100000</source_file></arg></da>
"""
content = {
"arg": [
f"<source_file>MEM://{hex(host_offset)}:{hex(length)}</source_file>"
]
}
cmd = self.create_cmd("SECURITY-SET-FLASH-POLICY", content)
return cmd
def cmd_boot_to(self, at_addr: int = 0x40000000, jmp_addr: int = 0x40000000, host_offset: int = 0x7fe83c09a04c, def cmd_boot_to(self, at_addr: int = 0x40000000, jmp_addr: int = 0x40000000, host_offset: int = 0x7fe83c09a04c,
length: int = 0x50c78): length: int = 0x50c78):
""" """

View file

@ -442,7 +442,7 @@ class DAXML(metaclass=LogBase):
if cmd == "CMD:START": if cmd == "CMD:START":
return True return True
else: else:
cmd, result = self.get_command_result() cmd, startresult = self.get_command_result()
self.error(result) self.error(result)
return False return False
else: else:

View file

@ -143,8 +143,10 @@ def disasm(code, cpu, mode, bigendian, size):
print("CPU and/or mode not supported!") print("CPU and/or mode not supported!")
exit(0) exit(0)
instr = [f"{i.mnemonic}\t{i.op_str}" for i in cs.disasm(code, size)] instr = []
# print("0x%x:\t%s\t%s" % (i.address, i.mnemonic, i.op_str)) for i in cs.disasm(code, size):
# print("0x%x:\t%s\t%s" % (i.address, i.mnemonic, i.op_str))
instr.append("%s\t%s" % (i.mnemonic, i.op_str))
return instr return instr

View file

@ -1336,6 +1336,9 @@ class Preloader(metaclass=LogBase):
time.sleep(0.035) time.sleep(0.035)
try: try:
res = self.rword(2) res = self.rword(2)
if isinstance(res, list) and res == []:
self.error("No reply from da loader.")
return False
if isinstance(res, list): if isinstance(res, list):
checksum, status = res checksum, status = res
if gen_chksum != checksum and checksum != 0: if gen_chksum != checksum and checksum != 0:

View file

@ -3,10 +3,15 @@
import os import os
import sys import sys
from struct import unpack from struct import unpack
import inspect
current_dir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
parent_dir = os.path.dirname(os.path.dirname(current_dir))
sys.path.insert(0, parent_dir)
from mtkclient.config.payloads import pathconfig from mtkclient.config.payloads import pathconfig
from mtkclient.Library.utils import read_object from mtkclient.Library.utils import read_object
from mtkclient.Library.utils import find_binary from mtkclient.Library.utils import find_binary
entry_region = [ entry_region = [
('m_buf', 'I'), ('m_buf', 'I'),
('m_len', 'I'), ('m_len', 'I'),

View file

@ -8,6 +8,7 @@ pyside6 >= 6.4.0.1
mock >= 4.0.3 mock >= 4.0.3
pyserial >= 3.5 pyserial >= 3.5
flake8 flake8
fusepy keystone-engine
unicorn
capstone capstone
unicorn
fusepy