Question

I decompiled an apk and see many while loops that return immediately only to be followed by other code:

while (true){
   return;
   if (!cond1){
     continue;
   }
   if (cond2){
     continue;
   }
}

If you wanted to produce this code in a decompile, what Java code would you write to get there?

Note. The decompile process is apktool -> baksmali -> smali -> dex2jar

EDIT

I can't actually get at the original Java bytecode from the Android APK (at least I don't know how to). It may be that my tools are doing a poor reverse-engineering job, but here is what the output of smali is:

:goto_8
return-void

.line 40
:sswitch_9
const/4 v0, 0x0

iput v0, p0, Lcom/sec/android/app/camera/command/ContextualTagSelectCommand;->mContextualTag:I

goto :goto_8

.line 44
:sswitch_d
const/4 v0, 0x1

iput v0, p0, Lcom/sec/android/app/camera/command/ContextualTagSelectCommand;->mContextualTag:I

goto :goto_8

Which corresponds to:

while (true)
{
  return;
  this.mContextualTag = 0;
  continue;
  this.mContextualTag = 1;
}
Was it helpful?

Solution

Your bytecode is a fragment of a compiled switch statement. Specifically, it was implemented using the sparse switch Dalvik bytecode instruction. You are showing only two switch cases, where both assign to mContextualTag and then execute the return statement. This return is placed at a single point in the program and the switch cases jump to it. The labels sswitch_9 and sswitch_d may be indicating the relative offsets from the sswitch instruction itself.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top