mirror of
https://github.com/bkerler/edl.git
synced 2024-11-14 19:14:58 -05:00
Reformat code
Fix A bug in enableadb
This commit is contained in:
parent
3e4e569cf7
commit
084ab71db2
33 changed files with 462 additions and 433 deletions
|
@ -1,6 +1,7 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
from edl.Library.tcpclient import tcpclient
|
from edl.Library.tcpclient import tcpclient
|
||||||
|
|
||||||
|
|
||||||
class client():
|
class client():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.commands = []
|
self.commands = []
|
||||||
|
@ -18,6 +19,7 @@ class client():
|
||||||
def memcpy(self, dest, src, size):
|
def memcpy(self, dest, src, size):
|
||||||
self.commands.append(f"memcpy:{hex(dest)},{hex(src)},{hex(size)}")
|
self.commands.append(f"memcpy:{hex(dest)},{hex(src)},{hex(size)}")
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
exp = client()
|
exp = client()
|
||||||
exp.commands = [
|
exp.commands = [
|
||||||
|
@ -29,5 +31,6 @@ def main():
|
||||||
]
|
]
|
||||||
exp.send()
|
exp.send()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
21
edl
21
edl
|
@ -127,28 +127,29 @@ Options:
|
||||||
--resetmode=mode Resetmode for reset (poweroff, reset, edl, etc.)
|
--resetmode=mode Resetmode for reset (poweroff, reset, edl, etc.)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import logging
|
|
||||||
import subprocess
|
|
||||||
import re
|
|
||||||
from docopt import docopt
|
from docopt import docopt
|
||||||
|
|
||||||
from edlclient.Config.usb_ids import default_ids
|
from edlclient.Config.usb_ids import default_ids
|
||||||
from edlclient.Library.utils import LogBase
|
|
||||||
from edlclient.Library.Connection.usblib import usb_class
|
|
||||||
from edlclient.Library.Connection.seriallib import serial_class
|
from edlclient.Library.Connection.seriallib import serial_class
|
||||||
from edlclient.Library.sahara import sahara
|
from edlclient.Library.Connection.usblib import usb_class
|
||||||
from edlclient.Library.streaming_client import streaming_client
|
|
||||||
from edlclient.Library.firehose_client import firehose_client
|
from edlclient.Library.firehose_client import firehose_client
|
||||||
from edlclient.Library.streaming import Streaming
|
from edlclient.Library.sahara import sahara
|
||||||
from edlclient.Library.sahara_defs import cmd_t, sahara_mode_t
|
from edlclient.Library.sahara_defs import cmd_t, sahara_mode_t
|
||||||
|
from edlclient.Library.streaming import Streaming
|
||||||
|
from edlclient.Library.streaming_client import streaming_client
|
||||||
|
from edlclient.Library.utils import LogBase
|
||||||
from edlclient.Library.utils import is_windows
|
from edlclient.Library.utils import is_windows
|
||||||
from binascii import hexlify
|
|
||||||
|
|
||||||
args = docopt(__doc__, version='3')
|
args = docopt(__doc__, version='3')
|
||||||
|
|
||||||
print("Qualcomm Sahara / Firehose Client V3.62 (c) B.Kerler 2018-2023.")
|
print("Qualcomm Sahara / Firehose Client V3.62 (c) B.Kerler 2018-2024.")
|
||||||
|
|
||||||
|
|
||||||
def parse_cmd(rargs):
|
def parse_cmd(rargs):
|
||||||
|
|
|
@ -5,8 +5,6 @@
|
||||||
#
|
#
|
||||||
# !!!!! If you use this code in commercial products, your product is automatically
|
# !!!!! If you use this code in commercial products, your product is automatically
|
||||||
# GPLv3 and has to be open sourced under GPLv3 as well. !!!!!
|
# GPLv3 and has to be open sourced under GPLv3 as well. !!!!!
|
||||||
import serial
|
|
||||||
import serial.tools.list_ports
|
|
||||||
import inspect
|
import inspect
|
||||||
import traceback
|
import traceback
|
||||||
from binascii import hexlify
|
from binascii import hexlify
|
||||||
|
|
|
@ -5,9 +5,8 @@
|
||||||
#
|
#
|
||||||
# !!!!! If you use this code in commercial products, your product is automatically
|
# !!!!! If you use this code in commercial products, your product is automatically
|
||||||
# GPLv3 and has to be open sourced under GPLv3 as well. !!!!!
|
# GPLv3 and has to be open sourced under GPLv3 as well. !!!!!
|
||||||
import os.path
|
|
||||||
import time
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
if not sys.platform.startswith('win32'):
|
if not sys.platform.startswith('win32'):
|
||||||
import termios
|
import termios
|
||||||
|
|
||||||
|
@ -15,15 +14,16 @@ if not sys.platform.startswith('win32'):
|
||||||
def _reset_input_buffer():
|
def _reset_input_buffer():
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def _reset_input_buffer_org(self):
|
def _reset_input_buffer_org(self):
|
||||||
if not sys.platform.startswith('win32'):
|
if not sys.platform.startswith('win32'):
|
||||||
return termios.tcflush(self.fd, termios.TCIFLUSH)
|
return termios.tcflush(self.fd, termios.TCIFLUSH)
|
||||||
|
|
||||||
|
|
||||||
import serial
|
import serial
|
||||||
import serial.tools.list_ports
|
import serial.tools.list_ports
|
||||||
import inspect
|
import inspect
|
||||||
import traceback
|
|
||||||
from binascii import hexlify
|
|
||||||
try:
|
try:
|
||||||
from edlclient.Library.utils import *
|
from edlclient.Library.utils import *
|
||||||
from edlclient.Library.Connection.devicehandler import DeviceClass
|
from edlclient.Library.Connection.devicehandler import DeviceClass
|
||||||
|
@ -94,7 +94,6 @@ class serial_class(DeviceClass):
|
||||||
self.device.setDTR(DTR)
|
self.device.setDTR(DTR)
|
||||||
self.debug("Linecoding set")
|
self.debug("Linecoding set")
|
||||||
|
|
||||||
|
|
||||||
def write(self, command, pktsize=None):
|
def write(self, command, pktsize=None):
|
||||||
if pktsize is None:
|
if pktsize is None:
|
||||||
pktsize = 512
|
pktsize = 512
|
||||||
|
@ -218,5 +217,3 @@ class serial_class(DeviceClass):
|
||||||
self.device.flush()
|
self.device.flush()
|
||||||
res = self.usbread(resplen)
|
res = self.usbread(resplen)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -5,26 +5,25 @@
|
||||||
#
|
#
|
||||||
# !!!!! If you use this code in commercial products, your product is automatically
|
# !!!!! If you use this code in commercial products, your product is automatically
|
||||||
# GPLv3 and has to be open sourced under GPLv3 as well. !!!!!
|
# GPLv3 and has to be open sourced under GPLv3 as well. !!!!!
|
||||||
import io
|
|
||||||
import logging
|
|
||||||
|
|
||||||
import usb.core # pyusb
|
|
||||||
import usb.util
|
|
||||||
import time
|
|
||||||
import inspect
|
|
||||||
import array
|
import array
|
||||||
import usb.backend.libusb0
|
import inspect
|
||||||
from enum import Enum
|
import logging
|
||||||
from binascii import hexlify
|
from binascii import hexlify
|
||||||
from ctypes import c_void_p, c_int
|
from ctypes import c_void_p, c_int
|
||||||
|
from enum import Enum
|
||||||
|
|
||||||
|
import usb.backend.libusb0
|
||||||
|
import usb.core # pyusb
|
||||||
|
import usb.util
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from edlclient.Library.utils import *
|
from edlclient.Library.utils import *
|
||||||
except:
|
except:
|
||||||
from Library.utils import *
|
from Library.utils import *
|
||||||
if not is_windows():
|
if not is_windows():
|
||||||
import usb.backend.libusb1
|
import usb.backend.libusb1
|
||||||
from struct import pack, calcsize
|
from struct import pack
|
||||||
import traceback
|
|
||||||
try:
|
try:
|
||||||
from edlclient.Library.Connection.devicehandler import DeviceClass
|
from edlclient.Library.Connection.devicehandler import DeviceClass
|
||||||
except:
|
except:
|
||||||
|
|
|
@ -36,6 +36,7 @@ except ImportError as e:
|
||||||
nothing = None
|
nothing = None
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class modules(metaclass=LogBase):
|
class modules(metaclass=LogBase):
|
||||||
def __init__(self, fh, serial: int, supported_functions, loglevel, devicemodel: str, args):
|
def __init__(self, fh, serial: int, supported_functions, loglevel, devicemodel: str, args):
|
||||||
self.fh = fh
|
self.fh = fh
|
||||||
|
|
|
@ -33,8 +33,9 @@ class nothing(metaclass=LogBase):
|
||||||
authresp = token1 + self.projid + ("%x" % self.serial) + self.hashverify
|
authresp = token1 + self.projid + ("%x" % self.serial) + self.hashverify
|
||||||
token2 = hashlib.sha256(bytes(authresp, 'utf-8')).hexdigest()[:64]
|
token2 = hashlib.sha256(bytes(authresp, 'utf-8')).hexdigest()[:64]
|
||||||
token3 = self.hashverify
|
token3 = self.hashverify
|
||||||
return bytes(f"<?xml version=\"1.0\" encoding=\"UTF-8\" ?><data>\n <ntprojectverify token1=\"{token1}\" token2=\"{token2}\" token3=\"{token3}\"/>\n</data>\n",'utf-8')
|
return bytes(
|
||||||
|
f"<?xml version=\"1.0\" encoding=\"UTF-8\" ?><data>\n <ntprojectverify token1=\"{token1}\" token2=\"{token2}\" token3=\"{token3}\"/>\n</data>\n",
|
||||||
|
'utf-8')
|
||||||
|
|
||||||
def ntprojectverify(self):
|
def ntprojectverify(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -25,6 +25,7 @@ from struct import pack
|
||||||
import logging
|
import logging
|
||||||
from edlclient.Library.utils import LogBase
|
from edlclient.Library.utils import LogBase
|
||||||
from edlclient.Library.Modules.oneplus_param import paramtools
|
from edlclient.Library.Modules.oneplus_param import paramtools
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from edlclient.Library.cryptutils import cryptutils
|
from edlclient.Library.cryptutils import cryptutils
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -128,7 +129,8 @@ deviceconfig = {
|
||||||
|
|
||||||
|
|
||||||
class oneplus(metaclass=LogBase):
|
class oneplus(metaclass=LogBase):
|
||||||
def __init__(self, fh, projid:str="18825", serial=123456, ATOBuild=0, Flash_Mode=0, cf=0, supported_functions=None,
|
def __init__(self, fh, projid: str = "18825", serial=123456, ATOBuild=0, Flash_Mode=0, cf=0,
|
||||||
|
supported_functions=None,
|
||||||
args=None, loglevel=logging.INFO):
|
args=None, loglevel=logging.INFO):
|
||||||
self.fh = fh
|
self.fh = fh
|
||||||
self.__logger = self.__logger
|
self.__logger = self.__logger
|
||||||
|
|
|
@ -109,7 +109,7 @@ class sid(Enum):
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
|
||||||
class paramtools():
|
class paramtools:
|
||||||
paramitems = {
|
paramitems = {
|
||||||
sid.PARAM_SID_PRODUCT.value[0]: {
|
sid.PARAM_SID_PRODUCT.value[0]: {
|
||||||
0x18: ["8c", "project_name"],
|
0x18: ["8c", "project_name"],
|
||||||
|
@ -375,7 +375,7 @@ class paramtools():
|
||||||
def parse_encrypted(self, rdata, sid):
|
def parse_encrypted(self, rdata, sid):
|
||||||
data = rdata[(sid * 0x400):(sid * 0x400) + 0x1000]
|
data = rdata[(sid * 0x400):(sid * 0x400) + 0x1000]
|
||||||
itemdata, hv, cv, updatecounter = self.decryptsid(data)
|
itemdata, hv, cv, updatecounter = self.decryptsid(data)
|
||||||
if itemdata != None:
|
if itemdata is not None:
|
||||||
itemdata = bytearray(itemdata)
|
itemdata = bytearray(itemdata)
|
||||||
print(
|
print(
|
||||||
f"Offset {hex(sid * 0x400)}: hv {hex(hv)}, cv {hex(cv)}, increase_enc_update_counter {hex(updatecounter)}.")
|
f"Offset {hex(sid * 0x400)}: hv {hex(hv)}, cv {hex(cv)}, increase_enc_update_counter {hex(updatecounter)}.")
|
||||||
|
@ -420,7 +420,7 @@ class paramtools():
|
||||||
itemlength = 0x400
|
itemlength = 0x400
|
||||||
itemdata = rdata[pos + 0x18:pos + 0x18 + itemlength]
|
itemdata = rdata[pos + 0x18:pos + 0x18 + itemlength]
|
||||||
i = 0
|
i = 0
|
||||||
while (i < len(itemdata) - 0x22):
|
while i < len(itemdata) - 0x22:
|
||||||
sidindex = (pos // 0x400) & 0x1FF
|
sidindex = (pos // 0x400) & 0x1FF
|
||||||
offset = i + 0x18
|
offset = i + 0x18
|
||||||
# if sidindex==0x334 and offset==0x80:
|
# if sidindex==0x334 and offset==0x80:
|
||||||
|
@ -439,7 +439,7 @@ class paramtools():
|
||||||
length = self.parse_data(i, itemdata, offset, param, sidindex)
|
length = self.parse_data(i, itemdata, offset, param, sidindex)
|
||||||
i += length
|
i += length
|
||||||
if length > 4:
|
if length > 4:
|
||||||
if (length % 4):
|
if length % 4:
|
||||||
i += 4 - (length % 4)
|
i += 4 - (length % 4)
|
||||||
|
|
||||||
def parse_data(self, i, itemdata, offset, param, sidindex, encrypted=False):
|
def parse_data(self, i, itemdata, offset, param, sidindex, encrypted=False):
|
||||||
|
|
|
@ -425,7 +425,7 @@ class cryptutils:
|
||||||
return q
|
return q
|
||||||
|
|
||||||
def pss_verify(self, e, N, msghash, signature, emBits=1024, salt=None):
|
def pss_verify(self, e, N, msghash, signature, emBits=1024, salt=None):
|
||||||
if salt == None:
|
if salt is None:
|
||||||
slen = self.digestLen
|
slen = self.digestLen
|
||||||
else:
|
else:
|
||||||
slen = len(salt)
|
slen = len(salt)
|
||||||
|
@ -482,7 +482,7 @@ class cryptutils:
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
class hash():
|
class hash:
|
||||||
def __init__(self, hashtype="SHA256"):
|
def __init__(self, hashtype="SHA256"):
|
||||||
if hashtype == "SHA1":
|
if hashtype == "SHA1":
|
||||||
self.hash = self.sha1
|
self.hash = self.sha1
|
||||||
|
|
|
@ -7,27 +7,22 @@
|
||||||
# GPLv3 and has to be open sourced under GPLv3 as well. !!!!!
|
# GPLv3 and has to be open sourced under GPLv3 as well. !!!!!
|
||||||
|
|
||||||
import binascii
|
import binascii
|
||||||
import io
|
import json
|
||||||
import os.path
|
import os.path
|
||||||
import platform
|
import platform
|
||||||
import time
|
|
||||||
import json
|
|
||||||
from struct import unpack
|
|
||||||
from binascii import hexlify
|
from binascii import hexlify
|
||||||
from queue import Queue
|
from queue import Queue
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
||||||
from edlclient.Library.Modules.nothing import nothing
|
from edlclient.Library.Modules.nothing import nothing
|
||||||
from edlclient.Library.utils import *
|
from edlclient.Library.gpt import gpt, AB_FLAG_OFFSET, AB_PARTITION_ATTR_SLOT_ACTIVE
|
||||||
from edlclient.Library.gpt import gpt, AB_FLAG_OFFSET, AB_PARTITION_ATTR_SLOT_ACTIVE, MAX_PRIORITY, PART_ATT_PRIORITY_BIT
|
|
||||||
from edlclient.Library.gpt import PART_ATT_PRIORITY_VAL, PART_ATT_ACTIVE_VAL, PART_ATT_MAX_RETRY_COUNT_VAL, PART_ATT_SUCCESSFUL_VAL, PART_ATT_UNBOOTABLE_VAL
|
|
||||||
from edlclient.Library.sparse import QCSparse
|
from edlclient.Library.sparse import QCSparse
|
||||||
|
from edlclient.Library.utils import *
|
||||||
from edlclient.Library.utils import progress
|
from edlclient.Library.utils import progress
|
||||||
from queue import Queue
|
|
||||||
from threading import Thread
|
|
||||||
|
|
||||||
rq = Queue()
|
rq = Queue()
|
||||||
|
|
||||||
|
|
||||||
def writedata(filename, rq):
|
def writedata(filename, rq):
|
||||||
pos = 0
|
pos = 0
|
||||||
with open(filename, "wb") as wf:
|
with open(filename, "wb") as wf:
|
||||||
|
@ -146,11 +141,10 @@ def writefile(wf, q, stop):
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
class asyncwriter():
|
class asyncwriter:
|
||||||
def __init__(self, wf):
|
def __init__(self, wf):
|
||||||
self.writequeue = Queue()
|
self.writequeue = Queue()
|
||||||
self.worker = Thread(target=writefile, args=(wf, self.writequeue, lambda: self.stopthreads,))
|
self.worker = Thread(target=writefile, args=(wf, self.writequeue, lambda: self.stopthreads,), daemon=True)
|
||||||
self.worker.setDaemon(True)
|
|
||||||
self.stopthreads = False
|
self.stopthreads = False
|
||||||
self.worker.start()
|
self.worker.start()
|
||||||
|
|
||||||
|
@ -231,7 +225,8 @@ class firehose(metaclass=LogBase):
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
if partitionname in guid_gpt.partentries:
|
if partitionname in guid_gpt.partentries:
|
||||||
return [True, lun, data, guid_gpt] if send_full else [True, lun, guid_gpt.partentries[partitionname]]
|
return [True, lun, data, guid_gpt] if send_full else [True, lun,
|
||||||
|
guid_gpt.partentries[partitionname]]
|
||||||
for part in guid_gpt.partentries:
|
for part in guid_gpt.partentries:
|
||||||
fpartitions[lunname].append(part)
|
fpartitions[lunname].append(part)
|
||||||
return [False, fpartitions]
|
return [False, fpartitions]
|
||||||
|
@ -1330,14 +1325,17 @@ class firehose(metaclass=LogBase):
|
||||||
new_flags &= ~(AB_PARTITION_ATTR_SLOT_ACTIVE << (AB_FLAG_OFFSET * 8))
|
new_flags &= ~(AB_PARTITION_ATTR_SLOT_ACTIVE << (AB_FLAG_OFFSET * 8))
|
||||||
return new_flags
|
return new_flags
|
||||||
|
|
||||||
def patch_helper(gpt_data_a, gpt_data_b, guid_gpt_a, guid_gpt_b, partition_a, partition_b, slot_a_status, slot_b_status, is_boot):
|
def patch_helper(gpt_data_a, gpt_data_b, guid_gpt_a, guid_gpt_b, partition_a, partition_b, slot_a_status,
|
||||||
|
slot_b_status, is_boot):
|
||||||
part_entry_size = guid_gpt_a.header.part_entry_size
|
part_entry_size = guid_gpt_a.header.part_entry_size
|
||||||
|
|
||||||
rf_a = BytesIO(gpt_data_a)
|
rf_a = BytesIO(gpt_data_a)
|
||||||
rf_b = BytesIO(gpt_data_b)
|
rf_b = BytesIO(gpt_data_b)
|
||||||
|
|
||||||
entryoffset_a = partition_a.entryoffset - ((guid_gpt_a.header.part_entry_start_lba - 2) * guid_gpt_a.sectorsize)
|
entryoffset_a = partition_a.entryoffset - (
|
||||||
entryoffset_b = partition_b.entryoffset - ((guid_gpt_b.header.part_entry_start_lba - 2) * guid_gpt_b.sectorsize)
|
(guid_gpt_a.header.part_entry_start_lba - 2) * guid_gpt_a.sectorsize)
|
||||||
|
entryoffset_b = partition_b.entryoffset - (
|
||||||
|
(guid_gpt_b.header.part_entry_start_lba - 2) * guid_gpt_b.sectorsize)
|
||||||
rf_a.seek(entryoffset_a)
|
rf_a.seek(entryoffset_a)
|
||||||
rf_b.seek(entryoffset_b)
|
rf_b.seek(entryoffset_b)
|
||||||
|
|
||||||
|
@ -1423,7 +1421,8 @@ class firehose(metaclass=LogBase):
|
||||||
prim_corrupted = prim_hdr_crc != test_hdr_crc or prim_part_table_crc != test_part_table_crc
|
prim_corrupted = prim_hdr_crc != test_hdr_crc or prim_part_table_crc != test_part_table_crc
|
||||||
|
|
||||||
backup_hdr = backup_gpt_data[headeroffset: headeroffset + backup_guid_gpt.header.header_size]
|
backup_hdr = backup_gpt_data[headeroffset: headeroffset + backup_guid_gpt.header.header_size]
|
||||||
test_hdr = backup_guid_gpt.fix_gpt_crc(backup_gpt_data)[headeroffset : headeroffset + backup_guid_gpt.header.header_size]
|
test_hdr = backup_guid_gpt.fix_gpt_crc(backup_gpt_data)[
|
||||||
|
headeroffset: headeroffset + backup_guid_gpt.header.header_size]
|
||||||
backup_hdr_crc, test_hdr_crc = backup_hdr[0x10: 0x10 + 4], test_hdr[0x10: 0x10 + 4]
|
backup_hdr_crc, test_hdr_crc = backup_hdr[0x10: 0x10 + 4], test_hdr[0x10: 0x10 + 4]
|
||||||
backup_part_table_crc, test_part_table_crc = backup_hdr[0x58: 0x58 + 4], test_hdr[0x58: 0x58 + 4]
|
backup_part_table_crc, test_part_table_crc = backup_hdr[0x58: 0x58 + 4], test_hdr[0x58: 0x58 + 4]
|
||||||
backup_corrupted = backup_hdr_crc != test_hdr_crc or backup_part_table_crc != test_part_table_crc
|
backup_corrupted = backup_hdr_crc != test_hdr_crc or backup_part_table_crc != test_part_table_crc
|
||||||
|
@ -1464,7 +1463,8 @@ class firehose(metaclass=LogBase):
|
||||||
slot = partitionname_a.lower()[-2:]
|
slot = partitionname_a.lower()[-2:]
|
||||||
partition_a = backup_guid_gpt_a.partentries[partitionname_a]
|
partition_a = backup_guid_gpt_a.partentries[partitionname_a]
|
||||||
if slot == "_a":
|
if slot == "_a":
|
||||||
active_a = ((partition_a.flags >> (AB_FLAG_OFFSET*8))&0xFF) & AB_PARTITION_ATTR_SLOT_ACTIVE == AB_PARTITION_ATTR_SLOT_ACTIVE
|
active_a = ((partition_a.flags >> (
|
||||||
|
AB_FLAG_OFFSET * 8)) & 0xFF) & AB_PARTITION_ATTR_SLOT_ACTIVE == AB_PARTITION_ATTR_SLOT_ACTIVE
|
||||||
if (active_a and slot_a_status) or (not active_a and slot_b_status):
|
if (active_a and slot_a_status) or (not active_a and slot_b_status):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -1483,14 +1483,22 @@ class firehose(metaclass=LogBase):
|
||||||
self.error(f"Cannot find partition {partitionname_b}")
|
self.error(f"Cannot find partition {partitionname_b}")
|
||||||
return False
|
return False
|
||||||
_, lun_b, gpt_data_b, guid_gpt_b = resp
|
_, lun_b, gpt_data_b, guid_gpt_b = resp
|
||||||
backup_gpt_data_b, backup_guid_gpt_b = self.get_gpt(lun_b, 0, 0 , 0, guid_gpt_b.header.backup_lba)
|
backup_gpt_data_b, backup_guid_gpt_b = self.get_gpt(lun_b, 0, 0, 0,
|
||||||
|
guid_gpt_b.header.backup_lba)
|
||||||
|
|
||||||
if not check_gpt_hdr and partitionname_a[:3] != "xbl": # xbl partition don't need check consistency
|
if not check_gpt_hdr and partitionname_a[
|
||||||
sts, gpt_data_a, backup_gpt_data_a = ensure_gpt_hdr_consistency(guid_gpt_a, backup_guid_gpt_a, gpt_data_a, backup_gpt_data_a)
|
:3] != "xbl": # xbl partition don't need check consistency
|
||||||
|
sts, gpt_data_a, backup_gpt_data_a = ensure_gpt_hdr_consistency(guid_gpt_a,
|
||||||
|
backup_guid_gpt_a,
|
||||||
|
gpt_data_a,
|
||||||
|
backup_gpt_data_a)
|
||||||
if not sts:
|
if not sts:
|
||||||
return False
|
return False
|
||||||
if lun_a != lun_b:
|
if lun_a != lun_b:
|
||||||
sts, gpt_data_b, backup_gpt_data_b = ensure_gpt_hdr_consistency(guid_gpt_b, backup_guid_gpt_b, gpt_data_b, backup_gpt_data_b)
|
sts, gpt_data_b, backup_gpt_data_b = ensure_gpt_hdr_consistency(guid_gpt_b,
|
||||||
|
backup_guid_gpt_b,
|
||||||
|
gpt_data_b,
|
||||||
|
backup_gpt_data_b)
|
||||||
if not sts:
|
if not sts:
|
||||||
return False
|
return False
|
||||||
check_gpt_hdr = True
|
check_gpt_hdr = True
|
||||||
|
@ -1513,8 +1521,6 @@ class firehose(metaclass=LogBase):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def cmd_test(self, cmd):
|
def cmd_test(self, cmd):
|
||||||
token = "1234"
|
token = "1234"
|
||||||
pk = "1234"
|
pk = "1234"
|
||||||
|
|
|
@ -649,7 +649,8 @@ class firehose_client(metaclass=LogBase):
|
||||||
prim_guid_gpt = res[3]
|
prim_guid_gpt = res[3]
|
||||||
_, backup_guid_gpt = self.firehose.get_gpt(lun, 0, 0, 0, prim_guid_gpt.header.backup_lba)
|
_, backup_guid_gpt = self.firehose.get_gpt(lun, 0, 0, 0, prim_guid_gpt.header.backup_lba)
|
||||||
partition = backup_guid_gpt.partentries["boot_a"]
|
partition = backup_guid_gpt.partentries["boot_a"]
|
||||||
active = ((partition.flags >> (AB_FLAG_OFFSET*8))&0xFF) & AB_PARTITION_ATTR_SLOT_ACTIVE == AB_PARTITION_ATTR_SLOT_ACTIVE
|
active = ((partition.flags >> (
|
||||||
|
AB_FLAG_OFFSET * 8)) & 0xFF) & AB_PARTITION_ATTR_SLOT_ACTIVE == AB_PARTITION_ATTR_SLOT_ACTIVE
|
||||||
if active:
|
if active:
|
||||||
self.printer("Current active slot: a")
|
self.printer("Current active slot: a")
|
||||||
return True
|
return True
|
||||||
|
@ -659,7 +660,8 @@ class firehose_client(metaclass=LogBase):
|
||||||
prim_guid_gpt = res[3]
|
prim_guid_gpt = res[3]
|
||||||
_, backup_guid_gpt = self.firehose.get_gpt(lun, 0, 0, 0, prim_guid_gpt.header.backup_lba)
|
_, backup_guid_gpt = self.firehose.get_gpt(lun, 0, 0, 0, prim_guid_gpt.header.backup_lba)
|
||||||
partition = backup_guid_gpt.partentries["boot_b"]
|
partition = backup_guid_gpt.partentries["boot_b"]
|
||||||
active = ((partition.flags >> (AB_FLAG_OFFSET*8))&0xFF) & AB_PARTITION_ATTR_SLOT_ACTIVE == AB_PARTITION_ATTR_SLOT_ACTIVE
|
active = ((partition.flags >> (
|
||||||
|
AB_FLAG_OFFSET * 8)) & 0xFF) & AB_PARTITION_ATTR_SLOT_ACTIVE == AB_PARTITION_ATTR_SLOT_ACTIVE
|
||||||
if active:
|
if active:
|
||||||
self.printer("Current active slot: b")
|
self.printer("Current active slot: b")
|
||||||
return True
|
return True
|
||||||
|
@ -762,7 +764,8 @@ class firehose_client(metaclass=LogBase):
|
||||||
int(options["--gpt-part-entry-size"]),
|
int(options["--gpt-part-entry-size"]),
|
||||||
int(options["--gpt-part-entry-start-lba"]))
|
int(options["--gpt-part-entry-start-lba"]))
|
||||||
if guid_gpt is None:
|
if guid_gpt is None:
|
||||||
self.error("Error: Can not fetch GPT table from device, you may need to use `edl w gpt` to write a partition table first.`")
|
self.error(
|
||||||
|
"Error: Can not fetch GPT table from device, you may need to use `edl w gpt` to write a partition table first.`")
|
||||||
break
|
break
|
||||||
for filename in filenames:
|
for filename in filenames:
|
||||||
partname = os.path.basename(filename)
|
partname = os.path.basename(filename)
|
||||||
|
|
|
@ -5,18 +5,19 @@
|
||||||
#
|
#
|
||||||
# !!!!! If you use this code in commercial products, your product is automatically
|
# !!!!! If you use this code in commercial products, your product is automatically
|
||||||
# GPLv3 and has to be open sourced under GPLv3 as well. !!!!!
|
# GPLv3 and has to be open sourced under GPLv3 as well. !!!!!
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
import argparse
|
import argparse
|
||||||
import colorama
|
|
||||||
import copy
|
import copy
|
||||||
import logging
|
import logging
|
||||||
import logging.config
|
import logging.config
|
||||||
from enum import Enum
|
import os
|
||||||
from binascii import hexlify
|
import sys
|
||||||
from struct import calcsize, unpack, pack
|
|
||||||
from io import BytesIO
|
|
||||||
from binascii import crc32
|
from binascii import crc32
|
||||||
|
from binascii import hexlify
|
||||||
|
from enum import Enum
|
||||||
|
from struct import calcsize, unpack, pack
|
||||||
|
|
||||||
|
import colorama
|
||||||
|
|
||||||
|
|
||||||
class ColorFormatter(logging.Formatter):
|
class ColorFormatter(logging.Formatter):
|
||||||
LOG_COLORS = {
|
LOG_COLORS = {
|
||||||
|
|
|
@ -7,9 +7,8 @@
|
||||||
# GPLv3 and has to be open sourced under GPLv3 as well. !!!!!
|
# GPLv3 and has to be open sourced under GPLv3 as well. !!!!!
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from binascii import hexlify
|
|
||||||
from struct import unpack
|
|
||||||
import time
|
import time
|
||||||
|
from struct import unpack
|
||||||
|
|
||||||
MAX_PACKET_LEN = 4096
|
MAX_PACKET_LEN = 4096
|
||||||
|
|
||||||
|
|
|
@ -5,13 +5,11 @@
|
||||||
#
|
#
|
||||||
# !!!!! If you use this code in commercial products, your product is automatically
|
# !!!!! If you use this code in commercial products, your product is automatically
|
||||||
# GPLv3 and has to be open sourced under GPLv3 as well. !!!!!
|
# GPLv3 and has to be open sourced under GPLv3 as well. !!!!!
|
||||||
import binascii
|
import inspect
|
||||||
import time
|
import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import logging
|
|
||||||
import inspect
|
|
||||||
from struct import unpack, pack
|
|
||||||
current_dir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
|
current_dir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
|
||||||
parent_dir = os.path.dirname(current_dir)
|
parent_dir = os.path.dirname(current_dir)
|
||||||
sys.path.insert(0, parent_dir)
|
sys.path.insert(0, parent_dir)
|
||||||
|
@ -22,6 +20,7 @@ except:
|
||||||
from Library.utils import read_object, print_progress, rmrf, LogBase
|
from Library.utils import read_object, print_progress, rmrf, LogBase
|
||||||
from Config.qualcomm_config import sochw, msmids, root_cert_hash
|
from Config.qualcomm_config import sochw, msmids, root_cert_hash
|
||||||
|
|
||||||
|
|
||||||
class loader_utils(metaclass=LogBase):
|
class loader_utils(metaclass=LogBase):
|
||||||
def __init__(self, loglevel=logging.INFO):
|
def __init__(self, loglevel=logging.INFO):
|
||||||
self.__logger = self.__logger
|
self.__logger = self.__logger
|
||||||
|
@ -88,4 +87,3 @@ class loader_utils(metaclass=LogBase):
|
||||||
rmsmid = '0' + rmsmid
|
rmsmid = '0' + rmsmid
|
||||||
msmiddb.append(rmsmid)
|
msmiddb.append(rmsmid)
|
||||||
return msmiddb
|
return msmiddb
|
||||||
|
|
||||||
|
|
|
@ -6,11 +6,11 @@
|
||||||
# !!!!! If you use this code in commercial products, your product is automatically
|
# !!!!! If you use this code in commercial products, your product is automatically
|
||||||
# GPLv3 and has to be open sourced under GPLv3 as well. !!!!!
|
# GPLv3 and has to be open sourced under GPLv3 as well. !!!!!
|
||||||
|
|
||||||
import os
|
|
||||||
import pt64
|
|
||||||
import pt
|
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
|
import pt
|
||||||
|
import pt64
|
||||||
|
|
||||||
|
|
||||||
def pt64_walk(data, ttbr, tnsz, levels=3):
|
def pt64_walk(data, ttbr, tnsz, levels=3):
|
||||||
print("Dumping page tables (levels=%d)" % levels)
|
print("Dumping page tables (levels=%d)" % levels)
|
||||||
|
|
|
@ -87,6 +87,7 @@ def get_fld(mfld, level):
|
||||||
return table_entry4k(mfld, level)
|
return table_entry4k(mfld, level)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
class descriptor(object):
|
class descriptor(object):
|
||||||
def get_name(self):
|
def get_name(self):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -5,21 +5,22 @@
|
||||||
#
|
#
|
||||||
# !!!!! If you use this code in commercial products, your product is automatically
|
# !!!!! If you use this code in commercial products, your product is automatically
|
||||||
# GPLv3 and has to be open sourced under GPLv3 as well. !!!!!
|
# GPLv3 and has to be open sourced under GPLv3 as well. !!!!!
|
||||||
import binascii
|
import inspect
|
||||||
import time
|
import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import logging
|
import time
|
||||||
import inspect
|
|
||||||
from struct import pack
|
from struct import pack
|
||||||
|
|
||||||
current_dir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
|
current_dir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
|
||||||
parent_dir = os.path.dirname(current_dir)
|
parent_dir = os.path.dirname(current_dir)
|
||||||
sys.path.insert(0, parent_dir)
|
sys.path.insert(0, parent_dir)
|
||||||
from edlclient.Library.utils import read_object, print_progress, rmrf, LogBase
|
from edlclient.Library.utils import print_progress, rmrf, LogBase
|
||||||
from edlclient.Config.qualcomm_config import sochw, msmids, root_cert_hash
|
from edlclient.Config.qualcomm_config import msmids, root_cert_hash
|
||||||
from edlclient.Library.loader_db import loader_utils
|
from edlclient.Library.loader_db import loader_utils
|
||||||
from edlclient.Library.sahara_defs import ErrorDesc, cmd_t, exec_cmd_t, sahara_mode_t, status_t, \
|
from edlclient.Library.sahara_defs import ErrorDesc, cmd_t, exec_cmd_t, sahara_mode_t, status_t, \
|
||||||
CommandHandler, SAHARA_VERSION
|
CommandHandler
|
||||||
|
|
||||||
|
|
||||||
class sahara(metaclass=LogBase):
|
class sahara(metaclass=LogBase):
|
||||||
def __init__(self, cdc, loglevel):
|
def __init__(self, cdc, loglevel):
|
||||||
|
|
|
@ -12,9 +12,11 @@ from io import BytesIO
|
||||||
SAHARA_VERSION = 2
|
SAHARA_VERSION = 2
|
||||||
SAHARA_MIN_VERSION = 1
|
SAHARA_MIN_VERSION = 1
|
||||||
|
|
||||||
|
|
||||||
class DataError(Exception):
|
class DataError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class cmd_t:
|
class cmd_t:
|
||||||
SAHARA_HELLO_REQ = 0x1
|
SAHARA_HELLO_REQ = 0x1
|
||||||
SAHARA_HELLO_RSP = 0x2
|
SAHARA_HELLO_RSP = 0x2
|
||||||
|
@ -36,6 +38,7 @@ class cmd_t:
|
||||||
SAHARA_64BIT_MEMORY_READ_DATA = 0x12
|
SAHARA_64BIT_MEMORY_READ_DATA = 0x12
|
||||||
SAHARA_RESET_STATE_MACHINE_ID = 0x13
|
SAHARA_RESET_STATE_MACHINE_ID = 0x13
|
||||||
|
|
||||||
|
|
||||||
class cmd_t_version:
|
class cmd_t_version:
|
||||||
SAHARA_HELLO_REQ = 0x1
|
SAHARA_HELLO_REQ = 0x1
|
||||||
SAHARA_HELLO_RSP = 1
|
SAHARA_HELLO_RSP = 1
|
||||||
|
@ -57,6 +60,7 @@ class cmd_t_version:
|
||||||
SAHARA_64BIT_MEMORY_READ_DATA = 2
|
SAHARA_64BIT_MEMORY_READ_DATA = 2
|
||||||
SAHARA_RESET_STATE_MACHINE_ID = 2
|
SAHARA_RESET_STATE_MACHINE_ID = 2
|
||||||
|
|
||||||
|
|
||||||
class exec_cmd_t:
|
class exec_cmd_t:
|
||||||
SAHARA_EXEC_CMD_NOP = 0x00
|
SAHARA_EXEC_CMD_NOP = 0x00
|
||||||
SAHARA_EXEC_CMD_SERIAL_NUM_READ = 0x01
|
SAHARA_EXEC_CMD_SERIAL_NUM_READ = 0x01
|
||||||
|
@ -69,6 +73,7 @@ class exec_cmd_t:
|
||||||
SAHARA_EXEC_CMD_GET_COMMAND_ID_LIST = 0x08
|
SAHARA_EXEC_CMD_GET_COMMAND_ID_LIST = 0x08
|
||||||
SAHARA_EXEC_CMD_GET_TRAINING_DATA = 0x09
|
SAHARA_EXEC_CMD_GET_TRAINING_DATA = 0x09
|
||||||
|
|
||||||
|
|
||||||
class sahara_mode_t:
|
class sahara_mode_t:
|
||||||
SAHARA_MODE_IMAGE_TX_PENDING = 0x0
|
SAHARA_MODE_IMAGE_TX_PENDING = 0x0
|
||||||
SAHARA_MODE_IMAGE_TX_COMPLETE = 0x1
|
SAHARA_MODE_IMAGE_TX_COMPLETE = 0x1
|
||||||
|
|
|
@ -5,13 +5,13 @@
|
||||||
#
|
#
|
||||||
# !!!!! If you use this code in commercial products, your product is automatically
|
# !!!!! If you use this code in commercial products, your product is automatically
|
||||||
# GPLv3 and has to be open sourced under GPLv3 as well. !!!!!
|
# GPLv3 and has to be open sourced under GPLv3 as well. !!!!!
|
||||||
|
import inspect
|
||||||
import logging
|
import logging
|
||||||
import sys
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import inspect
|
|
||||||
from queue import Queue
|
from queue import Queue
|
||||||
from struct import unpack
|
from struct import unpack
|
||||||
|
|
||||||
current_dir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
|
current_dir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
|
||||||
parent_dir = os.path.dirname(current_dir)
|
parent_dir = os.path.dirname(current_dir)
|
||||||
sys.path.insert(0, parent_dir)
|
sys.path.insert(0, parent_dir)
|
||||||
|
|
|
@ -43,6 +43,7 @@ class open_multi_mode_type:
|
||||||
OPEN_MULTI_MODE_EMMC_GPP3 = 0x27 # EMMC GPP partition 3
|
OPEN_MULTI_MODE_EMMC_GPP3 = 0x27 # EMMC GPP partition 3
|
||||||
OPEN_MULTI_MODE_EMMC_GPP4 = 0x28 # EMMC GPP partition 4
|
OPEN_MULTI_MODE_EMMC_GPP4 = 0x28 # EMMC GPP partition 4
|
||||||
|
|
||||||
|
|
||||||
class response_code_type:
|
class response_code_type:
|
||||||
ACK = 0x00 # Successful
|
ACK = 0x00 # Successful
|
||||||
RESERVED_1 = 0x01 # Reserved
|
RESERVED_1 = 0x01 # Reserved
|
||||||
|
|
|
@ -5,20 +5,21 @@
|
||||||
#
|
#
|
||||||
# !!!!! If you use this code in commercial products, your product is automatically
|
# !!!!! If you use this code in commercial products, your product is automatically
|
||||||
# GPLv3 and has to be open sourced under GPLv3 as well. !!!!!
|
# GPLv3 and has to be open sourced under GPLv3 as well. !!!!!
|
||||||
import sys
|
import codecs
|
||||||
|
import copy
|
||||||
|
import datetime as dt
|
||||||
import logging
|
import logging
|
||||||
import logging.config
|
import logging.config
|
||||||
import codecs
|
|
||||||
import struct
|
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import stat
|
import stat
|
||||||
import colorama
|
import struct
|
||||||
import copy
|
import sys
|
||||||
import datetime as dt
|
|
||||||
import time
|
import time
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from struct import unpack, pack
|
from struct import unpack
|
||||||
|
|
||||||
|
import colorama
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from capstone import *
|
from capstone import *
|
||||||
|
@ -124,7 +125,7 @@ class progress:
|
||||||
def calcProcessTime(self, starttime, cur_iter, max_iter):
|
def calcProcessTime(self, starttime, cur_iter, max_iter):
|
||||||
telapsed = time.time() - starttime
|
telapsed = time.time() - starttime
|
||||||
if telapsed > 0 and cur_iter > 0:
|
if telapsed > 0 and cur_iter > 0:
|
||||||
testimated = (telapsed / cur_iter) * (max_iter)
|
testimated = (telapsed / cur_iter) * max_iter
|
||||||
finishtime = starttime + testimated
|
finishtime = starttime + testimated
|
||||||
finishtime = dt.datetime.fromtimestamp(finishtime).strftime("%H:%M:%S") # in time
|
finishtime = dt.datetime.fromtimestamp(finishtime).strftime("%H:%M:%S") # in time
|
||||||
lefttime = testimated - telapsed # in seconds
|
lefttime = testimated - telapsed # in seconds
|
||||||
|
@ -575,7 +576,7 @@ class patchtools:
|
||||||
badchars = self.has_bad_uart_chars(data)
|
badchars = self.has_bad_uart_chars(data)
|
||||||
if not badchars:
|
if not badchars:
|
||||||
badchars = self.has_bad_uart_chars(data2)
|
badchars = self.has_bad_uart_chars(data2)
|
||||||
if not (badchars):
|
if not badchars:
|
||||||
return div
|
return div
|
||||||
div += 4
|
div += 4
|
||||||
|
|
||||||
|
@ -685,7 +686,7 @@ class patchtools:
|
||||||
continue
|
continue
|
||||||
rt += 1
|
rt += 1
|
||||||
prep = data[rt:].find(t[i])
|
prep = data[rt:].find(t[i])
|
||||||
if (prep != 0):
|
if prep != 0:
|
||||||
error = 1
|
error = 1
|
||||||
break
|
break
|
||||||
rt += len(t[i])
|
rt += len(t[i])
|
||||||
|
@ -699,7 +700,7 @@ class patchtools:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def read_object(data: object, definition: object) -> object:
|
def read_object(data: object, definition: object) -> dict:
|
||||||
"""
|
"""
|
||||||
Unpacks a structure using the given data and definition.
|
Unpacks a structure using the given data and definition.
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -7,9 +7,10 @@
|
||||||
# GPLv3 and has to be open sourced under GPLv3 as well. !!!!!
|
# GPLv3 and has to be open sourced under GPLv3 as well. !!!!!
|
||||||
# Beagle to EDL Loader
|
# Beagle to EDL Loader
|
||||||
|
|
||||||
import os,sys
|
import sys
|
||||||
from struct import unpack
|
from struct import unpack
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
if len(sys.argv) < 2:
|
if len(sys.argv) < 2:
|
||||||
print("Usage: ./beagle_to_loader.py [beagle_log.bin] [loader.elf]")
|
print("Usage: ./beagle_to_loader.py [beagle_log.bin] [loader.elf]")
|
||||||
|
@ -45,5 +46,6 @@ def main():
|
||||||
|
|
||||||
print("Done.")
|
print("Done.")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
|
@ -38,8 +38,9 @@ import logging.config
|
||||||
import logging.handlers
|
import logging.handlers
|
||||||
import colorama
|
import colorama
|
||||||
|
|
||||||
|
|
||||||
itoa64 = bytearray(b"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")
|
itoa64 = bytearray(b"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")
|
||||||
|
|
||||||
|
|
||||||
def _crypt_to64(s, v, n):
|
def _crypt_to64(s, v, n):
|
||||||
out = bytearray()
|
out = bytearray()
|
||||||
while --n >= 0:
|
while --n >= 0:
|
||||||
|
@ -191,7 +192,8 @@ class connection:
|
||||||
mode = "AT"
|
mode = "AT"
|
||||||
break
|
break
|
||||||
elif device.pid == 0x1403:
|
elif device.pid == 0x1403:
|
||||||
print(f"Detected a {atvendortable[device.vid][0]} device with pid {hex(device.pid)} in Web mode")
|
print(
|
||||||
|
f"Detected a {atvendortable[device.vid][0]} device with pid {hex(device.pid)} in Web mode")
|
||||||
mode = "Web"
|
mode = "Web"
|
||||||
self.ZTE_Web()
|
self.ZTE_Web()
|
||||||
break
|
break
|
||||||
|
@ -386,17 +388,14 @@ class adbtools(metaclass=LogBase):
|
||||||
print("Sending switch command via diag")
|
print("Sending switch command via diag")
|
||||||
res = self.ZTE(cn, enable)
|
res = self.ZTE(cn, enable)
|
||||||
elif info["vendor"] == "Simcom":
|
elif info["vendor"] == "Simcom":
|
||||||
res=self.Simcom(cn)
|
res = self.Simcom(cn, enable)
|
||||||
elif info["vendor"] == "Fibocom":
|
elif info["vendor"] == "Fibocom":
|
||||||
res = self.Fibocom(cn, enable)
|
res = self.Fibocom(cn, enable)
|
||||||
elif info["vendor"] == "Alcatel":
|
elif info["vendor"] == "Alcatel":
|
||||||
res = self.Alcatel(enable)
|
res = self.Alcatel(enable)
|
||||||
elif info["vendor"] == "Samsung":
|
elif info["vendor"] == "Samsung":
|
||||||
res = self.Samsung(cn, enable)
|
res = self.Samsung(cn, enable)
|
||||||
if enable:
|
mode = "enabled" if enable else "disabled"
|
||||||
mode="enabled"
|
|
||||||
else:
|
|
||||||
mode="disabled"
|
|
||||||
if res:
|
if res:
|
||||||
print("ADB successfully " + mode)
|
print("ADB successfully " + mode)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -5,21 +5,24 @@
|
||||||
#
|
#
|
||||||
# !!!!! If you use this code in commercial products, your product is automatically
|
# !!!!! If you use this code in commercial products, your product is automatically
|
||||||
# GPLv3 and has to be open sourced under GPLv3 as well. !!!!!
|
# GPLv3 and has to be open sourced under GPLv3 as well. !!!!!
|
||||||
|
import hashlib
|
||||||
|
import inspect
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from os import walk
|
|
||||||
import hashlib
|
|
||||||
from struct import unpack, pack
|
|
||||||
from shutil import copyfile
|
|
||||||
import os, sys, inspect
|
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from Library.utils import elf
|
from os import walk
|
||||||
from Library.loader_db import loader_utils
|
from shutil import copyfile
|
||||||
|
from struct import unpack
|
||||||
|
|
||||||
from Config.qualcomm_config import vendor
|
from Config.qualcomm_config import vendor
|
||||||
|
from Library.loader_db import loader_utils
|
||||||
|
from Library.utils import elf
|
||||||
|
|
||||||
current_dir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
|
current_dir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
|
||||||
|
|
||||||
lu = loader_utils()
|
lu = loader_utils()
|
||||||
|
|
||||||
|
|
||||||
class MBN:
|
class MBN:
|
||||||
def __init__(self, memory):
|
def __init__(self, memory):
|
||||||
self.imageid, self.flashpartitionversion, self.imagesrc, self.loadaddr, self.imagesz, self.codesz, \
|
self.imageid, self.flashpartitionversion, self.imagesrc, self.loadaddr, self.imagesz, self.codesz, \
|
||||||
|
@ -106,7 +109,8 @@ def extract_hdr(memsection, version, sign_info, mem_section, code_size, signatur
|
||||||
len1 = unpack(">H", mem_section[signatureoffset + 2:signatureoffset + 4])[0] + 4
|
len1 = unpack(">H", mem_section[signatureoffset + 2:signatureoffset + 4])[0] + 4
|
||||||
casignature2offset = signatureoffset + len1
|
casignature2offset = signatureoffset + len1
|
||||||
len2 = unpack(">H", mem_section[casignature2offset + 2:casignature2offset + 4])[0] + 4
|
len2 = unpack(">H", mem_section[casignature2offset + 2:casignature2offset + 4])[0] + 4
|
||||||
rootsignature3 = mem_section[(casignature2offset + len2):(casignature2offset + len2) + 999999999].split(b'\xff\xff\xff\xff\xff\xff\xff\xff\xff')[0]
|
rootsignature3 = mem_section[(casignature2offset + len2):(casignature2offset + len2) + 999999999].split(
|
||||||
|
b'\xff\xff\xff\xff\xff\xff\xff\xff\xff')[0]
|
||||||
|
|
||||||
idx = signatureoffset
|
idx = signatureoffset
|
||||||
signature = {}
|
signature = {}
|
||||||
|
@ -171,7 +175,8 @@ def extract_old_hdr(signatureoffset, sign_info, mem_section, code_size, signatur
|
||||||
len1 = unpack(">H", mem_section[signatureoffset + 2:signatureoffset + 4])[0] + 4
|
len1 = unpack(">H", mem_section[signatureoffset + 2:signatureoffset + 4])[0] + 4
|
||||||
casignature2offset = signatureoffset + len1
|
casignature2offset = signatureoffset + len1
|
||||||
len2 = unpack(">H", mem_section[casignature2offset + 2:casignature2offset + 4])[0] + 4
|
len2 = unpack(">H", mem_section[casignature2offset + 2:casignature2offset + 4])[0] + 4
|
||||||
rootsignature3 = mem_section[(casignature2offset + len2):(casignature2offset + len2) + 999999999].split(b'\xff\xff\xff\xff\xff\xff\xff\xff\xff')[0]
|
rootsignature3 = mem_section[(casignature2offset + len2):(casignature2offset + len2) + 999999999].split(
|
||||||
|
b'\xff\xff\xff\xff\xff\xff\xff\xff\xff')[0]
|
||||||
sign_info.pk_hash = hashlib.sha256(rootsignature3).hexdigest()
|
sign_info.pk_hash = hashlib.sha256(rootsignature3).hexdigest()
|
||||||
idx = signatureoffset
|
idx = signatureoffset
|
||||||
|
|
||||||
|
@ -381,7 +386,8 @@ def main(argv):
|
||||||
filelist.append(signinfo)
|
filelist.append(signinfo)
|
||||||
break
|
break
|
||||||
elif version >= 6: # SDM
|
elif version >= 6: # SDM
|
||||||
signinfo = extract_hdr(memsection, version, signinfo, mem_section, code_size, signature_size, hdr1,
|
signinfo = extract_hdr(memsection, version, signinfo, mem_section, code_size, signature_size,
|
||||||
|
hdr1,
|
||||||
hdr2, hdr3, hdr4)
|
hdr2, hdr3, hdr4)
|
||||||
if signinfo is None:
|
if signinfo is None:
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -90,7 +90,7 @@ subnvitem_type = [
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class fs_factimage_read_info():
|
class fs_factimage_read_info:
|
||||||
def_fs_factimage_read_info = [
|
def_fs_factimage_read_info = [
|
||||||
("stream_state", "B"), # 0 indicates no more data to be sent, otherwise set to 1
|
("stream_state", "B"), # 0 indicates no more data to be sent, otherwise set to 1
|
||||||
("info_cluster_sent", "B"), # 0 indicates if info_cluster was not sent, else 1
|
("info_cluster_sent", "B"), # 0 indicates if info_cluster was not sent, else 1
|
||||||
|
@ -117,7 +117,7 @@ class fs_factimage_read_info():
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
class FactoryHeader():
|
class FactoryHeader:
|
||||||
def_factory_header = [
|
def_factory_header = [
|
||||||
("magic1", "I"),
|
("magic1", "I"),
|
||||||
("magic2", "I"),
|
("magic2", "I"),
|
||||||
|
@ -160,7 +160,7 @@ class FactoryHeader():
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
class nvitem():
|
class nvitem:
|
||||||
item = 0x0
|
item = 0x0
|
||||||
data = b""
|
data = b""
|
||||||
status = 0x0
|
status = 0x0
|
||||||
|
@ -409,7 +409,7 @@ class qcdiag(metaclass=LogBase):
|
||||||
self.cdc.close(True)
|
self.cdc.close(True)
|
||||||
|
|
||||||
def send(self, cmd):
|
def send(self, cmd):
|
||||||
if self.hdlc != None:
|
if self.hdlc is not None:
|
||||||
return self.hdlc.send_cmd_np(cmd)
|
return self.hdlc.send_cmd_np(cmd)
|
||||||
|
|
||||||
def cmd_info(self):
|
def cmd_info(self):
|
||||||
|
@ -809,7 +809,7 @@ class qcdiag(metaclass=LogBase):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
write_handle.close()
|
write_handle.close()
|
||||||
if efserr == False:
|
if not efserr:
|
||||||
print("Successfully read EFS.")
|
print("Successfully read EFS.")
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
|
@ -1408,7 +1408,7 @@ def main():
|
||||||
parser_nvwritesub.add_argument("-debugmode", help="[Option] Enable verbose logging", action="store_true")
|
parser_nvwritesub.add_argument("-debugmode", help="[Option] Enable verbose logging", action="store_true")
|
||||||
|
|
||||||
parser_writeimei = subparser.add_parser("writeimei", help="Write imei")
|
parser_writeimei = subparser.add_parser("writeimei", help="Write imei")
|
||||||
parser_writeimei.add_argument("imei", metavar=("<imei1,imei2,...>"), help="[Option] IMEI to write", default="")
|
parser_writeimei.add_argument("imei", metavar="<imei1,imei2,...>", help="[Option] IMEI to write", default="")
|
||||||
parser_writeimei.add_argument("-vid", metavar="<vid>", help="[Option] Specify vid", default="")
|
parser_writeimei.add_argument("-vid", metavar="<vid>", help="[Option] Specify vid", default="")
|
||||||
parser_writeimei.add_argument("-pid", metavar="<pid>", help="[Option] Specify pid", default="")
|
parser_writeimei.add_argument("-pid", metavar="<pid>", help="[Option] Specify pid", default="")
|
||||||
parser_writeimei.add_argument("-interface", metavar="<pid>", help="[Option] Specify interface number, default=0)",
|
parser_writeimei.add_argument("-interface", metavar="<pid>", help="[Option] Specify interface number, default=0)",
|
||||||
|
|
|
@ -17,6 +17,7 @@ import logging.config
|
||||||
import logging.handlers
|
import logging.handlers
|
||||||
import colorama
|
import colorama
|
||||||
|
|
||||||
|
|
||||||
class ColorFormatter(logging.Formatter):
|
class ColorFormatter(logging.Formatter):
|
||||||
LOG_COLORS = {
|
LOG_COLORS = {
|
||||||
logging.ERROR: colorama.Fore.RED,
|
logging.ERROR: colorama.Fore.RED,
|
||||||
|
@ -210,7 +211,8 @@ keytable = bytearray([0xF0, 0x14, 0x55, 0x0D, 0x5E, 0xDA, 0x92, 0xB3, 0xA7, 0x6C
|
||||||
0x46, 0x30, 0x33, 0x43, 0x44, 0x36, 0x42, 0x34, 0x41, 0x32, 0x31, 0x32, 0x30, 0x35, 0x39, 0x37
|
0x46, 0x30, 0x33, 0x43, 0x44, 0x36, 0x42, 0x34, 0x41, 0x32, 0x31, 0x32, 0x30, 0x35, 0x39, 0x37
|
||||||
])
|
])
|
||||||
|
|
||||||
class SierraGenerator():
|
|
||||||
|
class SierraGenerator:
|
||||||
tbl = bytearray()
|
tbl = bytearray()
|
||||||
rtbl = bytearray()
|
rtbl = bytearray()
|
||||||
devicegeneration = None
|
devicegeneration = None
|
||||||
|
@ -425,7 +427,7 @@ class connection:
|
||||||
def readreply(self):
|
def readreply(self):
|
||||||
info = []
|
info = []
|
||||||
if self.serial is not None:
|
if self.serial is not None:
|
||||||
while (True):
|
while True:
|
||||||
tmp = self.serial.readline().decode('utf-8').replace('\r', '').replace('\n', '')
|
tmp = self.serial.readline().decode('utf-8').replace('\r', '').replace('\n', '')
|
||||||
if "OK" in info:
|
if "OK" in info:
|
||||||
return info
|
return info
|
||||||
|
@ -464,7 +466,7 @@ class SierraKeygen(metaclass=LogBase):
|
||||||
def __init__(self, cn, devicegeneration=None):
|
def __init__(self, cn, devicegeneration=None):
|
||||||
self.cn = cn
|
self.cn = cn
|
||||||
self.keygen = SierraGenerator()
|
self.keygen = SierraGenerator()
|
||||||
if devicegeneration == None:
|
if devicegeneration is None:
|
||||||
self.detectdevicegeneration()
|
self.detectdevicegeneration()
|
||||||
else:
|
else:
|
||||||
self.devicegeneration = devicegeneration
|
self.devicegeneration = devicegeneration
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
import os, sys
|
import os, sys
|
||||||
from struct import unpack
|
from struct import unpack
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
if len(sys.argv) < 2:
|
if len(sys.argv) < 2:
|
||||||
print("Usage: ./txt_to_loader.py [log.txt] [loader.elf]")
|
print("Usage: ./txt_to_loader.py [log.txt] [loader.elf]")
|
||||||
|
@ -53,5 +54,6 @@ def main():
|
||||||
|
|
||||||
print("Done.")
|
print("Done.")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
Loading…
Reference in a new issue