Skip to content

Commit

Permalink
优化usb端口和wifi配置保存到文件。优化fridaname可以自定义,自定义后需要重新上传frida,就是使用新的名字了。
Browse files Browse the repository at this point in the history
  • Loading branch information
init committed Jan 16, 2023
1 parent adf2097 commit 00feb9b
Show file tree
Hide file tree
Showing 10 changed files with 188 additions and 96 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ fridaUiTools是一个界面化整理脚本的工具。新人的练手作品。
## 交流群
<img src="./img/qun.jpg" style="zoom:50%">

## 更新 2022-01-16
优化usb端口和wifi配置保存到文件。优化fridaname可以自定义,自定义后需要重新上传frida,就是使用新的名字了。

## 更新 2022-01-08
新增语言切换功能,支持切换English,修复fart的部分bug

Expand Down
4 changes: 4 additions & 0 deletions config/conf.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
[kmain]
language = China
frida_name = fs
usb_port = 7777
wifi_addr = 127.0.0.1
wifi_port = 8989

4 changes: 4 additions & 0 deletions forms/Port.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@ def __init__(self, parent=None):
self.setWindowOpacity(0.93)
self.btnSubmit.clicked.connect(self.submit)
self.btnClear.clicked.connect(self.clearUi)
self.fridaName=""
self.port="6666"


def clearUi(self):
self.txtPort.setText("")
self.txtFridaName.setText("")

def submit(self):
port = self.txtPort.text()
if len(port) <= 0:
QMessageBox().information(self, "hint", "missing port")
return
self.port = port
self.fridaName = self.txtFridaName.text()
self.accept()
2 changes: 2 additions & 0 deletions forms/Wifi.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ def __init__(self, parent=None):
self.setWindowOpacity(0.93)
self.btnSubmit.clicked.connect(self.submit)
self.btnClear.clicked.connect(self.clearUi)
self.address=""
self.wifi_port=""


def clearUi(self):
Expand Down
99 changes: 71 additions & 28 deletions kmainForm.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ def initUi(self):
self.languageGroup = QActionGroup(self)
self.languageGroup.addAction(self.actionChina)
self.languageGroup.addAction(self.actionEnglish)

self.fridaName = conf.read("kmain", "frida_name")
self.customPort = conf.read("kmain", "usb_port")
self.address=conf.read("kmain", "wifi_addr")
self.wifi_port = conf.read("kmain", "wifi_port")
language = conf.read("kmain", "language")
if language == "China":
self.actionChina.setChecked(True)
Expand Down Expand Up @@ -133,6 +138,10 @@ def initUi(self):
self.actionFridax86Start.triggered.connect(self.FridaX86Start)
self.actionFridax64Start.triggered.connect(self.FridaX64Start)
self.actionPullApk.triggered.connect(self.PullApk)

self.connectHeadGroup = QActionGroup(self)
self.connectHeadGroup.addAction(self.actionWifi)
self.connectHeadGroup.addAction(self.actionUsb)
self.actionWifi.triggered.connect(self.WifiConn)
self.actionUsb.triggered.connect(self.UsbConn)
self.actionVer14.triggered.connect(self.ChangeVer14)
Expand Down Expand Up @@ -245,9 +254,6 @@ def initUi(self):
self.chkLibArt.tag = "libArt"
self.chkHookEvent.tag = "hookEvent"
self.connType="usb"
self.address=""
self.port=""
self.customPort=""

self.curFridaVer = "15.1.9"
self.actionVer15.setChecked(True)
Expand Down Expand Up @@ -440,18 +446,26 @@ def PullDumpDex(self):

def PushFridaServer(self):
try:
res = CmdUtil.execCmd(f"adb push ./exec/frida-server-{self.curFridaVer}-android-arm /data/local/tmp")
name32=""
name64=""
if self.fridaName!="":
name32=self.fridaName+"32"
name64=self.fridaName+"64"

res = CmdUtil.execCmd(f"adb push ./exec/frida-server-{self.curFridaVer}-android-arm /data/local/tmp/"+name32)
self.log(res)
if "error" in res:
QMessageBox().information(self, "hint",self._translate("kmainForm", "上传失败.") + res)
return
res = CmdUtil.execCmd(f"adb push ./exec/frida-server-{self.curFridaVer}-android-arm64 /data/local/tmp")
res = CmdUtil.execCmd(f"adb push ./exec/frida-server-{self.curFridaVer}-android-arm64 /data/local/tmp/"+name64)
self.log(res)
if "file pushed" not in res:
QMessageBox().information(self, "hint",self._translate("kmainForm", "上传失败,可能未连接设备.") + res)
return

