Skip to content

Commit

Permalink
Update pyside2 to pyside6
Browse files Browse the repository at this point in the history
  • Loading branch information
bkerler committed Dec 31, 2021
1 parent d9625d1 commit 3c77a1b
Show file tree
Hide file tree
Showing 28 changed files with 686 additions and 412 deletions.
6 changes: 3 additions & 3 deletions mtk_gui
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import traceback
import math
import logging
import ctypes
from PySide2.QtCore import Qt, QVariantAnimation, Signal, QObject, QSize, QTranslator, QLocale, QLibraryInfo
from PySide2.QtGui import QTextOption, QPixmap, QTransform, QIcon
from PySide2.QtWidgets import QMainWindow, QApplication, QAction, QWidget
from PySide6.QtCore import Qt, QVariantAnimation, Signal, QObject, QSize, QTranslator, QLocale, QLibraryInfo
from PySide6.QtGui import QTextOption, QPixmap, QTransform, QIcon, QAction
from PySide6.QtWidgets import QMainWindow, QApplication, QWidget

from mtkclient.Library.mtk import Mtk
from mtkclient.Library.mtk_da_cmd import DA_handler
Expand Down
36 changes: 24 additions & 12 deletions mtkclient/Library/hwcrypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from mtkclient.Library.hwcrypto_dxcc import dxcc
from mtkclient.Library.hwcrypto_sej import sej
from mtkclient.Library.cqdma import cqdma
from struct import unpack

class crypto_setup:
hwcode = None
Expand Down Expand Up @@ -42,6 +43,29 @@ def __init__(self, setup, loglevel=logging.INFO, gui:bool=False):
self.socid_addr = setup.socid_addr
self.prov_addr = setup.prov_addr

def mtee(self, filename, offset):
with open(filename, "rb") as rf:
rf.seek(offset + 8)
pos = unpack("<I", rf.read(4))[0]
rf.seek(offset + 0x14)
length = unpack("<I", rf.read(4))[0]
rf.seek(offset + 0x1C)
seed = rf.read(0x20)
rf.seek(offset + pos)
data = rf.read(length)
self.gcpu.init()
self.gcpu.acquire()
self.write32(0x1000009C, self.read32(0x1000009C) | 0x8000000)
self.write32(0x1020D000, self.read32(0x1020D000) & 0xFFFFFFF0)
self.write32(0x1020D000, self.read32(0x1020D000) | 0xF)
res = self.read32(0x1020D004) | 0x10000
self.write32(0x1020D000, self.read32(0x1020D000) & 0xFFFFFFE0)
self.write32(0x1020D004, self.read32(0x1020D004) | 0x10000)
self.write32(0x1020D000, self.read32(0x1020D000) | 0x1F)
self.write32(0x1020D004, self.read32(0x1020D004) | 0x2000)

return self.gcpu.mtk_gcpu_decrypt_mtee_img(data, seed)

