Normative code

This commit is contained in:
ColdWindScholar 2024-06-10 01:44:14 +08:00
parent 1a1bec8671
commit 3b9a6927fb
10 changed files with 27 additions and 30 deletions

View file

@ -172,7 +172,7 @@ class serial_class(DeviceClass):
bytestoread = resplen - len(info) bytestoread = resplen - len(info)
extend(info) extend(info)
if b"<?xml " in 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)) extend(epr(1))
return res return res
bytestoread = resplen bytestoread = resplen

View file

@ -337,7 +337,7 @@ class usb_class(DeviceClass):
def write(self, command, pktsize=None): def write(self, command, pktsize=None):
if pktsize is None: if pktsize is None:
#pktsize = self.EP_OUT.wMaxPacketSize # pktsize = self.EP_OUT.wMaxPacketSize
pktsize = MAX_USB_BULK_BUFFER_SIZE pktsize = MAX_USB_BULK_BUFFER_SIZE
if isinstance(command, str): if isinstance(command, str):
command = bytes(command, 'utf-8') command = bytes(command, 'utf-8')

View file

@ -575,11 +575,11 @@ def main():
op2 = oneplus(None, projid="20889", serial=serial, ATOBuild=0, Flash_Mode=0, cf=0) op2 = oneplus(None, projid="20889", serial=serial, ATOBuild=0, Flash_Mode=0, cf=0)
op2.ops.device_timestamp = int(device_timestamp) op2.ops.device_timestamp = int(device_timestamp)
# 20889 OP N10 5G Europe # 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> # Response should be : <?xml version="1.0" ?><data><response value=1 device_timestamp="%llu" /></data>
pk, token = op2.generatetoken(False) pk, token = op2.generatetoken(False)
print( 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") f"token=\\\"{token}\\\" pk=\\\"{pk}\\\" /></data>\" --debugmode")
elif args["setprojmodel_verify"]: elif args["setprojmodel_verify"]:
projid = args["--projid"][0] projid = args["--projid"][0]
@ -618,8 +618,7 @@ def main():
def test_setswprojmodel_verify(): def test_setswprojmodel_verify():
deviceresp = b"RX:<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\nRX:<data>\nRX:<response value=\"ACK\" " + \ 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>'
b"device_timestamp=\"2507003650\" /></data>\n<?xmlversion=\"1.0\" ? ><data><setprocstart /></data>"
projid = "20889" projid = "20889"
op = oneplus(None, projid=projid, serial=123456) op = oneplus(None, projid=projid, serial=123456)
data = deviceresp.decode('utf-8') data = deviceresp.decode('utf-8')

View file

@ -328,7 +328,7 @@ class firehose(metaclass=LogBase):
def cmd_reset(self, mode="reset"): def cmd_reset(self, mode="reset"):
if mode is None: if mode is None:
mode = "reset" 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) val = self.xmlsend(data)
try: try:
v = None v = None
@ -361,7 +361,7 @@ class firehose(metaclass=LogBase):
return val.error return val.error
def cmd_nop(self): 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) resp = self.xmlsend(data, True)
self.debug(resp.data.hex()) self.debug(resp.data.hex())
info = b"" info = b""
@ -1241,7 +1241,7 @@ class firehose(metaclass=LogBase):
if len(imei) != 16: if len(imei) != 16:
self.info("IMEI must be 16 digits") self.info("IMEI must be 16 digits")
return False 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) val = self.xmlsend(data)
if val.resp: if val.resp:
self.info("writeIMEI succeeded.") self.info("writeIMEI succeeded.")
@ -1251,7 +1251,7 @@ class firehose(metaclass=LogBase):
return False return False
def cmd_getstorageinfo(self): 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) val = self.xmlsend(data)
if val.data == '' and val.log == '' and val.resp: if val.data == '' and val.log == '' and val.resp:
return None return None
@ -1266,7 +1266,7 @@ class firehose(metaclass=LogBase):
if len(v) > 1: if len(v) > 1:
res[v[0]] = v[1] res[v[0]] = v[1]
else: else:
if "\"storage_info\"" in value: if '"storage_info"' in value:
try: try:
info = value.replace("INFO:", "") info = value.replace("INFO:", "")
si = json.loads(info)["storage_info"] si = json.loads(info)["storage_info"]
@ -1524,7 +1524,7 @@ class firehose(metaclass=LogBase):
def cmd_test(self, cmd): def cmd_test(self, cmd):
token = "1234" token = "1234"
pk = "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) val = self.xmlsend(data)
if val.resp: if val.resp:
if b"raw hex token" in val[2]: if b"raw hex token" in val[2]:
@ -1534,7 +1534,7 @@ class firehose(metaclass=LogBase):
return False return False
def cmd_getstorageinfo_string(self): 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) val = self.xmlsend(data)
if val.resp: if val.resp:
self.info(f"GetStorageInfo:\n--------------------\n") self.info(f"GetStorageInfo:\n--------------------\n")

View file