res = CmdUtil.adbshellCmd("chmod 0777 /data/local/tmp/frida*")
if self.fridaName!="":
res = CmdUtil.adbshellCmd("chmod 0777 /data/local/tmp/"+self.fridaName+"*")
else:
res = CmdUtil.adbshellCmd("chmod 0777 /data/local/tmp/frida*")
self.log(res)
if "invalid" in res:
QMessageBox().information(self, "hint",self._translate("kmainForm", "上传完成,但是设置权限失败。可能是su权限错误,请先cmd切换."))
Expand Down Expand Up @@ -571,13 +585,17 @@ def PullApk(self):

def ReplaceSh(self,rfile,wfile,name):
data = FileUtil.readFile(rfile)
adb = "adb"
if platform.system() == "Darwin":
adb = "%adb%"
if self.connType == "wifi":
data = data.replace("%fridaName%", name + " -l 0.0.0.0:" + self.port)
data=data.replace("%customPort%",f"adb forward tcp:{self.customPort} tcp:{self.customPort}")
data = data.replace("%fridaName%", name + " -l 0.0.0.0:" + self.wifi_port)

data=data.replace("%customPort%",f"{adb} forward tcp:{self.customPort} tcp:{self.customPort}")
elif self.connType == "usb":
if self.customPort!=None and len(self.customPort)>0:
data = data.replace("%fridaName%", name + " -l 0.0.0.0:" + self.customPort)
data=data.replace("%customPort%",f"adb forward tcp:{self.customPort} tcp:{self.customPort}")
data=data.replace("%customPort%",f"{adb} forward tcp:{self.customPort} tcp:{self.customPort}")
else:
data = data.replace("%fridaName%", name)
data = data.replace("%customPort%","")
Expand All @@ -587,15 +605,17 @@ def ReplaceSh(self,rfile,wfile,name):
data = data.replace("%sumod%", "su -c")
elif self.actionMks0.isChecked():
data = data.replace("%sumod%", "mks 0")

if platform.system()=="Darwin":
adbPath= CmdUtil.execCmdData("which adb")
data=data.replace("%adb%",adbPath.replace("\n",""))

if self.fridaName != None and len(self.fridaName) > 0:
data = data.replace("%fName%", self.fridaName)
FileUtil.writeFile(wfile,data)

def ShStart(self, name):
projectPath = os.path.abspath("./")

if platform.system() == "Windows":
shfile = "%s\\sh\\tmp\\frida_win.tmp"% (projectPath)
savefile="%s\\sh\\tmp\\frida_win.bat"% (projectPath)
Expand Down Expand Up @@ -652,16 +672,32 @@ def ChangeChina(self,checked):
restart_real_live()

def Frida32Start(self):
self.ShStart(f"frida-server-{self.curFridaVer}-android-arm")
if self.fridaName !=None and len(self.fridaName)>0:
name=self.fridaName+"32"
else:
name=f"frida-server-{self.curFridaVer}-android-arm"
self.ShStart(name)

def Frida64Start(self):
self.ShStart(f"frida-server-{self.curFridaVer}-android-arm64")
if self.fridaName !=None and len(self.fridaName)>0:
name=self.fridaName+"64"
else:
name=f"frida-server-{self.curFridaVer}-android-arm64"
self.ShStart(name)

def FridaX86Start(self):
self.ShStart(f"frida-server-{self.curFridaVer}-android-x86")
if self.fridaName !=None and len(self.fridaName)>0:
name=self.fridaName+"64"
else:
name=f"frida-server-{self.curFridaVer}-android-x86"
self.ShStart(name)

def FridaX64Start(self):
self.ShStart(f"frida-server-{self.curFridaVer}-android-x86_64")
if self.fridaName !=None and len(self.fridaName)>0:
name=self.fridaName+"64"
else:
name=f"frida-server-{self.curFridaVer}-android-x86_64"
self.ShStart(name)

def changeCmdType(self,data):
CmdUtil.cmdhead = data
Expand Down Expand Up @@ -727,7 +763,7 @@ def getFridaDevice(self):
else:
return frida.get_usb_device()
elif self.connType=="wifi":
str_host = "%s:%s" % (self.address, self.port)
str_host = "%s:%s" % (self.address, self.wifi_port)
manager = frida.get_device_manager()
device = manager.add_remote_device(str_host)
return device
Expand All @@ -737,7 +773,7 @@ def actionAttachStart(self):
self.log("actionAttach")
try:
if self.connType=="wifi":
if len(self.address)<8 or len(self.port)<0:
if len(self.address)<8 or len(self.wifi_port)<0:
QMessageBox().information(self, "hint", self._translate("kmainForm","当前为wifi连接,但是未设置地址或端口"))
return