def aes_hwcrypt(self, data=b"", iv=None, encrypt=True, otp=None, mode="cbc", btype="sej"):
if otp is None:
otp=32*b"\00"
Expand All @@ -64,18 +88,6 @@ def aes_hwcrypt(self, data=b"", iv=None, encrypt=True, otp=None, mode="cbc", bty
elif mode == "cbc":
if self.gcpu.aes_setup_cbc(addr=addr, data=data, iv=iv, encrypt=encrypt):
return self.gcpu.aes_read_cbc(addr=addr, encrypt=encrypt)
"""
elif mode == "mtee":
path = "tee_tee.bin"
with open(path,"rb") as rf:
rf.seek(0x240)
data=rf.read(0x25D3C0)
rf.seek(0x1C)
seed=rf.read(0x20)
self.gcpu.init()
self.gcpu.acquire()
self.gcpu.mtk_gcpu_decrypt_mtee_img(data,seed)
"""
elif btype == "dxcc":
if mode == "fde":
return self.dxcc.generate_rpmb(1)
Expand Down
35 changes: 20 additions & 15 deletions mtkclient/Library/hwcrypto_gcpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ def reset(self):
self.reg.GCPU_REG_CTL = ctl | 0x1f

def init(self):
keyslot = 18
ivslot = 26
keyslot = 0x12
ivslot = 0x1A
self.reg.GCPU_REG_MEM_P2 = 0x0
self.reg.GCPU_REG_MEM_P3 = 0x0
self.reg.GCPU_REG_MEM_P4 = 0x0
Expand Down Expand Up @@ -238,14 +238,14 @@ def mem_write(self, addr: int, data):
self.reg.GCPU_REG_MEM_DATA = data

def acquire(self):
if self.hwcode in [0x8172, 0x8127]:
if self.hwcode in [0x8172, 0x8127, None]:
self.release()
self.reg.GCPU_REG_MSC = self.reg.GCPU_REG_MSC & 0xFFFFDFFF
else:
self.reg.GCPU_REG_CTL = [0x1F, 0x12000]

def release(self):
if self.hwcode in [0x8172, 0x8127]:
if self.hwcode in [0x8172, 0x8127, None]:
self.reg.GCPU_REG_CTL = self.reg.GCPU_REG_CTL & 0xFFFFFFF0
self.reg.GCPU_REG_CTL = self.reg.GCPU_REG_CTL | 0xF

Expand Down Expand Up @@ -380,9 +380,9 @@ def readmem(self, addr, length):
return b"".join([pack("<I", val) for val in self.read32(addr, length // 4)])

def mtk_gcpu_decrypt_mtee_img(self, data, seed):
src = 0x68000000
dst = 0x68000000
data = data[:0x200]
src = 0x43001240
dst = 0x43001000
#data = data[:0x200]
self.write32(src, to_dwords(data))
aeskey1 = bytes.fromhex("A5DA42C3B4F6C5BAE162C568ADBD2605")
aeskey2 = bytes.fromhex("5572247C05586BAA37818D2868949ADB")
Expand All @@ -393,17 +393,22 @@ def mtk_gcpu_decrypt_mtee_img(self, data, seed):
self.reg.GCPU_REG_MEM_P0 = 1
self.reg.GCPU_REG_MEM_P2 = 0x16
self.reg.GCPU_REG_MEM_P3 = 0x1A
self.cmd(AESPK_D) # 0x78
out = bytearray()
for i in range(4):
val = unpack("<I", seed[0x10 + (i * 4):0x10 + (i * 4) + 4])[0]
out.extend(pack("<I", unpack("<I", aeskey2[i * 4:(i * 4) + 4])[0] ^ val))
self.memptr_set(0x12, out)
self.cmd(AESPK_D) # 0x78
seed=bytearray(seed)
aeskey2=bytearray(aeskey2)
for i in range(0x10):
v=seed[0x10 + i:0x10 + i + 1][0]
b=aeskey2[i]
r = v ^ b
aeskey2[i] = r
self.info(hexlify(aeskey2))
self.memptr_set(0x12, aeskey2)
self.reg.GCPU_REG_MEM_P0 = src
self.reg.GCPU_REG_MEM_P1 = dst
self.reg.GCPU_REG_MEM_P2 = len(data) >> 4
self.reg.GCPU_REG_MEM_P3 = 0x1A
self.reg.GCPU_REG_MEM_P4 = 0x1A
self.reg.GCPU_REG_MEM_P4 = 0x12
self.reg.GCPU_REG_MEM_P5 = 0x1A
self.reg.GCPU_REG_MEM_P6 = 0x1A
self.cmd(AESPK_EK_DCBC) # 0x7E
rdata = self.readmem(dst, len(data))
return rdata
Expand Down
37 changes: 23 additions & 14 deletions mtkclient/Library/xflash_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,27 +265,36 @@ def custom_writeregister(self, addr, data):

def readmem(self, addr, dwords=1):
res = []
for pos in range(dwords):
val = self.custom_readregister(addr + pos * 4)
if val == b"":
return False
data = unpack("<I", val)[0]
if dwords == 1:
self.debug(f"RX: {hex(addr + (pos * 4))} -> " + hex(data))
return data
res.append(data)
if dwords<0x20:
for pos in range(dwords):
val = self.custom_readregister(addr + pos * 4)
if val == b"":
return False
data = unpack("<I", val)[0]
if dwords == 1:
self.debug(f"RX: {hex(addr + (pos * 4))} -> " + hex(data))
return data
res.append(data)
else:
res=self.custom_read(addr,dwords*4)
res=[unpack("<I",res[i:i+4])[0] for i in range(0,len(res),4)]

self.debug(f"RX: {hex(addr)} -> " + hexlify(b"".join(pack("<I", val) for val in res)).decode('utf-8'))
return res

def writeregister(self, addr, dwords):
if isinstance(dwords, int):
dwords = [dwords]
pos = 0
for val in dwords:
self.debug(f"TX: {hex(addr + pos)} -> " + hex(val))
if not self.custom_writeregister(addr + pos, val):
return False
pos += 4
if len(dwords)<0x20:
for val in dwords:
self.debug(f"TX: {hex(addr + pos)} -> " + hex(val))
if not self.custom_writeregister(addr + pos, val):
return False
pos += 4
else:
dat=b"".join([pack("<I",val) for val in dwords])
self.custom_write(addr,dat)
return True

def writemem(self, addr, data):
Expand Down
12 changes: 6 additions & 6 deletions mtkclient/gui/create_gui.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh
pyside2-uic main_gui.ui -o main_gui.py
pyside2-uic erasepart_gui.ui -o erasepart_gui.py
pyside2-uic readpart_gui.ui -o readpart_gui.py
pyside2-uic writepart_gui.ui -o writepart_gui.py
pyside2-uic readfull_gui.ui -o readfull_gui.py
pyside2-uic writefull_gui.ui -o writefull_gui.py
pyside6-uic main_gui.ui -o main_gui.py
pyside6-uic erasepart_gui.ui -o erasepart_gui.py
pyside6-uic readpart_gui.ui -o readpart_gui.py
pyside6-uic writepart_gui.ui -o writepart_gui.py
pyside6-uic readfull_gui.ui -o readfull_gui.py
pyside6-uic writefull_gui.ui -o writefull_gui.py
4 changes: 2 additions & 2 deletions mtkclient/gui/eraseFlashPartitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import sys
import mock
import time
from PySide2.QtCore import Slot, Qt
from PySide2.QtWidgets import QDialog, QCheckBox, QVBoxLayout, QWidget
from PySide6.QtCore import Slot, Qt
from PySide6.QtWidgets import QDialog, QCheckBox, QVBoxLayout, QWidget
from mtkclient.gui.toolkit import convert_size, FDialog, TimeEstim
from mtkclient.gui.toolkit import trap_exc_during_debug, asyncThread
from mtkclient.gui.erasepart_gui import Ui_partitionListWidget
Expand Down
16 changes: 11 additions & 5 deletions mtkclient/gui/erasepart_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,21 @@
################################################################################
## Form generated from reading UI file 'erasepart_gui.ui'
##
## Created by: Qt User Interface Compiler version 5.15.2
## Created by: Qt User Interface Compiler version 6.2.2
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################

from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *

from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale,
QMetaObject, QObject, QPoint, QRect,
QSize, QTime, QUrl, Qt)
from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor,
QFont, QFontDatabase, QGradient, QIcon,
QImage, QKeySequence, QLinearGradient, QPainter,
QPalette, QPixmap, QRadialGradient, QTransform)
from PySide6.QtWidgets import (QAbstractScrollArea, QApplication, QCheckBox, QGridLayout,
QHBoxLayout, QLabel, QProgressBar, QPushButton,
QScrollArea, QSizePolicy, QSpacerItem, QWidget)

class Ui_partitionListWidget(object):
def setupUi(self, partitionListWidget):
Expand Down
Binary file modified mtkclient/gui/i18n/de_DE.qm
Binary file not shown.
Loading

0 comments on commit 3c77a1b

Please sign in to comment.