3636 + os .sep
3737 + "adb"
3838 ) # 默认mac环境
39- frida_server = "hluda-server-15.2.2"
39+ frida_server_arm = "hluda-server-15.2.2-arm64"
40+ frida_server_x86 = "hluda-server-15.2.2-x86"
41+ # 根据手机架构选择 frida-server, arm和x86
42+ # 兼容模拟器
43+ detecting_phone_architecture_cmd = [adb_path , "shell" , "su -c 'getprop ro.product.cpu.abi'" ]
44+ frida_server = ""
4045frida_path = (
4146 os .path .abspath (os .path .join (os .path .dirname (__file__ ), "../.." ))
4247 + os .sep
7075 "su -c 'setprop persist.device_config.runtime_native.usap_pool_enabled false'" ,
7176]
7277
78+ def generation_cmd ():
79+ # 重新生成cmd
80+ global adb_path
81+ global frida_server
82+ global frida_path
83+ global colse_SELinux_cmd
84+ global kill_cmd
85+ global clean_cmd
86+ global push_cmd
87+ global mv_cmd
88+ global chmod_cmd
89+ global run_cmd
90+ global devices_cmd
91+ global root_cmd
92+ global stop_adb_cmd
93+ global start_adb_cmd
94+ global close_usap_cmd
95+ global detecting_phone_architecture_cmd
96+ global frida_server_arm
97+ global frida_server_x86
98+ adb_path = (
99+ os .path .abspath (os .path .join (os .path .dirname (__file__ ), "../.." ))
100+ + os .sep
101+ + "static"
102+ + os .sep
103+ + "windows"
104+ + os .sep
105+ + "adb.exe"
106+ ) # default windows
107+ if platform .system ().lower () == "darwin" :
108+ # mac 环境
109+ adb_path = (
110+ os .path .abspath (os .path .join (os .path .dirname (__file__ ), "../.." ))
111+ + os .sep
112+ + "static"
113+ + os .sep
114+ + "darwin"
115+ + os .sep
116+ + "adb"
117+ ) # 默认mac环境
118+ frida_server_arm = "hluda-server-15.2.2-arm64"
119+ frida_server_x86 = "hluda-server-15.2.2-x86"
120+ # 根据手机架构选择 frida-server, arm和x86
121+ # 兼容模拟器
122+ detecting_phone_architecture_cmd = [adb_path , "shell" , "su -c 'getprop ro.product.cpu.abi'" ]
123+ frida_path = (
124+ os .path .abspath (os .path .join (os .path .dirname (__file__ ), "../.." ))
125+ + os .sep
126+ + "static"
127+ + os .sep
128+ + frida_server
129+ )
130+ colse_SELinux_cmd = [adb_path , "shell" , "su -c 'setenforce 0'" ]
131+ kill_cmd = [adb_path , "shell" , "su -c 'pkill -9 hluda'" ]
132+ clean_cmd = [adb_path , "shell" , "su -c 'rm -rf /data/local/tmp/*'" ]
133+ push_cmd = [adb_path , "push" , frida_path , "/storage/emulated/0/{}" .format (frida_server )]
134+ mv_cmd = [
135+ adb_path ,
136+ "shell" ,
137+ "su -c 'mv /storage/emulated/0/{} /data/local/tmp/'" .format (frida_server ),
138+ ]
139+ chmod_cmd = [
140+ adb_path ,
141+ "shell" ,
142+ "su -c 'chmod 777 /data/local/tmp/{}'" .format (frida_server ),
143+ ]
144+ run_cmd = [adb_path , "shell" , "su -c 'nohup /data/local/tmp/{} &'" .format (frida_server )]
145+ devices_cmd = [adb_path , "devices" ]
146+ root_cmd = [adb_path , "shell" , "su -c 'exit'" ]
147+ stop_adb_cmd = [adb_path , "kill-server" ]
148+ start_adb_cmd = [adb_path , "start-server" ]
149+ # https://github.com/frida/frida/issues/1788
150+ close_usap_cmd = [
151+ adb_path ,
152+ "shell" ,
153+ "su -c 'setprop persist.device_config.runtime_native.usap_pool_enabled false'" ,
154+ ]
155+
156+ def detecting_phone_architecture ():
157+ # 检测手机架构
158+ global frida_server
159+ result = subprocess .Popen (detecting_phone_architecture_cmd , stdout = subprocess .PIPE ).communicate ()
160+ outdata = result [0 ].decode ("utf-8" )
161+ if "arm" in outdata :
162+ frida_server = frida_server_arm
163+ elif "x86" in outdata :
164+ frida_server = frida_server_x86
165+ else :
166+ raise Exception ("手机架构不支持" , outdata )
167+ return frida_server
73168
74169@router .post ("" , response_model = ApiBaseResponse , response_model_exclude_unset = False )
75170async def init ():
@@ -91,6 +186,9 @@ async def init():
91186 # kill 可能残留的进程
92187 subprocess .call (kill_cmd )
93188 time .sleep (2 )
189+ # 获取手机架构
190+ detecting_phone_architecture ()
191+ generation_cmd ()
94192 # 清理数据
95193 subprocess .call (clean_cmd )
96194 # 推送 frida-server 到设备
0 commit comments