Skip to content

Commit

Permalink
Restructure and fix incorrect MTK_DA_V6
Browse files Browse the repository at this point in the history
  • Loading branch information
bkerler committed Jun 12, 2024
1 parent bb28c35 commit d394dbd
Show file tree
Hide file tree
Showing 21 changed files with 62 additions and 40 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion mtk.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@echo off
title MTKClient
python "%~dp0mtk" %*
python "%~dp0mtk.py" %*
2 changes: 1 addition & 1 deletion mtk → mtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import argparse
from mtkclient.Library.mtk_main import Main, metamodes

info = "MTK Flash/Exploit Client Public V2.0.0 (c) B.Kerler 2018-2024"
info = "MTK Flash/Exploit Client Public V2.0.1 (c) B.Kerler 2018-2024"

cmds = {
"printgpt": "Print GPT Table information",
Expand Down
2 changes: 1 addition & 1 deletion mtk_console.spec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ today = date.today()
block_cipher = None


a = Analysis(['mtk'],
a = Analysis(['mtk.py'],
pathex=[],
binaries=[],
datas=[('mtkclient/Windows/*', '.'), ('mtkclient/payloads', 'mtkclient/payloads'), ('mtkclient/Loader', 'mtkclient/Loader'), ('mtkclient/Library/Filesystem/bin', 'mtkclient/Library/Filesystem/bin')],
Expand Down
2 changes: 1 addition & 1 deletion mtk_gui.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@echo off
title MTKClient Log
python "%~dp0mtk_gui"
python "%~dp0mtk_gui.py"
File renamed without changes.
2 changes: 1 addition & 1 deletion mtk_standalone.spec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ today = date.today()
block_cipher = None


a = Analysis(['mtk_gui'],
a = Analysis(['mtk_gui.py'],
pathex=[],
binaries=[],
datas=[('mtkclient/gui/images', 'mtkclient/gui/images'), ('mtkclient/Windows/*', '.'), ('mtkclient/payloads', 'mtkclient/payloads'), ('mtkclient/Loader', 'mtkclient/Loader'), ('mtkclient/Library/Filesystem/bin', 'mtkclient/Library/Filesystem/bin')],
Expand Down
10 changes: 5 additions & 5 deletions mtkclient/Library/DA/mtk_da_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def configure_da(self, mtk, preloader):
else:
if mtk.serialportname is not None:
mtk.preloader.init()
if mtk.port.cdc.connected and os.path.exists(".state"):
if mtk.port.cdc.connected and os.path.exists(os.path.join(mtk.hwparamFolder,".state")):
mtk.daloader.reinit()
return mtk
if mtk.config.target_config is None:
Expand Down Expand Up @@ -757,10 +757,10 @@ def handle_da_cmds(self, mtk, cmd: str, args):
self.close()
self.da_ess(sector=sector, parttype=parttype, sectors=sectors)
elif cmd == "reset":
if os.path.exists(".state"):
os.remove(".state")
if os.path.exists(os.path.join("logs", "hwparam.json")):
os.remove(os.path.join("logs", "hwparam.json"))
if os.path.exists(os.path.join(self.mtk.config.hwparam_path, ".state")):
os.remove(os.path.join(self.mtk.config.hwparam_path, ".state"))
if os.path.exists(os.path.join(self.mtk.config.hwparam_path, "hwparam.json")):
os.remove(os.path.join(self.mtk.config.hwparam_path, "hwparam.json"))
mtk.daloader.shutdown(bootmode=0)
print("Reset command was sent. Disconnect usb cable to power off.")
elif cmd == "da":
Expand Down
8 changes: 4 additions & 4 deletions mtkclient/Library/DA/mtk_daloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def writestate(self):
if not self.mtk.config.iot:
config["m_sdmmc_ua_size"] = self.da.sdc.m_sdmmc_ua_size

open(".state", "w").write(json.dumps(config))
open(os.path.join(self.mtk.config.hwparam_path, ".state"), "w").write(json.dumps(config))

def compute_hash_pos(self, da1, da2, da1sig_len, da2sig_len, v6):
hashlen = len(da2) - da2sig_len
Expand Down Expand Up @@ -135,8 +135,8 @@ def fix_hash(da1, da2, hashpos, hashmode, hashlen):
return da1

def reinit(self):
if os.path.exists(".state"):
config = json.loads(open(".state", "r").read())
if os.path.exists(os.path.join(self.mtk.config.hwparam_path, ".state")):
config = json.loads(open(os.path.join(self.mtk.config.hwparam_path, ".state"), "r").read())
self.config.hwcode = config["hwcode"]
if "meid" in config:
self.config.meid = bytes.fromhex(config["meid"])
Expand All @@ -153,7 +153,7 @@ def reinit(self):
self.flashmode = damodes.XML
self.config.init_hwcode(self.config.hwcode)
if self.config.meid is not None:
self.config.hwparam = hwparam(self.config.meid.hex(), self.mtk.config.hwparam_path)
self.config.hwparam = hwparam(self.mtk.config, self.config.meid.hex(), self.mtk.config.hwparam_path)
if self.flashmode == damodes.XML:
self.da = DAXML(self.mtk, self.daconfig, self.loglevel)
self.daconfig.flashtype = config["flashtype"]
Expand Down
2 changes: 1 addition & 1 deletion mtkclient/Library/DA/xflash/xflash_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1188,7 +1188,7 @@ def upload_da(self):
if status == 0x0 and unpack("<I", ret)[0] == 0xA1A2A3A4:
self.info("DA Extensions successfully added")
self.daext = True
self.config.hwparam = hwparam(self.mtk.config.meid, self.mtk.config.hwparam_path)
self.config.hwparam = hwparam(self.mtk.config, self.mtk.config.meid, self.mtk.config.hwparam_path)
self.config.hwparam.writesetting("hwcode", hex(self.config.hwcode))
if not self.daext:
self.warning("DA Extensions failed to enable")
Expand Down
Empty file.
7 changes: 4 additions & 3 deletions mtkclient/Library/mtk_preloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from Cryptodome.Util.number import bytes_to_long, long_to_bytes, ceil_div, size
from Cryptodome.PublicKey import RSA

import mtkclient.Library.settings
from mtkclient.Library.utils import LogBase, logsetup
from mtkclient.Library.error import ErrorHandler
from mtkclient.config.brom_config import damodes
Expand Down Expand Up @@ -162,10 +163,10 @@ def __init__(self, mtk, loglevel=logging.INFO):
self.sendcmd = self.mtk.port.mtk_cmd

def init(self, maxtries=None, display=True):
if os.path.exists(".state"):
if os.path.exists(os.path.join(self.mtk.config.hwparam_path, ".state")):
try:
os.remove(".state")
os.remove(os.path.join("logs", "hwparam.json"))
os.remove(os.path.join(self.mtk.config.hwparam_path, ".state"))
os.remove(os.path.join(self.mtk.config.hwparam_path, "hwparam.json"))
except OSError:
pass
readsocid = self.config.readsocid
Expand Down
15 changes: 8 additions & 7 deletions mtkclient/Library/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@ class hwparam:
hwcode = None
appid = b""

def __init__(self, meid: str, path: str = "logs"):
def __init__(self, config, meid: str, path: str = "logs"):
self.config = config
self.paramfile = "hwparam.json"
self.hwparampath = path
self.config.hwparam_path = path
self.appid = b""
if isinstance(meid, bytearray) or isinstance(meid, bytes):
meid = hexlify(meid).decode('utf-8')
if meid is None:
self.paramsetting = {}
if meid is not None:
self.paramsetting["meid"] = meid
if not os.path.exists(self.hwparampath):
os.mkdir(self.hwparampath)
if not os.path.exists(self.config.hwparam_path):
os.mkdir(self.config.hwparam_path)
open(os.path.join(path, self.paramfile), "w").write(json.dumps(self.paramsetting))
else:
self.paramsetting = {}
Expand All @@ -43,6 +44,6 @@ def writesetting(self, key: str, value: str):

def write_json(self):
if self.paramsetting is not None:
if not os.path.exists(self.hwparampath):
os.mkdir(self.hwparampath)
open(os.path.join(self.hwparampath, self.paramfile), "w").write(json.dumps(self.paramsetting))
if not os.path.exists(self.config.hwparam_path):
os.mkdir(self.config.hwparam_path)
open(os.path.join(self.config.hwparam_path, self.paramfile), "w").write(json.dumps(self.paramsetting))
Binary file modified mtkclient/Loader/MTK_DA_V6.bin
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions mtkclient/config/mtk_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ def __init__(self, loglevel=logging.INFO, gui=None, guiprogress=None, update_sta
self.chipconfig = chipconfig()
self.gpt_settings = None
self.hwparam = None
self.hwparam_path = "logs"
self.hwparam_path = "."
self.sram = None
self.dram = None
self.otp = None
if loglevel == logging.DEBUG:
logfilename = os.path.join("logs", "log.txt")
logfilename = os.path.join(self.hwparam_path, "log.txt")
fh = logging.FileHandler(logfilename)
self.__logger.addHandler(fh)
self.__logger.setLevel(logging.DEBUG)
Expand Down Expand Up @@ -113,7 +113,7 @@ def set_hwcode(self, hwcode):
self.hwparam.writesetting("hwcode", hex(hwcode))

def set_meid(self, meid):
self.hwparam = hwparam(meid, self.hwparam_path)
self.hwparam = hwparam(self, meid, self.hwparam_path)
self.meid = meid
self.hwparam.writesetting("meid", hexlify(meid).decode('utf-8'))

Expand Down
26 changes: 22 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[build-system]
requires = [
"setuptools>=42",
"setuptools>=61",
"wheel",
]
build-backend = "setuptools.build_meta"
Expand All @@ -13,7 +13,7 @@ maintainers = [
]
readme = "README.md"
license = {file = "LICENSE"}
version = "2.0.0"
version = "2.0.1"
requires-python = ">= 3.8"
dependencies = [
"pyusb",
Expand All @@ -40,12 +40,30 @@ Issues = "https://github.com/bkerler/mtkclient/issues"

[project.scripts]
mtk = "mtk:main"
stage2 = "stage2:main"
stage2 = "mtkclient.Tools.stage2:main"
da_parser = "mtkclient.Tools.da_parser:main"
brom_to_offs = "mtkclient.Tools.brom_to_offs:main"

[project.gui-scripts]
mtk_gui = "mtk_gui:main"
mtk_gui = "mtkclient.mtk_gui:main"

[tool.setuptools]
# See also the MANIFEST.in file.
packages = [
"mtkclient.config",
"mtkclient.Library",
"mtkclient.Library.Connection",
"mtkclient.Library.DA",
"mtkclient.Library.DA.legacy",
"mtkclient.Library.DA.legacy.extension",
"mtkclient.Library.DA.xflash",
"mtkclient.Library.DA.xflash.extension",
"mtkclient.Library.DA.xml",
"mtkclient.Library.DA.xml.extension",
"mtkclient.Library.Exploit",
"mtkclient.Library.Filesystem",
"mtkclient.Library.Hardware",
"mtkclient.Tools",
]
# We want to install all the files in the package directories...
include-package-data = true
18 changes: 10 additions & 8 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
wheel >= 0.37.1
pyusb >= 1.2.1
pycryptodome >= 3.15.0
wheel
setuptools
pyusb
pycryptodome
pycryptodomex
colorama >= 0.4.4
shiboken6 >= 6.4.0.1
pyside6 >= 6.4.0.1
mock >= 4.0.3
pyserial >= 3.5
colorama
shiboken6
pyside6
mock
pyserial
flake8
keystone-engine
capstone
unicorn
fusepy

Binary file removed vbmeta.img.empty
Binary file not shown.

0 comments on commit d394dbd

Please sign in to comment.