Expand All @@ -747,7 +783,7 @@ def actionAttachStart(self):
self.changeAttachStatus(True)
self.th = TraceThread.Runthread(self.hooksData, "", False,self.connType)
self.th.address=self.address
self.th.port=self.port
self.th.port=self.wifi_port
self.th.customPort=self.customPort
self.th.taskOverSignel.connect(self.taskOver)
self.th.loggerSignel.connect(self.log)
Expand All @@ -774,7 +810,7 @@ def actionSpawnStart(self):
if res == 0:
return
try:
if self.connType=="wifi" and (len(self.address)<8 or len(self.port)):
if self.connType=="wifi" and (len(self.address)<8 or len(self.wifi_port)):
QMessageBox().information(self, "hint",self._translate("kmainForm","当前为wifi连接,但是未设置地址或端口"))
return
# 查下进程。能查到说明frida_server开启了
Expand All @@ -783,7 +819,7 @@ def actionSpawnStart(self):
self.changeAttachStatus(True)
self.th = TraceThread.Runthread(self.hooksData, self.spawnAttachForm.packageName, True,self.connType)
self.th.address=self.address
self.th.port=self.port
self.th.port=self.wifi_port
self.th.taskOverSignel.connect(self.taskOver)
self.th.loggerSignel.connect(self.log)
self.th.outloggerSignel.connect(self.outlog)
Expand Down Expand Up @@ -816,7 +852,7 @@ def changeAttachStatus(self, isattach):
def actionAttachNameStart(self):
self.log("actionAttachName")
try:
if self.connType=="wifi" and (len(self.address)<8 or len(self.port)):
if self.connType=="wifi" and (len(self.address)<8 or len(self.wifi_port)):
QMessageBox().information(self, "hint", self._translate("kmainForm","当前为wifi连接,但是未设置地址或端口"))
return
device = self.getFridaDevice()
Expand All @@ -829,7 +865,7 @@ def actionAttachNameStart(self):
self.changeAttachStatus(True)
self.th = TraceThread.Runthread(self.hooksData, selectPackageForm.packageName, False,self.connType)
self.th.address=self.address
self.th.port=self.port
self.th.port=self.wifi_port
self.th.taskOverSignel.connect(self.taskOver)
self.th.loggerSignel.connect(self.log)
self.th.outloggerSignel.connect(self.outlog)
Expand All @@ -844,21 +880,27 @@ def actionAttachNameStart(self):
QMessageBox().information(self, "hint", self._translate("kmainForm","附加异常.") + str(ex))

def ChangePort(self):
self.portForm.txtFridaName.setText(self.fridaName)
self.portForm.txtPort.setText(self.customPort)
res=self.portForm.exec()
if res==0:
return
self.fridaName = self.portForm.fridaName
self.customPort = self.portForm.port
conf.write("kmain", "frida_name", self.fridaName)
conf.write("kmain", "usb_port", self.customPort)

def WifiConn(self):
self.wifiForm.txtAddress.setText(self.address)
self.wifiForm.txtPort.setText(self.wifi_port)
res=self.wifiForm.exec()
if res==0:
self.actionWifi.setChecked(False)
if res==0 :
return
self.connType="wifi"
self.address=self.wifiForm.address
self.port=self.wifiForm.port
self.actionWifi.setChecked(True)
self.actionUsb.setChecked(False)
self.wifi_port=self.wifiForm.port
conf.write("kmain", "wifi_addr", self.address)
conf.write("kmain", "wifi_port", self.wifi_port)
def UsbConn(self):
self.connType="usb"
self.actionUsb.setChecked(True)
Expand Down Expand Up @@ -1187,6 +1229,7 @@ def antiFrida(self):
"bak": self._translate("kmainForm","简单的过frida检测."), "address": self.pform.address, "code": self.pform.patch}
typeStr = "antiFrida"
self.hooksData[typeStr]=hookData
CmdUtil.adbshellCmd("touch /data/local/tmp/maps && chmod 777 /data/local/tmp/maps")
self.updateTabHooks()

def saveHooks(self):
Expand Down
2 changes: 1 addition & 1 deletion sh/tmp/frida_linux.tmp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
adb shell %sumod% 'pkill -9 frida-server '
adb shell %sumod% 'pkill -9 %fName% '
adb forward tcp:27042 tcp:27042
adb forward tcp:27043 tcp:27043
%customPort%
Expand Down
2 changes: 1 addition & 1 deletion sh/tmp/frida_mac.tmp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
osascript <<END

tell application "Terminal"
do script "%adb% shell %sumod% 'pkill -9 frida-server '; %adb% forward tcp:27042 tcp:27042 ;%adb% forward tcp:27043 tcp:27043 ; %customPort%; %adb% shell %sumod% '/data/local/tmp/%fridaName%'"
do script "%adb% shell %sumod% 'pkill -9 %fName% '; %adb% forward tcp:27042 tcp:27042 ;%adb% forward tcp:27043 tcp:27043 ; %customPort%; %adb% shell %sumod% '/data/local/tmp/%fridaName%'"

