If you are looking for the decompiler itself, visit https://github.com/jindrapetrik/jpexs-decompiler
NEW : We have got a new blog where we post some interesting SWF internals info.
List of issues#10 Missing "default" code block when decompiling switch .. case sometimes
Author: googleCode
Date created:
Type: bug
Visibility: Everybody
Assigned to:
Labels: DecompilationGoogle Code
State: closed
Hi all. Thank you very much for your work, it's really cool thing. While using the prog i
found a little error with decompiling switch .. case code blocks.
The point is that the result code lines do not contain "default" case when there
is not "break" statement at the end in the source code.
Here is the example.
The original source code:
var jj:int = 1;
switch(jj)
{
case 1:
jj = 1;
break;
case 2:
jj = 2;
break;
default:
jj = 3;
}
The decompiled code:
jj=1;
switch(jj)
{
case 1:
jj=1;
break;
case 2:
jj=2;
break;
}
If you place "break" statement after jj=3, the code is decompiled right way.
I found the reason of that strange behavior. There is a little issue in AVM2Code.java
within toSource method.
Here is the code.
if (evalTo == -1)
subend--;
List commands = toSource(isStatic, classIndex, localRegs, new Stack<TreeItem>(),
scopeStack, abc, constants, method_info, body, substart, subend).output;
if ((evalTo == -1) && (casePos < code.get(switchPos).operands.length - 2)) {
if (commands.size() == 1) {
commands.remove(0);
}
if (commands.size() > 0) {
//hasDefault=true;
}
}
The error is that you compare zero based casePos variable with the count of case blocks of
lookupswitch instruction (including the default one).
So casePos < code.get(switchPos).operands.length - 2 will always true.
I changed this line to
if ((evalTo == -1) && (casePos + 1 < code.get(switchPos).operands.length - 2))
{
...
After that the example code is decompiled properly
Hi, thank you very much. I have implemented your change, it is in the repository.
State: →closed
Title: Missing "default" code block when decompiling switch .. case sometimes→Missing "default" code block when decompiling switch .. case sometimes
Type: →bug
Visibility: →Everybody
Title: Missing "default" code block when decompiling switch .. case sometimes→Missing "default" code block when decompiling switch .. case sometimes
Type: →bug
Visibility: →Everybody