2

I'm wishing to return to a project to which I have lost source to a time ago but have managed to get the compiled version from a user. I've used a few decompilers to slowly piece together the code again but am stuck with two final 'labels'.

After spending the past three days trying a range of decompilers only to find that most of them find these snippets even more of a struggle I am coming here as a last resort. I understand this is quite a large request especially as the context is missing and what is present of it is unusual but with a bit of luck someone experienced will be able to make sense of this.

The following snippet has 'label337' which I have no clue how to work around. I understand they are pointers of sorts but it does not occur to me how I would rearrange the code. Output produced by JD-GUI. http://pastebin.com/mVNksm13

The following snippet has 'label711' which I am also unaware of what to do with. Although taken hugely out of context it's an entire conditional although I don't know how much of sense it will make. Output produced by JD-GUI. http://pastebin.com/5MLFxHPb

Once again I wish to reiterate that I am aware how great of a request this is but after becoming sick of the sight of Java or decompilers I come here in hopes that any further light can be shed on this scenario than what I already know.

EDIT: The jar I am trying to decompile is heavily dependent on another jar which I have access to. Would somehow pointing to the jar on which the classes are dependent on during decompilation produce better output? I tried searching for how I would link to such dependancies in a decompiler but found nothing.

Ploo
  • 417
  • 1
  • 5
  • 12

2 Answers2

1

If I understand your question properly you are looking to refactor the pasted code. The breaks are like GOTO statements. The easiest way to re-factor this code would be with the use of methods.

You have one long if/else statement which if moved into a method would allow you to use return statements instead. Here is a shortened form of your first example

for (final TileInfo t : this.myTiles) {
  if (rsi != null) {
    //do something
  } else if (rso != null) {
    //if some condition; break label337;
  }else{
    //do something else
  }
}
label337: for (TileInfo t : fallenTiles) {         
}

instead of this create new methods to perform your logic

private void CheckMyConditionsMethod(MyParameters obj){
    if (rsi != null) {
        //do something
    } else if (rso != null) {
        //if some condition return;
    }else{
        //do something else
    }
    fallenTilesMethod(fallenTiles);
}

private void fallenTilesMethod(ArrayList<TileInfo> fallenTiles){
   for (TileInfo t : fallenTiles) {         
   }
}

now your code is shortened to

for (final TileInfo t : this.myTiles) {
      CheckMyConditionsMethod(myobj);
}

Also in your original case, you most likely have a compilation error "The label label337 is missing" since it is declared after its use. using methods will help remove that error as well.

Sean
  • 7,597
  • 1
  • 24
  • 26
  • If that's the case, what block of code does a label refer to. Is it the block of code beginning just after the label all the way uptil the next } or does it refer just to the for loop it preceeds? – Ploo Jun 14 '11 at 18:32
  • the label starts your 2nd for statement, and the break jumps to that point in the code and continues on – Sean Jun 14 '11 at 18:33
  • In that case simply is it not a matter of moving for for (TileInfo t : fallenTiles) loop to replace both of the break label337; statements, after of course adding braces or am I missing something? – Ploo Jun 14 '11 at 18:36
  • in the case I gave above, all you need to do is replace the 'break label337' statements with 'return'. By doing that, you exit the method and go to the 2nd for loop, which you would have broken to anyway – Sean Jun 14 '11 at 18:39
  • let me contradict myself for a moment, I just read the doc, it has been some time since i looked, used labels. if used on a break, it will skip passed the ending bracket of the labeled code. let me edit the above code some – Sean Jun 14 '11 at 18:55
0

That looks like your decompiler messed up and put the labels in the wrong spot. At least for the first example, if you move label337 to the outer most for-loop in which the breaks occur, it should compile just fine and do what you expect. For the other one, you will have to modify the if block to near the last break to get to compile.

Here is a brief tutorial on how to use breaks with labels: http://download.oracle.com/javase/tutorial/java/nutsandbolts/branch.html

Mikola
  • 9,176
  • 2
  • 34
  • 41