Kaushal Surana
Kaushal Surana

Reputation: 1

Is it possible to retrieve the name of the variable that is passed in a function call in java using code analysis of findbugs

url = "abc";  Intent intent = Intent.parseUri(url,other_variable);

What I want is to retrieve "url" but not "abc".

Is there any possible way to retrieve the name of the variable passed rather than its value using any kind of static code analysis?

Upvotes: 0

Views: 73

Answers (1)

TheWanderer
TheWanderer

Reputation: 17844

No.

For the most part, Java doesn't save local variable names when compiling. They are simply seen as registers: v0 = "abc", v1 = new Something() etc.

Occasionally, a variable name is saved as a "local," but this isn't something you can count on, and I don't believe you can retrieve it even if it does exist.

I'm saying this as someone who's done a lot of coding in Smali. While it's not Assembly or binary, it's lower level than Java and shows that the names aren't conserved. For example, the following Java:

String url = "abc";

would be the following in Smali:

const-string/jumbo v0, "abc"

No sign of a variable name to retrieve.

It can be shown again when decompiling to Java.

String url = "abc";

when compiled loses its variable name. So it's up to the decompiler to give it one. It'll usually pick

String string = "abc";

since that's the easiest and most readable option.

Upvotes: 1

Related Questions