mirror of
https://github.com/bkerler/edl.git
synced 2024-11-14 11:05:05 -05:00
Normative code
This commit is contained in:
parent
1a1bec8671
commit
3b9a6927fb
10 changed files with 27 additions and 30 deletions
|
@ -172,7 +172,7 @@ class serial_class(DeviceClass):
|
|||
bytestoread = resplen - len(info)
|
||||
extend(info)
|
||||
if b"<?xml " in info:
|
||||
while not b"response " in res or res[-7:] != b"</data>":
|
||||
while b"response " not in res or res[-7:] != b"</data>":
|
||||
extend(epr(1))
|
||||
return res
|
||||
bytestoread = resplen
|
||||
|
|
|
@ -337,7 +337,7 @@ class usb_class(DeviceClass):
|
|||
|
||||
def write(self, command, pktsize=None):
|
||||
if pktsize is None:
|
||||
#pktsize = self.EP_OUT.wMaxPacketSize
|
||||
# pktsize = self.EP_OUT.wMaxPacketSize
|
||||
pktsize = MAX_USB_BULK_BUFFER_SIZE
|
||||
if isinstance(command, str):
|
||||
command = bytes(command, 'utf-8')
|
||||
|
|
|
@ -575,11 +575,11 @@ def main():
|
|||
op2 = oneplus(None, projid="20889", serial=serial, ATOBuild=0, Flash_Mode=0, cf=0)
|
||||
op2.ops.device_timestamp = int(device_timestamp)
|
||||
# 20889 OP N10 5G Europe
|
||||
print(f"./edl.py rawxml \"<?xml version=\\\"1.0\\\" ?><data><setprocstart /></data>\"")
|
||||
print('./edl.py rawxml "<?xml version=\\"1.0\\" ?><data><setprocstart /></data>"')
|
||||
# Response should be : <?xml version="1.0" ?><data><response value=1 device_timestamp="%llu" /></data>
|
||||
pk, token = op2.generatetoken(False)
|
||||
print(
|
||||
f"./edl.py rawxml \"<?xml version=\\\"1.0\\\" ?><data><setswprojmodel " +
|
||||
'./edl.py rawxml "<?xml version=\\"1.0\\" ?><data><setswprojmodel ' +
|
||||
f"token=\\\"{token}\\\" pk=\\\"{pk}\\\" /></data>\" --debugmode")
|
||||
elif args["setprojmodel_verify"]:
|
||||
projid = args["--projid"][0]
|
||||
|
@ -618,8 +618,7 @@ def main():
|
|||
|
||||
|
||||
def test_setswprojmodel_verify():
|
||||
deviceresp = b"RX:<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\nRX:<data>\nRX:<response value=\"ACK\" " + \
|
||||
b"device_timestamp=\"2507003650\" /></data>\n<?xmlversion=\"1.0\" ? ><data><setprocstart /></data>"
|
||||
deviceresp = b'RX:<?xml version="1.0" encoding="UTF-8" ?>\nRX:<data>\nRX:<response value="ACK" device_timestamp="2507003650" /></data>\n<?xmlversion="1.0" ? ><data><setprocstart /></data>'
|
||||
projid = "20889"
|
||||
op = oneplus(None, projid=projid, serial=123456)
|
||||
data = deviceresp.decode('utf-8')
|
||||
|
|
|
@ -328,7 +328,7 @@ class firehose(metaclass=LogBase):
|
|||
def cmd_reset(self, mode="reset"):
|
||||
if mode is None:
|
||||
mode = "reset"
|
||||
data = "<?xml version=\"1.0\" ?><data><power value=\"" + mode + "\"/></data>"
|
||||
data = f'<?xml version="1.0" ?><data><power value="{mode}"/></data>'
|
||||
val = self.xmlsend(data)
|
||||
try:
|
||||
v = None
|
||||
|
@ -361,7 +361,7 @@ class firehose(metaclass=LogBase):
|
|||
return val.error
|
||||
|
||||
def cmd_nop(self):
|
||||
data = "<?xml version=\"1.0\" ?><data><nop /></data>"
|
||||
data = '<?xml version="1.0" ?><data><nop /></data>'
|
||||
resp = self.xmlsend(data, True)
|
||||
self.debug(resp.data.hex())
|
||||
info = b""
|
||||
|
@ -1241,7 +1241,7 @@ class firehose(metaclass=LogBase):
|
|||
if len(imei) != 16:
|
||||
self.info("IMEI must be 16 digits")
|
||||
return False
|
||||
data = "<?xml version=\"1.0\" ?><data><writeIMEI len=\"16\"/></data>"
|
||||
data = '<?xml version="1.0" ?><data><writeIMEI len="16"/></data>'
|
||||
val = self.xmlsend(data)
|
||||
if val.resp:
|
||||
self.info("writeIMEI succeeded.")
|
||||
|
@ -1251,7 +1251,7 @@ class firehose(metaclass=LogBase):
|
|||
return False
|
||||
|
||||
def cmd_getstorageinfo(self):
|
||||
data = "<?xml version=\"1.0\" ?><data><getstorageinfo physical_partition_number=\"0\"/></data>"
|
||||
data = '<?xml version="1.0" ?><data><getstorageinfo physical_partition_number="0"/></data>'
|
||||
val = self.xmlsend(data)
|
||||
if val.data == '' and val.log == '' and val.resp:
|
||||
return None
|
||||
|
@ -1266,7 +1266,7 @@ class firehose(metaclass=LogBase):
|
|||
if len(v) > 1:
|
||||
res[v[0]] = v[1]
|
||||
else:
|
||||
if "\"storage_info\"" in value:
|
||||
if '"storage_info"' in value:
|
||||
try:
|
||||
info = value.replace("INFO:", "")
|
||||
si = json.loads(info)["storage_info"]
|
||||
|
@ -1524,7 +1524,7 @@ class firehose(metaclass=LogBase):
|
|||
def cmd_test(self, cmd):
|
||||
token = "1234"
|
||||
pk = "1234"
|
||||
data = "<?xml version=\"1.0\" ?>\n<data>\n<" + cmd + " token=\"" + token + "\" pk=\"" + pk + "\" />\n</data>"
|
||||
data = f'<?xml version="1.0" ?>\n<data>\n<{cmd} token="{token}" pk="{pk}" />\n</data>'
|
||||
val = self.xmlsend(data)
|
||||
if val.resp:
|
||||
if b"raw hex token" in val[2]:
|
||||
|
@ -1534,7 +1534,7 @@ class firehose(metaclass=LogBase):
|
|||
return False
|
||||
|
||||
def cmd_getstorageinfo_string(self):
|
||||
data = "<?xml version=\"1.0\" ?><data><getstorageinfo /></data>"
|
||||
data = '<?xml version="1.0" ?><data><getstorageinfo /></data>'
|
||||
val = self.xmlsend(data)
|
||||
if val.resp:
|
||||
self.info(f"GetStorageInfo:\n--------------------\n")
|
||||
|
|
|
@ -194,7 +194,6 @@ AB_SLOT_INACTIVE_VAL = 0x0
|
|||
AB_SLOT_ACTIVE = 1
|
||||
AB_SLOT_INACTIVE = 0
|
||||
|
||||
|
||||
PART_ATT_PRIORITY_BIT = 48
|
||||
PART_ATT_ACTIVE_BIT = 50
|
||||
PART_ATT_MAX_RETRY_CNT_BIT = 51
|
||||
|
@ -205,7 +204,7 @@ PART_ATT_UNBOOTABLE_BIT = 55
|
|||
PART_ATT_PRIORITY_VAL = 0x3 << PART_ATT_PRIORITY_BIT
|
||||
PART_ATT_ACTIVE_VAL = 0x1 << PART_ATT_ACTIVE_BIT
|
||||
PART_ATT_MAX_RETRY_COUNT_VAL = 0x7 << PART_ATT_MAX_RETRY_CNT_BIT
|
||||
PART_ATT_SUCCESSFUL_VAL = 0x1 << PART_ATT_SUCCESS_BIT
|
||||
PART_ATT_SUCCESSFUL_VAL = 0x1 << PART_ATT_SUCCESS_BIT
|
||||
PART_ATT_UNBOOTABLE_VAL = 0x1 << PART_ATT_UNBOOTABLE_BIT
|
||||
|
||||
|
||||
|
@ -350,7 +349,6 @@ class gpt(metaclass=LogBase):
|
|||
def parseheader(self, gptdata, sectorsize=512):
|
||||
return self.gpt_header(gptdata[sectorsize:sectorsize + 0x5C])
|
||||
|
||||
|
||||
def parse(self, gptdata, sectorsize=512):
|
||||
self.header = self.gpt_header(gptdata[sectorsize:sectorsize + 0x5C])
|
||||
self.sectorsize = sectorsize
|
||||
|
@ -362,7 +360,7 @@ class gpt(metaclass=LogBase):
|
|||
if self.part_entry_start_lba != 0:
|
||||
start = self.part_entry_start_lba
|
||||
else:
|
||||
start = 2 * sectorsize # mbr + header + part_table
|
||||
start = 2 * sectorsize # mbr + header + part_table
|
||||
|
||||
entrysize = self.header.part_entry_size
|
||||
self.partentries = {}
|
||||
|
@ -404,7 +402,7 @@ class gpt(metaclass=LogBase):
|
|||
pa.name = partentry.name.replace(b"\x00\x00", b"").decode('utf-16')
|
||||
if pa.type == "EFI_UNUSED":
|
||||
continue
|
||||
self.partentries[pa.name]=pa
|
||||
self.partentries[pa.name] = pa
|
||||
self.totalsectors = self.header.first_usable_lba + self.header.last_usable_lba
|
||||
return True
|
||||
|
||||
|
@ -415,7 +413,8 @@ class gpt(metaclass=LogBase):
|
|||
mstr = "\nGPT Table:\n-------------\n"
|
||||
for partitionname in self.partentries:
|
||||
partition = self.partentries[partitionname]
|
||||
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
|
||||
mstr += ("{:20} Offset 0x{:016x}, Length 0x{:016x}, Flags 0x{:016x}, UUID {}, Type {}, Active {}\n".format(
|
||||
partition.name + ":", partition.sector * self.sectorsize, partition.sectors * self.sectorsize,
|
||||
partition.flags, partition.unique, partition.type, active))
|
||||
|
@ -566,12 +565,12 @@ if __name__ == "__main__":
|
|||
with open(args.image, "rb") as rf:
|
||||
size = min(32 * 4096, filesize)
|
||||
data = bytearray(rf.read(size))
|
||||
pdata, poffset = gp.patch(data,partitition, active=active)
|
||||
pdata, poffset = gp.patch(data, partitition, active=active)
|
||||
data[poffset:poffset + len(pdata)] = pdata
|
||||
wdata = gp.fix_gpt_crc(data)
|
||||
if data is not None:
|
||||
wfilename = args.image + ".patched"
|
||||
with open(wfilename,"wb") as wf:
|
||||
with open(wfilename, "wb") as wf:
|
||||
wf.write(wdata)
|
||||
print(f"Successfully wrote patched gpt to {wfilename}")
|
||||
else:
|
||||
|
|
|
@ -153,8 +153,8 @@ class hdlc:
|
|||
data = unescape(replybuf)
|
||||
# print(hexlify(data))
|
||||
if len(data) > 3:
|
||||
if data[0]==0x7E:
|
||||
data=data[1:]
|
||||
if data[0] == 0x7E:
|
||||
data = data[1:]
|
||||
crc16val = crc16(0xFFFF, data[:-3])
|
||||
reccrc = int(data[-3]) + (int(data[-2]) << 8)
|
||||
if crc16val != reccrc:
|
||||
|
|
|
@ -50,7 +50,7 @@ def pt32_walk(data, ttbr, skip):
|
|||
i += 1
|
||||
if i <= skip:
|
||||
continue
|
||||
if type(fl) == pt.pt_desc:
|
||||
if isinstance(fl, pt.pt_desc):
|
||||
print("")
|
||||
print("Second level (va = %08x)" % va)
|
||||
print("---------------------------------------------")
|
||||
|
|
|
@ -17,8 +17,7 @@ parent_dir = os.path.dirname(current_dir)
|
|||
sys.path.insert(0, parent_dir)
|
||||
from edlclient.Library.utils import LogBase, print_progress
|
||||
|
||||
|
||||
MAX_STORE_SIZE = 1024 * 1024 * 1024 * 2 # 2 GBs
|
||||
MAX_STORE_SIZE = 1024 * 1024 * 1024 * 2 # 2 GBs
|
||||
|
||||
|
||||
class QCSparse(metaclass=LogBase):
|
||||
|
@ -183,13 +182,13 @@ class QCSparse(metaclass=LogBase):
|
|||
if length is None:
|
||||
return self.unsparse()
|
||||
if (self.tmp_offset + length) <= len(self.tmpdata):
|
||||
tdata = self.tmpdata[self.tmp_offset : self.tmp_offset + length]
|
||||
tdata = self.tmpdata[self.tmp_offset: self.tmp_offset + length]
|
||||
self.tmp_offset += length
|
||||
return tdata
|
||||
while (self.tmp_offset + length) > len(self.tmpdata):
|
||||
self.tmpdata.extend(self.unsparse())
|
||||
if (self.tmp_offset + length) <= len(self.tmpdata):
|
||||
tdata = self.tmpdata[self.tmp_offset : self.tmp_offset + length]
|
||||
tdata = self.tmpdata[self.tmp_offset: self.tmp_offset + length]
|
||||
self.tmp_offset += length
|
||||
return tdata
|
||||
|
||||
|
|
|
@ -508,7 +508,7 @@ class SierraKeygen(metaclass=LogBase):
|
|||
devicegeneration = "MDM9x30_V1"
|
||||
else:
|
||||
devicegeneration = "MDM9x30"
|
||||
elif "9X40" in revision and not "9X40C" in revision:
|
||||
elif "9X40" in revision and "9X40C" not in revision:
|
||||
devicegeneration = "MDM9x40"
|
||||
elif "9X50" in revision:
|
||||
if "NTG9X50" in revision:
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Challenge/Response Generator for Sierra Wireless Cards V1.2
|
||||
(c) B. Kerler 2019-2023
|
||||
(c) B. Kerler 2019-2024
|
||||
GPLv3 License
|
||||
|
||||
## Why
|
||||
|
|
Loading…
Reference in a new issue