Compare commits

...

8 commits

Author SHA1 Message Date
hopez13
cc4cc1a87c
Merge e3cd58a837 into 20c7a50b17 2024-10-20 18:15:02 +02:00
Bjoern Kerler
20c7a50b17
Merge pull request #1251 from bignaux/nixshell
Some checks are pending
Python application / Test (push) Waiting to run
add a nix shell script for nix users
2024-10-20 18:10:28 +02:00
Bjoern Kerler
161ac0f664
Merge pull request #1261 from emmanuel-ferdman/main
Update multiple commands example
2024-10-20 18:08:58 +02:00
Emmanuel Ferdman
dcc431022a
Update multiple commands example
Signed-off-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
2024-10-19 23:17:05 -07:00
Bignaux Ronan
b59f65f94e add a nix shell script for nix users 2024-10-11 12:25:39 +02:00
hopez13
e3cd58a837
Fix Preloader Handshake In Debug Mode 2024-09-16 21:06:29 +05:30
hopez13
35c5803ae0
Update Port.py 2024-09-15 01:52:34 +05:30
hopez13
2e65679cc8
Fix preloader handshake 2024-09-15 01:30:13 +05:30
5 changed files with 62 additions and 51 deletions

View file

@ -202,13 +202,13 @@ python mtk.py --stock
### Run multiple commands
```bash
python mtk.py script run.example
python mtk.py script examples/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
See the file "[run.example](https://github.com/bkerler/mtkclient/blob/main/examples/run.example)" on how to structure the script file
### Root the phone (Tested with android 9 - 12)

View file

@ -309,7 +309,7 @@ class UsbClass(DeviceClass):
break
if self.device is None:
self.debug("Couldn't detect the device. Is it connected ?")
# self.debug("Couldn't detect the device. Is it connected ?")
return False
try:

View file

@ -125,63 +125,51 @@ class Port(metaclass=LogBase):
pass
return False
def run_handshake(self):
ep_out = self.cdc.EP_OUT.write
ep_in = self.cdc.EP_IN.read
maxinsize = self.cdc.EP_IN.wMaxPacketSize
i = 0
startcmd = b"\xa0\x0a\x50\x05"
length = len(startcmd)
# On preloader, send 0xa0 first
if self.cdc.pid!=0x3:
ep_out(startcmd[0:1])
try:
while i < length:
if ep_out(startcmd[i:i+1]):
if ep_in(maxinsize)[-1] == ~(startcmd[i]) & 0xFF:
i += 1
else:
i = 0
self.info("Device detected :)")
return True
except Exception as serr:
self.debug(str(serr))
time.sleep(0.005)
return False
# def run_handshake(self):
def handshake(self, maxtries=None, loop=0):
counter = 0
while not self.cdc.connected:
try:
if maxtries is not None and counter == maxtries:
break
counter += 1
if self.cdc.connect() and self.run_handshake():
return True
else:
if loop == 5:
sys.stdout.write('\n')
self.info("Hint:\n\nPower off the phone before connecting.\n" +
"For brom mode, press and hold vol up, vol dwn, or all hw buttons and " +
"connect usb.\n" +
"For preloader mode, don't press any hw button and connect usb.\n"
"If it is already connected and on, hold power for 10 seconds to reset.\n")
sys.stdout.write('\n')
if loop >= 10:
sys.stdout.write('.')
if loop >= 20:
sys.stdout.write('\n')
loop = 0
loop += 1
time.sleep(0.3)
sys.stdout.flush()
self.cdc.connect()
ep_out = self.cdc.EP_OUT.write
ep_in = self.cdc.EP_IN.read
maxinsize = self.cdc.EP_IN.wMaxPacketSize
i = 0
startcmd = b"\xa0\x0a\x50\x05"
length = len(startcmd)
# On preloader, send 0xa0 first
if self.cdc.pid!=0x3:
ep_out(startcmd[0:1])
try:
while i < length:
if ep_out(startcmd[i:i+1]):
if ep_in(maxinsize)[-1] == ~(startcmd[i]) & 0xFF:
i += 1
else:
i = 0
self.info("Device detected :)")
return True
except Exception as serr:
self.debug(str(serr))
time.sleep(0.005)
return False
except Exception as serr:
if "access denied" in str(serr):
self.warning(str(serr))
self.debug(str(serr))
# self.debug(str(serr))
pass
return False

View file

@ -160,9 +160,6 @@ class Preloader(metaclass=LogBase):
else:
res = self.mtk.port.handshake(maxtries=maxtries)
if not res:
if display:
self.error("Status: Handshake failed, retrying...")
self.config.set_gui_status(self.config.tr("Status: Handshake failed, retrying..."))
self.mtk.port.close()
tries += 1
if tries == 1000:

26
shell.nix Normal file
View file

@ -0,0 +1,26 @@
with import <nixpkgs> { };
mkShell {
name = "mtkclient";
buildInputs = with python3Packages; [
capstone
colorama
flake8
fusepy
keystone
keystone-engine
mock
pycryptodome
pycryptodomex
pyserial
pyside6
pyusb
setuptools
shiboken6
unicorn
wheel
];
}