0
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?

3
  • 4
    Short answer would be "no", but probably I didn't fully understand your use case. So maybe you could explain a little bit more, what you want to do with the variable name, so that we can better help you achieve your overall goal. Commented Sep 10, 2018 at 17:38
  • I just want to get the name of the variable that is passed in the calling function son that I can check it with the name of all the variables of the current method that can be retrieved by StackUtils class in java Commented Sep 10, 2018 at 17:47
  • 1
    I still don't understand why you'd want to compare the variable naming of the caller method against the variable names inside the current method. What would you want to do differently if the caller's variable name changed e.g. from url to myUrl? Normally, such a change should have no influence on the program's behaviour. So, what you want to do, would become a big surprise to anyone calling your method. Commented Sep 10, 2018 at 17:58

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.