new tests for FQNs and namespaces, using pluginpath config

This commit is contained in:
honfika@gmail.com
2015-10-23 10:52:44 +02:00
parent f977c1c381
commit cbb3b1bff2
15 changed files with 227 additions and 20 deletions

View File

@@ -61,7 +61,6 @@ import java.util.Set;
*/
public class AVM2DeobfuscatorRegisters extends AVM2DeobfuscatorSimple {
//private final int executionLimit = 30000;
@Override
public void actionListParsed(ActionList actions, SWF swf) {
@@ -118,7 +117,7 @@ public class AVM2DeobfuscatorRegisters extends AVM2DeobfuscatorSimple {
MethodBody bodybefore = body;
body = bodybefore.clone();
setReg = getFirstRegisterSetter(assignmentRef, classIndex, isStatic, scriptIndex, abc, body, ignoredRegs, ignoredRegGets);
//System.err.println("setreg " + setReg + " ass:" + assignment);
//System.err.println("setreg " + setReg + " ass:" + assignmentRef.getVal());
if (setReg < 0) {
break;
}

View File

@@ -17,6 +17,7 @@
package com.jpexs.decompiler.flash.abc.types;
import com.jpexs.decompiler.flash.abc.types.traits.TraitSlotConst;
import com.jpexs.decompiler.flash.configuration.Configuration;
import java.util.HashMap;
import java.util.Map;
@@ -26,5 +27,11 @@ import java.util.Map;
*/
public class ConvertData {
public int deobfuscationMode;
public Map<TraitSlotConst, AssignedValue> assignedValues = new HashMap<>();
public ConvertData() {
deobfuscationMode = Configuration.autoDeobfuscate.get() ? (Configuration.deobfuscationOldMode.get() ? 0 : 1) : -1;
}
}

View File

@@ -30,6 +30,7 @@ import com.jpexs.decompiler.flash.abc.types.traits.Traits;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.flash.helpers.HighlightedTextWriter;
import com.jpexs.decompiler.flash.helpers.NulWriter;
import com.jpexs.decompiler.flash.types.annotations.Internal;
import com.jpexs.decompiler.flash.types.annotations.SWFField;
@@ -294,7 +295,7 @@ public final class MethodBody implements Cloneable {
@Override
public Void call() throws InterruptedException {
try (Statistics s1 = new Statistics("MethodBody.convert")) {
MethodBody converted = convertMethodBody(path, isStatic, scriptIndex, classIndex, abc, trait, scopeStack, initializerType != GraphTextWriter.TRAIT_INSTANCE_INITIALIZER, fullyQualifiedNames, initTraits);
MethodBody converted = convertMethodBody(convertData, path, isStatic, scriptIndex, classIndex, abc, trait, scopeStack, initializerType != GraphTextWriter.TRAIT_INSTANCE_INITIALIZER, fullyQualifiedNames, initTraits);
HashMap<Integer, String> localRegNames = getLocalRegNames(abc);
List<GraphTargetItem> convertedItems1;
try (Statistics s = new Statistics("AVM2Code.toGraphTargetItems")) {
@@ -365,13 +366,13 @@ public final class MethodBody implements Cloneable {
return writer;
}
public MethodBody convertMethodBody(String path, boolean isStatic, int scriptIndex, int classIndex, ABC abc, Trait trait, ScopeStack scopeStack, boolean isStaticInitializer, List<DottedChain> fullyQualifiedNames, List<Traits> initTraits) throws InterruptedException {
public MethodBody convertMethodBody(ConvertData convertData, String path, boolean isStatic, int scriptIndex, int classIndex, ABC abc, Trait trait, ScopeStack scopeStack, boolean isStaticInitializer, List<DottedChain> fullyQualifiedNames, List<Traits> initTraits) throws InterruptedException {
MethodBody body = clone();
AVM2Code code = body.getCode();
code.markMappedOffsets();
code.fixJumps(path, body);
if (Configuration.autoDeobfuscate.get()) {
if (convertData.deobfuscationMode != -1) {
try {
code.removeTraps(trait, method_info, body, abc, scriptIndex, classIndex, isStatic, path);
} catch (ThreadDeath | InterruptedException ex) {
@@ -390,6 +391,23 @@ public final class MethodBody implements Cloneable {
return body;
}
public String toSource() {
ConvertData convertData = new ConvertData();
convertData.deobfuscationMode = -1;
try {
convert(convertData, "", ScriptExportMode.AS, false, method_info, 0, 0, abc, null, new ScopeStack(), 0, new NulWriter(), new ArrayList<>(), new ArrayList<>(), true);
HighlightedTextWriter writer = new HighlightedTextWriter(Configuration.getCodeFormatting(), false);
writer.indent().indent().indent();
toString("", ScriptExportMode.AS, abc, null, writer, new ArrayList<>());
writer.unindent().unindent().unindent();
return writer.toString();
} catch (InterruptedException ex) {
Logger.getLogger(MethodBody.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
@Override
public MethodBody clone() {
try {

View File

@@ -21,6 +21,7 @@ import com.jpexs.decompiler.flash.abc.ABC;
import com.jpexs.decompiler.flash.abc.types.MethodBody;
import com.jpexs.decompiler.flash.abc.types.traits.Trait;
import com.jpexs.decompiler.flash.action.ActionList;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.helpers.Helper;
import com.jpexs.helpers.Path;
@@ -53,9 +54,18 @@ public class SWFDecompilerPlugin {
public static void loadPlugins() {
try {
File f = new File(SWFDecompilerPlugin.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath());
File dir = f.getAbsoluteFile().getParentFile().getParentFile();
File pluginPath = new File(Path.combine(dir.getPath(), "plugins")).getCanonicalFile();
File pluginPath = null;
String pluginPathConfig = Configuration.pluginPath.get();
if (pluginPathConfig != null && !pluginPathConfig.isEmpty()) {
pluginPath = new File(pluginPathConfig);
}
if (pluginPath == null || !pluginPath.exists()) {
File f = new File(SWFDecompilerPlugin.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath());
File dir = f.getAbsoluteFile().getParentFile().getParentFile();
pluginPath = new File(Path.combine(dir.getPath(), "plugins")).getCanonicalFile();
}
if (pluginPath.exists()) {
System.out.println("Loading plugins from " + pluginPath.getPath());
File[] files = pluginPath.listFiles();