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

Mitesh Shah
  • 192
  • 4
  • 16
  • Not just android, but to any modern languages, as far as I know, we don't use these kind of jump statements. – Nabin Jul 08 '15 at 07:13
  • This is the re-engineered code of one app. Not the code developed by me. I have extracted the code from apk. – Mitesh Shah Jul 08 '15 at 07:24
  • 3
    This happens when you **pirate** someone else's work!! This is what you will always get from a decompiled app. – Phantômaxx Jul 08 '15 at 07: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. – Mitesh Shah Jul 08 '15 at 09:49

1 Answers1

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;
}
Sergey Glotov
  • 20,200
  • 11
  • 84
  • 98