Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Frida snippet don't work for constructors anymore #1714

Closed
daMatz opened this issue Nov 2, 2022 · 9 comments · Fixed by #1715
Closed

Frida snippet don't work for constructors anymore #1714

daMatz opened this issue Nov 2, 2022 · 9 comments · Fixed by #1715

Comments

@daMatz
Copy link
Contributor

daMatz commented Nov 2, 2022

When generating a Frida snippet via jadx for a constructor, the code looks like this:

let MyClass = Java.use("com.MyClass");
MyClass["$init"].implementation = function () {
    console.log('$init is called');
    let ret = this.$new();
    console.log('$init ret value is ' + ret);
    return ret;
};

This generates the following error in the latest frida versions (haven't tested how far back that dates):

Error: Implementation for MyClass expected return value compatible with void

When using let ret = this.$init(); instead, it works for me.

let MyClass = Java.use("com.MyClass");
MyClass["$init"].implementation = function () {
    console.log('$init is called');
    let ret = this.$init();
    console.log('$init ret value is ' + ret);
    return ret;
};
@jpstotz
Copy link
Collaborator

jpstotz commented Nov 2, 2022

According to #1605 $new should the the correct way to call an constructor.

What version of Frida and frida-server do you use?

@daMatz
Copy link
Contributor Author

daMatz commented Nov 2, 2022

The current one, 16.0.2.
$new also used to work for me in the past, but currently I get the error above.

@skylot
Copy link
Owner

skylot commented Nov 2, 2022

Hm. I am not a Frida expert, but I believe that a $new is a correct call here. Unfortunately, error message is not very helpful, so it is hard to understand what is the main cause of the issue. I will try to reproduce it, so I will keep this issue open for some time.

As a workaround, I can move template for this snippet to the preferences, so it will be possible to edit it, but this solution is not flexible enough, because a lot of code used to form a strings in snippet. So maybe script for that will be better (I will try to make it).

@skylot skylot added need help GUI Issues in jadx-gui module discussion labels Nov 2, 2022
@skylot skylot added this to the TBD milestone Nov 2, 2022
@daMatz
Copy link
Contributor Author

daMatz commented Nov 3, 2022

@skylot I created a controlled environment to test this.

I created new Android Studio Project with a basic Activity and a basic class with constructor.
Here is the working example with $init:

image

Here is the failing example with $new:

image

I am happy to provide the code or condunct further tests.

Seems like the frida workflow here is strange, created a ticket for it in the frida repo: frida/frida#2302

@xxr0ss
Copy link
Contributor

xxr0ss commented Nov 4, 2022

Hi @skylot @daMatz @jpstotz ,

See frida/frida#2302 (comment) and $init's document:

image

So I think even $new should not be called in the $init, because the instance is already created.

@daMatz
Copy link
Contributor Author

daMatz commented Nov 4, 2022

@xxr0ss thank you for clarifying

image

Therefore the FridaAction needs to be adapted further.

skylot pushed a commit that referenced this issue Nov 7, 2022
…(PR #1715)

* Change callMethodName of constructors in Frida action

* Fix format violation in FridaAction

* Fix format violation in FridaAction
@skylot skylot reopened this Nov 7, 2022
@skylot
Copy link
Owner

skylot commented Nov 7, 2022

@daMatz I commit additional changes including separate template for constructors and void methods. Please check 🙂

@xxr0ss thank you for your help 👍

@daMatz
Copy link
Contributor Author

daMatz commented Nov 7, 2022

Thanks @skylot!
Just tried the nightly build jadx-1.4.5.95-bb4d88cc.zip.

The generated code for the example above is now

	let MyClass = Java.use("com.jadx.test.MyClass");
	MyClass["$init"].implementation = function (str) {
		console.log('MyClass.$init is called' + ', ' + 'str: ' + str);
                this["$init"](str);
	};

Looking good!

@skylot
Copy link
Owner

skylot commented Nov 7, 2022

Great! Thanks for verify.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants