Compare commits

...

11 commits

Author SHA1 Message Date
Bjoern Kerler
8d36ea4ef8
Fix stock parameter issue
Some checks failed
Python application / Test (push) Has been cancelled
2024-09-19 19:06:12 +02:00
Bjoern Kerler
4a827df91e
Merge pull request #1215 from shmu1i/main
New argument 'multi'
2024-09-19 18:59:46 +02:00
shmu1i
c33522ba5d
Update README.md 2024-09-19 12:33:12 -04:00
shmu1i
236db70e9f
Update mtk.py 2024-09-19 12:32:34 -04:00
shmu1i
798696990a
Update mtk_main.py 2024-09-19 12:31:14 -04:00
shmu1i
4e95d315c5
Merge branch 'bkerler:main' into main 2024-09-19 12:27:47 -04:00
Bjoern Kerler
2a8131d881
Fix sla issue 2024-09-19 18:04:49 +02:00
shmu1i
2e70acc705
Update README.md 2024-09-19 11:37:21 -04:00
shmu1i
485e1e911d
Update README.md 2024-09-19 11:35:33 -04:00
shmu1i
2fc9aa36c3
Update mtk_main.py
Add argument 'multi' to run multiple commands without a script
2024-09-19 09:29:43 -04:00
shmu1i
30cd8da27b
Update mtk.py
Add argument 'multi' to run multiple commands without a script
2024-09-19 09:28:35 -04:00
5 changed files with 38 additions and 6 deletions

View file

@ -204,6 +204,10 @@ python mtk.py --stock
```bash
python mtk.py script run.example
```
or
```
python mtk.py multi "cmd1;cmd2"
```
See the file "[run.example](https://github.com/bkerler/mtkclient/blob/main/run.example)" on how to structure the script file
### Root the phone (Tested with android 9 - 12)

7
mtk.py
View file

@ -37,7 +37,8 @@ cmds = {
"stage": "Run stage2 payload via boot rom mode (kamakiri)",
"plstage": "Run stage2 payload via preloader mode (send_da)",
"da": "Run da xflash/legacy special commands",
"script": "Run multiple commands using text script"
"script": "Run multiple commands using text script",
"multi": 'Run multiple commands using a semicolon-separated list (enclose list in quotes)'
}
@ -52,6 +53,10 @@ def main():
'gettargetconfig, peek, stage, plstage, da, script\n')
parser_script = subparsers.add_parser("script", help="Run text script")
parser_multi = subparsers.add_parser("multi", help='Run multiple commands using a semicolon-separatedlist (enclose list in quotes)')
parser_multi.add_argument('commands', help='semicolon-separated list of commands to run')
parser_printgpt = subparsers.add_parser("printgpt", help="Print GPT Table information")
parser_gpt = subparsers.add_parser("gpt", help="Save gpt table to given directory")
parser_r = subparsers.add_parser("r", help="Read flash to filename")

View file

@ -8,6 +8,8 @@ import sys
from binascii import hexlify
from struct import pack, unpack
from Cryptodome.Util.number import long_to_bytes
from mtkclient.Library.Auth.sla import generate_da_sla_signature
from mtkclient.Library.DA.xflash.xflash_flash_param import NandExtension
from mtkclient.Library.DA.xflash.xflash_param import Cmd, ChecksumAlgorithm, FtSystemOSE, DataType
@ -1142,7 +1144,7 @@ class DAXFlash(metaclass=LogBase):
rsakey = None
from mtkclient.Library.Auth.sla_keys import da_sla_keys
for key in da_sla_keys:
if da2.find(bytes.fromhex(key.n)) != -1:
if da2.find(long_to_bytes(key.n)) != -1:
rsakey = key
break
if rsakey is None:

View file

@ -7,6 +7,7 @@ from struct import pack, unpack
from queue import Queue
from threading import Thread
from Cryptodome.Util.number import long_to_bytes
from Cryptodome.Cipher import PKCS1_OAEP
from Cryptodome.Hash import SHA256
from Cryptodome.PublicKey import RSA
@ -624,7 +625,7 @@ class DAXML(metaclass=LogBase):
from mtkclient.Library.Auth.sla_keys import da_sla_keys, SlaKey
for key in da_sla_keys:
if isinstance(key, SlaKey):
if da2.find(bytes.fromhex(key.n)) != -1:
if da2.find(long_to_bytes(key.n)) != -1:
rsakey = key
if rsakey is None:
print("No valid sla key found, using dummy auth ....")

View file

@ -42,7 +42,7 @@ class ArgHandler(metaclass=LogBase):
config.pid = getint(args.pid)
except AttributeError:
pass
config.stock = True
config.stock = False
try:
if args.stock is not None:
config.stock = args.stock
@ -413,6 +413,26 @@ class Main(metaclass=LogBase):
sys.stderr.flush()
else:
self.close()
elif cmd == "multi":
# Split the commands in the multi argument
commands = self.args.commands.split(';')
# DA / Flash commands start here
try:
preloader = self.args.preloader
except Exception:
preloader = None
da_handler = DaHandler(mtk, loglevel)
mtk = da_handler.configure_da(mtk, preloader)
if mtk is not None:
for rcmd in commands:
self.args = parser.parse_args(rcmd.split(" "))
ArgHandler(self.args, config)
cmd = self.args.cmd
da_handler.handle_da_cmds(mtk, cmd, self.args)
sys.stdout.flush()
sys.stderr.flush()
else:
self.close()
elif cmd == "dumpbrom":
if mtk.preloader.init():
rmtk = mtk.crasher()
@ -662,8 +682,8 @@ class Main(metaclass=LogBase):
mtk = da_handler.configure_da(mtk, preloader)
if mtk is not None:
da_handler.handle_da_cmds(mtk, cmd, self.args)
else:
self.close()
mtk.port.close()
self.close()
def cmd_log(self, mtk, filename):
if mtk.preloader.init():