@ -194,7 +194,6 @@ AB_SLOT_INACTIVE_VAL = 0x0
AB_SLOT_ACTIVE = 1 AB_SLOT_ACTIVE = 1
AB_SLOT_INACTIVE = 0 AB_SLOT_INACTIVE = 0
PART_ATT_PRIORITY_BIT = 48 PART_ATT_PRIORITY_BIT = 48
PART_ATT_ACTIVE_BIT = 50 PART_ATT_ACTIVE_BIT = 50
PART_ATT_MAX_RETRY_CNT_BIT = 51 PART_ATT_MAX_RETRY_CNT_BIT = 51
@ -350,7 +349,6 @@ class gpt(metaclass=LogBase):
def parseheader(self, gptdata, sectorsize=512): def parseheader(self, gptdata, sectorsize=512):
return self.gpt_header(gptdata[sectorsize:sectorsize + 0x5C]) return self.gpt_header(gptdata[sectorsize:sectorsize + 0x5C])
def parse(self, gptdata, sectorsize=512): def parse(self, gptdata, sectorsize=512):
self.header = self.gpt_header(gptdata[sectorsize:sectorsize + 0x5C]) self.header = self.gpt_header(gptdata[sectorsize:sectorsize + 0x5C])
self.sectorsize = sectorsize self.sectorsize = sectorsize
@ -404,7 +402,7 @@ class gpt(metaclass=LogBase):
pa.name = partentry.name.replace(b"\x00\x00", b"").decode('utf-16') pa.name = partentry.name.replace(b"\x00\x00", b"").decode('utf-16')
if pa.type == "EFI_UNUSED": if pa.type == "EFI_UNUSED":
continue continue
self.partentries[pa.name]=pa self.partentries[pa.name] = pa
self.totalsectors = self.header.first_usable_lba + self.header.last_usable_lba self.totalsectors = self.header.first_usable_lba + self.header.last_usable_lba
return True return True
@ -415,7 +413,8 @@ class gpt(metaclass=LogBase):
mstr = "\nGPT Table:\n-------------\n" mstr = "\nGPT Table:\n-------------\n"
for partitionname in self.partentries: for partitionname in self.partentries:
partition = self.partentries[partitionname] 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( 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.name + ":", partition.sector * self.sectorsize, partition.sectors * self.sectorsize,
partition.flags, partition.unique, partition.type, active)) partition.flags, partition.unique, partition.type, active))
@ -566,12 +565,12 @@ if __name__ == "__main__":
with open(args.image, "rb") as rf: with open(args.image, "rb") as rf:
size = min(32 * 4096, filesize) size = min(32 * 4096, filesize)
data = bytearray(rf.read(size)) 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 data[poffset:poffset + len(pdata)] = pdata
wdata = gp.fix_gpt_crc(data) wdata = gp.fix_gpt_crc(data)
if data is not None: if data is not None:
wfilename = args.image + ".patched" wfilename = args.image + ".patched"
with open(wfilename,"wb") as wf: with open(wfilename, "wb") as wf:
wf.write(wdata) wf.write(wdata)
print(f"Successfully wrote patched gpt to {wfilename}") print(f"Successfully wrote patched gpt to {wfilename}")
else: else:

View file

@ -153,8 +153,8 @@ class hdlc:
data = unescape(replybuf) data = unescape(replybuf)
# print(hexlify(data)) # print(hexlify(data))
if len(data) > 3: if len(data) > 3:
if data[0]==0x7E: if data[0] == 0x7E:
data=data[1:] data = data[1:]
crc16val = crc16(0xFFFF, data[:-3]) crc16val = crc16(0xFFFF, data[:-3])
reccrc = int(data[-3]) + (int(data[-2]) << 8) reccrc = int(data[-3]) + (int(data[-2]) << 8)
if crc16val != reccrc: if crc16val != reccrc:

View file

@ -50,7 +50,7 @@ def pt32_walk(data, ttbr, skip):
i += 1 i += 1
if i <= skip: if i <= skip:
continue continue
if type(fl) == pt.pt_desc: if isinstance(fl, pt.pt_desc):
print("") print("")
print("Second level (va = %08x)" % va) print("Second level (va = %08x)" % va)
print("---------------------------------------------") print("---------------------------------------------")

View file

@ -17,7 +17,6 @@ parent_dir = os.path.dirname(current_dir)
sys.path.insert(0, parent_dir) sys.path.insert(0, parent_dir)
from edlclient.Library.utils import LogBase, print_progress 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
@ -183,13 +182,13 @@ class QCSparse(metaclass=LogBase):
if length is None: if length is None:
return self.unsparse() return self.unsparse()
if (self.tmp_offset + length) <= len(self.tmpdata): 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 self.tmp_offset += length
return tdata return tdata
while (self.tmp_offset + length) > len(self.tmpdata): while (self.tmp_offset + length) > len(self.tmpdata):
self.tmpdata.extend(self.unsparse()) self.tmpdata.extend(self.unsparse())
if (self.tmp_offset + length) <= len(self.tmpdata): 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 self.tmp_offset += length
return tdata return tdata

View file

@ -508,7 +508,7 @@ class SierraKeygen(metaclass=LogBase):
devicegeneration = "MDM9x30_V1" devicegeneration = "MDM9x30_V1"
else: else:
devicegeneration = "MDM9x30" devicegeneration = "MDM9x30"
elif "9X40" in revision and not "9X40C" in revision: elif "9X40" in revision and "9X40C" not in revision:
devicegeneration = "MDM9x40" devicegeneration = "MDM9x40"
elif "9X50" in revision: elif "9X50" in revision:
if "NTG9X50" in revision: if "NTG9X50" in revision:

View file

@ -1,5 +1,5 @@
# Challenge/Response Generator for Sierra Wireless Cards V1.2 # Challenge/Response Generator for Sierra Wireless Cards V1.2
(c) B. Kerler 2019-2023 (c) B. Kerler 2019-2024
GPLv3 License GPLv3 License
## Why ## Why