diff --git a/helper/routers/adb/command.py b/helper/routers/adb/command.py new file mode 100644 index 0000000..a03c6e7 --- /dev/null +++ b/helper/routers/adb/command.py @@ -0,0 +1,120 @@ +import os +import platform + +class Command: + def __init__(self, Architecture: str, IsRemoteDevices: bool, RemoteDevicesIP: str, RemoteDevicesPort: int, IsNeedSU: bool): + # 用户手动配置 + self._devices_architecture = Architecture + self._is_remote_devices = IsRemoteDevices + self._remote_devices_ip = RemoteDevicesIP + self._remote_devices_port = RemoteDevicesPort + self._is_need_su = IsNeedSU + + # 对外暴露的command + self.connect_remote_cmd = [] + self.stop_adb_cmd = [] + self.start_adb_cmd = [] + self.devices_cmd = [] + self.colse_SELinux_cmd = [] + self.close_usap_cmd = [] + self.kill_cmd = [] + self.clean_cmd = [] + self.push_cmd = [] + self.mv_cmd = [] + self.chmod_cmd = [] + self.run_cmd = [] + + # 根据配置生成合适的cmd命令 + def detecting(self): + # 根据本机os生成adb路径 + adb_path = "" + if platform.system().lower() == "darwin": + # mac 环境 + adb_path = ( + os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")) + + os.sep + + "static" + + os.sep + + "darwin" + + os.sep + + "adb" + ) + else: + adb_path = ( + os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")) + + os.sep + + "static" + + os.sep + + "windows" + + os.sep + + "adb.exe" + ) + # 远程remote连接 + if self._is_remote_devices: + self.connect_remote_cmd = [adb_path, "connect", "{}:{}".format(self._remote_devices_ip, self._remote_devices_port)] + else: + self.connect_remote_cmd = [] + # 目前可以确定的命令 + self.stop_adb_cmd = [adb_path, "kill-server"] + self.start_adb_cmd = [adb_path, "start-server"] + # 根据设备架构生成frida_server路径 + frida_server = "" + if self._devices_architecture == "x86": + frida_server = "hluda-server-x86" + elif self._devices_architecture == "arm": + frida_server = "hluda-server-arm64" + # 生成frida_server路径 + frida_path = ( + os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")) + + os.sep + + "static" + + os.sep + + frida_server + ) + if self._is_need_su: + self.colse_SELinux_cmd = [adb_path, "shell", "su -c 'setenforce 0'"] + self.kill_cmd = [adb_path, "shell", "su -c 'pkill -9 hluda'"] + self.clean_cmd = [adb_path, "shell", "su -c 'rm -rf /data/local/tmp/*'"] + self.mv_cmd = [ + adb_path, + "shell", + "su -c 'mv /storage/emulated/0/{} /data/local/tmp/'".format(frida_server), + ] + self.chmod_cmd = [ + adb_path, + "shell", + "su -c 'chmod 777 /data/local/tmp/{}'".format(frida_server), + ] + self.run_cmd = [adb_path, "shell", "su -c 'nohup /data/local/tmp/{} &'".format(frida_server)] + self.devices_cmd = [adb_path, "devices"] + self.root_cmd = [adb_path, "shell", "su -c 'exit'"] + # https://github.com/frida/frida/issues/1788 + self.close_usap_cmd = [ + adb_path, + "shell", + "su -c 'setprop persist.device_config.runtime_native.usap_pool_enabled false'", + ] + else: + self.colse_SELinux_cmd = [adb_path, "shell", "-c 'setenforce 0'"] + self.kill_cmd = [adb_path, "shell", "-c 'pkill -9 hluda'"] + self.clean_cmd = [adb_path, "shell", "-c 'rm -rf /data/local/tmp/*'"] + self.mv_cmd = [ + adb_path, + "shell", + "-c 'mv /storage/emulated/0/{} /data/local/tmp/'".format(frida_server), + ] + self.chmod_cmd = [ + adb_path, + "shell", + "-c 'chmod 777 /data/local/tmp/{}'".format(frida_server), + ] + self.run_cmd = [adb_path, "shell", "-c 'nohup /data/local/tmp/{} &'".format(frida_server)] + self.devices_cmd = [adb_path, "devices"] + self.root_cmd = [adb_path, "shell", "-c 'exit'"] + # https://github.com/frida/frida/issues/1788 + self.close_usap_cmd = [ + adb_path, + "shell", + "-c 'setprop persist.device_config.runtime_native.usap_pool_enabled false'", + ] + self.push_cmd = [adb_path, "push", frida_path, "/storage/emulated/0/{}".format(frida_server)] diff --git a/helper/routers/adb/init.py b/helper/routers/adb/init.py index ece6dc1..acd8e5f 100644 --- a/helper/routers/adb/init.py +++ b/helper/routers/adb/init.py @@ -4,6 +4,8 @@ import subprocess from copy import deepcopy from fastapi import APIRouter +from pydantic import BaseModel +from .command import Command from internal.response.model import ( ApiBaseResponse, @@ -16,190 +18,55 @@ router = APIRouter(prefix="/adb/init") -adb_path = ( - os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")) - + os.sep - + "static" - + os.sep - + "windows" - + os.sep - + "adb.exe" -) # default windows -if platform.system().lower() == "darwin": - # mac 环境 - adb_path = ( - os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")) - + os.sep - + "static" - + os.sep - + "darwin" - + os.sep - + "adb" - ) # 默认mac环境 -frida_server_arm = "hluda-server-arm64" -frida_server_x86 = "hluda-server-x86" -# 根据手机架构选择 frida-server, arm和x86 -# 兼容模拟器 -detecting_phone_architecture_cmd = [adb_path, "shell", "su -c 'getprop ro.product.cpu.abi'"] -frida_server = "" -frida_path = ( - os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")) - + os.sep - + "static" - + os.sep - + frida_server -) -colse_SELinux_cmd = [adb_path, "shell", "su -c 'setenforce 0'"] -kill_cmd = [adb_path, "shell", "su -c 'pkill -9 hluda'"] -clean_cmd = [adb_path, "shell", "su -c 'rm -rf /data/local/tmp/*'"] -push_cmd = [adb_path, "push", frida_path, "/storage/emulated/0/{}".format(frida_server)] -mv_cmd = [ - adb_path, - "shell", - "su -c 'mv /storage/emulated/0/{} /data/local/tmp/'".format(frida_server), -] -chmod_cmd = [ - adb_path, - "shell", - "su -c 'chmod 777 /data/local/tmp/{}'".format(frida_server), -] -run_cmd = [adb_path, "shell", "su -c 'nohup /data/local/tmp/{} &'".format(frida_server)] -devices_cmd = [adb_path, "devices"] -root_cmd = [adb_path, "shell", "su -c 'exit'"] -stop_adb_cmd = [adb_path, "kill-server"] -start_adb_cmd = [adb_path, "start-server"] -# https://github.com/frida/frida/issues/1788 -close_usap_cmd = [ - adb_path, - "shell", - "su -c 'setprop persist.device_config.runtime_native.usap_pool_enabled false'", -] - -def generation_cmd(): - # 重新生成cmd - global adb_path - global frida_server - global frida_path - global colse_SELinux_cmd - global kill_cmd - global clean_cmd - global push_cmd - global mv_cmd - global chmod_cmd - global run_cmd - global devices_cmd - global root_cmd - global stop_adb_cmd - global start_adb_cmd - global close_usap_cmd - global detecting_phone_architecture_cmd - global frida_server_arm - global frida_server_x86 - adb_path = ( - os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")) - + os.sep - + "static" - + os.sep - + "windows" - + os.sep - + "adb.exe" - ) # default windows - if platform.system().lower() == "darwin": - # mac 环境 - adb_path = ( - os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")) - + os.sep - + "static" - + os.sep - + "darwin" - + os.sep - + "adb" - ) # 默认mac环境 - frida_server_arm = "hluda-server-arm64" - frida_server_x86 = "hluda-server-x86" - # 根据手机架构选择 frida-server, arm和x86 - # 兼容模拟器 - detecting_phone_architecture_cmd = [adb_path, "shell", "su -c 'getprop ro.product.cpu.abi'"] - frida_path = ( - os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")) - + os.sep - + "static" - + os.sep - + frida_server - ) - colse_SELinux_cmd = [adb_path, "shell", "su -c 'setenforce 0'"] - kill_cmd = [adb_path, "shell", "su -c 'pkill -9 hluda'"] - clean_cmd = [adb_path, "shell", "su -c 'rm -rf /data/local/tmp/*'"] - push_cmd = [adb_path, "push", frida_path, "/storage/emulated/0/{}".format(frida_server)] - mv_cmd = [ - adb_path, - "shell", - "su -c 'mv /storage/emulated/0/{} /data/local/tmp/'".format(frida_server), - ] - chmod_cmd = [ - adb_path, - "shell", - "su -c 'chmod 777 /data/local/tmp/{}'".format(frida_server), - ] - run_cmd = [adb_path, "shell", "su -c 'nohup /data/local/tmp/{} &'".format(frida_server)] - devices_cmd = [adb_path, "devices"] - root_cmd = [adb_path, "shell", "su -c 'exit'"] - stop_adb_cmd = [adb_path, "kill-server"] - start_adb_cmd = [adb_path, "start-server"] - # https://github.com/frida/frida/issues/1788 - close_usap_cmd = [ - adb_path, - "shell", - "su -c 'setprop persist.device_config.runtime_native.usap_pool_enabled false'", - ] - -def detecting_phone_architecture(): - # 检测手机架构 - global frida_server - result = subprocess.Popen(detecting_phone_architecture_cmd, stdout=subprocess.PIPE).communicate() - outdata = result[0].decode("utf-8") - if "arm" in outdata: - frida_server = frida_server_arm - elif "x86" in outdata: - frida_server = frida_server_x86 - else: - raise Exception("手机架构不支持", outdata) - return frida_server +class DevicesOptionItem(BaseModel): + DevicesArchitecture: str = "" # arm/x86 + IsRemoteDevices: bool = False # 是否是远程设备 + RemoteDevicesIP: str = "" # 远程设备IP + RemoteDevicesPort: int = "" # 远程设备端口 + IsNeedSU: bool = True # 是否需要su才能申请root权限(正常需要, 特殊rom不需要) @router.post("", response_model=ApiBaseResponse, response_model_exclude_unset=False) -async def init(): +async def init(item: DevicesOptionItem): res = deepcopy(OK) try: + cmd = Command( + item.DevicesArchitecture, + item.IsRemoteDevices, + item.RemoteDevicesIP, + item.RemoteDevicesPort, + item.IsNeedSU + ) + cmd.detecting() # https://github.com/zhengjim/camille/pull/32/commits/1be9236d7b0d8d4369ba0e0e84df5c660dc35c87 # 重启一下 adb, 防止 adb 偶尔抽风 # 停止 adb - subprocess.call(stop_adb_cmd) + subprocess.call(cmd.stop_adb_cmd) # 启动adb - subprocess.call(start_adb_cmd) - time.sleep(5) + subprocess.call(cmd.start_adb_cmd) + time.sleep(3) + if item.IsRemoteDevices: + subprocess.call(cmd.connect_remote_cmd) + time.sleep(3) # https://github.com/zhengjim/camille/pull/32/commits/e3084d92ba0db4206409246d5e8145c9b5820640 - subprocess.call(devices_cmd) + subprocess.call(cmd.devices_cmd) # 关闭SELinux - subprocess.call(colse_SELinux_cmd) + subprocess.call(cmd.colse_SELinux_cmd) # https://github.com/frida/frida/issues/1788 适配ROM - subprocess.call(close_usap_cmd) + subprocess.call(cmd.close_usap_cmd) # kill 可能残留的进程 - subprocess.call(kill_cmd) + subprocess.call(cmd.kill_cmd) time.sleep(2) - # 获取手机架构 - detecting_phone_architecture() - generation_cmd() # 清理数据 - subprocess.call(clean_cmd) + subprocess.call(cmd.clean_cmd) # 推送 frida-server 到设备 - subprocess.call(push_cmd) + subprocess.call(cmd.push_cmd) time.sleep(3) # 移动文件 - subprocess.call(mv_cmd) + subprocess.call(cmd.mv_cmd) # 设置权限 - subprocess.call(chmod_cmd) + subprocess.call(cmd.chmod_cmd) # 启动 - pid = subprocess.Popen(run_cmd) + pid = subprocess.Popen(cmd.run_cmd) time.sleep(5) pid.kill() except Exception as e: @@ -212,11 +79,29 @@ async def init(): @router.get( "/verify", response_model=ApiBaseResponse, response_model_exclude_unset=False ) -async def verify(): +async def verify(item: DevicesOptionItem): res = deepcopy(OK) try: + cmd = Command( + item.DevicesArchitecture, + item.IsRemoteDevices, + item.RemoteDevicesIP, + item.RemoteDevicesPort, + item.IsNeedSU + ) + cmd.detecting() + # https://github.com/zhengjim/camille/pull/32/commits/1be9236d7b0d8d4369ba0e0e84df5c660dc35c87 + # 重启一下 adb, 防止 adb 偶尔抽风 + # 停止 adb + subprocess.call(cmd.stop_adb_cmd) + # 启动adb + subprocess.call(cmd.start_adb_cmd) + time.sleep(3) + if item.IsRemoteDevices: + subprocess.call(cmd.connect_remote_cmd) + time.sleep(3) # 确认是否打开了 usb 调试 - result = subprocess.Popen(devices_cmd, stdout=subprocess.PIPE).communicate() + result = subprocess.Popen(cmd.devices_cmd, stdout=subprocess.PIPE).communicate() if ( result[0].decode("utf-8").split("\n")[1] == "" or result[0].decode("utf-8").split("\n")[1] == "\r" @@ -231,7 +116,7 @@ async def verify(): res = deepcopy(USB_UNAUTHORIZED) return res if result[0].decode("utf-8").split("\n")[1].split()[1] == "device": - root_check = subprocess.call(root_cmd) + root_check = subprocess.call(cmd.root_cmd) if root_check != 0: res = deepcopy(ROOT_CLOSED) return res diff --git a/view/src-electron/electron-preload.js b/view/src-electron/electron-preload.js index e26ba70..f967c91 100644 --- a/view/src-electron/electron-preload.js +++ b/view/src-electron/electron-preload.js @@ -31,7 +31,7 @@ contextBridge.exposeInMainWorld("systemApi", { return await ipcRenderer.send("checkForUpdate", bySelf); }, //打开文档 - openDocs: () => ipcRenderer.send("open-url", "https://appscan.ly.com"), + openDocs: () => ipcRenderer.send("open-url", "https://github.com/TongchengOpenSource/AppScan/wiki"), //打开issues openIssues: () => ipcRenderer.send( diff --git a/view/src/components/AboutUsDialog.vue b/view/src/components/AboutUsDialog.vue index 695b196..009ae3d 100644 --- a/view/src/components/AboutUsDialog.vue +++ b/view/src/components/AboutUsDialog.vue @@ -39,28 +39,6 @@ - - @@ -92,22 +70,10 @@ export default defineComponent({ // 获取版本数据 synopsis.version = getVersion(); - // //获取历史数据; - // getHistory() - // .then((res) => { - // if (res.code == 200) { - // history.data = res.result; - // } - // }) - // .catch((rej) => { - // console.log("请求版本信息失败:" + rej); - // }); - // getHistory(); return { alert, synopsis, history, - // getHistory, openIssues, }; }, diff --git a/view/src/components/SettingModal.vue b/view/src/components/SettingModal.vue index 3a13df7..a133566 100644 --- a/view/src/components/SettingModal.vue +++ b/view/src/components/SettingModal.vue @@ -1,4 +1,46 @@ @@ -282,6 +214,8 @@ import { useAppInfoStore } from "stores/app-info"; import AboutUsDialog from "src/components/AboutUsDialog.vue"; // 错误提交组件 import errorSubmitDialog from "../components/errorSubmitDialog.vue"; +// 设置组件 +import SettingModal from "../components/SettingModal.vue"; let activeMenu = ref("privacy"); let updating = ref(false); @@ -373,7 +307,7 @@ export default defineComponent({ } // 设置弹窗 function openSetting() { - settingDialog.value = true; + setting.value.visible = true; } // 保存设置(存储mode、waitTime) function saveSetting() {