end tell

Expand Down
2 changes: 1 addition & 1 deletion sh/tmp/frida_win.tmp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
adb shell %sumod% 'pkill -9 frida-server '
adb shell %sumod% 'pkill -9 %fName% '
adb forward tcp:27042 tcp:27042
adb forward tcp:27043 tcp:27043
%customPort%
Expand Down
62 changes: 38 additions & 24 deletions ui/port.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,53 @@


class Ui_Port(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(372, 212)
self.gridLayout_2 = QtWidgets.QGridLayout(Dialog)
def setupUi(self, Port):
Port.setObjectName("Port")
Port.resize(372, 212)
self.gridLayout_2 = QtWidgets.QGridLayout(Port)
self.gridLayout_2.setObjectName("gridLayout_2")
self.groupBox = QtWidgets.QGroupBox(Dialog)
self.groupBox = QtWidgets.QGroupBox(Port)
self.groupBox.setObjectName("groupBox")
self.gridLayout = QtWidgets.QGridLayout(self.groupBox)
self.gridLayout_3 = QtWidgets.QGridLayout(self.groupBox)
self.gridLayout_3.setObjectName("gridLayout_3")
self.gridLayout = QtWidgets.QGridLayout()
self.gridLayout.setObjectName("gridLayout")
self.label_4 = QtWidgets.QLabel(self.groupBox)
self.label_4.setObjectName("label_4")
self.gridLayout.addWidget(self.label_4, 0, 0, 1, 1)
self.txtPort = QtWidgets.QLineEdit(self.groupBox)
self.txtPort.setObjectName("txtPort")
self.gridLayout.addWidget(self.txtPort, 0, 1, 1, 2)
self.btnSubmit = QtWidgets.QPushButton(self.groupBox)
self.btnSubmit.setMaximumSize(QtCore.QSize(120, 16777215))
self.btnSubmit.setObjectName("btnSubmit")
self.gridLayout.addWidget(self.btnSubmit, 1, 2, 1, 1)
self.gridLayout.addWidget(self.txtPort, 1, 1, 1, 1)
self.label_4 = QtWidgets.QLabel(self.groupBox)
self.label_4.setObjectName("label_4")
self.gridLayout.addWidget(self.label_4, 1, 0, 1, 1)
self.label_5 = QtWidgets.QLabel(self.groupBox)
self.label_5.setObjectName("label_5")
self.gridLayout.addWidget(self.label_5, 0, 0, 1, 1)
self.txtFridaName = QtWidgets.QLineEdit(self.groupBox)
self.txtFridaName.setText("")
self.txtFridaName.setObjectName("txtFridaName")
self.gridLayout.addWidget(self.txtFridaName, 0, 1, 1, 1)
self.gridLayout_3.addLayout(self.gridLayout, 0, 0, 1, 1)
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
self.btnClear = QtWidgets.QPushButton(self.groupBox)
self.btnClear.setMaximumSize(QtCore.QSize(120, 16777215))
self.btnClear.setObjectName("btnClear")
self.gridLayout.addWidget(self.btnClear, 1, 1, 1, 1)
self.horizontalLayout.addWidget(self.btnClear)
self.btnSubmit = QtWidgets.QPushButton(self.groupBox)
self.btnSubmit.setMaximumSize(QtCore.QSize(120, 16777215))
self.btnSubmit.setObjectName("btnSubmit")
self.horizontalLayout.addWidget(self.btnSubmit)
self.gridLayout_3.addLayout(self.horizontalLayout, 1, 0, 1, 1)
self.gridLayout_2.addWidget(self.groupBox, 0, 0, 1, 1)

self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
self.retranslateUi(Port)
QtCore.QMetaObject.connectSlotsByName(Port)

def retranslateUi(self, Dialog):
def retranslateUi(self, Port):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "无线连接设置"))
self.groupBox.setTitle(_translate("Dialog", "设置"))
self.label_4.setText(_translate("Dialog", "端口:"))
self.txtPort.setText(_translate("Dialog", "6666"))
self.btnSubmit.setText(_translate("Dialog", "提交"))
self.btnClear.setText(_translate("Dialog", "清空"))
Port.setWindowTitle(_translate("Port", "连接配置"))
self.groupBox.setTitle(_translate("Port", "设置"))
self.txtPort.setText(_translate("Port", "6666"))
self.label_4.setText(_translate("Port", "端口:"))
self.label_5.setText(_translate("Port", "frida_name:"))
self.btnClear.setText(_translate("Port", "清空"))
self.btnSubmit.setText(_translate("Port", "提交"))
Loading

0 comments on commit 00feb9b

Please sign in to comment.