mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-07-16 17:10:22 +00:00
Improved error handling
This commit is contained in:
@@ -1221,15 +1221,13 @@ public class AVM2Code implements Serializable {
|
||||
|
||||
try {
|
||||
list = AVM2Graph.translateViaGraph(path, this, abc, body, isStatic, scriptIndex, classIndex, localRegs, scopeStack, localRegNames, fullyQualifiedNames);
|
||||
} catch (Exception ex2) {
|
||||
} catch (Exception | OutOfMemoryError | StackOverflowError ex2) {
|
||||
Logger.getLogger(AVM2Code.class.getName()).log(Level.SEVERE, "Decompilation error in " + path, ex2);
|
||||
return "/*\r\n * Decompilation error\r\n * Code may be obfuscated\r\n * Error Message: " + ex2.getMessage() + "\r\n */";
|
||||
if (ex2 instanceof OutOfMemoryError) {
|
||||
System.gc();
|
||||
}
|
||||
return "/*\r\n * Decompilation error\r\n * Code may be obfuscated\r\n * Error type: " + ex2.getClass().getSimpleName() + "\r\n */\r\nthrow new IllegalOperationError(\"Not decompiled due to error\");\r\n";
|
||||
}
|
||||
/*try{
|
||||
list=toSourceOutput(true,isStatic, classIndex, localRegs, new Stack<TreeItem>(), scopeStack, abc, constants, method_info, body, 0, code.size() - 1, localRegNames, fullyQualifiedNames, null).output;
|
||||
}catch(Exception ex){
|
||||
|
||||
}*/
|
||||
if (initTraits != null) {
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
GraphTargetItem ti = list.get(i);
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2013 JPEXS
|
||||
*
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
@@ -157,7 +157,7 @@ public class AVM2Graph extends Graph {
|
||||
}
|
||||
}
|
||||
|
||||
/*for(ABCException ex:body.exceptions){
|
||||
/*for(ABCException ex:body.exceptions){
|
||||
for(GraphPart p:allBlocks){
|
||||
boolean next_is_ex_start=false;
|
||||
for(GraphPart n:p.nextParts){
|
||||
@@ -579,43 +579,45 @@ public class AVM2Graph extends Graph {
|
||||
WhileItem w = (WhileItem) loopItem;
|
||||
|
||||
if ((!w.expression.isEmpty()) && (w.expression.get(w.expression.size() - 1) instanceof HasNextTreeItem)) {
|
||||
if (((HasNextTreeItem) w.expression.get(w.expression.size() - 1)).collection.getNotCoerced().getThroughRegister() instanceof FilteredCheckTreeItem) {
|
||||
//GraphTargetItem gti = ((HasNextTreeItem) ((HasNextTreeItem) w.expression.get(w.expression.size() - 1))).collection.getNotCoerced().getThroughRegister();
|
||||
if (w.commands.size() >= 3) { //((w.commands.size() == 3) || (w.commands.size() == 4)) {
|
||||
int pos = 0;
|
||||
while (w.commands.get(pos) instanceof SetLocalTreeItem) {
|
||||
pos++;
|
||||
}
|
||||
GraphTargetItem ft = w.commands.get(pos);
|
||||
if (ft instanceof WithTreeItem) {
|
||||
ft = w.commands.get(pos + 1);
|
||||
if (ft instanceof IfItem) {
|
||||
IfItem ift = (IfItem) ft;
|
||||
if (ift.onTrue.size() > 0) {
|
||||
ft = ift.onTrue.get(0);
|
||||
if (ft instanceof SetPropertyTreeItem) {
|
||||
SetPropertyTreeItem spt = (SetPropertyTreeItem) ft;
|
||||
if (spt.object instanceof LocalRegTreeItem) {
|
||||
int regIndex = ((LocalRegTreeItem) spt.object).regIndex;
|
||||
HasNextTreeItem iti = (HasNextTreeItem) w.expression.get(w.expression.size() - 1);
|
||||
@SuppressWarnings("unchecked")
|
||||
HashMap<Integer, GraphTargetItem> localRegs = (HashMap<Integer, GraphTargetItem>) localData.get(DATA_LOCALREGS);
|
||||
localRegs.put(regIndex, new FilterTreeItem(null, iti.collection.getThroughRegister(), ift.expression));
|
||||
return null;
|
||||
if (((HasNextTreeItem) w.expression.get(w.expression.size() - 1)).collection != null) {
|
||||
if (((HasNextTreeItem) w.expression.get(w.expression.size() - 1)).collection.getNotCoerced().getThroughRegister() instanceof FilteredCheckTreeItem) {
|
||||
//GraphTargetItem gti = ((HasNextTreeItem) ((HasNextTreeItem) w.expression.get(w.expression.size() - 1))).collection.getNotCoerced().getThroughRegister();
|
||||
if (w.commands.size() >= 3) { //((w.commands.size() == 3) || (w.commands.size() == 4)) {
|
||||
int pos = 0;
|
||||
while (w.commands.get(pos) instanceof SetLocalTreeItem) {
|
||||
pos++;
|
||||
}
|
||||
GraphTargetItem ft = w.commands.get(pos);
|
||||
if (ft instanceof WithTreeItem) {
|
||||
ft = w.commands.get(pos + 1);
|
||||
if (ft instanceof IfItem) {
|
||||
IfItem ift = (IfItem) ft;
|
||||
if (ift.onTrue.size() > 0) {
|
||||
ft = ift.onTrue.get(0);
|
||||
if (ft instanceof SetPropertyTreeItem) {
|
||||
SetPropertyTreeItem spt = (SetPropertyTreeItem) ft;
|
||||
if (spt.object instanceof LocalRegTreeItem) {
|
||||
int regIndex = ((LocalRegTreeItem) spt.object).regIndex;
|
||||
HasNextTreeItem iti = (HasNextTreeItem) w.expression.get(w.expression.size() - 1);
|
||||
@SuppressWarnings("unchecked")
|
||||
HashMap<Integer, GraphTargetItem> localRegs = (HashMap<Integer, GraphTargetItem>) localData.get(DATA_LOCALREGS);
|
||||
localRegs.put(regIndex, new FilterTreeItem(null, iti.collection.getThroughRegister(), ift.expression));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (!w.commands.isEmpty()) {
|
||||
if (w.commands.get(0) instanceof SetTypeTreeItem) {
|
||||
SetTypeTreeItem sti = (SetTypeTreeItem) w.commands.remove(0);
|
||||
GraphTargetItem gti = sti.getValue().getNotCoerced();
|
||||
if (gti instanceof NextValueTreeItem) {
|
||||
return new ForEachInTreeItem(w.src, w.loop, new InTreeItem(null, sti.getObject(), ((HasNextTreeItem) w.expression.get(w.expression.size() - 1)).collection), w.commands);
|
||||
} else if (gti instanceof NextNameTreeItem) {
|
||||
return new ForInTreeItem(w.src, w.loop, new InTreeItem(null, sti.getObject(), ((HasNextTreeItem) w.expression.get(w.expression.size() - 1)).collection), w.commands);
|
||||
} else if (!w.commands.isEmpty()) {
|
||||
if (w.commands.get(0) instanceof SetTypeTreeItem) {
|
||||
SetTypeTreeItem sti = (SetTypeTreeItem) w.commands.remove(0);
|
||||
GraphTargetItem gti = sti.getValue().getNotCoerced();
|
||||
if (gti instanceof NextValueTreeItem) {
|
||||
return new ForEachInTreeItem(w.src, w.loop, new InTreeItem(null, sti.getObject(), ((HasNextTreeItem) w.expression.get(w.expression.size() - 1)).collection), w.commands);
|
||||
} else if (gti instanceof NextNameTreeItem) {
|
||||
return new ForInTreeItem(w.src, w.loop, new InTreeItem(null, sti.getObject(), ((HasNextTreeItem) w.expression.get(w.expression.size() - 1)).collection), w.commands);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -638,7 +640,7 @@ public class AVM2Graph extends Graph {
|
||||
|
||||
if (list.get(i) instanceof WhileItem) {
|
||||
WhileItem w = (WhileItem) list.get(i);
|
||||
|
||||
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
@@ -16,11 +16,9 @@
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.abc.avm2.instructions.localregs;
|
||||
|
||||
import com.jpexs.decompiler.flash.abc.ABC;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.ConstantPool;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.LocalDataArea;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.treemodel.ClassTreeItem;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.treemodel.ScriptTreeItem;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.treemodel.ThisTreeItem;
|
||||
@@ -30,7 +28,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
|
||||
public class GetLocal0Ins extends InstructionDefinition implements GetLocalTypeIns {
|
||||
public class GetLocal0Ins extends GetLocalTypeIns {
|
||||
|
||||
public GetLocal0Ins() {
|
||||
super(0xd0, "getlocal_0", new int[]{});
|
||||
@@ -58,9 +56,4 @@ public class GetLocal0Ins extends InstructionDefinition implements GetLocalTypeI
|
||||
public int getRegisterId(AVM2Instruction par0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStackDelta(AVM2Instruction ins, ABC abc) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,19 +16,12 @@
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.abc.avm2.instructions.localregs;
|
||||
|
||||
import com.jpexs.decompiler.flash.abc.ABC;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.ConstantPool;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.LocalDataArea;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.treemodel.LocalRegTreeItem;
|
||||
import com.jpexs.decompiler.flash.abc.types.MethodInfo;
|
||||
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
|
||||
public class GetLocal1Ins extends InstructionDefinition implements GetLocalTypeIns {
|
||||
public class GetLocal1Ins extends GetLocalTypeIns {
|
||||
|
||||
public GetLocal1Ins() {
|
||||
super(0xd1, "getlocal_1", new int[]{});
|
||||
@@ -39,18 +32,8 @@ public class GetLocal1Ins extends InstructionDefinition implements GetLocalTypeI
|
||||
lda.operandStack.push(lda.localRegisters.get(1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void translate(boolean isStatic, int scriptIndex, int classIndex, java.util.HashMap<Integer, GraphTargetItem> localRegs, Stack<GraphTargetItem> stack, java.util.Stack<GraphTargetItem> scopeStack, ConstantPool constants, AVM2Instruction ins, MethodInfo[] method_info, List<GraphTargetItem> output, com.jpexs.decompiler.flash.abc.types.MethodBody body, com.jpexs.decompiler.flash.abc.ABC abc, HashMap<Integer, String> localRegNames, List<String> fullyQualifiedNames) {
|
||||
stack.push(new LocalRegTreeItem(ins, 1, localRegs.get(1)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRegisterId(AVM2Instruction par0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStackDelta(AVM2Instruction ins, ABC abc) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,19 +16,12 @@
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.abc.avm2.instructions.localregs;
|
||||
|
||||
import com.jpexs.decompiler.flash.abc.ABC;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.ConstantPool;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.LocalDataArea;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.treemodel.LocalRegTreeItem;
|
||||
import com.jpexs.decompiler.flash.abc.types.MethodInfo;
|
||||
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
|
||||
public class GetLocal2Ins extends InstructionDefinition implements GetLocalTypeIns {
|
||||
public class GetLocal2Ins extends GetLocalTypeIns {
|
||||
|
||||
public GetLocal2Ins() {
|
||||
super(0xd2, "getlocal_2", new int[]{});
|
||||
@@ -39,18 +32,8 @@ public class GetLocal2Ins extends InstructionDefinition implements GetLocalTypeI
|
||||
lda.operandStack.push(lda.localRegisters.get(2));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void translate(boolean isStatic, int scriptIndex, int classIndex, java.util.HashMap<Integer, GraphTargetItem> localRegs, Stack<GraphTargetItem> stack, java.util.Stack<GraphTargetItem> scopeStack, ConstantPool constants, AVM2Instruction ins, MethodInfo[] method_info, List<GraphTargetItem> output, com.jpexs.decompiler.flash.abc.types.MethodBody body, com.jpexs.decompiler.flash.abc.ABC abc, HashMap<Integer, String> localRegNames, List<String> fullyQualifiedNames) {
|
||||
stack.push(new LocalRegTreeItem(ins, 2, localRegs.get(2)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRegisterId(AVM2Instruction par0) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStackDelta(AVM2Instruction ins, ABC abc) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,19 +16,12 @@
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.abc.avm2.instructions.localregs;
|
||||
|
||||
import com.jpexs.decompiler.flash.abc.ABC;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.ConstantPool;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.LocalDataArea;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.treemodel.LocalRegTreeItem;
|
||||
import com.jpexs.decompiler.flash.abc.types.MethodInfo;
|
||||
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
|
||||
public class GetLocal3Ins extends InstructionDefinition implements GetLocalTypeIns {
|
||||
public class GetLocal3Ins extends GetLocalTypeIns {
|
||||
|
||||
public GetLocal3Ins() {
|
||||
super(0xd3, "getlocal_3", new int[]{});
|
||||
@@ -39,18 +32,8 @@ public class GetLocal3Ins extends InstructionDefinition implements GetLocalTypeI
|
||||
lda.operandStack.push(lda.localRegisters.get(3));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void translate(boolean isStatic, int scriptIndex, int classIndex, java.util.HashMap<Integer, GraphTargetItem> localRegs, Stack<GraphTargetItem> stack, java.util.Stack<GraphTargetItem> scopeStack, ConstantPool constants, AVM2Instruction ins, MethodInfo[] method_info, List<GraphTargetItem> output, com.jpexs.decompiler.flash.abc.types.MethodBody body, com.jpexs.decompiler.flash.abc.ABC abc, HashMap<Integer, String> localRegNames, List<String> fullyQualifiedNames) {
|
||||
stack.push(new LocalRegTreeItem(ins, 3, localRegs.get(3)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRegisterId(AVM2Instruction par0) {
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStackDelta(AVM2Instruction ins, ABC abc) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,20 +16,13 @@
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.abc.avm2.instructions.localregs;
|
||||
|
||||
import com.jpexs.decompiler.flash.abc.ABC;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.AVM2Code;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.ConstantPool;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.LocalDataArea;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.treemodel.LocalRegTreeItem;
|
||||
import com.jpexs.decompiler.flash.abc.types.MethodInfo;
|
||||
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
|
||||
public class GetLocalIns extends InstructionDefinition implements GetLocalTypeIns {
|
||||
public class GetLocalIns extends GetLocalTypeIns {
|
||||
|
||||
public GetLocalIns() {
|
||||
super(0x62, "getlocal", new int[]{AVM2Code.DAT_LOCAL_REG_INDEX});
|
||||
@@ -40,19 +33,8 @@ public class GetLocalIns extends InstructionDefinition implements GetLocalTypeIn
|
||||
lda.operandStack.push(lda.localRegisters.get((int) (long) (Long) arguments.get(0)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void translate(boolean isStatic, int scriptIndex, int classIndex, java.util.HashMap<Integer, GraphTargetItem> localRegs, Stack<GraphTargetItem> stack, java.util.Stack<GraphTargetItem> scopeStack, ConstantPool constants, AVM2Instruction ins, MethodInfo[] method_info, List<GraphTargetItem> output, com.jpexs.decompiler.flash.abc.types.MethodBody body, com.jpexs.decompiler.flash.abc.ABC abc, HashMap<Integer, String> localRegNames, List<String> fullyQualifiedNames) {
|
||||
int regIndex = ins.operands[0];
|
||||
stack.push(new LocalRegTreeItem(ins, regIndex, localRegs.get(regIndex)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRegisterId(AVM2Instruction ins) {
|
||||
return ins.operands[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStackDelta(AVM2Instruction ins, ABC abc) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,9 +16,39 @@
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.abc.avm2.instructions.localregs;
|
||||
|
||||
import com.jpexs.decompiler.flash.abc.ABC;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.ConstantPool;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.treemodel.LocalRegTreeItem;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.treemodel.UndefinedTreeItem;
|
||||
import com.jpexs.decompiler.flash.abc.types.MethodInfo;
|
||||
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
|
||||
public interface GetLocalTypeIns {
|
||||
public abstract class GetLocalTypeIns extends InstructionDefinition {
|
||||
|
||||
public GetLocalTypeIns(int instructionCode, String instructionName, int[] operands) {
|
||||
super(instructionCode, instructionName, operands);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void translate(boolean isStatic, int scriptIndex, int classIndex, java.util.HashMap<Integer, GraphTargetItem> localRegs, Stack<GraphTargetItem> stack, java.util.Stack<GraphTargetItem> scopeStack, ConstantPool constants, AVM2Instruction ins, MethodInfo[] method_info, List<GraphTargetItem> output, com.jpexs.decompiler.flash.abc.types.MethodBody body, com.jpexs.decompiler.flash.abc.ABC abc, HashMap<Integer, String> localRegNames, List<String> fullyQualifiedNames) {
|
||||
GraphTargetItem computedValue = localRegs.get(getRegisterId(ins));
|
||||
if (computedValue == null) {
|
||||
if (!localRegNames.containsKey(getRegisterId(ins))) {
|
||||
computedValue = new UndefinedTreeItem(null);
|
||||
}
|
||||
}
|
||||
stack.push(new LocalRegTreeItem(ins, getRegisterId(ins), computedValue));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStackDelta(AVM2Instruction ins, ABC abc) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public abstract int getRegisterId(AVM2Instruction ins);
|
||||
}
|
||||
|
||||
@@ -31,4 +31,19 @@ public class UndefinedTreeItem extends TreeItem {
|
||||
public String toString(ConstantPool constants, HashMap<Integer, String> localRegNames, List<String> fullyQualifiedNames) {
|
||||
return hilight("undefined");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCompileTime() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double toNumber() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean toBoolean() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ import java.util.logging.Logger;
|
||||
|
||||
public class MethodBody implements Cloneable, Serializable {
|
||||
|
||||
boolean debugMode = false;
|
||||
public int method_info;
|
||||
public int max_stack;
|
||||
public int max_regs;
|
||||
@@ -102,6 +103,9 @@ public class MethodBody implements Cloneable, Serializable {
|
||||
}
|
||||
|
||||
public String toString(String path, boolean pcode, boolean isStatic, int scriptIndex, int classIndex, ABC abc, ConstantPool constants, MethodInfo method_info[], Stack<GraphTargetItem> scopeStack, boolean isStaticInitializer, boolean hilight, List<String> fullyQualifiedNames, Traits initTraits) {
|
||||
if (debugMode) {
|
||||
System.err.println("Decompiling " + path);
|
||||
}
|
||||
String s = "";
|
||||
if (!(Boolean) Configuration.getConfig("decompile", Boolean.TRUE)) {
|
||||
s = "//Decompilation skipped";
|
||||
@@ -125,20 +129,16 @@ public class MethodBody implements Cloneable, Serializable {
|
||||
}
|
||||
}
|
||||
//deobfuscated.restoreControlFlow(constants, b);
|
||||
try {
|
||||
s += deobfuscated.toSource(path, isStatic, scriptIndex, classIndex, abc, constants, method_info, b, hilight, getLocalRegNames(abc), scopeStack, isStaticInitializer, fullyQualifiedNames, initTraits);
|
||||
s = s.trim();
|
||||
if (hilight) {
|
||||
s = Highlighting.hilighMethod(s, this.method_info);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Logger.getLogger(MethodBody.class.getName()).log(Level.SEVERE, "Exception during decompilation", ex);
|
||||
s = "//error:" + ex.toString();
|
||||
} catch (OutOfMemoryError er) {
|
||||
Logger.getLogger(MethodBody.class.getName()).log(Level.SEVERE, "Error during decompilation", er);
|
||||
s = "//error:" + er.toString();
|
||||
System.gc();
|
||||
//try {
|
||||
s += deobfuscated.toSource(path, isStatic, scriptIndex, classIndex, abc, constants, method_info, b, hilight, getLocalRegNames(abc), scopeStack, isStaticInitializer, fullyQualifiedNames, initTraits);
|
||||
s = s.trim();
|
||||
if (hilight) {
|
||||
s = Highlighting.hilighMethod(s, this.method_info);
|
||||
}
|
||||
/*} catch (Exception|StackOverflowError|OutOfMemoryError er) {
|
||||
Logger.getLogger(MethodBody.class.getName()).log(Level.SEVERE, "Error during decompilation", er);
|
||||
s = "//error:" + er.toString();
|
||||
}*/
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,6 @@ import java.util.List;
|
||||
|
||||
public abstract class Trait implements Serializable {
|
||||
|
||||
public static boolean debugMode = false;
|
||||
public int name_index;
|
||||
public int kindType;
|
||||
public int kindFlags;
|
||||
|
||||
@@ -349,9 +349,6 @@ public class TraitClass extends Trait implements TraitWithSlot {
|
||||
}
|
||||
|
||||
String packageName = abc.instance_info[class_info].getName(abc.constants).getNamespace(abc.constants).getName(abc.constants);
|
||||
if (debugMode) {
|
||||
System.err.println("Decompiling " + packageName + "." + abc.instance_info[class_info].getName(abc.constants).getName(abc.constants, fullyQualifiedNames));
|
||||
}
|
||||
List<String> namesInThisPackage = new ArrayList<>();
|
||||
for (ABCContainerTag tag : abcTags) {
|
||||
for (ScriptInfo si : tag.getABC().script_info) {
|
||||
|
||||
@@ -54,21 +54,12 @@ public class TraitMethodGetterSetter extends Trait {
|
||||
|
||||
@Override
|
||||
public String convert(String path, List<ABCContainerTag> abcTags, ABC abc, boolean isStatic, boolean pcode, int scriptIndex, int classIndex, boolean highlight, List<String> fullyQualifiedNames, boolean paralel) {
|
||||
|
||||
if (debugMode) {
|
||||
System.err.println("Decompiling " + path + "." + getName(abc).getName(abc.constants, fullyQualifiedNames));
|
||||
}
|
||||
String header = convertHeader(path, abcTags, abc, isStatic, pcode, scriptIndex, classIndex, highlight, fullyQualifiedNames, paralel);
|
||||
|
||||
String bodyStr = "";
|
||||
int bodyIndex = abc.findBodyIndex(method_info);
|
||||
if (bodyIndex != -1) {
|
||||
try {
|
||||
bodyStr = ABC.addTabs(abc.bodies[bodyIndex].toString(path + "." + getName(abc).getName(abc.constants, fullyQualifiedNames), pcode, isStatic, scriptIndex, classIndex, abc, abc.constants, abc.method_info, new Stack<GraphTargetItem>(), false, highlight, fullyQualifiedNames, null), 3);
|
||||
} catch (StackOverflowError er) {
|
||||
er.printStackTrace();
|
||||
bodyStr = "//StackOverflowError";
|
||||
}
|
||||
bodyStr = ABC.addTabs(abc.bodies[bodyIndex].toString(path + "." + getName(abc).getName(abc.constants, fullyQualifiedNames), pcode, isStatic, scriptIndex, classIndex, abc, abc.constants, abc.method_info, new Stack<GraphTargetItem>(), false, highlight, fullyQualifiedNames, null), 3);
|
||||
}
|
||||
return ABC.IDENT_STRING + ABC.IDENT_STRING + header + ((classIndex != -1 && abc.instance_info[classIndex].isInterface()) ? ";" : " {\r\n" + bodyStr + "\r\n" + ABC.IDENT_STRING + ABC.IDENT_STRING + "}");
|
||||
}
|
||||
|
||||
@@ -360,10 +360,13 @@ public class Action implements GraphSourceItem {
|
||||
/**
|
||||
* Converts list of actions to ASM source
|
||||
*
|
||||
* @param listeners
|
||||
* @param address
|
||||
* @param list List of actions
|
||||
* @param importantOffsets List of important offsets to mark as labels
|
||||
* @param version SWF version
|
||||
* @param hex Add hexadecimal?
|
||||
* @param swfPos
|
||||
* @return ASM source as String
|
||||
*/
|
||||
public static String actionsToString(List<DisassemblyListener> listeners, long address, List<Action> list, List<Long> importantOffsets, int version, boolean hex, long swfPos) {
|
||||
@@ -373,11 +376,14 @@ public class Action implements GraphSourceItem {
|
||||
/**
|
||||
* Converts list of actions to ASM source
|
||||
*
|
||||
* @param listeners
|
||||
* @param address
|
||||
* @param list List of actions
|
||||
* @param importantOffsets List of important offsets to mark as labels
|
||||
* @param constantPool Constant pool
|
||||
* @param version SWF version
|
||||
* @param hex Add hexadecimal?
|
||||
* @param swfPos
|
||||
* @return ASM source as String
|
||||
*/
|
||||
public static String actionsToString(List<DisassemblyListener> listeners, long address, List<Action> list, List<Long> importantOffsets, List<String> constantPool, int version, boolean hex, long swfPos) {
|
||||
@@ -541,6 +547,7 @@ public class Action implements GraphSourceItem {
|
||||
/**
|
||||
* Convert action to ASM source
|
||||
*
|
||||
* @param container
|
||||
* @param knownAddreses List of important offsets to mark as labels
|
||||
* @param constantPool Constant pool
|
||||
* @param version SWF version
|
||||
@@ -647,9 +654,12 @@ public class Action implements GraphSourceItem {
|
||||
|
||||
|
||||
return Graph.graphToString(tree);
|
||||
} catch (Exception ex) {
|
||||
Logger.getLogger(Action.class.getName()).log(Level.SEVERE, null, ex);
|
||||
return "//Decompilation error :" + ex.getLocalizedMessage();
|
||||
} catch (Exception | OutOfMemoryError | StackOverflowError ex2) {
|
||||
Logger.getLogger(Action.class.getName()).log(Level.SEVERE, "Decompilation error", ex2);
|
||||
if (ex2 instanceof OutOfMemoryError) {
|
||||
System.gc();
|
||||
}
|
||||
return "/*\r\n * Decompilation error\r\n * Code may be obfuscated\r\n * Error type: " + ex2.getClass().getSimpleName() + "\r\n */";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -657,6 +667,8 @@ public class Action implements GraphSourceItem {
|
||||
* Converts list of actions to List of treeItems
|
||||
*
|
||||
* @param regNames Register names
|
||||
* @param variables
|
||||
* @param functions
|
||||
* @param actions List of actions
|
||||
* @param version SWF version
|
||||
* @return List of treeItems
|
||||
@@ -804,10 +816,13 @@ public class Action implements GraphSourceItem {
|
||||
List<GraphTargetItem> out;
|
||||
try {
|
||||
out = ActionGraph.translateViaGraph(cnt.getRegNames(), variables, functions, actions.subList(adr2ip(actions, endAddr, version), adr2ip(actions, endAddr + size, version)), version);
|
||||
} catch (RuntimeException re) {
|
||||
} catch (Exception | OutOfMemoryError | StackOverflowError ex2) {
|
||||
Logger.getLogger(Action.class.getName()).log(Level.SEVERE, "Decompilation error", ex2);
|
||||
if (ex2 instanceof OutOfMemoryError) {
|
||||
System.gc();
|
||||
}
|
||||
out = new ArrayList<>();
|
||||
out.add(new CommentItem("Error " + re.getMessage()));
|
||||
Logger.getLogger(Action.class.getName()).log(Level.SEVERE, "Error during container translation", re);
|
||||
out.add(new CommentItem("\r\n * Decompilation error\r\n * Code may be obfuscated\r\n * Error type: " + ex2.getClass().getSimpleName() + "\r\n"));
|
||||
}
|
||||
outs.add(out);
|
||||
endAddr += size;
|
||||
|
||||
@@ -25,8 +25,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Stack;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -536,37 +534,31 @@ public class Graph {
|
||||
}
|
||||
|
||||
public List<GraphTargetItem> translate(List<Object> localData) {
|
||||
try {
|
||||
List<GraphPart> allParts = new ArrayList<>();
|
||||
for (GraphPart head : heads) {
|
||||
populateParts(head, allParts);
|
||||
}
|
||||
Stack<GraphTargetItem> stack = new Stack<>();
|
||||
List<Loop> loops = new ArrayList<>();
|
||||
getLoops(heads.get(0), loops, null);
|
||||
/*System.out.println("<loops>");
|
||||
for (Loop el : loops) {
|
||||
System.out.println(el);
|
||||
}
|
||||
System.out.println("</loops>");*/
|
||||
getPrecontinues(null, heads.get(0), loops, null);
|
||||
/*System.err.println("<loopspre>");
|
||||
for (Loop el : loops) {
|
||||
System.err.println(el);
|
||||
}
|
||||
System.err.println("</loopspre>");//*/
|
||||
|
||||
List<GraphTargetItem> ret = printGraph(new ArrayList<GraphPart>(), localData, stack, allParts, null, heads.get(0), null, loops);
|
||||
processIfs(ret);
|
||||
finalProcessStack(stack, ret);
|
||||
finalProcessAll(ret, 0);
|
||||
return ret;
|
||||
} catch (StackOverflowError soe) {
|
||||
List<GraphTargetItem> ret = new ArrayList<>();
|
||||
ret.add(new CommentItem("StackOverflowError"));
|
||||
Logger.getLogger(Graph.class.getName()).log(Level.SEVERE, "error during printGraph", soe);
|
||||
return ret;
|
||||
List<GraphPart> allParts = new ArrayList<>();
|
||||
for (GraphPart head : heads) {
|
||||
populateParts(head, allParts);
|
||||
}
|
||||
Stack<GraphTargetItem> stack = new Stack<>();
|
||||
List<Loop> loops = new ArrayList<>();
|
||||
getLoops(heads.get(0), loops, null);
|
||||
/*System.out.println("<loops>");
|
||||
for (Loop el : loops) {
|
||||
System.out.println(el);
|
||||
}
|
||||
System.out.println("</loops>");*/
|
||||
getPrecontinues(null, heads.get(0), loops, null);
|
||||
/*System.err.println("<loopspre>");
|
||||
for (Loop el : loops) {
|
||||
System.err.println(el);
|
||||
}
|
||||
System.err.println("</loopspre>");//*/
|
||||
|
||||
List<GraphTargetItem> ret = printGraph(new ArrayList<GraphPart>(), localData, stack, allParts, null, heads.get(0), null, loops);
|
||||
processIfs(ret);
|
||||
finalProcessStack(stack, ret);
|
||||
finalProcessAll(ret, 0);
|
||||
return ret;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1543,14 +1535,9 @@ public class Graph {
|
||||
end = p.end;
|
||||
int start = p.start;
|
||||
|
||||
try {
|
||||
output.addAll(code.translatePart(p, localData, stack, start, end));
|
||||
if ((end >= code.size() - 1) && p.nextParts.isEmpty()) {
|
||||
output.add(new ScriptEndItem());
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Logger.getLogger(Graph.class.getName()).log(Level.SEVERE, "error during printgraph", ex);
|
||||
return ret;
|
||||
output.addAll(code.translatePart(p, localData, stack, start, end));
|
||||
if ((end >= code.size() - 1) && p.nextParts.isEmpty()) {
|
||||
output.add(new ScriptEndItem());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user