logger classes fixed, added new events (swf, abc, method body parsed)

This commit is contained in:
honfika@gmail.com
2014-09-01 13:33:35 +02:00
parent c27eeafce4
commit 8325d07b24
26 changed files with 186 additions and 120 deletions

View File

@@ -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) {
} catch (IOException ex) {
Logger.getLogger(SWC.class.getName()).log(Level.SEVERE, null, ex);
}
}

View File

@@ -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<Integer, String> 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) {
} catch (IOException ex) {
logger.log(Level.SEVERE, "Cannot save SWF", ex);
}
}
public SWF(InputStream is, boolean parallelRead) throws IOException, InterruptedException {
public SWF(InputStream is, boolean parallelRead) throws IOException, InterruptedException {
this(is, null, parallelRead, false);
}
/**
@@ -851,7 +853,7 @@ public final class SWF implements TreeItem, Timelined {
for (MyEntry<ClassPath, ScriptPack> item : packs) {
for (MyEntry<ClassPath, ScriptPack> itemOld : ret) {
if (item.key.equals(itemOld.key)) {
if (item.key.equals(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) {
} catch (TimeoutException ex) {
logger.log(Level.SEVERE, Helper.formatTimeToText(Configuration.exportTimeout.get()) + " ActionScript export limit reached", ex);
} catch (Exception ex) {
} catch (Exception 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)) {
if (!executor.awaitTermination(Configuration.exportTimeout.get(), TimeUnit.SECONDS)) {
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) {
} catch (ExecutionException 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
} catch (Exception | Error e) { //Something wrong in the packer
logger.log(Level.WARNING, "JPacker: Cannot minimize script");
f.renameTo(fmin);
}
} else {

View File

@@ -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");

View File

@@ -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;
}

View File

@@ -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<AVM2Instruction> 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;
}
}

View File

@@ -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.exporters.modes.ScriptExportMode;
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<Action> {
try (FileTextWriter writer = new FileTextWriter(Configuration.getCodeFormatting(), new FileOutputStream(file))) {
Action.actionsToString(new ArrayList<DisassemblyListener>(), 0, this, SWF.DEFAULT_VERSION, ScriptExportMode.PCODE, writer);
} catch (IOException ex) {
} catch (IOException ex) {
Logger.getLogger(ActionList.class.getName()).log(Level.SEVERE, null, ex);
}
}

View File

@@ -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);
}
}

View File

@@ -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;

View File

@@ -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;

View File

@@ -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.
}

View File

@@ -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);
}

View File

@@ -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 {
private static final Logger logger = Logger.getLogger(SWFDecompilerPlugin.class.getName());
private static final List<SWFDecompilerListener> 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 {
try {
listeners.add((SWFDecompilerListener) fileManager.getClassLoader(null).loadClass(fullName).newInstance());
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) {
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException 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();
}
}

View File

@@ -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) {
} catch (Exception ex) {
Logger.getLogger(DefineButtonTag.class.getName()).log(Level.SEVERE, null, ex);
return new ActionList();
}
}

View File

@@ -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) {
} catch (Exception ex) {
Logger.getLogger(DoInitActionTag.class.getName()).log(Level.SEVERE, null, ex);
return new ActionList();
}
}

View File

@@ -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) {
} catch (Exception ex) {
Logger.getLogger(CLIPACTIONRECORD.class.getName()).log(Level.SEVERE, null, ex);
return new ActionList();
}
}

View File

@@ -133,7 +133,7 @@ public class Cache<E> {
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<E> {
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;
}