本帖最后由 p1s1lver 于 2023-4-8 12:01 编辑
不少的自动化工具中会自己封装 startActivity 方法,这些方法相较于 am 命令,不会将大部分时间都放在虚拟机初始化上,性能更高,但是对应的 IntentFilter 机制的原理是没有变的,以如下代码为例:
构造一个 JavaScript 函数打印出构造的 python 语句字符串如打开开发者选项设置是 device.start_activity(action="android.settings.APPLICATION_DEVELOPMENT_SETTINGS")
这个 start_activity 方法的参数规则对应 am 命令的规则如下:
- action 参数对应于 am 命令中的 -a (action)
- category 参数对应 am 命令中的 -c (category)
- component 参数对应 am 命令中的 -n (component)
- extras 参数(dict) 对应 am 命令中的 -e 参数
现在在代码中也封装了对应的 python 语句的打印,这样就省去所有的步骤了,有就是能用,没有就是非 activity 启动,打印的代码及如何删除无用逻辑举例如下图:
代码如下:
[JavaScript] 纯文本查看 复制代码 function constructAmCommand(action, categories, component, extras) {
let amCommand = "am start"
if (action !== null) {
amCommand += ` -a ${action}`
}
if (categories && categories.length > 0) {
categories.forEach(category => {
amCommand += ` -c ${category}`
})
}
if (component !== null) {
amCommand += ` -n ${component.getPackageName()}/${component.getClassName()}`
}
if (extras !== null) {
amCommand += ` -e`
let iter = extras.keySet().iterator()
while (iter.hasNext()) {
let key = iter.next()
let value = extras.getString(key)
amCommand += ` "${key}" "${value}"`
}
}
return amCommand
}
function constructPythonStatement(action, categories, component, extras) {
let params_dict = {}
if (action !== null) {
params_dict["action"] = action
}
if (categories && categories.length > 0) {
params_dict["categories"] = categories
}
if (component !== null) {
params_dict["component"] = `${component.getPackageName()}/${component.getClassName()}`
}
if (extras !== null) {
let extras_params_dict = {}
let iter = extras.keySet().iterator()
while (iter.hasNext()) {
let key = iter.next()
let value = extras.getString(key)
if (value !== null) {
extras_params_dict[key] = value
}
}
params_dict["extras"] = extras_params_dict
}
let params = Object.entries(params_dict).map(([key, value]) => `${key}=${JSON.stringify(value)}`).join(", ")
let pythonStatement = `device.start_activity(${params})`
console.log(pythonStatement)
}
function printAmAndPython(intent) {
let am_command = constructAmCommand(intent.getAction(), intent.getCategories(), intent.getComponent(), intent.getExtras())
let python_statement = constructPythonStatement(intent.getAction(), intent.getCategories(), intent.getComponent(), intent.getExtras())
console.log(am_command)
console.log(python_statement)
}
function hookOnCreate() {
var Activity = Java.use("android.app.Activity");
Activity.onCreate.overload('android.os.Bundle').implementation = function (arg1) {
var theIntent = this.getIntent()
printAmAndPython(theIntent)
constructPythonStatement(theIntent.getAction(), theIntent.getCategories(), theIntent.getComponent(), theIntent.getExtras())
return this.onCreate(arg1)
};
}
setTimeout(() => {
Java.perform(() => {
console.log("[~] Inject FRIDA ...");
try {
hookOnCreate();
} catch (err) { console.error(err.stack); }
console.log("[-] FRIDA end mocking.");
})
}, 2000) |