Patch improvement, oppo security

This commit is contained in:
Bjoern Kerler 2021-08-31 22:34:17 +02:00
parent 055190bcf3
commit 388e8d85ca
4 changed files with 15 additions and 15 deletions

3
mtk
View file

@ -63,7 +63,8 @@ class Mtk(metaclass=LogBase):
patched = False
data = bytearray(data)
patches = [
("B3F5807F01D1", "B3F5807F01D14FF000004FF000007047"), #confirmed : mt6739 c30
("A3687BB12846","0123A3602846"), #oppo security
("B3F5807F01D1", "B3F5807F01D14FF000004FF000007047"), #confirmed : mt6739 c30, mt6833
("B3F5807F04BF4FF4807305F011B84FF0FF307047", "B3F5807F04BF4FF480734FF000004FF000007047"),
]

View file

@ -564,8 +564,10 @@ class Preloader(metaclass=LogBase):
data = (data[:maxsize] + sigdata)
if len(data + sigdata) % 2 != 0:
data += b"\x00"
for i in range(0, len(data), 2):
gen_chksum ^= unpack("<H", data[i:i + 2])[0]
for x in range(0, len(data), 2):
gen_chksum ^= unpack("<H", data[x:x + 2])[0] #3CDC
if len(data)&1!=0:
gen_chksum ^= data[-1:]
return gen_chksum, data
def upload_data(self, data, gen_chksum):
@ -580,8 +582,7 @@ class Preloader(metaclass=LogBase):
try:
checksum, status = self.rword(2)
if gen_chksum != checksum and checksum != 0:
self.error("Checksum of upload doesn't match !")
return False
self.warning("Checksum of upload doesn't match !")
if 0 <= status <= 0xFF:
return True
else:

View file

@ -5,6 +5,6 @@ default_ids = [
[0x0E8D, 0x2001, -1], # MTK Preloader
[0x0E8D, 0x20FF, -1], # MTK Preloader
[0x1004, 0x6000, 2], # LG Preloader
[0x22d9, 0x0006, 2], # OPPO Preloader
[0x22d9, 0x0006, -1], # OPPO Preloader
[0x1a86, 0x7523, 0]
]

16
stage2
View file

@ -14,6 +14,7 @@ from mtkclient.Library.utils import LogBase
from mtkclient.Library.utils import print_progress
from mtkclient.Library.hwcrypto import crypto_setup, hwcrypto
from mtkclient.config.brom_config import Mtk_Config
from mtkclient.config.usb_ids import default_ids
class Stage2(metaclass=LogBase):
def __init__(self, args, loglevel=logging.INFO):
@ -37,8 +38,7 @@ class Stage2(metaclass=LogBase):
else:
self.__logger.setLevel(logging.INFO)
portconfig = [[0x0E8D, 0x0003, -1], [0x0E8D, 0x2000, -1]]
self.cdc = usb_class(portconfig=portconfig, loglevel=loglevel, devclass=10)
self.cdc = usb_class(portconfig=default_ids, loglevel=loglevel, devclass=10)
def preinit(self):
try:
@ -494,6 +494,8 @@ def main():
parser_keys = subparsers.add_parser("keys", help="Write memory")
parser_keys.add_argument('--otp', dest='otp', type=str,
help='OTP for keys (dxcc,sej,gcpu)')
parser_keys.add_argument('--mode', dest='mode', default=None, type=str,
help='keymode (dxcc,sej,gcpu)')
args = parser.parse_args()
cmd = args.cmd
if cmd not in cmds:
@ -555,6 +557,7 @@ def main():
print(f"Failed to write data to {hex(start)}.")
elif cmd == "keys":
keyinfo=""
data=b""
if st2.hwcrypto.meid_addr:
meid = st2.memread(st2.hwcrypto.meid_addr, 16)
keyinfo+=f"MEID: {hexlify(meid).decode('utf-8')}\n"
@ -565,21 +568,16 @@ def main():
keyinfo += f"SOCID: {hexlify(socid).decode('utf-8')}\n"
with open(os.path.join("logs", "socid.txt"), "wb") as wf:
wf.write(hexlify(meid))
if args.mode is None:
print("Option --mode is needed")
exit(0)
if args.mode == "sej":
if st2.setup.sej_base or args.mode == "sej":
data = meid
# if not args.otp:
# print("Option --otp is needed")
# exit(0)
elif args.mode == "sej_aes_decrypt" or args.mode == "sej_aes_encrypt":
if args.mode == "sej_aes_decrypt" or args.mode == "sej_aes_encrypt":
if not args.data:
print("Option --data is needed")
exit(0)
data = bytes.fromhex(args.data)
else:
data = b""
# otp_hisense=bytes.fromhex("486973656E736500000000000000000000000000000000000000000000000000")
# st2.jump(0x223449)
keyinfo+=st2.keys(data=data, mode=args.mode, otp=args.otp)