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
|
||||
from edl.Library.tcpclient import tcpclient
|
||||
|
||||
|
||||
class client():
|
||||
def __init__(self):
|
||||
self.commands = []
|
||||
|
@ -18,6 +19,7 @@ class client():
|
|||
def memcpy(self, dest, src, size):
|
||||
self.commands.append(f"memcpy:{hex(dest)},{hex(src)},{hex(size)}")
|
||||
|
||||
|
||||
def main():
|
||||
exp = client()
|
||||
exp.commands = [
|
||||
|
@ -29,5 +31,6 @@ def main():
|
|||
]
|
||||
exp.send()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
21
edl
21
edl
|
@ -127,28 +127,29 @@ Options:
|
|||
--resetmode=mode Resetmode for reset (poweroff, reset, edl, etc.)
|
||||
"""
|
||||
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
import logging
|
||||
import subprocess
|
||||
import re
|
||||
|
||||
from docopt import docopt
|
||||
|
||||
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.sahara import sahara
|
||||
from edlclient.Library.streaming_client import streaming_client
|
||||
from edlclient.Library.Connection.usblib import usb_class
|
||||
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.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 binascii import hexlify
|
||||
|
||||
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):
|
||||
|
|
|
@ -5,8 +5,6 @@
|
|||
#
|
||||
# !!!!! If you use this code in commercial products, your product is automatically
|
||||
# GPLv3 and has to be open sourced under GPLv3 as well. !!!!!
|
||||
import serial
|
||||
import serial.tools.list_ports
|
||||
import inspect
|
||||
import traceback
|
||||
from binascii import hexlify
|
||||
|
|
|
@ -5,9 +5,8 @@
|
|||
#
|
||||
# !!!!! If you use this code in commercial products, your product is automatically
|
||||
# GPLv3 and has to be open sourced under GPLv3 as well. !!!!!
|
||||
import os.path
|
||||
import time
|
||||
import sys
|
||||
|
||||
if not sys.platform.startswith('win32'):
|
||||
import termios
|
||||
|
||||
|
@ -15,15 +14,16 @@ if not sys.platform.startswith('win32'):
|
|||
def _reset_input_buffer():
|
||||
return
|
||||
|
||||
|
||||
def _reset_input_buffer_org(self):
|
||||
if not sys.platform.startswith('win32'):
|
||||
return termios.tcflush(self.fd, termios.TCIFLUSH)
|
||||
|
||||
|
||||
import serial
|
||||
import serial.tools.list_ports
|
||||
import inspect
|
||||
import traceback
|
||||
from binascii import hexlify
|
||||
|
||||
try:
|
||||
from edlclient.Library.utils import *
|
||||
from edlclient.Library.Connection.devicehandler import DeviceClass
|
||||
|
@ -94,7 +94,6 @@ class serial_class(DeviceClass):
|
|||
self.device.setDTR(DTR)
|
||||
self.debug("Linecoding set")
|
||||
|
||||
|
||||
def write(self, command, pktsize=None):
|
||||
if pktsize is None:
|
||||
pktsize = 512
|
||||
|
@ -218,5 +217,3 @@ class serial_class(DeviceClass):
|
|||
self.device.flush()
|
||||
res = self.usbread(resplen)
|
||||
return res
|
||||
|
||||
|
||||
|
|
|
@ -5,26 +5,25 @@
|
|||
#
|
||||
# !!!!! If you use this code in commercial products, your product is automatically
|
||||
# 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 usb.backend.libusb0
|
||||
from enum import Enum
|
||||
import inspect
|
||||
import logging
|
||||
from binascii import hexlify
|
||||
from ctypes import c_void_p, c_int
|
||||
from enum import Enum
|
||||
|
||||
import usb.backend.libusb0
|
||||
import usb.core # pyusb
|
||||
import usb.util
|
||||
|
||||
try:
|
||||
from edlclient.Library.utils import *
|
||||
except:
|
||||
from Library.utils import *
|
||||
if not is_windows():
|
||||
import usb.backend.libusb1
|
||||
from struct import pack, calcsize
|
||||
import traceback
|
||||
from struct import pack
|
||||
|
||||
try:
|
||||
from edlclient.Library.Connection.devicehandler import DeviceClass
|
||||
except:
|
||||
|
|
|
@ -36,6 +36,7 @@ except ImportError as e:
|
|||
nothing = None
|
||||
pass
|
||||
|
||||
|
||||
class modules(metaclass=LogBase):
|
||||
def __init__(self, fh, serial: int, supported_functions, loglevel, devicemodel: str, args):
|
||||
self.fh = fh
|
||||
|
|
|
@ -33,8 +33,9 @@ class nothing(metaclass=LogBase):
|
|||
authresp = token1 + self.projid + ("%x" % self.serial) + self.hashverify
|
||||
token2 = hashlib.sha256(bytes(authresp, 'utf-8')).hexdigest()[:64]
|
||||
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):
|
||||
"""
|
||||
|
|
|
@ -25,6 +25,7 @@ from struct import pack
|
|||
import logging
|
||||
from edlclient.Library.utils import LogBase
|
||||
from edlclient.Library.Modules.oneplus_param import paramtools
|
||||
|
||||
try:
|
||||
from edlclient.Library.cryptutils import cryptutils
|
||||
except Exception as e:
|
||||
|
@ -128,7 +129,8 @@ deviceconfig = {
|
|||
|
||||
|
||||
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):
|
||||
self.fh = fh
|
||||
self.__logger = self.__logger
|
||||
|
|
|
@ -109,7 +109,7 @@ class sid(Enum):
|
|||
'''
|
||||
|
||||
|
||||
class paramtools():
|
||||
class paramtools:
|
||||
paramitems = {
|
||||
sid.PARAM_SID_PRODUCT.value[0]: {
|
||||
0x18: ["8c", "project_name"],
|
||||
|
@ -375,7 +375,7 @@ class paramtools():
|
|||
def parse_encrypted(self, rdata, sid):
|
||||
data = rdata[(sid * 0x400):(sid * 0x400) + 0x1000]
|
||||
itemdata, hv, cv, updatecounter = self.decryptsid(data)
|
||||
if itemdata != None:
|
||||
if itemdata is not None:
|
||||
itemdata = bytearray(itemdata)
|
||||
print(
|
||||
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
|
||||
itemdata = rdata[pos + 0x18:pos + 0x18 + itemlength]
|
||||
i = 0
|
||||
while (i < len(itemdata) - 0x22):
|
||||
while i < len(itemdata) - 0x22:
|
||||
sidindex = (pos // 0x400) & 0x1FF
|
||||
offset = i + 0x18
|
||||
# if sidindex==0x334 and offset==0x80:
|
||||
|
@ -439,7 +439,7 @@ class paramtools():
|
|||
length = self.parse_data(i, itemdata, offset, param, sidindex)
|
||||
i += length
|
||||
if length > 4:
|
||||
if (length % 4):
|
||||
if length % 4:
|
||||
i += 4 - (length % 4)
|
||||
|
||||
def parse_data(self, i, itemdata, offset, param, sidindex, encrypted=False):
|
||||
|
|
|
@ -425,7 +425,7 @@ class cryptutils:
|
|||
return q
|
||||
|
||||
def pss_verify(self, e, N, msghash, signature, emBits=1024, salt=None):
|
||||
if salt == None:
|
||||
if salt is None:
|
||||
slen = self.digestLen
|
||||
else:
|
||||
slen = len(salt)
|
||||
|
@ -482,7 +482,7 @@ class cryptutils:
|
|||
else:
|
||||
return False
|
||||
|
||||
class hash():
|
||||
class hash:
|
||||
def __init__(self, hashtype="SHA256"):
|
||||
if hashtype == "SHA1":
|
||||
self.hash = self.sha1
|
||||
|
|
|
@ -7,27 +7,22 @@
|
|||
# GPLv3 and has to be open sourced under GPLv3 as well. !!!!!
|
||||
|
||||
import binascii
|
||||
import io
|
||||
import json
|
||||
import os.path
|
||||
import platform
|
||||
import time
|
||||
import json
|
||||
from struct import unpack
|
||||
from binascii import hexlify
|
||||
from queue import Queue
|
||||
from threading import Thread
|
||||
|
||||
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, 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.gpt import gpt, AB_FLAG_OFFSET, AB_PARTITION_ATTR_SLOT_ACTIVE
|
||||
from edlclient.Library.sparse import QCSparse
|
||||
from edlclient.Library.utils import *
|
||||
from edlclient.Library.utils import progress
|
||||
from queue import Queue
|
||||
from threading import Thread
|
||||
|
||||
rq = Queue()
|
||||
|
||||
|
||||
def writedata(filename, rq):
|
||||
pos = 0
|
||||
with open(filename, "wb") as wf:
|
||||
|
@ -146,11 +141,10 @@ def writefile(wf, q, stop):
|
|||
break
|
||||
|
||||
|
||||
class asyncwriter():
|
||||
class asyncwriter:
|
||||
def __init__(self, wf):
|
||||
self.writequeue = Queue()
|
||||
self.worker = Thread(target=writefile, args=(wf, self.writequeue, lambda: self.stopthreads,))
|
||||
self.worker.setDaemon(True)
|
||||
self.worker = Thread(target=writefile, args=(wf, self.writequeue, lambda: self.stopthreads,), daemon=True)
|
||||
self.stopthreads = False
|
||||
self.worker.start()
|
||||
|
||||
|
@ -231,7 +225,8 @@ class firehose(metaclass=LogBase):
|
|||
break
|
||||
else:
|
||||
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:
|
||||
fpartitions[lunname].append(part)
|
||||
return [False, fpartitions]
|
||||
|
@ -1330,14 +1325,17 @@ class firehose(metaclass=LogBase):
|
|||
new_flags &= ~(AB_PARTITION_ATTR_SLOT_ACTIVE << (AB_FLAG_OFFSET * 8))
|
||||
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
|
||||
|
||||
rf_a = BytesIO(gpt_data_a)
|
||||
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_b = partition_b.entryoffset - ((guid_gpt_b.header.part_entry_start_lba - 2) * guid_gpt_b.sectorsize)
|
||||
entryoffset_a = partition_a.entryoffset - (
|
||||
(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_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
|
||||
|
||||
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_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
|
||||
|
@ -1464,7 +1463,8 @@ class firehose(metaclass=LogBase):
|
|||
slot = partitionname_a.lower()[-2:]
|
||||
partition_a = backup_guid_gpt_a.partentries[partitionname_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):
|
||||
return True
|
||||
|
||||
|
@ -1483,14 +1483,22 @@ class firehose(metaclass=LogBase):
|
|||
self.error(f"Cannot find partition {partitionname_b}")
|
||||
return False
|
||||
_, 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
|
||||
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 check_gpt_hdr and partitionname_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:
|
||||
return False
|
||||
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:
|
||||
return False
|
||||
check_gpt_hdr = True
|
||||
|
@ -1513,8 +1521,6 @@ class firehose(metaclass=LogBase):
|
|||
return False
|
||||
return True
|
||||
|
||||
|
||||
|
||||
def cmd_test(self, cmd):
|
||||
token = "1234"
|
||||
pk = "1234"
|
||||
|
|
|
@ -649,7 +649,8 @@ class firehose_client(metaclass=LogBase):
|
|||
prim_guid_gpt = res[3]
|
||||
_, backup_guid_gpt = self.firehose.get_gpt(lun, 0, 0, 0, prim_guid_gpt.header.backup_lba)
|
||||
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:
|
||||
self.printer("Current active slot: a")
|
||||
return True
|
||||
|
@ -659,7 +660,8 @@ class firehose_client(metaclass=LogBase):
|
|||
prim_guid_gpt = res[3]
|
||||
_, backup_guid_gpt = self.firehose.get_gpt(lun, 0, 0, 0, prim_guid_gpt.header.backup_lba)
|
||||
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:
|
||||
self.printer("Current active slot: b")
|
||||
return True
|
||||
|
@ -762,7 +764,8 @@ class firehose_client(metaclass=LogBase):
|
|||
int(options["--gpt-part-entry-size"]),
|
||||
int(options["--gpt-part-entry-start-lba"]))
|
||||
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
|
||||
for filename in filenames:
|
||||
partname = os.path.basename(filename)
|
||||
|
|
|
@ -5,18 +5,19 @@
|
|||
#
|
||||
# !!!!! If you use this code in commercial products, your product is automatically
|
||||
# GPLv3 and has to be open sourced under GPLv3 as well. !!!!!
|
||||
import os
|
||||
import sys
|
||||
import argparse
|
||||
import colorama
|
||||
import copy
|
||||
import logging
|
||||
import logging.config
|
||||
from enum import Enum
|
||||
from binascii import hexlify
|
||||
from struct import calcsize, unpack, pack
|
||||
from io import BytesIO
|
||||
import os
|
||||
import sys
|
||||
from binascii import crc32
|
||||
from binascii import hexlify
|
||||
from enum import Enum
|
||||
from struct import calcsize, unpack, pack
|
||||
|
||||
import colorama
|
||||
|
||||
|
||||
class ColorFormatter(logging.Formatter):
|
||||
LOG_COLORS = {
|
||||
|
|
|
@ -7,9 +7,8 @@
|
|||
# GPLv3 and has to be open sourced under GPLv3 as well. !!!!!
|
||||
|
||||
import logging
|
||||
from binascii import hexlify
|
||||
from struct import unpack
|
||||
import time
|
||||
from struct import unpack
|
||||
|
||||
MAX_PACKET_LEN = 4096
|
||||
|
||||
|
|
|
@ -5,13 +5,11 @@
|
|||
#
|
||||
# !!!!! If you use this code in commercial products, your product is automatically
|
||||
# GPLv3 and has to be open sourced under GPLv3 as well. !!!!!
|
||||
import binascii
|
||||
import time
|
||||
import inspect
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
import logging
|
||||
import inspect
|
||||
from struct import unpack, pack
|
||||
|
||||
current_dir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
|
||||
parent_dir = os.path.dirname(current_dir)
|
||||
sys.path.insert(0, parent_dir)
|
||||
|
@ -22,6 +20,7 @@ except:
|
|||
from Library.utils import read_object, print_progress, rmrf, LogBase
|
||||
from Config.qualcomm_config import sochw, msmids, root_cert_hash
|
||||
|
||||
|
||||
class loader_utils(metaclass=LogBase):
|
||||
def __init__(self, loglevel=logging.INFO):
|
||||
self.__logger = self.__logger
|
||||
|
@ -88,4 +87,3 @@ class loader_utils(metaclass=LogBase):
|
|||
rmsmid = '0' + rmsmid
|
||||
msmiddb.append(rmsmid)
|
||||
return msmiddb
|
||||
|
||||
|
|
|
@ -6,11 +6,11 @@
|
|||
# !!!!! If you use this code in commercial products, your product is automatically
|
||||
# GPLv3 and has to be open sourced under GPLv3 as well. !!!!!
|
||||
|
||||
import os
|
||||
import pt64
|
||||
import pt
|
||||
import argparse
|
||||
|
||||
import pt
|
||||
import pt64
|
||||
|
||||
|
||||
def pt64_walk(data, ttbr, tnsz, levels=3):
|
||||
print("Dumping page tables (levels=%d)" % levels)
|
||||
|
|
|
@ -87,6 +87,7 @@ def get_fld(mfld, level):
|
|||
return table_entry4k(mfld, level)
|
||||
return None
|
||||
|
||||
|
||||
class descriptor(object):
|
||||
def get_name(self):
|
||||
pass
|
||||
|
|
|
@ -5,21 +5,22 @@
|
|||
#
|
||||
# !!!!! If you use this code in commercial products, your product is automatically
|
||||
# GPLv3 and has to be open sourced under GPLv3 as well. !!!!!
|
||||
import binascii
|
||||
import time
|
||||
import inspect
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
import logging
|
||||
import inspect
|
||||
import time
|
||||
from struct import pack
|
||||
|
||||
current_dir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
|
||||
parent_dir = os.path.dirname(current_dir)
|
||||
sys.path.insert(0, parent_dir)
|
||||
from edlclient.Library.utils import read_object, print_progress, rmrf, LogBase
|
||||
from edlclient.Config.qualcomm_config import sochw, msmids, root_cert_hash
|
||||
from edlclient.Library.utils import print_progress, rmrf, LogBase
|
||||
from edlclient.Config.qualcomm_config import msmids, root_cert_hash
|
||||
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, \
|
||||
CommandHandler, SAHARA_VERSION
|
||||
CommandHandler
|
||||
|
||||
|
||||
class sahara(metaclass=LogBase):
|
||||
def __init__(self, cdc, loglevel):
|
||||
|
|
|
@ -12,9 +12,11 @@ from io import BytesIO
|
|||
SAHARA_VERSION = 2
|
||||
SAHARA_MIN_VERSION = 1
|
||||
|
||||
|
||||
class DataError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class cmd_t:
|
||||
SAHARA_HELLO_REQ = 0x1
|
||||
SAHARA_HELLO_RSP = 0x2
|
||||
|
@ -36,6 +38,7 @@ class cmd_t:
|
|||
SAHARA_64BIT_MEMORY_READ_DATA = 0x12
|
||||
SAHARA_RESET_STATE_MACHINE_ID = 0x13
|
||||
|
||||
|
||||
class cmd_t_version:
|
||||
SAHARA_HELLO_REQ = 0x1
|
||||
SAHARA_HELLO_RSP = 1
|
||||
|
@ -57,6 +60,7 @@ class cmd_t_version:
|
|||
SAHARA_64BIT_MEMORY_READ_DATA = 2
|
||||
SAHARA_RESET_STATE_MACHINE_ID = 2
|
||||
|
||||
|
||||
class exec_cmd_t:
|
||||
SAHARA_EXEC_CMD_NOP = 0x00
|
||||
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_TRAINING_DATA = 0x09
|
||||
|
||||
|
||||
class sahara_mode_t:
|
||||
SAHARA_MODE_IMAGE_TX_PENDING = 0x0
|
||||
SAHARA_MODE_IMAGE_TX_COMPLETE = 0x1
|
||||
|
|
|
@ -5,13 +5,13 @@
|
|||
#
|
||||
# !!!!! If you use this code in commercial products, your product is automatically
|
||||
# GPLv3 and has to be open sourced under GPLv3 as well. !!!!!
|
||||
import inspect
|
||||
import logging
|
||||
import sys
|
||||
import os
|
||||
import sys
|
||||
import inspect
|
||||
from queue import Queue
|
||||
from struct import unpack
|
||||
|
||||
current_dir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
|
||||
parent_dir = os.path.dirname(current_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_GPP4 = 0x28 # EMMC GPP partition 4
|
||||
|
||||
|
||||
class response_code_type:
|
||||
ACK = 0x00 # Successful
|
||||
RESERVED_1 = 0x01 # Reserved
|
||||
|
|
|
@ -5,20 +5,21 @@
|
|||
#
|
||||
# !!!!! If you use this code in commercial products, your product is automatically
|
||||
# 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.config
|
||||
import codecs
|
||||
import struct
|
||||
import os
|
||||
import shutil
|
||||
import stat
|
||||
import colorama
|
||||
import copy
|
||||
import datetime as dt
|
||||
import struct
|
||||
import sys
|
||||
import time
|
||||
from io import BytesIO
|
||||
from struct import unpack, pack
|
||||
from struct import unpack
|
||||
|
||||
import colorama
|
||||
|
||||
try:
|
||||
from capstone import *
|
||||
|
@ -124,7 +125,7 @@ class progress:
|
|||
def calcProcessTime(self, starttime, cur_iter, max_iter):
|
||||
telapsed = time.time() - starttime
|
||||
if telapsed > 0 and cur_iter > 0:
|
||||
testimated = (telapsed / cur_iter) * (max_iter)
|
||||
testimated = (telapsed / cur_iter) * max_iter
|
||||
finishtime = starttime + testimated
|
||||
finishtime = dt.datetime.fromtimestamp(finishtime).strftime("%H:%M:%S") # in time
|
||||
lefttime = testimated - telapsed # in seconds
|
||||
|
@ -575,7 +576,7 @@ class patchtools:
|
|||
badchars = self.has_bad_uart_chars(data)
|
||||
if not badchars:
|
||||
badchars = self.has_bad_uart_chars(data2)
|
||||
if not (badchars):
|
||||
if not badchars:
|
||||
return div
|
||||
div += 4
|
||||
|
||||
|
@ -685,7 +686,7 @@ class patchtools:
|
|||
continue
|
||||
rt += 1
|
||||
prep = data[rt:].find(t[i])
|
||||
if (prep != 0):
|
||||
if prep != 0:
|
||||
error = 1
|
||||
break
|
||||
rt += len(t[i])
|
||||
|
@ -699,7 +700,7 @@ class patchtools:
|
|||
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.
|
||||
"""
|
||||
|
|
|
@ -7,9 +7,10 @@
|
|||
# GPLv3 and has to be open sourced under GPLv3 as well. !!!!!
|
||||
# Beagle to EDL Loader
|
||||
|
||||
import os,sys
|
||||
import sys
|
||||
from struct import unpack
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2:
|
||||
print("Usage: ./beagle_to_loader.py [beagle_log.bin] [loader.elf]")
|
||||
|
@ -45,5 +46,6 @@ def main():
|
|||
|
||||
print("Done.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
|
@ -38,8 +38,9 @@ import logging.config
|
|||
import logging.handlers
|
||||
import colorama
|
||||
|
||||
|
||||
itoa64 = bytearray(b"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")
|
||||
|
||||
|
||||
def _crypt_to64(s, v, n):
|
||||
out = bytearray()
|
||||
while --n >= 0:
|
||||
|
@ -191,7 +192,8 @@ class connection:
|
|||
mode = "AT"
|
||||
break
|
||||
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"
|
||||
self.ZTE_Web()
|
||||
break
|
||||
|
@ -386,17 +388,14 @@ class adbtools(metaclass=LogBase):
|
|||
print("Sending switch command via diag")
|
||||
res = self.ZTE(cn, enable)
|
||||
elif info["vendor"] == "Simcom":
|
||||
res=self.Simcom(cn)
|
||||
res = self.Simcom(cn, enable)
|
||||
elif info["vendor"] == "Fibocom":
|
||||
res = self.Fibocom(cn, enable)
|
||||
elif info["vendor"] == "Alcatel":
|
||||
res = self.Alcatel(enable)
|
||||
elif info["vendor"] == "Samsung":
|
||||
res = self.Samsung(cn, enable)
|
||||
if enable:
|
||||
mode="enabled"
|
||||
else:
|
||||
mode="disabled"
|
||||
mode = "enabled" if enable else "disabled"
|
||||
if res:
|
||||
print("ADB successfully " + mode)
|
||||
else:
|
||||
|
|
|
@ -5,21 +5,24 @@
|
|||
#
|
||||
# !!!!! If you use this code in commercial products, your product is automatically
|
||||
# GPLv3 and has to be open sourced under GPLv3 as well. !!!!!
|
||||
import hashlib
|
||||
import inspect
|
||||
import os
|
||||
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 Library.utils import elf
|
||||
from Library.loader_db import loader_utils
|
||||
from os import walk
|
||||
from shutil import copyfile
|
||||
from struct import unpack
|
||||
|
||||
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())))
|
||||
|
||||
lu = loader_utils()
|
||||
|
||||
|
||||
class MBN:
|
||||
def __init__(self, memory):
|
||||
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
|
||||
casignature2offset = signatureoffset + len1
|
||||
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
|
||||
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
|
||||
casignature2offset = signatureoffset + len1
|
||||
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()
|
||||
idx = signatureoffset
|
||||
|
||||
|
@ -381,7 +386,8 @@ def main(argv):
|
|||
filelist.append(signinfo)
|
||||
break
|
||||
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)
|
||||
if signinfo is None:
|
||||
continue
|
||||
|
|
|
@ -90,7 +90,7 @@ subnvitem_type = [
|
|||
]
|
||||
|
||||
|
||||
class fs_factimage_read_info():
|
||||
class fs_factimage_read_info:
|
||||
def_fs_factimage_read_info = [
|
||||
("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
|
||||
|
@ -117,7 +117,7 @@ class fs_factimage_read_info():
|
|||
return data
|
||||
|
||||
|
||||
class FactoryHeader():
|
||||
class FactoryHeader:
|
||||
def_factory_header = [
|
||||
("magic1", "I"),
|
||||
("magic2", "I"),
|
||||
|
@ -160,7 +160,7 @@ class FactoryHeader():
|
|||
return data
|
||||
|
||||
|
||||
class nvitem():
|
||||
class nvitem:
|
||||
item = 0x0
|
||||
data = b""
|
||||
status = 0x0
|
||||
|
@ -409,7 +409,7 @@ class qcdiag(metaclass=LogBase):
|
|||
self.cdc.close(True)
|
||||
|
||||
def send(self, cmd):
|
||||
if self.hdlc != None:
|
||||
if self.hdlc is not None:
|
||||
return self.hdlc.send_cmd_np(cmd)
|
||||
|
||||
def cmd_info(self):
|
||||
|
@ -809,7 +809,7 @@ class qcdiag(metaclass=LogBase):
|
|||
return False
|
||||
|
||||
write_handle.close()
|
||||
if efserr == False:
|
||||
if not efserr:
|
||||
print("Successfully read EFS.")
|
||||
return True
|
||||
else:
|
||||
|
@ -1408,7 +1408,7 @@ def main():
|
|||
parser_nvwritesub.add_argument("-debugmode", help="[Option] Enable verbose logging", action="store_true")
|
||||
|
||||
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("-pid", metavar="<pid>", help="[Option] Specify pid", default="")
|
||||
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 colorama
|
||||
|
||||
|
||||
class ColorFormatter(logging.Formatter):
|
||||
LOG_COLORS = {
|
||||
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
|
||||
])
|
||||
|
||||
class SierraGenerator():
|
||||
|
||||
class SierraGenerator:
|
||||
tbl = bytearray()
|
||||
rtbl = bytearray()
|
||||
devicegeneration = None
|
||||
|
@ -425,7 +427,7 @@ class connection:
|
|||
def readreply(self):
|
||||
info = []
|
||||
if self.serial is not None:
|
||||
while (True):
|
||||
while True:
|
||||
tmp = self.serial.readline().decode('utf-8').replace('\r', '').replace('\n', '')
|
||||
if "OK" in info:
|
||||
return info
|
||||
|
@ -464,7 +466,7 @@ class SierraKeygen(metaclass=LogBase):
|
|||
def __init__(self, cn, devicegeneration=None):
|
||||
self.cn = cn
|
||||
self.keygen = SierraGenerator()
|
||||
if devicegeneration == None:
|
||||
if devicegeneration is None:
|
||||
self.detectdevicegeneration()
|
||||
else:
|
||||
self.devicegeneration = devicegeneration
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
import os, sys
|
||||
from struct import unpack
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2:
|
||||
print("Usage: ./txt_to_loader.py [log.txt] [loader.elf]")
|
||||
|
@ -53,5 +54,6 @@ def main():
|
|||
|
||||
print("Done.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Reference in a new issue