mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-09-25 12:50:46 +00:00
AS3 better deobfuscation
This commit is contained in:
@@ -2411,11 +2411,22 @@ public class AVM2Code implements Serializable {
|
|||||||
public boolean skipUsed = false;
|
public boolean skipUsed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int removeTraps(boolean secondPass, boolean useVisited, List localData, Stack<GraphTargetItem> stack, List<GraphTargetItem> output, AVM2GraphSource code, int ip, int lastIp, List<Integer> visited, HashMap<GraphSourceItem, Decision> decisions) {
|
private static int removeTraps(boolean secondPass, boolean useVisited, List localData, Stack<GraphTargetItem> stack, List<GraphTargetItem> output, AVM2GraphSource code, int ip, int lastIp, List<Integer> visited, HashMap<Integer, HashMap<Integer, GraphTargetItem>> visitedStates, HashMap<GraphSourceItem, Decision> decisions) {
|
||||||
boolean debugMode = false;
|
boolean debugMode = false;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
iploop:
|
iploop:
|
||||||
while ((ip > -1) && ip < code.size()) {
|
while ((ip > -1) && ip < code.size()) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
HashMap<Integer, GraphTargetItem> currentState = (HashMap<Integer, GraphTargetItem>) localData.get(2);
|
||||||
|
if (visitedStates.containsKey(ip)) {
|
||||||
|
HashMap<Integer, GraphTargetItem> lastState = visitedStates.get(ip);
|
||||||
|
if (lastState.equals(currentState)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
visitedStates.put(ip, (HashMap<Integer, GraphTargetItem>) currentState.clone());
|
||||||
if (useVisited && visited.contains(ip)) {
|
if (useVisited && visited.contains(ip)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -2536,7 +2547,7 @@ public class AVM2Code implements Serializable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret += removeTraps(secondPass, useVisited, localData, stack, output, code, condition ? branches.get(0) : branches.get(1), ip, visited, decisions);
|
ret += removeTraps(secondPass, useVisited, localData, stack, output, code, condition ? branches.get(0) : branches.get(1), ip, visited, visitedStates, decisions);
|
||||||
} else {
|
} else {
|
||||||
if (ins.isBranch() && (!ins.isJump())) {
|
if (ins.isBranch() && (!ins.isJump())) {
|
||||||
stack.pop();
|
stack.pop();
|
||||||
@@ -2545,7 +2556,7 @@ public class AVM2Code implements Serializable {
|
|||||||
for (int b : branches) {
|
for (int b : branches) {
|
||||||
Stack<GraphTargetItem> brStack = (Stack<GraphTargetItem>) stack.clone();
|
Stack<GraphTargetItem> brStack = (Stack<GraphTargetItem>) stack.clone();
|
||||||
if (b >= 0) {
|
if (b >= 0) {
|
||||||
ret += removeTraps(secondPass, useVisited || (!ins.isJump()), localData, brStack, output, code, b, ip, visited, decisions);
|
ret += removeTraps(secondPass, useVisited || (!ins.isJump()), localData, brStack, output, code, b, ip, visited, visitedStates, decisions);
|
||||||
} else {
|
} else {
|
||||||
if (debugMode) {
|
if (debugMode) {
|
||||||
System.out.println("Negative branch:" + b);
|
System.out.println("Negative branch:" + b);
|
||||||
@@ -2565,7 +2576,7 @@ public class AVM2Code implements Serializable {
|
|||||||
|
|
||||||
public static int removeTraps(List localData, AVM2GraphSource code, int addr) {
|
public static int removeTraps(List localData, AVM2GraphSource code, int addr) {
|
||||||
HashMap<GraphSourceItem, AVM2Code.Decision> decisions = new HashMap<GraphSourceItem, AVM2Code.Decision>();
|
HashMap<GraphSourceItem, AVM2Code.Decision> decisions = new HashMap<GraphSourceItem, AVM2Code.Decision>();
|
||||||
removeTraps(false, false, localData, new Stack<GraphTargetItem>(), new ArrayList<GraphTargetItem>(), code, code.adr2pos(addr), 0, new ArrayList<Integer>(), decisions);
|
removeTraps(false, false, localData, new Stack<GraphTargetItem>(), new ArrayList<GraphTargetItem>(), code, code.adr2pos(addr), 0, new ArrayList<Integer>(), new HashMap<Integer, HashMap<Integer, GraphTargetItem>>(), decisions);
|
||||||
return removeTraps(true, false, localData, new Stack<GraphTargetItem>(), new ArrayList<GraphTargetItem>(), code, code.adr2pos(addr), 0, new ArrayList<Integer>(), decisions);
|
return removeTraps(true, false, localData, new Stack<GraphTargetItem>(), new ArrayList<GraphTargetItem>(), code, code.adr2pos(addr), 0, new ArrayList<Integer>(), new HashMap<Integer, HashMap<Integer, GraphTargetItem>>(), decisions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.jpexs.decompiler.flash.abc.types;
|
package com.jpexs.decompiler.flash.abc.types;
|
||||||
|
|
||||||
|
import com.jpexs.decompiler.flash.Configuration;
|
||||||
import com.jpexs.decompiler.flash.Main;
|
import com.jpexs.decompiler.flash.Main;
|
||||||
import com.jpexs.decompiler.flash.abc.ABC;
|
import com.jpexs.decompiler.flash.abc.ABC;
|
||||||
import com.jpexs.decompiler.flash.abc.avm2.AVM2Code;
|
import com.jpexs.decompiler.flash.abc.avm2.AVM2Code;
|
||||||
@@ -42,6 +43,7 @@ public class MethodBody implements Cloneable, Serializable {
|
|||||||
public AVM2Code code;
|
public AVM2Code code;
|
||||||
public ABCException exceptions[] = new ABCException[0];
|
public ABCException exceptions[] = new ABCException[0];
|
||||||
public Traits traits = new Traits();
|
public Traits traits = new Traits();
|
||||||
|
private static boolean AUTO_DEOBFUSCATE = (Boolean) Configuration.getConfig("autoDeobfuscate", true);
|
||||||
|
|
||||||
public List<Integer> getExceptionEntries() {
|
public List<Integer> getExceptionEntries() {
|
||||||
List<Integer> ret = new ArrayList<Integer>();
|
List<Integer> ret = new ArrayList<Integer>();
|
||||||
@@ -115,7 +117,9 @@ public class MethodBody implements Cloneable, Serializable {
|
|||||||
MethodBody b = (MethodBody) Helper.deepCopy(this);
|
MethodBody b = (MethodBody) Helper.deepCopy(this);
|
||||||
deobfuscated = b.code;
|
deobfuscated = b.code;
|
||||||
deobfuscated.markMappedOffsets();
|
deobfuscated.markMappedOffsets();
|
||||||
deobfuscated.removeTraps(constants, b, abc);
|
if (AUTO_DEOBFUSCATE) {
|
||||||
|
deobfuscated.removeTraps(constants, b, abc);
|
||||||
|
}
|
||||||
//deobfuscated.restoreControlFlow(constants, b);
|
//deobfuscated.restoreControlFlow(constants, b);
|
||||||
try {
|
try {
|
||||||
s += deobfuscated.toSource(path, isStatic, classIndex, abc, constants, method_info, b, hilight, getLocalRegNames(abc), scopeStack, isStaticInitializer, fullyQualifiedNames, initTraits);
|
s += deobfuscated.toSource(path, isStatic, classIndex, abc, constants, method_info, b, hilight, getLocalRegNames(abc), scopeStack, isStaticInitializer, fullyQualifiedNames, initTraits);
|
||||||
|
|||||||
Reference in New Issue
Block a user