From 79f382c1d9f93da93073bf7b88231c1ac8998dc3 Mon Sep 17 00:00:00 2001 From: Vitali Deatlov Date: Thu, 26 May 2016 17:45:40 +0300 Subject: [PATCH 1/6] fixed forward slash translation in RegExp --- .../jpexs/decompiler/flash/abc/avm2/model/RegExpAvm2Item.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/RegExpAvm2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/RegExpAvm2Item.java index b8fda568a..26b7a666f 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/RegExpAvm2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/RegExpAvm2Item.java @@ -60,8 +60,6 @@ public class RegExpAvm2Item extends AVM2Item implements Callable { ret.append("\\b"); } else if (c == '\f') { ret.append("\\f"); - } else if (c == '/') { - ret.append("\\/"); } else if (c < 32) { ret.append("\\x").append(Helper.byteToHex((byte) c)); } else { From 800caa77c071157824f066578020b42eaaf3f5cb Mon Sep 17 00:00:00 2001 From: Vitali Deatlov Date: Fri, 27 May 2016 23:16:08 +0300 Subject: [PATCH 2/6] improved deobfuscation of ternary operator --- .../AVM2DeobfuscatorSimpleOld.java | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorSimpleOld.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorSimpleOld.java index 472aa6bdd..5fadb3a3d 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorSimpleOld.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorSimpleOld.java @@ -155,6 +155,16 @@ public class AVM2DeobfuscatorSimpleOld extends SWFDecompilerAdapter { return false; } + // find jump targets + List jumpTargets = new ArrayList(); + for (int i = 0; i < code.code.size(); i++) { + AVM2Instruction ins = code.code.get(i); + if (ins.definition instanceof JumpIns) { + long address = ins.getTargetAddress(); + jumpTargets.add( code.adr2pos(address) ); + } + } + AVM2LocalData localData = newLocalData(scriptIndex, abc, abc.constants, body, isStatic, classIndex); int localReservedCount = body.getLocalReservedCount(); for (int i = 0; i < code.code.size(); i++) { @@ -168,7 +178,7 @@ public class AVM2DeobfuscatorSimpleOld extends SWFDecompilerAdapter { localData.localRegs.clear(); initLocalRegs(localData, localReservedCount, body.max_regs); - executeInstructions(staticRegs, body, abc, code, localData, i, code.code.size() - 1, null, inlineIns); + executeInstructions(staticRegs, body, abc, code, localData, i, code.code.size() - 1, null, inlineIns, jumpTargets); } return false; @@ -218,7 +228,7 @@ public class AVM2DeobfuscatorSimpleOld extends SWFDecompilerAdapter { } } - private void executeInstructions(Map staticRegs, MethodBody body, ABC abc, AVM2Code code, AVM2LocalData localData, int idx, int endIdx, ExecutionResult result, List inlineIns) throws InterruptedException { + private void executeInstructions(Map staticRegs, MethodBody body, ABC abc, AVM2Code code, AVM2LocalData localData, int idx, int endIdx, ExecutionResult result, List inlineIns, List jumpTargets) throws InterruptedException { List output = new ArrayList<>(); FixItemCounterTranslateStack stack = new FixItemCounterTranslateStack(""); @@ -284,9 +294,13 @@ public class AVM2DeobfuscatorSimpleOld extends SWFDecompilerAdapter { if (inlineIns.contains(ins)) { if (def instanceof SetLocalTypeIns) { - int regId = ((SetLocalTypeIns) def).getRegisterId(ins); - staticRegs.put(regId, localData.localRegs.get(regId).getNotCoerced()); - code.replaceInstruction(idx, new AVM2Instruction(0, DeobfuscatePopIns.getInstance(), null), body); + InstructionDefinition prevDef = code.code.get(idx-1).definition; + if ((prevDef instanceof DupIns && !jumpTargets.contains(idx-2)) || !jumpTargets.contains(idx-1)) + { + int regId = ((SetLocalTypeIns) def).getRegisterId(ins); + staticRegs.put(regId, localData.localRegs.get(regId).getNotCoerced()); + code.replaceInstruction(idx, new AVM2Instruction(0, DeobfuscatePopIns.getInstance(), null), body); + } } } if (def instanceof GetLocalTypeIns) { From 4f8dab84094eaa7cc9ea763af2158b15ab80b158 Mon Sep 17 00:00:00 2001 From: "honfika@gmail.com" Date: Wed, 18 May 2016 15:56:54 +0200 Subject: [PATCH 3/6] hide memory search on non windows platform + show warning on command-line memory search on non-windows platform --- .../console/CommandLineArgumentParser.java | 122 ++++++++++-------- .../decompiler/flash/gui/MainFrameMenu.java | 6 +- 2 files changed, 69 insertions(+), 59 deletions(-) diff --git a/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java b/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java index f8c1c38b2..2c0491e9b 100644 --- a/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java +++ b/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java @@ -1922,75 +1922,83 @@ public class CommandLineArgumentParser { badArguments("memorysearch"); } - AtomicInteger cnt = new AtomicInteger(); - List procs = new ArrayList<>(); - List processList = ProcessTools.listProcesses(); - while (args.size() > 0) { - String arg = args.pop(); - if (arg.matches("\\d+")) { - int processId = 0; - try { - processId = Integer.parseInt(arg); - } catch (NumberFormatException nfe) { - System.err.println("ProcessId should be integer"); - badArguments("memorysearch"); - } - - boolean found = false; - for (Process process : processList) { - if (process.getPid() == processId) { - if (!procs.contains(process)) { - procs.add(process); - } - - found = true; - break; // only 1 process can have this process id + if (Platform.isWindows()) { + AtomicInteger cnt = new AtomicInteger(); + List procs = new ArrayList<>(); + List processList = ProcessTools.listProcesses(); + while (args.size() > 0) { + String arg = args.pop(); + if (arg.matches("\\d+")) { + int processId = 0; + try { + processId = Integer.parseInt(arg); + } catch (NumberFormatException nfe) { + System.err.println("ProcessId should be integer"); + badArguments("memorysearch"); } - } - if (!found) { - System.out.println("Process id=" + processId + " was not found."); - } - } else { - boolean found = false; - for (Process process : processList) { - if (process.getFileName().equals(arg)) { - if (!procs.contains(process)) { - procs.add(process); + boolean found = false; + if (processList != null) { + for (Process process : processList) { + if (process.getPid() == processId) { + if (!procs.contains(process)) { + procs.add(process); + } + + found = true; + break; // only 1 process can have this process id + } } - - found = true; } - } - if (!found) { - System.out.println("Process name=" + arg + " was not found."); + if (!found) { + System.out.println("Process id=" + processId + " was not found."); + } + } else { + boolean found = false; + if (processList != null) { + for (Process process : processList) { + if (process.getFileName().equals(arg)) { + if (!procs.contains(process)) { + procs.add(process); + } + + found = true; + } + } + } + + if (!found) { + System.out.println("Process name=" + arg + " was not found."); + } } } - } - try { - new SearchInMemory(new SearchInMemoryListener() { + try { + new SearchInMemory(new SearchInMemoryListener() { - @Override - public void publish(Object... chunks) { - for (Object s : chunks) { - if (s instanceof SwfInMemory) { - SwfInMemory swf = (SwfInMemory) s; - String fileName = cnt.getAndIncrement() + ".swf"; - System.out.println("SWF found (" + fileName + "). Version: " + swf.version + ", file size: " + swf.fileSize + ", address: " + swf.address); - Helper.writeFile(fileName, swf.is); + @Override + public void publish(Object... chunks) { + for (Object s : chunks) { + if (s instanceof SwfInMemory) { + SwfInMemory swf = (SwfInMemory) s; + String fileName = cnt.getAndIncrement() + ".swf"; + System.out.println("SWF found (" + fileName + "). Version: " + swf.version + ", file size: " + swf.fileSize + ", address: " + swf.address); + Helper.writeFile(fileName, swf.is); + } } } - } - @Override - public void setProgress(int progress) { - // ignore - } - }).search(procs); - } catch (Exception ex) { - logger.log(Level.SEVERE, null, ex); + @Override + public void setProgress(int progress) { + // ignore + } + }).search(procs); + } catch (Exception ex) { + logger.log(Level.SEVERE, null, ex); + } + } else { + System.err.println("Memory search is only available on Windows platform."); } System.exit(0); diff --git a/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java b/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java index 978640bd3..93efd3cff 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java +++ b/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java @@ -882,9 +882,11 @@ public abstract class MainFrameMenu implements MenuBuilder { addToggleMenuItem("/tools/timeline", translate("menu.tools.timeline"), null, "timeline32", this::timelineActionPerformed, PRIORITY_TOP, null); addMenuItem("/tools/showProxy", translate("menu.tools.proxy"), "proxy16", this::showProxyActionPerformed, PRIORITY_MEDIUM, null, true, null, false); - addMenuItem("/tools/searchMemory", translate("menu.tools.searchMemory"), "loadmemory16", this::searchMemoryActionPerformed, PRIORITY_MEDIUM, null, true, null, false); - //addMenuItem("/tools/searchCache", translate("menu.tools.searchCache"), "loadcache16", this::searchCacheActionPerformed, PRIORITY_MEDIUM, null, true, null); + if (Platform.isWindows()) { + addMenuItem("/tools/searchMemory", translate("menu.tools.searchMemory"), "loadmemory16", this::searchMemoryActionPerformed, PRIORITY_MEDIUM, null, true, null, false); + } + //addMenuItem("/tools/searchCache", translate("menu.tools.searchCache"), "loadcache16", this::searchCacheActionPerformed, PRIORITY_MEDIUM, null, true, null); addMenuItem("/tools/deobfuscation", translate("menu.tools.deobfuscation"), "deobfuscate16", null, 0, null, false, null, false); addMenuItem("/tools/deobfuscation/renameOneIdentifier", translate("menu.tools.deobfuscation.globalrename"), "rename16", this::renameOneIdentifier, PRIORITY_MEDIUM, null, true, null, false); addMenuItem("/tools/deobfuscation/renameInvalidIdentifiers", translate("menu.tools.deobfuscation.renameinvalid"), "renameall16", this::renameInvalidIdentifiers, PRIORITY_MEDIUM, null, true, null, false); From bf07805219341a4160d5c37991013c558f5508f3 Mon Sep 17 00:00:00 2001 From: Vitali Deatlov Date: Mon, 30 May 2016 15:37:48 +0300 Subject: [PATCH 4/6] NewFunction instruction should always have a non-static context --- .../abc/avm2/instructions/construction/NewFunctionIns.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/construction/NewFunctionIns.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/construction/NewFunctionIns.java index a2360d9d5..c24b2756a 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/construction/NewFunctionIns.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/construction/NewFunctionIns.java @@ -39,7 +39,7 @@ public class NewFunctionIns extends InstructionDefinition { @Override public void translate(AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List output, String path) { int methodIndex = ins.operands[0]; - NewFunctionAVM2Item function = new NewFunctionAVM2Item(ins, localData.lineStartInstruction, "", path, localData.isStatic, localData.scriptIndex, localData.classIndex, localData.abc, localData.fullyQualifiedNames, methodIndex); + NewFunctionAVM2Item function = new NewFunctionAVM2Item(ins, localData.lineStartInstruction, "", path, false, localData.scriptIndex, localData.classIndex, localData.abc, localData.fullyQualifiedNames, methodIndex); stack.push(function); } From 018df9f9b99453659f2c1b8e4e308c981aa128a8 Mon Sep 17 00:00:00 2001 From: "honfika@gmail.com" Date: Wed, 18 May 2016 15:56:54 +0200 Subject: [PATCH 5/6] hide memory search on non windows platform + show warning on command-line memory search on non-windows platform --- .../console/CommandLineArgumentParser.java | 122 ++++++++++-------- .../decompiler/flash/gui/MainFrameMenu.java | 6 +- 2 files changed, 69 insertions(+), 59 deletions(-) diff --git a/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java b/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java index f8c1c38b2..2c0491e9b 100644 --- a/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java +++ b/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java @@ -1922,75 +1922,83 @@ public class CommandLineArgumentParser { badArguments("memorysearch"); } - AtomicInteger cnt = new AtomicInteger(); - List procs = new ArrayList<>(); - List processList = ProcessTools.listProcesses(); - while (args.size() > 0) { - String arg = args.pop(); - if (arg.matches("\\d+")) { - int processId = 0; - try { - processId = Integer.parseInt(arg); - } catch (NumberFormatException nfe) { - System.err.println("ProcessId should be integer"); - badArguments("memorysearch"); - } - - boolean found = false; - for (Process process : processList) { - if (process.getPid() == processId) { - if (!procs.contains(process)) { - procs.add(process); - } - - found = true; - break; // only 1 process can have this process id + if (Platform.isWindows()) { + AtomicInteger cnt = new AtomicInteger(); + List procs = new ArrayList<>(); + List processList = ProcessTools.listProcesses(); + while (args.size() > 0) { + String arg = args.pop(); + if (arg.matches("\\d+")) { + int processId = 0; + try { + processId = Integer.parseInt(arg); + } catch (NumberFormatException nfe) { + System.err.println("ProcessId should be integer"); + badArguments("memorysearch"); } - } - if (!found) { - System.out.println("Process id=" + processId + " was not found."); - } - } else { - boolean found = false; - for (Process process : processList) { - if (process.getFileName().equals(arg)) { - if (!procs.contains(process)) { - procs.add(process); + boolean found = false; + if (processList != null) { + for (Process process : processList) { + if (process.getPid() == processId) { + if (!procs.contains(process)) { + procs.add(process); + } + + found = true; + break; // only 1 process can have this process id + } } - - found = true; } - } - if (!found) { - System.out.println("Process name=" + arg + " was not found."); + if (!found) { + System.out.println("Process id=" + processId + " was not found."); + } + } else { + boolean found = false; + if (processList != null) { + for (Process process : processList) { + if (process.getFileName().equals(arg)) { + if (!procs.contains(process)) { + procs.add(process); + } + + found = true; + } + } + } + + if (!found) { + System.out.println("Process name=" + arg + " was not found."); + } } } - } - try { - new SearchInMemory(new SearchInMemoryListener() { + try { + new SearchInMemory(new SearchInMemoryListener() { - @Override - public void publish(Object... chunks) { - for (Object s : chunks) { - if (s instanceof SwfInMemory) { - SwfInMemory swf = (SwfInMemory) s; - String fileName = cnt.getAndIncrement() + ".swf"; - System.out.println("SWF found (" + fileName + "). Version: " + swf.version + ", file size: " + swf.fileSize + ", address: " + swf.address); - Helper.writeFile(fileName, swf.is); + @Override + public void publish(Object... chunks) { + for (Object s : chunks) { + if (s instanceof SwfInMemory) { + SwfInMemory swf = (SwfInMemory) s; + String fileName = cnt.getAndIncrement() + ".swf"; + System.out.println("SWF found (" + fileName + "). Version: " + swf.version + ", file size: " + swf.fileSize + ", address: " + swf.address); + Helper.writeFile(fileName, swf.is); + } } } - } - @Override - public void setProgress(int progress) { - // ignore - } - }).search(procs); - } catch (Exception ex) { - logger.log(Level.SEVERE, null, ex); + @Override + public void setProgress(int progress) { + // ignore + } + }).search(procs); + } catch (Exception ex) { + logger.log(Level.SEVERE, null, ex); + } + } else { + System.err.println("Memory search is only available on Windows platform."); } System.exit(0); diff --git a/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java b/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java index 978640bd3..93efd3cff 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java +++ b/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java @@ -882,9 +882,11 @@ public abstract class MainFrameMenu implements MenuBuilder { addToggleMenuItem("/tools/timeline", translate("menu.tools.timeline"), null, "timeline32", this::timelineActionPerformed, PRIORITY_TOP, null); addMenuItem("/tools/showProxy", translate("menu.tools.proxy"), "proxy16", this::showProxyActionPerformed, PRIORITY_MEDIUM, null, true, null, false); - addMenuItem("/tools/searchMemory", translate("menu.tools.searchMemory"), "loadmemory16", this::searchMemoryActionPerformed, PRIORITY_MEDIUM, null, true, null, false); - //addMenuItem("/tools/searchCache", translate("menu.tools.searchCache"), "loadcache16", this::searchCacheActionPerformed, PRIORITY_MEDIUM, null, true, null); + if (Platform.isWindows()) { + addMenuItem("/tools/searchMemory", translate("menu.tools.searchMemory"), "loadmemory16", this::searchMemoryActionPerformed, PRIORITY_MEDIUM, null, true, null, false); + } + //addMenuItem("/tools/searchCache", translate("menu.tools.searchCache"), "loadcache16", this::searchCacheActionPerformed, PRIORITY_MEDIUM, null, true, null); addMenuItem("/tools/deobfuscation", translate("menu.tools.deobfuscation"), "deobfuscate16", null, 0, null, false, null, false); addMenuItem("/tools/deobfuscation/renameOneIdentifier", translate("menu.tools.deobfuscation.globalrename"), "rename16", this::renameOneIdentifier, PRIORITY_MEDIUM, null, true, null, false); addMenuItem("/tools/deobfuscation/renameInvalidIdentifiers", translate("menu.tools.deobfuscation.renameinvalid"), "renameall16", this::renameInvalidIdentifiers, PRIORITY_MEDIUM, null, true, null, false); From f8413c665cdafe39554493482d0a7cf9dcee8cc8 Mon Sep 17 00:00:00 2001 From: Vitali Deatlov Date: Wed, 1 Jun 2016 13:16:31 +0300 Subject: [PATCH 6/6] fixed missing dots in namespaced property --- .../src/com/jpexs/decompiler/flash/abc/avm2/model/AVM2Item.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/AVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/AVM2Item.java index 423dbc074..3d1159eaf 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/AVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/AVM2Item.java @@ -108,6 +108,8 @@ public abstract class AVM2Item extends GraphTargetItem { } if (propertyName instanceof FullMultinameAVM2Item) { if (((FullMultinameAVM2Item) propertyName).name != null) { + if (((FullMultinameAVM2Item) propertyName).namespace != null) + writer.append("."); return propertyName.toString(writer, localData); } else { writer.append(".");