-2

I am working on a project for which I have reverse engineered the code of other project. But, the code contains so much goto statements and a label with it.

I tried to rearrange the code as per the labels used, but not getting the proper output. I know this could be out of scope for you guys because you don't know the code.

My query is regarding how can I use the labeled statements in Android, as I am unable to find any specific code or demo examples.

Below is the code snippet of the code on which I am working.

    public static String computeIMEI()
{
    String s1 = ((TelephonyManager)getInstance().getSystemService("phone")).getDeviceId();
    if (s1 != null) goto _L2; else goto _L1
 _L1:
    String s = "not available";
 _L4:
    Log.d("IMEI", (new StringBuilder()).append("got deviceID='").append(s).append("'").toString());
    return s;
 _L2:
    s = s1;
    if (s1.equals("000000000000000"))
    {
        s = "1971b8df0a9dccfd";
    }
    if (true) goto _L4; else goto _L3
_L3:
}

Your little help will be much appreciated, thank you.

4
  • Not just android, but to any modern languages, as far as I know, we don't use these kind of jump statements.
    – Nabin
    Commented Jul 8, 2015 at 7:13
  • This is the re-engineered code of one app. Not the code developed by me. I have extracted the code from apk. Commented Jul 8, 2015 at 7:24
  • 3
    This happens when you pirate someone else's work!! This is what you will always get from a decompiled app. Commented Jul 8, 2015 at 7:37
  • :D :D I know it. But, our client wants exact same output which have complex canvas drawing. I found this app near to our requirements so I de-complied it. Commented Jul 8, 2015 at 9:49

1 Answer 1

1

OMG! Where did you get it? :)
Normally nobody uses goto statements. The code with it quite hard to read and understand.

if (s1 != null) goto _L2; else goto _L1 pretty evident. If s1 equals null, we go to _L1 label, and then to _L4 and return from method.

If s1 not equals null, we go to _L2 label, and then to _L4 again (if (true) goto _L4; else goto _L3, else branch never will be executed) and return from method.

Your code in "translated" form:

public static String computeIMEI() {
    String s1 = ((TelephonyManager)getInstance().getSystemService("phone")).getDeviceId();
    if (s1 != null) {
        s = s1;
        if (s1.equals("000000000000000")) {
            s = "1971b8df0a9dccfd";
        }
    } else {
        String s = "not available";
    }

    Log.d("IMEI", (new StringBuilder()).append("got deviceID='").append(s).append("'").toString());
    return s;
}
1
  • I haven't made this. I have extracted this code from apk of live app. Commented Jul 8, 2015 at 7:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.