diff --git a/.gitignore b/.gitignore index 6724a8300..a5fe3d50f 100644 --- a/.gitignore +++ b/.gitignore @@ -59,4 +59,7 @@ hs_err_pid*.log /tools.properties /nbproject/private/ /libsrc/cmykjpeg/build/ -/libsrc/cmykjpeg/nbproject/private/ \ No newline at end of file +/libsrc/cmykjpeg/nbproject/private/ +/libsrc/Plugins/nbproject/private/ +/libsrc/Plugins/build/ +/libsrc/Plugins/dist/ \ No newline at end of file diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionList.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionList.java index 51c30f4e1..cc69607d2 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionList.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionList.java @@ -348,6 +348,25 @@ public class ActionList extends ArrayList { return -1; } + public GraphSourceItemContainer getContainer(int idx) { + Action action = get(idx); + int i = idx - 1; + while (i >= 0) { + Action a = get(i); + if (a instanceof GraphSourceItemContainer) { + List lastActions = getContainerLastActions(a); + Action lastAction = lastActions.get(lastActions.size() - 1); + if (lastAction.getAddress() >= action.getAddress()) { + return (GraphSourceItemContainer) a; + } + } + + i--; + } + + return null; + } + public int getContainerEndIndex(int idx) { Action action = get(idx); int i = idx - 1; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/SWFDecompilerPlugin.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/SWFDecompilerPlugin.java index 6f7b4bea4..a7dd39591 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/SWFDecompilerPlugin.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/SWFDecompilerPlugin.java @@ -26,6 +26,12 @@ import com.jpexs.helpers.Helper; import com.jpexs.helpers.Path; import com.jpexs.helpers.plugin.CharSequenceJavaFileObject; import com.jpexs.helpers.plugin.ClassFileManager; +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URISyntaxException; +import java.net.URL; +import java.net.URLClassLoader; import java.util.ArrayList; import java.util.List; import java.util.logging.Level; @@ -45,6 +51,26 @@ public class SWFDecompilerPlugin { private static final List listeners = new ArrayList<>(); + 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(); + if (pluginPath.exists()) { + System.out.println("Loading plugins from " + pluginPath.getPath()); + File[] files = pluginPath.listFiles(); + if (files != null) { + for (File file : files) { + System.out.println("Loading plugin: " + file.getPath()); + loadPlugin(file.getPath()); + } + } + } + } catch (IOException | URISyntaxException ex) { + Logger.getLogger(SWFDecompilerPlugin.class.getName()).log(Level.SEVERE, null, ex); + } + } + public static void loadPlugin(String path) { if (".class".equals(Path.getExtension(path))) { loadPluginCompiled(path); @@ -54,7 +80,28 @@ public class SWFDecompilerPlugin { } private static void loadPluginCompiled(String path) { + File pluginFile = new File(path); + File file = pluginFile.getParentFile(); + try { + // Convert File to a URL + URL url = file.toURI().toURL(); + URL[] urls = new URL[]{url}; + + // Create a new class loader with the directory + ClassLoader cl = new URLClassLoader(urls); + + String pluginName = Path.getFileNameWithoutExtension(pluginFile); + Class cls = cl.loadClass(pluginName); + if (SWFDecompilerListener.class.isAssignableFrom(cls)) { + SWFDecompilerListener listener = (SWFDecompilerListener) cls.newInstance(); + listeners.add(listener); + } + + System.out.println("Plugin loaded: " + pluginName); + } catch (MalformedURLException | ClassNotFoundException | InstantiationException | IllegalAccessException ex) { + Logger.getLogger(SWFDecompilerPlugin.class.getName()).log(Level.SEVERE, null, ex); + } } private static void loadPluginSource(String path) { @@ -74,6 +121,11 @@ public class SWFDecompilerPlugin { // we create a file manager // (our custom implementation of it) JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); + if (compiler == null) { + logger.log(Level.SEVERE, "Compiler is null"); + return; + } + JavaFileManager fileManager = new ClassFileManager(compiler.getStandardFileManager(null, null, null)); // Dynamic compiling requires specifying @@ -91,6 +143,7 @@ public class SWFDecompilerPlugin { // Creating an instance of our compiled class and try { listeners.add((SWFDecompilerListener) fileManager.getClassLoader(null).loadClass(fullName).newInstance()); + System.out.println("Plugin loaded: " + fullName); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) { logger.log(Level.SEVERE, null, ex); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/helpers/Path.java b/libsrc/ffdec_lib/src/com/jpexs/helpers/Path.java index f39ac5651..e603341cb 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/helpers/Path.java +++ b/libsrc/ffdec_lib/src/com/jpexs/helpers/Path.java @@ -64,18 +64,19 @@ public class Path { if (i > 0 && i < s.length() - 1) { ext = s.substring(i).toLowerCase(); } + return ext; } public static String getFileNameWithoutExtension(File f) { - String ext = null; - String s = f.getName(); - int i = s.lastIndexOf('.'); + String fileName = f.getName(); + int i = fileName.lastIndexOf('.'); - if (i > 0 && i < s.length() - 1) { - ext = s.substring(0, i); + if (i > 0 && i < fileName.length() - 1) { + fileName = fileName.substring(0, i); } - return ext; + + return fileName; } public static void createDirectorySafe(File directory) throws IOException { diff --git a/libsrc/plugins/build.xml b/libsrc/plugins/build.xml new file mode 100644 index 000000000..02eb01e25 --- /dev/null +++ b/libsrc/plugins/build.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + Builds, tests, and runs the project plugins. + + + diff --git a/libsrc/plugins/nbproject/build-impl.xml b/libsrc/plugins/nbproject/build-impl.xml new file mode 100644 index 000000000..8e89a2114 --- /dev/null +++ b/libsrc/plugins/nbproject/build-impl.xml @@ -0,0 +1,1413 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + Must select one file in the IDE or set profile.class + This target only works when run from inside the NetBeans IDE. + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + Must select some files in the IDE or set test.includes + + + + + Must select one file in the IDE or set run.class + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libsrc/plugins/nbproject/genfiles.properties b/libsrc/plugins/nbproject/genfiles.properties new file mode 100644 index 000000000..bd83f09ce --- /dev/null +++ b/libsrc/plugins/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=6dffdf48 +build.xml.script.CRC32=7d1b4467 +build.xml.stylesheet.CRC32=8064a381@1.75.2.48 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=6dffdf48 +nbproject/build-impl.xml.script.CRC32=d6ccf12e +nbproject/build-impl.xml.stylesheet.CRC32=876e7a8f@1.75.2.48 diff --git a/libsrc/plugins/nbproject/project.properties b/libsrc/plugins/nbproject/project.properties new file mode 100644 index 000000000..9bec2a6dd --- /dev/null +++ b/libsrc/plugins/nbproject/project.properties @@ -0,0 +1,75 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=plugins +application.vendor=JPEXS +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# Files in build.classes.dir which should be excluded from distribution jar +dist.archive.excludes= +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/plugins.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +file.reference.ffdec_lib.jar=../../lib/ffdec_lib.jar +includes=** +jar.compress=false +javac.classpath=\ + ${file.reference.ffdec_lib.jar} +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.8 +javac.target=1.8 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=true +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project. +# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. +# To set system properties for unit tests define test-sys-prop.name=value: +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/libsrc/plugins/nbproject/project.xml b/libsrc/plugins/nbproject/project.xml new file mode 100644 index 000000000..354b39596 --- /dev/null +++ b/libsrc/plugins/nbproject/project.xml @@ -0,0 +1,16 @@ + + + org.netbeans.modules.java.j2seproject + + + plugins + + + + + + + + + + diff --git a/libsrc/plugins/src/AS3JumpOverflowFix.java b/libsrc/plugins/src/AS3JumpOverflowFix.java new file mode 100644 index 000000000..9e5c7a2d3 --- /dev/null +++ b/libsrc/plugins/src/AS3JumpOverflowFix.java @@ -0,0 +1,74 @@ + +import com.jpexs.decompiler.flash.SWF; +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.Action; +import com.jpexs.decompiler.flash.action.ActionList; +import com.jpexs.decompiler.flash.action.swf4.ActionIf; +import com.jpexs.decompiler.flash.action.swf4.ActionJump; +import com.jpexs.decompiler.flash.helpers.SWFDecompilerListener; +import com.jpexs.decompiler.graph.GraphTargetItem; +import java.util.List; + +public class AS3JumpOverflowFix implements SWFDecompilerListener { + + @Override + public byte[] proxyFileCatched(byte[] data) { + return null; + } + + @Override + public void actionListParsed(ActionList actions, SWF swf) { + if (actions.isEmpty()) { + return; + } + + long startAddress = actions.get(0).getAddress(); + long endAddress = actions.get(actions.size() - 1).getAddress(); + for (int i = 0; i < actions.size(); i++) { + Action action = actions.get(i); + if (action instanceof ActionIf || action instanceof ActionJump) { + Action container = (Action) actions.getContainer(i); + long containerStartAddress = startAddress; + if (container != null) { + containerStartAddress = container.getAddress(); + } + + if (action instanceof ActionIf) { + ActionIf aIf = (ActionIf) action; + long target = aIf.getTargetAddress(); + if (target < containerStartAddress && target + 0xffff < endAddress) { + aIf.setJumpOffset(aIf.getJumpOffset() + 0xffff); + } + } else if (action instanceof ActionJump) { + ActionJump aJump = (ActionJump) action; + long target = aJump.getTargetAddress(); + if (target < containerStartAddress && target + 0xffff < endAddress) { + aJump.setJumpOffset(aJump.getJumpOffset() + 0xffff); + } + } + } + } + } + + @Override + public void actionTreeCreated(List tree, SWF swf) { + } + + @Override + public void swfParsed(SWF swf) { + } + + @Override + public void abcParsed(ABC abc, SWF swf) { + } + + @Override + public void methodBodyParsed(MethodBody body, SWF swf) { + } + + @Override + public void avm2CodeRemoveTraps(String path, int classIndex, boolean isStatic, int scriptIndex, ABC abc, Trait trait, int methodInfo, MethodBody body) throws InterruptedException { + } +} diff --git a/src/com/jpexs/decompiler/flash/gui/Main.java b/src/com/jpexs/decompiler/flash/gui/Main.java index aaf948821..4d68cc83a 100644 --- a/src/com/jpexs/decompiler/flash/gui/Main.java +++ b/src/com/jpexs/decompiler/flash/gui/Main.java @@ -1146,13 +1146,14 @@ public class Main { public static void main(String[] args) throws IOException { clearTemp(); - String pluginPath = Configuration.pluginPath.get(); - if (pluginPath != null && !pluginPath.isEmpty()) { - try { - SWFDecompilerPlugin.loadPlugin(pluginPath); - } catch (Throwable e) { - View.showMessageDialog(null, "Failed to load plugin: " + pluginPath); - } + //String pluginPath = Configuration.pluginPath.get(); + //if (pluginPath != null && !pluginPath.isEmpty()) { + //} + + try { + SWFDecompilerPlugin.loadPlugins(); + } catch (Throwable ex) { + logger.log(Level.SEVERE, "Failed to load plugins", ex); } AppStrings.setResourceClass(MainFrame.class);