Dealing with labels in decompiled code
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 reque开发者_StackOverflowst 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.
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.
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
精彩评论