frida-java-bridge icon indicating copy to clipboard operation
frida-java-bridge copied to clipboard

[Feature] Add annotations to Java.registerClass

Open realgam3 opened this issue 1 year ago • 1 comments

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...

realgam3 avatar Jul 28 '24 07:07 realgam3

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

5andr0 avatar Oct 22 '24 11:10 5andr0