调用 API 以从 Frida 中的非主线程修改应用程序的 GUI



我刚刚开始使用Frida,并且已经学习了使用JavaScript和python绑定的代码注入和钩子的基本教程。我目前的问题是确定如何从非主线程调用GUI更新方法。感谢这是不可能做和搜索我发现代码在java,将调度主线程上的任务。我不知道的是如何在JavaScript中表示此代码,即如何在Frida JavaScript中表示以下java代码(在注入代码中):

android_View.getActivity().runOnUiThread(new Runnable() 
{
@Override
public void run() 
{
android_View.setVisibility(View.VISIBLE);
}
}

谢谢

在上面Robert的评论后面添加答案-谢谢,帮助很大。

// Assign the javascript code to a variable.
jsCode = """
// Create a method called Cheese that will be exported.
function Cheese()
{
// Perform the code from injected context.
Java.perform(function ()
{
// Variable to store the view representing the button 
// to click programmatically.
var view;
// Define the Runnable type javascript wrapper.
var Runnable = Java.use("java.lang.Runnable");
// Find the MainActivity class in myApp.
Java.choose("com.example.myApp.MainActivity", 
{
// Once it has been found execute the following code.
onMatch:    function(instance)
{
// Get the view representing button to click.
// 2131436712 id derived from decompiling app.
view = instance.findViewById(2131436712);
// Define a new class that implements Runnable and provide
// the implementation of the run() method which, will 
// execute from the Main thread.
const MyRunnable = Java.registerClass({
name:'com.example.MyRunnable',
implements: [Runnable],
methods: {
// run executes button click.            
run(){
instance.onClick(view);
},
}
});
// Create an instance of the class just created.
var MyGuiUpdate = MyRunnable .$new();
// Schedule the run method in MyGuiUpdate to 
// execute on the UI thread.
instance.runOnUiThread(MyGuiUpdate );
},
onComplete:function(){}
});
});
}
// Export Cheese function to python with name fromage
rpc.exports = {
fromage:Cheese
};
"""

使用上面的代码,你可以从python调用fromage,它会向定义的按钮发出一个点击事件。该调用由非UI线程发出,并使用runOnUiThread调度到UI线程。

最新更新