Fixed AS1/2 DefineFunction cleaner

This commit is contained in:
Jindra Petřík
2021-11-21 10:22:11 +01:00
parent 21bedc7182
commit 9969a5cae5
4 changed files with 80 additions and 3 deletions

View File

@@ -12,7 +12,8 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.action;
import com.jpexs.decompiler.flash.SWF;
@@ -206,7 +207,25 @@ public class ActionDefineFunctionPushRegistersCleaner extends SWFDecompilerAdapt
return false;
}
Action actionWithRefs = asr;
//Special: ignore zero jump when pushundefined is stripped as unreachable
if (code.get(pos - 1) instanceof ActionJump) {
if (((ActionJump) code.get(pos - 1)).getJumpOffset() == 0) {
Iterator<Action> zit = code.getReferencesFor(code.get(pos));
int refCnt = 0;
while (zit.hasNext()) {
zit.next();
refCnt++;
}
if (refCnt == 1) {
actionWithRefs = code.get(pos - 1);
pos--;
}
}
}
Iterator<Action> ait = code.getReferencesFor(actionWithRefs);
while (ait.hasNext()) {
Action a = ait.next();
if (!(a instanceof ActionJump)) {
@@ -215,6 +234,7 @@ public class ActionDefineFunctionPushRegistersCleaner extends SWFDecompilerAdapt
jumpsToReturnPositions.add(code.indexOf(a));
}
pos--;
if (!(code.get(pos) instanceof ActionJump)) {
actionBeforeFinishPart = code.get(pos);
}

View File

@@ -12,7 +12,8 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.action;
import com.jpexs.decompiler.flash.DisassemblyListener;
@@ -28,13 +29,16 @@ import com.jpexs.decompiler.flash.action.swf4.ActionJump;
import com.jpexs.decompiler.flash.action.swf4.ActionPush;
import com.jpexs.decompiler.flash.action.swf5.ActionConstantPool;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode;
import com.jpexs.decompiler.flash.helpers.SWFDecompilerPlugin;
import com.jpexs.decompiler.graph.GraphSourceItemContainer;
import com.jpexs.helpers.CancellableWorker;
import com.jpexs.helpers.Helper;
import com.jpexs.helpers.stat.Statistics;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -163,6 +167,13 @@ public class ActionListReader {
}
}
/*System.err.println("=======================");
int p = 0;
for (Action a : actions) {
System.err.println("loc" + Helper.formatAddress(a.getAddress()) + " (" + p + "): " + a.getASMSource(actions, new HashSet<Long>(), ScriptExportMode.PCODE));
p++;
}*/
//TODO: This cleaner needs to be executed only before actual decompilation, not when disassembly only
try {
new ActionDefineFunctionPushRegistersCleaner().actionListParsed(actions, sis.getSwf());