frida-java-bridge
frida-java-bridge copied to clipboard
[Feature] Add annotations to Java.registerClass
Here's an example code in java to add Dialog function as JavaScript Interface to a WebView:
public class MainActivity extends AppCompatActivity {
WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = findViewById(R.id.interface_web);
// opening the html file in webview
webView.loadUrl("file:///android_asset/test.html");
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setSupportZoom(true);
webView.addJavascriptInterface(this, "Dialog");
}
@JavascriptInterface
public void showMsg(String fname, String pswd) {
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("Confirmation").setMessage("UserName:\t" + fname + "\nPassword:\t" + pswd)
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Toast.makeText(getApplicationContext(), " Data Saved Locally", Toast.LENGTH_SHORT).show();
// You can use shared preference or db here to store The Data
}
});
builder.create().show();
}
}
Everything in this code can be written with frida except using the annotation "@JavascriptInterface", without the "@JavascriptInterface" annotation the Dialog function will not be available in the WebView...
Don't expect anyone to work on this. You can try to implement it at mkdex.js + class-factory.js and make a PR. If there's an existing class in your process with this signature I would recommend to hook/modify the functions and create a new instance of it. Alternatively you compile your class to a dex and use a dex class loader