diff --git a/CHANGELOG.md b/CHANGELOG.md index 34d73e82f..691938d76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ All notable changes to this project will be documented in this file. - Dot parent operator not detected in some cases - Namespaces handling - Incorrectly colliding class names detection on script private classes +- AS3 deobfuscator of registers parsing of exception targets ### Changed - AS3 test methods separated to classes diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorRegistersOld.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorRegistersOld.java index c8ebbf890..aa79e62dc 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorRegistersOld.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorRegistersOld.java @@ -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.abc.avm2.deobfuscation; import com.jpexs.decompiler.flash.BaseLocalData; @@ -30,6 +31,8 @@ import com.jpexs.decompiler.flash.abc.avm2.instructions.other.ReturnValueIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.other.ReturnVoidIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.other.ThrowIns; import com.jpexs.decompiler.flash.abc.avm2.model.NullAVM2Item; +import com.jpexs.decompiler.flash.abc.avm2.model.clauses.ExceptionAVM2Item; +import com.jpexs.decompiler.flash.abc.types.ABCException; import com.jpexs.helpers.Reference; import com.jpexs.decompiler.flash.abc.types.MethodBody; import com.jpexs.decompiler.flash.abc.types.traits.Trait; @@ -42,8 +45,10 @@ import com.jpexs.decompiler.graph.TranslateException; import com.jpexs.decompiler.graph.TranslateStack; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; /** @@ -154,10 +159,42 @@ public class AVM2DeobfuscatorRegistersOld extends AVM2DeobfuscatorSimpleOld { return -1; } - return visitCode(assignment, new HashSet<>(), new TranslateStack("deo"), classIndex, isStatic, body, scriptIndex, abc, code, 0, code.code.size() - 1, ignoredRegisters, ignoredGets); + Set visited = new HashSet<>(); + return visitCode(assignment, visited, new TranslateStack("deo"), classIndex, isStatic, body, scriptIndex, abc, code, 0, code.code.size() - 1, ignoredRegisters, ignoredGets); + } + + private class ExceptionTargetIpPair { + + private final ABCException exception; + private final int targetIp; + + public ExceptionTargetIpPair(ABCException exception, int targetIp) { + this.exception = exception; + this.targetIp = targetIp; + } + + public ABCException getException() { + return exception; + } + + public int getTargetIp() { + return targetIp; + } + } private int visitCode(Reference assignment, Set visited, TranslateStack stack, int classIndex, boolean isStatic, MethodBody body, int scriptIndex, ABC abc, AVM2Code code, int idx, int endIdx, Set ignored, Set ignoredGets) throws InterruptedException { + + Map> exceptionStartToTargets = new HashMap<>(); + for (ABCException ex : body.exceptions) { + int startIp = code.adr2pos(ex.start); + int targetIp = code.adr2pos(ex.target); + if (!exceptionStartToTargets.containsKey(startIp)) { + exceptionStartToTargets.put(startIp, new ArrayList<>()); + } + exceptionStartToTargets.get(startIp).add(new ExceptionTargetIpPair(ex, targetIp)); + } + List output = new ArrayList<>(); AVM2LocalData localData = newLocalData(scriptIndex, abc, abc.constants, body, isStatic, classIndex); initLocalRegs(localData, body.getLocalReservedCount(), body.max_regs); @@ -185,6 +222,20 @@ public class AVM2DeobfuscatorRegistersOld extends AVM2DeobfuscatorSimpleOld { } visited.add(idx); + if (exceptionStartToTargets.containsKey(idx)) { + for (ExceptionTargetIpPair pair : exceptionStartToTargets.get(idx)) { + toVisit.add(pair.targetIp); + TranslateStack targetStack = (TranslateStack) stack.clone(); + targetStack.push(new ExceptionAVM2Item(pair.exception)); + toVisitStacks.add(targetStack); + } + } + for (ABCException ex : body.exceptions) { + if (code.pos2adr(idx) == ex.start) { + + } + } + AVM2Instruction ins = code.code.get(idx); InstructionDefinition def = ins.definition; //System.err.println("" + idx + ": " + ins + " stack:" + stack.size());