From 8325d07b2418691854d618bc8dba5577dc86f32e Mon Sep 17 00:00:00 2001 From: "honfika@gmail.com" Date: Mon, 1 Sep 2014 13:33:35 +0200 Subject: [PATCH] logger classes fixed, added new events (swf, abc, method body parsed) --- examples/AS2DeobfuscatorSample.java | 10 ---- examples/DeobfuscatorSample.java | 24 ++++++++ .../src/com/jpexs/decompiler/flash/SWC.java | 5 +- .../src/com/jpexs/decompiler/flash/SWF.java | 20 ++++--- .../com/jpexs/decompiler/flash/abc/ABC.java | 2 +- .../decompiler/flash/abc/ScriptPack.java | 5 +- .../decompiler/flash/abc/avm2/AVM2Code.java | 25 ++++---- .../decompiler/flash/action/ActionList.java | 6 +- .../flash/action/ActionListReader.java | 19 ++---- .../deobfuscation/ActionDeobfuscator.java | 17 +++++- .../ActionDeobfuscatorSimple.java | 17 +++++- .../helpers/EmptySWFDecompilerListener.java | 32 ---------- .../flash/helpers/SWFDecompilerListener.java | 11 +++- .../flash/helpers/SWFDecompilerPlugin.java | 58 +++++++++++++++++-- .../flash/tags/DefineButtonTag.java | 5 +- .../flash/tags/DoInitActionTag.java | 5 +- .../flash/types/CLIPACTIONRECORD.java | 5 +- .../src/com/jpexs/helpers/Cache.java | 5 +- .../console/CommandLineArgumentParser.java | 4 +- .../flash/gui/GenericTagTreePanel.java | 4 +- src/com/jpexs/decompiler/flash/gui/Main.java | 2 +- .../flash/gui/MainFrameClassicMenu.java | 2 +- .../jpexs/decompiler/flash/gui/MainPanel.java | 16 ++--- .../decompiler/flash/gui/PreviewPanel.java | 2 +- src/com/jpexs/decompiler/flash/gui/View.java | 3 +- .../flash/gui/abc/ASMSourceEditorPane.java | 2 +- 26 files changed, 186 insertions(+), 120 deletions(-) delete mode 100644 examples/AS2DeobfuscatorSample.java create mode 100644 examples/DeobfuscatorSample.java delete mode 100644 libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/EmptySWFDecompilerListener.java diff --git a/examples/AS2DeobfuscatorSample.java b/examples/AS2DeobfuscatorSample.java deleted file mode 100644 index c4fee3cca..000000000 --- a/examples/AS2DeobfuscatorSample.java +++ /dev/null @@ -1,10 +0,0 @@ -import com.jpexs.decompiler.flash.SWF; -import com.jpexs.decompiler.flash.action.ActionList; -import com.jpexs.decompiler.flash.helpers.SWFDecompilerListener; - -public class AS2DeobfuscatorSample implements SWFDecompilerListener { - - @Override - public void actionListParsed(ActionList actions, SWF swf) { - } -} diff --git a/examples/DeobfuscatorSample.java b/examples/DeobfuscatorSample.java new file mode 100644 index 000000000..5d9bf6089 --- /dev/null +++ b/examples/DeobfuscatorSample.java @@ -0,0 +1,24 @@ +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.action.ActionList; +import com.jpexs.decompiler.flash.helpers.SWFDecompilerListener; + +public class DeobfuscatorSample implements SWFDecompilerListener { + + @Override + public void actionListParsed(ActionList actions, SWF swf) { + } + + @Override + public void swfParsed(SWF swf) { + } + + @Override + public void abcParsed(ABC abc, SWF swf) { + } + + @Override + public void methodBodyParsed(MethodBody body, SWF swf) { + } +} diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWC.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWC.java index ad88984d1..5660c0ce7 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWC.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWC.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; import java.io.IOException; @@ -66,7 +67,7 @@ public class SWC extends ZippedSWFBundle { } } } catch (IOException ex) { - Logger.getLogger(ZippedSWFBundle.class.getName()).log(Level.SEVERE, null, ex); + Logger.getLogger(SWC.class.getName()).log(Level.SEVERE, null, ex); } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java index 522ddc408..4d980d56d 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.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; import SevenZip.Compression.LZMA.Decoder; @@ -271,6 +272,7 @@ public final class SWF implements TreeItem, Timelined { public JPEGTablesTag jtt; public Map sourceFontsMap = new HashMap<>(); public static final double unitDivisor = 20; + private static final Logger logger = Logger.getLogger(SWF.class.getName()); private Timeline timeline; @@ -491,12 +493,12 @@ public final class SWF implements TreeItem, Timelined { byte[] swfData = baos.toByteArray(); uncompressedData = swfData; } catch (IOException ex) { - Logger.getLogger(SWF.class.getName()).log(Level.SEVERE, "Cannot save SWF", ex); + logger.log(Level.SEVERE, "Cannot save SWF", ex); } } public SWF(InputStream is, boolean parallelRead) throws IOException, InterruptedException { - this(is, null, parallelRead); + this(is, null, parallelRead, false); } /** @@ -851,7 +853,7 @@ public final class SWF implements TreeItem, Timelined { for (MyEntry item : packs) { for (MyEntry itemOld : ret) { if (item.key.equals(itemOld.key)) { - Logger.getLogger(SWF.class.getName()).log(Level.SEVERE, "Duplicate pack path found (" + itemOld.key + ")!"); + logger.log(Level.SEVERE, "Duplicate pack path found (" + itemOld.key + ")!"); break; } } @@ -970,9 +972,9 @@ public final class SWF implements TreeItem, Timelined { } }, Configuration.exportTimeout.get(), TimeUnit.SECONDS); } catch (TimeoutException ex) { - Logger.getLogger(ABC.class.getName()).log(Level.SEVERE, Helper.formatTimeToText(Configuration.exportTimeout.get()) + " ActionScript export limit reached", ex); + logger.log(Level.SEVERE, Helper.formatTimeToText(Configuration.exportTimeout.get()) + " ActionScript export limit reached", ex); } catch (Exception ex) { - Logger.getLogger(ABC.class.getName()).log(Level.SEVERE, "Error during ABC export", ex); + logger.log(Level.SEVERE, "Error during ABC export", ex); } } else { ExecutorService executor = Executors.newFixedThreadPool(Configuration.parallelThreadCount.get()); @@ -985,7 +987,7 @@ public final class SWF implements TreeItem, Timelined { try { executor.shutdown(); if (!executor.awaitTermination(Configuration.exportTimeout.get(), TimeUnit.SECONDS)) { - Logger.getLogger(ABC.class.getName()).log(Level.SEVERE, Helper.formatTimeToText(Configuration.exportTimeout.get()) + " ActionScript export limit reached"); + logger.log(Level.SEVERE, Helper.formatTimeToText(Configuration.exportTimeout.get()) + " ActionScript export limit reached"); } } catch (InterruptedException ex) { } finally { @@ -999,7 +1001,7 @@ public final class SWF implements TreeItem, Timelined { } } catch (InterruptedException ex) { } catch (ExecutionException ex) { - Logger.getLogger(SWF.class.getName()).log(Level.SEVERE, "Error during ABC export", ex); + logger.log(Level.SEVERE, "Error during ABC export", ex); } } } @@ -1527,7 +1529,7 @@ public final class SWF implements TreeItem, Timelined { JPacker.main(new String[]{"-q", "-b", "62", "-o", fmin.getAbsolutePath(), f.getAbsolutePath()}); f.delete(); } catch (Exception | Error e) { //Something wrong in the packer - Logger.getLogger(SWF.class.getName()).log(Level.WARNING, "JPacker: Cannot minimize script"); + logger.log(Level.WARNING, "JPacker: Cannot minimize script"); f.renameTo(fmin); } } else { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ABC.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ABC.java index 0b86f4136..f677005f3 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ABC.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ABC.java @@ -542,7 +542,7 @@ public class ABC { mb.code = new AVM2Code(ais2); } catch (UnknownInstructionCode re) { mb.code = new AVM2Code(); - Logger.getLogger(ABC.class.getName()).log(Level.SEVERE, null, re); + logger.log(Level.SEVERE, null, re); } mb.code.compact(); int ex_count = ais.readU30("ex_count"); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ScriptPack.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ScriptPack.java index 2ce47c975..4d53ccc04 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ScriptPack.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ScriptPack.java @@ -17,7 +17,6 @@ package com.jpexs.decompiler.flash.abc; import com.jpexs.decompiler.flash.SWF; -import com.jpexs.decompiler.flash.abc.types.MethodBody; import com.jpexs.decompiler.flash.abc.types.Multiname; import com.jpexs.decompiler.flash.abc.types.Namespace; import com.jpexs.decompiler.flash.abc.types.traits.Trait; @@ -161,12 +160,12 @@ public class ScriptPack implements TreeElementItem { }, timeout, TimeUnit.SECONDS); } catch (TimeoutException ex) { writer.continueMeasure(); - Logger.getLogger(MethodBody.class.getName()).log(Level.SEVERE, "Decompilation error", ex); + Logger.getLogger(ScriptPack.class.getName()).log(Level.SEVERE, "Decompilation error", ex); Helper.appendTimeoutComment(writer, timeout); return; } catch (ExecutionException ex) { writer.continueMeasure(); - Logger.getLogger(MethodBody.class.getName()).log(Level.SEVERE, "Decompilation error", ex); + Logger.getLogger(ScriptPack.class.getName()).log(Level.SEVERE, "Decompilation error", ex); Helper.appendErrorComment(writer, ex); return; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java index 982a688d7..6605b7d2e 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java @@ -251,6 +251,7 @@ import java.util.logging.Logger; public class AVM2Code implements Serializable { public static final long serialVersionUID = 1L; + private static final Logger logger = Logger.getLogger(AVM2Code.class.getName()); private static final boolean DEBUG_MODE = false; public static int toSourceLimit = -1; public List code = new ArrayList<>(); @@ -730,7 +731,7 @@ public class AVM2Code implements Serializable { InstructionDefinition[] result = new InstructionDefinition[256]; for (InstructionDefinition id : instructionSet) { if (result[id.instructionCode] != null) { - Logger.getLogger(AVM2Code.class.getName()).log(Level.WARNING, "Duplicate OPCODE for instruction {0} {1}", new Object[]{result[id.instructionCode], id}); + logger.log(Level.WARNING, "Duplicate OPCODE for instruction {0} {1}", new Object[]{result[id.instructionCode], id}); } result[id.instructionCode] = id; } @@ -1296,7 +1297,7 @@ public class AVM2Code implements Serializable { throw new UnknownJumpException(stack, ip, output); } if (visited[ip]) { - Logger.getLogger(AVM2Code.class.getName()).warning("Code already visited, ofs:" + Helper.formatAddress(pos2adr(ip)) + ", ip:" + ip); + logger.warning("Code already visited, ofs:" + Helper.formatAddress(pos2adr(ip)) + ", ip:" + ip); break; } visited[ip] = true; @@ -2059,13 +2060,13 @@ public class AVM2Code implements Serializable { ip = adr2pos(pos2adr(ip) + ins.getBytes().length + ins.operands[0]); continue; } catch (ConvertException ex) { - Logger.getLogger(AVM2Code.class.getName()).log(Level.FINE, null, ex); + logger.log(Level.FINE, null, ex); } } else if (ins.definition instanceof IfTypeIns) { try { visitCode(adr2pos(pos2adr(ip) + ins.getBytes().length + ins.operands[0]), ip, refs); } catch (ConvertException ex) { - Logger.getLogger(AVM2Code.class.getName()).log(Level.FINE, null, ex); + logger.log(Level.FINE, null, ex); } } ip++; @@ -2087,7 +2088,7 @@ public class AVM2Code implements Serializable { visitCode(adr2pos(e.target), adr2pos(e.end), refs); visitCode(adr2pos(e.end), -pos, refs); } catch (ConvertException ex) { - Logger.getLogger(AVM2Code.class.getName()).log(Level.FINE, null, ex); + logger.log(Level.FINE, null, ex); } } return refs; @@ -2129,7 +2130,7 @@ public class AVM2Code implements Serializable { prev = ins; continue; } catch (ConvertException ex) { - Logger.getLogger(AVM2Code.class.getName()).log(Level.FINE, null, ex); + logger.log(Level.FINE, null, ex); } } else if (ins.definition instanceof IfTypeIns) { if ((prev != null) && (prev2 != null)) { @@ -2195,7 +2196,7 @@ public class AVM2Code implements Serializable { try { ret += visitCodeTrap(adr2pos(pos2adr(ip) + ins.getBytes().length + ins.operands[0]), visited, prev, prev2); } catch (ConvertException ex) { - Logger.getLogger(AVM2Code.class.getName()).log(Level.FINE, null, ex); + logger.log(Level.FINE, null, ex); } } ip++; @@ -2322,7 +2323,7 @@ public class AVM2Code implements Serializable { restoreControlFlow(adr2pos(e.target), refs, visited2, appended); restoreControlFlow(adr2pos(e.end), refs, visited2, appended); } catch (ConvertException ex) { - Logger.getLogger(AVM2Code.class.getName()).log(Level.FINE, null, ex); + logger.log(Level.FINE, null, ex); } } } @@ -2330,7 +2331,7 @@ public class AVM2Code implements Serializable { code.get(ip).replaceWith = appended.get(ip); } } catch (ConvertException cex) { - Logger.getLogger(AVM2Code.class.getName()).log(Level.SEVERE, "Error during restore control flow", cex); + logger.log(Level.SEVERE, "Error during restore control flow", cex); } invalidateCache(); try { @@ -2354,9 +2355,9 @@ public class AVM2Code implements Serializable { } this.code = acode.code; } catch (IOException ex) { - Logger.getLogger(AVM2Code.class.getName()).log(Level.SEVERE, null, ex); + logger.log(Level.SEVERE, null, ex); } catch (ParseException ex) { - Logger.getLogger(AVM2Code.class.getName()).log(Level.FINE, null, ex); + logger.log(Level.FINE, null, ex); } invalidateCache(); removeDeadCode(constants, trait, info, body); @@ -2446,7 +2447,7 @@ public class AVM2Code implements Serializable { } return copy; } catch (IOException | ClassNotFoundException ex) { - Logger.getLogger(AVM2Code.class.getName()).log(Level.SEVERE, "Error during deepCopy", ex); + logger.log(Level.SEVERE, "Error during deepCopy", ex); return null; } } 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 63b11eddb..d69609f0b 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 @@ -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.action; import com.jpexs.decompiler.flash.DisassemblyListener; @@ -23,7 +24,6 @@ import com.jpexs.decompiler.flash.action.swf4.ActionIf; import com.jpexs.decompiler.flash.action.swf4.ActionJump; import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode; -import com.jpexs.decompiler.flash.helpers.EmptySWFDecompilerListener; import com.jpexs.decompiler.flash.helpers.FileTextWriter; import com.jpexs.decompiler.graph.GraphSourceItemContainer; import java.io.File; @@ -183,7 +183,7 @@ public class ActionList extends ArrayList { try (FileTextWriter writer = new FileTextWriter(Configuration.getCodeFormatting(), new FileOutputStream(file))) { Action.actionsToString(new ArrayList(), 0, this, SWF.DEFAULT_VERSION, ScriptExportMode.PCODE, writer); } catch (IOException ex) { - Logger.getLogger(EmptySWFDecompilerListener.class.getName()).log(Level.SEVERE, null, ex); + Logger.getLogger(ActionList.class.getName()).log(Level.SEVERE, null, ex); } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionListReader.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionListReader.java index f22625d83..55a345848 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionListReader.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionListReader.java @@ -72,7 +72,7 @@ import java.util.logging.Logger; */ public class ActionListReader { - private static final Logger logger = Logger.getLogger(SWFInputStream.class.getName()); + private static final Logger logger = Logger.getLogger(ActionListReader.class.getName()); /** * Reads list of actions from the stream. Reading ends with @@ -108,7 +108,7 @@ public class ActionListReader { } else if (cause instanceof InterruptedException) { throw (IOException) cause; } else { - Logger.getLogger(ActionListReader.class.getName()).log(Level.SEVERE, null, ex); + logger.log(Level.SEVERE, null, ex); } } return new ActionList(); @@ -166,15 +166,8 @@ public class ActionListReader { jump.setJumpOffset((int) (entryAction.getAddress() - jump.getTotalActionLength())); } - if (SWFDecompilerPlugin.listener != null) { - try { - SWFDecompilerPlugin.listener.actionListParsed(actions, sis.getSwf()); - - actions = fixActionList(actions, null, version); - } catch (Throwable e) { - Logger.getLogger(ActionListReader.class.getName()).log(Level.SEVERE, null, e); - //View.showMessageDialog(null, "Failed to call plugin method actionListParsed. Exception: " + e.getMessage()); - } + if (SWFDecompilerPlugin.fireActionListParsed(actions, sis.getSwf())) { + actions = fixActionList(actions, null, version); } if (deobfuscationMode == 0) { @@ -183,7 +176,7 @@ public class ActionListReader { updateActionLengths(actions, version); } catch (OutOfMemoryError | StackOverflowError | TranslateException ex) { // keep orignal (not deobfuscated) actions - Logger.getLogger(ActionListReader.class.getName()).log(Level.SEVERE, null, ex); + logger.log(Level.SEVERE, null, ex); } } else if (deobfuscationMode == 1) { try { @@ -191,7 +184,7 @@ public class ActionListReader { new ActionDeobfuscator().actionListParsed(actions, sis.getSwf()); } catch (OutOfMemoryError | StackOverflowError | TranslateException ex) { // keep orignal (not deobfuscated) actions - Logger.getLogger(ActionListReader.class.getName()).log(Level.SEVERE, null, ex); + logger.log(Level.SEVERE, null, ex); } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/deobfuscation/ActionDeobfuscator.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/deobfuscation/ActionDeobfuscator.java index 41be66746..5abed61ac 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/deobfuscation/ActionDeobfuscator.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/deobfuscation/ActionDeobfuscator.java @@ -12,12 +12,15 @@ * 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.action.deobfuscation; import com.jpexs.decompiler.flash.DisassemblyListener; import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.SWFInputStream; +import com.jpexs.decompiler.flash.abc.ABC; +import com.jpexs.decompiler.flash.abc.types.MethodBody; import com.jpexs.decompiler.flash.action.Action; import com.jpexs.decompiler.flash.action.ActionList; import com.jpexs.decompiler.flash.action.ActionListReader; @@ -469,6 +472,18 @@ public class ActionDeobfuscator implements SWFDecompilerListener { return results; } + @Override + public void swfParsed(SWF swf) { + } + + @Override + public void abcParsed(ABC abc, SWF swf) { + } + + @Override + public void methodBodyParsed(MethodBody body, SWF swf) { + } + class ExecutionResult { public int idx = -1; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/deobfuscation/ActionDeobfuscatorSimple.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/deobfuscation/ActionDeobfuscatorSimple.java index 15bf93156..e34c54e64 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/deobfuscation/ActionDeobfuscatorSimple.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/deobfuscation/ActionDeobfuscatorSimple.java @@ -12,10 +12,13 @@ * 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.action.deobfuscation; 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.action.Action; import com.jpexs.decompiler.flash.action.ActionList; import com.jpexs.decompiler.flash.action.ActionLocalData; @@ -185,6 +188,18 @@ public class ActionDeobfuscatorSimple implements SWFDecompilerListener { } } + @Override + public void swfParsed(SWF swf) { + } + + @Override + public void abcParsed(ABC abc, SWF swf) { + } + + @Override + public void methodBodyParsed(MethodBody body, SWF swf) { + } + class ExecutionResult { public int idx = -1; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/EmptySWFDecompilerListener.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/EmptySWFDecompilerListener.java deleted file mode 100644 index bfb8bac56..000000000 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/EmptySWFDecompilerListener.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (C) 2010-2014 JPEXS, All rights reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3.0 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ -package com.jpexs.decompiler.flash.helpers; - -import com.jpexs.decompiler.flash.SWF; -import com.jpexs.decompiler.flash.action.ActionList; - -/** - * - * @author JPEXS - */ -public class EmptySWFDecompilerListener implements SWFDecompilerListener { - - @Override - public void actionListParsed(ActionList actions, SWF swf) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - -} diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/SWFDecompilerListener.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/SWFDecompilerListener.java index 8f8da08da..7243afa83 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/SWFDecompilerListener.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/SWFDecompilerListener.java @@ -12,10 +12,13 @@ * 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.helpers; 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.action.ActionList; /** @@ -24,5 +27,11 @@ import com.jpexs.decompiler.flash.action.ActionList; */ public interface SWFDecompilerListener { + void swfParsed(SWF swf); + void actionListParsed(ActionList actions, SWF swf); + + void abcParsed(ABC abc, SWF swf); + + void methodBodyParsed(MethodBody body, SWF swf); } 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 e843395fd..2444ed84d 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 @@ -12,9 +12,14 @@ * 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.helpers; +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.action.ActionList; import com.jpexs.helpers.Helper; import com.jpexs.helpers.plugin.CharSequenceJavaFileObject; import com.jpexs.helpers.plugin.ClassFileManager; @@ -33,7 +38,8 @@ import javax.tools.ToolProvider; */ public class SWFDecompilerPlugin { - public static SWFDecompilerListener listener; + private static final Logger logger = Logger.getLogger(SWFDecompilerPlugin.class.getName()); + private static final List listeners = new ArrayList<>(); public static void loadPlugin(String path) { @@ -68,9 +74,53 @@ public class SWFDecompilerPlugin { // Creating an instance of our compiled class and try { - listener = (SWFDecompilerListener) fileManager.getClassLoader(null).loadClass(fullName).newInstance(); + listeners.add((SWFDecompilerListener) fileManager.getClassLoader(null).loadClass(fullName).newInstance()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) { - Logger.getLogger(SWFDecompilerPlugin.class.getName()).log(Level.SEVERE, null, ex); + logger.log(Level.SEVERE, null, ex); } } + + public static boolean fireSwfParsed(SWF swf) { + for (SWFDecompilerListener listener : listeners) { + try { + listener.swfParsed(swf); + } catch (Throwable e) { + logger.log(Level.SEVERE, "Failed to call plugin method swfParsed.", e); + } + } + return !listeners.isEmpty(); + } + + public static boolean fireActionListParsed(ActionList actions, SWF swf) { + for (SWFDecompilerListener listener : listeners) { + try { + listener.actionListParsed(actions, swf); + } catch (Throwable e) { + logger.log(Level.SEVERE, "Failed to call plugin method actionListParsed.", e); + } + } + return !listeners.isEmpty(); + } + + public static boolean fireAbcParsed(ABC abc, SWF swf) { + for (SWFDecompilerListener listener : listeners) { + try { + listener.abcParsed(abc, swf); + } catch (Throwable e) { + logger.log(Level.SEVERE, "Failed to call plugin method abcParsed.", e); + } + } + return !listeners.isEmpty(); + } + + public static boolean fireMethodBodyParsed(MethodBody body, SWF swf) { + for (SWFDecompilerListener listener : listeners) { + try { + listener.methodBodyParsed(body, swf); + } catch (Throwable e) { + logger.log(Level.SEVERE, "Failed to call plugin method methodBodyParsed.", e); + } + } + return !listeners.isEmpty(); + } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineButtonTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineButtonTag.java index 5e9fbe16c..bc19d135e 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineButtonTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineButtonTag.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.tags; import com.jpexs.decompiler.flash.DisassemblyListener; @@ -179,7 +180,7 @@ public class DefineButtonTag extends ButtonTag implements ASMSource { } catch (InterruptedException ex) { throw ex; } catch (Exception ex) { - Logger.getLogger(DoActionTag.class.getName()).log(Level.SEVERE, null, ex); + Logger.getLogger(DefineButtonTag.class.getName()).log(Level.SEVERE, null, ex); return new ActionList(); } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoInitActionTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoInitActionTag.java index 81e984a83..5cc176d4d 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoInitActionTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoInitActionTag.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.tags; import com.jpexs.decompiler.flash.DisassemblyListener; @@ -127,7 +128,7 @@ public class DoInitActionTag extends CharacterIdTag implements ASMSource { } catch (InterruptedException ex) { throw ex; } catch (Exception ex) { - Logger.getLogger(DoActionTag.class.getName()).log(Level.SEVERE, null, ex); + Logger.getLogger(DoInitActionTag.class.getName()).log(Level.SEVERE, null, ex); return new ActionList(); } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/CLIPACTIONRECORD.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/CLIPACTIONRECORD.java index 4dd65b39f..173a4ea11 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/CLIPACTIONRECORD.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/CLIPACTIONRECORD.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.types; import com.jpexs.decompiler.flash.DisassemblyListener; @@ -206,7 +207,7 @@ public class CLIPACTIONRECORD implements ASMSource, Exportable, ContainerItem, S } catch (InterruptedException ex) { throw ex; } catch (Exception ex) { - Logger.getLogger(BUTTONCONDACTION.class.getName()).log(Level.SEVERE, null, ex); + Logger.getLogger(CLIPACTIONRECORD.class.getName()).log(Level.SEVERE, null, ex); return new ActionList(); } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/helpers/Cache.java b/libsrc/ffdec_lib/src/com/jpexs/helpers/Cache.java index e2735b55d..e2d603082 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/helpers/Cache.java +++ b/libsrc/ffdec_lib/src/com/jpexs/helpers/Cache.java @@ -133,7 +133,7 @@ public class Cache { E item = (E) ois.readObject(); return item; } catch (IOException | ClassNotFoundException ex) { - Logger.getLogger(Helper.class.getName()).log(Level.SEVERE, null, ex); + Logger.getLogger(Cache.class.getName()).log(Level.SEVERE, null, ex); } return null; } else if (storageType == STORAGE_MEMORY) { @@ -151,8 +151,7 @@ public class Cache { try { temp = File.createTempFile("ffdec_cache", ".tmp"); } catch (IOException ex) { - Logger.getLogger(Cache.class - .getName()).log(Level.SEVERE, null, ex); + Logger.getLogger(Cache.class.getName()).log(Level.SEVERE, null, ex); return; } diff --git a/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java b/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java index eef680e61..ca86dd206 100644 --- a/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java +++ b/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java @@ -750,9 +750,7 @@ public class CommandLineArgumentParser { } else { classes = new String[]{classesStr}; } - for (String c : classes) { - ret.add(c); - } + ret.addAll(Arrays.asList(classes)); return ret; } diff --git a/src/com/jpexs/decompiler/flash/gui/GenericTagTreePanel.java b/src/com/jpexs/decompiler/flash/gui/GenericTagTreePanel.java index 4bec55b39..c3a759098 100644 --- a/src/com/jpexs/decompiler/flash/gui/GenericTagTreePanel.java +++ b/src/com/jpexs/decompiler/flash/gui/GenericTagTreePanel.java @@ -443,7 +443,7 @@ public class GenericTagTreePanel extends GenericTagPanel { val = ReflectionTools.newInstanceOf(field.getType()); ReflectionTools.setValue(obj, field, index, val); } catch (InstantiationException | IllegalAccessException ex) { - Logger.getLogger(GenericTagPanel.class.getName()).log(Level.SEVERE, null, ex); + Logger.getLogger(GenericTagTreePanel.class.getName()).log(Level.SEVERE, null, ex); return null; } } @@ -695,7 +695,7 @@ public class GenericTagTreePanel extends GenericTagPanel { try { f.set(t, f.get(assigned)); } catch (IllegalArgumentException | IllegalAccessException ex) { - Logger.getLogger(GenericTagPanel.class.getName()).log(Level.SEVERE, null, ex); + Logger.getLogger(GenericTagTreePanel.class.getName()).log(Level.SEVERE, null, ex); } } } diff --git a/src/com/jpexs/decompiler/flash/gui/Main.java b/src/com/jpexs/decompiler/flash/gui/Main.java index 4e912fccd..7693cd389 100644 --- a/src/com/jpexs/decompiler/flash/gui/Main.java +++ b/src/com/jpexs/decompiler/flash/gui/Main.java @@ -777,7 +777,7 @@ public class Main { field.setAccessible(true); field.set(null, null); } catch (Throwable ex) { - Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); + logger.log(Level.SEVERE, null, ex); } UIManager.put("OptionPane.okButtonText", AppStrings.translate("button.ok")); diff --git a/src/com/jpexs/decompiler/flash/gui/MainFrameClassicMenu.java b/src/com/jpexs/decompiler/flash/gui/MainFrameClassicMenu.java index c58e83b28..d496ceda9 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainFrameClassicMenu.java +++ b/src/com/jpexs/decompiler/flash/gui/MainFrameClassicMenu.java @@ -492,7 +492,7 @@ public class MainFrameClassicMenu implements MainFrameMenu, ActionListener { snode.binaryData.setModified(true); saved = true; } catch (IOException ex) { - Logger.getLogger(MainFrameRibbonMenu.class.getName()).log(Level.SEVERE, "Cannot save SWF", ex); + Logger.getLogger(MainFrameClassicMenu.class.getName()).log(Level.SEVERE, "Cannot save SWF", ex); } } else if (swf.file == null) { saved = saveAs(swf, SaveFileMode.SAVEAS); diff --git a/src/com/jpexs/decompiler/flash/gui/MainPanel.java b/src/com/jpexs/decompiler/flash/gui/MainPanel.java index 2db9db6e6..ae03deb8b 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/MainPanel.java @@ -628,7 +628,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec } updateClassesList(); } catch (InterruptedException ex) { - Logger.getLogger(MainPanel.class.getName()).log(Level.SEVERE, null, ex); + logger.log(Level.SEVERE, null, ex); } } @@ -1347,7 +1347,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec try { renameIdentifier(swf, identifier); } catch (InterruptedException ex) { - Logger.getLogger(MainPanel.class.getName()).log(Level.SEVERE, null, ex); + logger.log(Level.SEVERE, null, ex); } return null; } @@ -1463,7 +1463,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec try { Desktop.getDesktop().open(selfile.getAbsoluteFile().getParentFile()); } catch (IOException ex) { - Logger.getLogger(MainPanel.class.getName()).log(Level.SEVERE, null, ex); + logger.log(Level.SEVERE, null, ex); } } } @@ -1686,7 +1686,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec swf.exportActionScript(errorHandler, selFile, exportMode, Configuration.parallelSpeedUp.get()); } } catch (Exception ex) { - Logger.getLogger(MainPanel.class.getName()).log(Level.SEVERE, "Error during export", ex); + logger.log(Level.SEVERE, "Error during export", ex); View.showMessageDialog(null, translate("error.export") + ": " + ex.getClass().getName() + " " + ex.getLocalizedMessage()); } return null; @@ -1784,7 +1784,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec updateClassesList(); reload(true); } catch (Exception ex) { - Logger.getLogger(MainPanel.class.getName()).log(Level.SEVERE, "Error during renaming identifiers", ex); + logger.log(Level.SEVERE, "Error during renaming identifiers", ex); Main.stopWork(); View.showMessageDialog(null, translate("error.occured").replace("%error%", ex.getClass().getSimpleName())); } @@ -1834,7 +1834,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec abcPanel.detailPanel.methodTraitPanel.methodCodePanel.setBodyIndex(bi, abcPanel.abc, t); } } catch (Exception ex) { - Logger.getLogger(MainPanel.class.getName()).log(Level.SEVERE, "Deobfuscation error", ex); + logger.log(Level.SEVERE, "Deobfuscation error", ex); } return true; } @@ -2041,7 +2041,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec } SWF.clearImageCache(); } catch (IOException ex) { - Logger.getLogger(MainPanel.class.getName()).log(Level.SEVERE, "Invalid image", ex); + logger.log(Level.SEVERE, "Invalid image", ex); View.showMessageDialog(null, translate("error.image.invalid"), translate("error"), JOptionPane.ERROR_MESSAGE); } reload(true); @@ -2346,7 +2346,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec previewPanel.setMedia(soundThread); soundThread.play(); } catch (LineUnavailableException | IOException | UnsupportedAudioFileException ex) { - Logger.getLogger(MainPanel.class.getName()).log(Level.SEVERE, null, ex); + logger.log(Level.SEVERE, null, ex); } } else if (((tagObj instanceof FrameNodeItem) && ((FrameNodeItem) tagObj).isDisplayed()) || ((tagObj instanceof CharacterTag) || (tagObj instanceof FontTag)) && (tagObj instanceof Tag) || (tagObj instanceof SoundStreamHeadTypeTag)) { showCard(CARDPREVIEWPANEL); diff --git a/src/com/jpexs/decompiler/flash/gui/PreviewPanel.java b/src/com/jpexs/decompiler/flash/gui/PreviewPanel.java index 0a2bbb8f4..49093612d 100644 --- a/src/com/jpexs/decompiler/flash/gui/PreviewPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/PreviewPanel.java @@ -830,7 +830,7 @@ public class PreviewPanel extends JSplitPane implements ActionListener { } showFlashViewerPanel(); } catch (IOException | com.jpexs.decompiler.flash.action.parser.ParseException ex) { - Logger.getLogger(MainPanel.class.getName()).log(Level.SEVERE, null, ex); + Logger.getLogger(PreviewPanel.class.getName()).log(Level.SEVERE, null, ex); } } diff --git a/src/com/jpexs/decompiler/flash/gui/View.java b/src/com/jpexs/decompiler/flash/gui/View.java index 52323a5d3..04ea9cc20 100644 --- a/src/com/jpexs/decompiler/flash/gui/View.java +++ b/src/com/jpexs/decompiler/flash/gui/View.java @@ -17,7 +17,6 @@ package com.jpexs.decompiler.flash.gui; import com.jpexs.decompiler.flash.configuration.ConfigurationItem; -import com.jpexs.helpers.Helper; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; @@ -534,7 +533,7 @@ public class View { desktop.browse(uri); return true; } catch (URISyntaxException | IOException ex) { - Logger.getLogger(Helper.class.getName()).log(Level.SEVERE, null, ex); + Logger.getLogger(View.class.getName()).log(Level.SEVERE, null, ex); } } } diff --git a/src/com/jpexs/decompiler/flash/gui/abc/ASMSourceEditorPane.java b/src/com/jpexs/decompiler/flash/gui/abc/ASMSourceEditorPane.java index 14f868928..99a2e673b 100644 --- a/src/com/jpexs/decompiler/flash/gui/abc/ASMSourceEditorPane.java +++ b/src/com/jpexs/decompiler/flash/gui/abc/ASMSourceEditorPane.java @@ -199,7 +199,7 @@ public class ASMSourceEditorPane extends LineMarkedEditorPane implements CaretLi mb.code = new AVM2Code(ais); } catch (UnknownInstructionCode re) { mb.code = new AVM2Code(); - Logger.getLogger(ABC.class.getName()).log(Level.SEVERE, null, re); + Logger.getLogger(ASMSourceEditorPane.class.getName()).log(Level.SEVERE, null, re); } mb.code.compact(); } else {