diff --git a/trunk/src/com/jpexs/decompiler/flash/DisassemblyListener.java b/trunk/src/com/jpexs/decompiler/flash/DisassemblyListener.java
new file mode 100644
index 000000000..0a13b4ddf
--- /dev/null
+++ b/trunk/src/com/jpexs/decompiler/flash/DisassemblyListener.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2013 JPEXS
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package com.jpexs.decompiler.flash;
+
+/**
+ *
+ * @author JPEXS
+ */
+public interface DisassemblyListener {
+
+ public void progress(String phase, long pos, long total);
+}
diff --git a/trunk/src/com/jpexs/decompiler/flash/ReReadableInputStream.java b/trunk/src/com/jpexs/decompiler/flash/ReReadableInputStream.java
index f59c4c248..8d87b5cf6 100644
--- a/trunk/src/com/jpexs/decompiler/flash/ReReadableInputStream.java
+++ b/trunk/src/com/jpexs/decompiler/flash/ReReadableInputStream.java
@@ -81,4 +81,8 @@ public class ReReadableInputStream extends InputStream {
public int available() throws IOException {
return (count + is.available()) - pos;
}
+
+ public long length() throws IOException {
+ return count + is.available();
+ }
}
diff --git a/trunk/src/com/jpexs/decompiler/flash/SWFInputStream.java b/trunk/src/com/jpexs/decompiler/flash/SWFInputStream.java
index 228b37d8c..88766cce5 100644
--- a/trunk/src/com/jpexs/decompiler/flash/SWFInputStream.java
+++ b/trunk/src/com/jpexs/decompiler/flash/SWFInputStream.java
@@ -502,22 +502,25 @@ public class SWFInputStream extends InputStream {
return ret;
}
- public List readActionList(long address, long containerSWFOffset) throws IOException {
+ public List readActionList(List listeners, long address, long containerSWFOffset) throws IOException {
ReReadableInputStream rri = new ReReadableInputStream(this);
- return readActionList(address, containerSWFOffset, rri, version, 0, -1);
+ return readActionList(listeners, address, containerSWFOffset, rri, version, 0, -1);
}
- public List readActionList(long address, long containerSWFOffset, ReReadableInputStream rri, int maxlen) throws IOException {
- return readActionList(address, containerSWFOffset, rri, version, rri.getPos(), rri.getPos() + maxlen);
+ public List readActionList(List listeners, long address, long containerSWFOffset, ReReadableInputStream rri, int maxlen) throws IOException {
+ return readActionList(listeners, address, containerSWFOffset, rri, version, rri.getPos(), rri.getPos() + maxlen);
}
- private static void getConstantPool(ConstantPool cpool, List localData, Stack stack, List output, ActionGraphSource code, int ip, int lastIp, List constantPools, List visited, int version, int endIp) {
+ private static void getConstantPool(List listeners, ConstantPool cpool, List localData, Stack stack, List output, ActionGraphSource code, int ip, int lastIp, List constantPools, List visited, int version, int endIp) {
boolean debugMode = false;
+ boolean deobfuscate = (Boolean) Configuration.getConfig("autoDeobfuscate", true);
while (((endIp == -1) || (endIp > ip)) && (ip > -1) && ip < code.size()) {
if (visited.contains(ip)) {
break;
}
-
+ for (DisassemblyListener listener : listeners) {
+ listener.progress("constantpool", ip + 1, code.size());
+ }
lastIp = ip;
GraphSourceItem ins = code.get(ip);
if (ins.isIgnored()) {
@@ -538,10 +541,12 @@ public class SWFInputStream extends InputStream {
List localData2 = Helper.toList(new HashMap(), new HashMap(), new HashMap());
List output2 = new ArrayList();
output2s.add(output2);
- getConstantPool(cpool, localData2, new Stack(), output2, code, code.adr2pos(endAddr), lastIp, constantPools, visited, version, code.adr2pos(endAddr + size));
+ getConstantPool(listeners, cpool, localData2, new Stack(), output2, code, code.adr2pos(endAddr), lastIp, constantPools, visited, version, code.adr2pos(endAddr + size));
endAddr += size;
}
- cnt.translateContainer(output2s, stack, output, (HashMap) localData.get(0), (HashMap) localData.get(1), (HashMap) localData.get(2));
+ if (deobfuscate) {
+ cnt.translateContainer(output2s, stack, output, (HashMap) localData.get(0), (HashMap) localData.get(1), (HashMap) localData.get(2));
+ }
ip = code.adr2pos(endAddr);
continue;
}
@@ -586,13 +591,15 @@ public class SWFInputStream extends InputStream {
}
//for..in return
- if (((ins instanceof ActionEquals) || (ins instanceof ActionEquals2)) && (stack.size() == 1) && (stack.peek() instanceof DirectValueTreeItem)) {
- stack.push(new DirectValueTreeItem(null, 0, new Null(), new ArrayList()));
- }
- try {
- ins.translate(localData, stack, output);
- } catch (Exception ex) {
- Logger.getLogger(SWFInputStream.class.getName()).log(Level.SEVERE, "Error during getting constantpool", ex);
+ if (deobfuscate) {
+ if (((ins instanceof ActionEquals) || (ins instanceof ActionEquals2)) && (stack.size() == 1) && (stack.peek() instanceof DirectValueTreeItem)) {
+ stack.push(new DirectValueTreeItem(null, 0, new Null(), new ArrayList()));
+ }
+ try {
+ ins.translate(localData, stack, output);
+ } catch (Exception ex) {
+ Logger.getLogger(SWFInputStream.class.getName()).log(Level.SEVERE, "Error during getting constantpool", ex);
+ }
}
if (ins.isExit()) {
break;
@@ -600,7 +607,7 @@ public class SWFInputStream extends InputStream {
if (ins.isBranch() || ins.isJump()) {
- if ((Boolean) Configuration.getConfig("autoDeobfuscate", true) && (ins instanceof ActionIf) && !stack.isEmpty() && (stack.peek().isCompileTime() && (!stack.peek().hasSideEffect()))) {
+ if (deobfuscate && (ins instanceof ActionIf) && !stack.isEmpty() && (stack.peek().isCompileTime() && (!stack.peek().hasSideEffect()))) {
ActionIf aif = (ActionIf) ins;
if (aif.ignoreUsed && (!aif.jumpUsed)) {
ins.setIgnored(true);
@@ -636,9 +643,9 @@ public class SWFInputStream extends InputStream {
}
}
stack.pop();
- getConstantPool(cpool, localData, stack, output, code, condition ? (code.adr2pos(((ActionIf) ins).getAddress() + ((ActionIf) ins).getBytes(code.version).length + ((ActionIf) ins).getJumpOffset())) : ip + 1, ip, constantPools, visited, version, endIp);
+ getConstantPool(listeners, cpool, localData, stack, output, code, condition ? (code.adr2pos(((ActionIf) ins).getAddress() + ((ActionIf) ins).getBytes(code.version).length + ((ActionIf) ins).getJumpOffset())) : ip + 1, ip, constantPools, visited, version, endIp);
} else {
- if (ins instanceof ActionIf) {
+ if (deobfuscate && ins instanceof ActionIf) {
stack.pop();
}
visited.add(ip);
@@ -646,7 +653,7 @@ public class SWFInputStream extends InputStream {
for (int b : branches) {
Stack brStack = (Stack) stack.clone();
if (b >= 0) {
- getConstantPool(cpool, localData, brStack, output, code, b, ip, constantPools, visited, version, endIp);
+ getConstantPool(listeners, cpool, localData, brStack, output, code, b, ip, constantPools, visited, version, endIp);
} else {
if (debugMode) {
System.out.println("Negative branch:" + b);
@@ -661,13 +668,16 @@ public class SWFInputStream extends InputStream {
if (ip < 0) {
System.out.println("Visited Negative: " + ip);
}
+ for (DisassemblyListener listener : listeners) {
+ listener.progress("constantpool", ip + 1, code.size());
+ }
}
- public static List getConstantPool(ActionGraphSource code, int addr, int version) {
+ public static List getConstantPool(List listeners, ActionGraphSource code, int addr, int version) {
List ret = new ArrayList();
List localData = Helper.toList(new HashMap(), new HashMap(), new HashMap());
try {
- getConstantPool(null, localData, new Stack(), new ArrayList(), code, code.adr2pos(addr), 0, ret, new ArrayList(), version, -1);
+ getConstantPool(listeners, null, localData, new Stack(), new ArrayList(), code, code.adr2pos(addr), 0, ret, new ArrayList(), version, -1);
} catch (Exception ex) {
log.log(Level.SEVERE, "Error during getting constantpool", ex);
}
@@ -681,7 +691,7 @@ public class SWFInputStream extends InputStream {
* @return List of actions
* @throws IOException
*/
- public static List readActionList(long address, long containerSWFOffset, ReReadableInputStream rri, int version, int ip, int endip) throws IOException {
+ public static List readActionList(List listeners, long address, long containerSWFOffset, ReReadableInputStream rri, int version, int ip, int endip) throws IOException {
List retdups = new ArrayList();
ConstantPool cpool = new ConstantPool();
@@ -699,7 +709,7 @@ public class SWFInputStream extends InputStream {
method = 2;
goesPrev = readActionListAtPos(true, localData, stack, cpool, sis, rri, ip, retdups, ip);
}*/
- goesPrev = readActionListAtPos(new ArrayList(), new HashMap>(), address, containerSWFOffset, false, true, localData, stack, cpool, sis, rri, ip, retdups, ip, endip);
+ goesPrev = readActionListAtPos(listeners, new ArrayList(), new HashMap>(), address, containerSWFOffset, false, true, localData, stack, cpool, sis, rri, ip, retdups, ip, endip);
if (goesPrev) {
} else {
@@ -739,7 +749,7 @@ public class SWFInputStream extends InputStream {
br.append(((Action) ret.get(i)).getASMSource(new ArrayList(), new ArrayList(), cpool.constants, version, false));
br.append("\r\n");
}
- pools = getConstantPool(new ActionGraphSource(ret, version, new HashMap(), new HashMap(), new HashMap()), ip, version);
+ pools = getConstantPool(listeners, new ActionGraphSource(ret, version, new HashMap(), new HashMap(), new HashMap()), ip, version);
if (pools.size() == 1) {
Action.setConstantPool(ret, pools.get(0));
@@ -766,9 +776,11 @@ public class SWFInputStream extends InputStream {
return reta;
}
- private static boolean readActionListAtPos(List output, HashMap> containers, long address, long containerSWFOffset, boolean notCompileTime, boolean enableVariables, List localData, Stack stack, ConstantPool cpool, SWFInputStream sis, ReReadableInputStream rri, int ip, List ret, int startIp, int endip) throws IOException {
+ private static boolean readActionListAtPos(List listeners, List output, HashMap> containers, long address, long containerSWFOffset, boolean notCompileTime, boolean enableVariables, List localData, Stack stack, ConstantPool cpool, SWFInputStream sis, ReReadableInputStream rri, int ip, List ret, int startIp, int endip) throws IOException {
boolean debugMode = false;
boolean decideBranch = false;
+
+ boolean deobfuscate = (Boolean) Configuration.getConfig("autoDeobfuscate", true);
boolean retv = false;
rri.setPos(ip);
Action a;
@@ -776,6 +788,9 @@ public class SWFInputStream extends InputStream {
Scanner sc = new Scanner(System.in);
int prevIp = ip;
while (((endip == -1) || (endip > ip)) && (a = sis.readAction(rri)) != null) {
+ for (DisassemblyListener listener : listeners) {
+ listener.progress("Reading", rri.getCount(), rri.length());
+ }
if ((ip < ret.size()) && (!(ret.get(ip) instanceof ActionNop))) {
a = ret.get(ip);
if (a.getAddress() != ip) {
@@ -870,9 +885,11 @@ public class SWFInputStream extends InputStream {
try {
if (a instanceof ActionIf) {
aif = (ActionIf) a;
- GraphTargetItem top = null;
- top = stack.pop();
+ GraphTargetItem top = null;
+ if (deobfuscate) {
+ top = stack.pop();
+ }
int nip = rri.getPos() + aif.getJumpOffset();
if (decideBranch) {
@@ -887,7 +904,7 @@ public class SWFInputStream extends InputStream {
} else if (next.equals("c")) {
goaif = true;
}
- } else if ((Boolean) Configuration.getConfig("autoDeobfuscate", true) && top.isCompileTime() && (!top.hasSideEffect()) && ((!top.isVariableComputed()) || (top.isVariableComputed() && enableVariables && (!notCompileTime)))) {
+ } else if (deobfuscate && top.isCompileTime() && (!top.hasSideEffect()) && ((!top.isVariableComputed()) || (top.isVariableComputed() && enableVariables && (!notCompileTime)))) {
//if(top.isCompileTime()) {
//if(false){
if (enableVariables) {
@@ -957,14 +974,16 @@ public class SWFInputStream extends InputStream {
//rri.setPos(newip);
//}
} else if (!(a instanceof GraphSourceItemContainer)) {
- //return in for..in, TODO:Handle this better way
- if (((a instanceof ActionEquals) || (a instanceof ActionEquals2)) && (stack.size() == 1) && (stack.peek() instanceof DirectValueTreeItem)) {
- stack.push(new DirectValueTreeItem(null, 0, new Null(), new ArrayList()));
+ if (deobfuscate) {
+ //return in for..in, TODO:Handle this better way
+ if (((a instanceof ActionEquals) || (a instanceof ActionEquals2)) && (stack.size() == 1) && (stack.peek() instanceof DirectValueTreeItem)) {
+ stack.push(new DirectValueTreeItem(null, 0, new Null(), new ArrayList()));
+ }
+ if ((a instanceof ActionStoreRegister) && stack.isEmpty()) {
+ stack.push(new DirectValueTreeItem(null, 0, new Null(), new ArrayList()));
+ }
+ a.translate(localData, stack, output);
}
- if ((a instanceof ActionStoreRegister) && stack.isEmpty()) {
- stack.push(new DirectValueTreeItem(null, 0, new Null(), new ArrayList()));
- }
- a.translate(localData, stack, output);
}
} catch (RuntimeException ex) {
if (!enableVariables) {
@@ -1012,11 +1031,13 @@ public class SWFInputStream extends InputStream {
}
List localData2 = Helper.toList(new HashMap(), new HashMap(), new HashMap());
List output2 = new ArrayList();
- readActionListAtPos(output2, containers, address, containerSWFOffset, notCompileTime, enableVariables, localData2, new Stack(), cpool, sis, rri, (int) endAddr, ret, startIp, (int) (endAddr + size));
+ readActionListAtPos(listeners, output2, containers, address, containerSWFOffset, notCompileTime, enableVariables, localData2, new Stack(), cpool, sis, rri, (int) endAddr, ret, startIp, (int) (endAddr + size));
output2s.add(output2);
endAddr += size;
}
- cnt.translateContainer(output2s, stack, output, (HashMap) localData.get(0), (HashMap) localData.get(1), (HashMap) localData.get(2));
+ if (deobfuscate) {
+ cnt.translateContainer(output2s, stack, output, (HashMap) localData.get(0), (HashMap) localData.get(1), (HashMap) localData.get(2));
+ }
ip = (int) endAddr;
prevIp = ip;
rri.setPos(ip);
@@ -1044,7 +1065,7 @@ public class SWFInputStream extends InputStream {
aif.jumpUsed = true;
int oldPos = rri.getPos();
Stack substack = (Stack) stack.clone();
- if (readActionListAtPos(output, containers, address, containerSWFOffset, true, enableVariables, localData, substack, cpool, sis, rri, rri.getPos() + aif.getJumpOffset(), ret, startIp, endip)) {
+ if (readActionListAtPos(listeners, output, containers, address, containerSWFOffset, true, enableVariables, localData, substack, cpool, sis, rri, rri.getPos() + aif.getJumpOffset(), ret, startIp, endip)) {
retv = true;
}
rri.setPos(oldPos);
@@ -1052,6 +1073,9 @@ public class SWFInputStream extends InputStream {
}
prevIp = ip;
}
+ for (DisassemblyListener listener : listeners) {
+ listener.progress("Reading", rri.getCount(), rri.length());
+ }
return retv;
}
diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/DivideTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/DivideTreeItem.java
index 66ebca0db..f33e32c63 100644
--- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/DivideTreeItem.java
+++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/DivideTreeItem.java
@@ -28,6 +28,9 @@ public class DivideTreeItem extends BinaryOpItem {
@Override
public double toNumber() {
+ if (Double.compare(rightSide.toNumber(), 0) == 0) {
+ return Double.NaN;
+ }
return leftSide.toNumber() / rightSide.toNumber();
}
}
diff --git a/trunk/src/com/jpexs/decompiler/flash/action/Action.java b/trunk/src/com/jpexs/decompiler/flash/action/Action.java
index 5703ad890..c342b5db3 100644
--- a/trunk/src/com/jpexs/decompiler/flash/action/Action.java
+++ b/trunk/src/com/jpexs/decompiler/flash/action/Action.java
@@ -16,6 +16,7 @@
*/
package com.jpexs.decompiler.flash.action;
+import com.jpexs.decompiler.flash.DisassemblyListener;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.SWFInputStream;
import com.jpexs.decompiler.flash.SWFOutputStream;
@@ -364,8 +365,8 @@ public class Action implements GraphSourceItem {
* @param hex Add hexadecimal?
* @return ASM source as String
*/
- public static String actionsToString(long address, List list, List importantOffsets, int version, boolean hex, long swfPos) {
- return actionsToString(address, list, importantOffsets, new ArrayList(), version, hex, swfPos);
+ public static String actionsToString(List listeners, long address, List list, List importantOffsets, int version, boolean hex, long swfPos) {
+ return actionsToString(listeners, address, list, importantOffsets, new ArrayList(), version, hex, swfPos);
}
/**
@@ -378,8 +379,7 @@ public class Action implements GraphSourceItem {
* @param hex Add hexadecimal?
* @return ASM source as String
*/
- public static String actionsToString(long address, List list, List importantOffsets, List constantPool, int version, boolean hex, long swfPos) {
- String ret = "";
+ public static String actionsToString(List listeners, long address, List list, List importantOffsets, List constantPool, int version, boolean hex, long swfPos) {
long offset;
if (importantOffsets == null) {
//setActionsAddresses(list, 0, version);
@@ -391,7 +391,7 @@ public class Action implements GraphSourceItem {
srcList.add((Action) o);
}
}
- List cps = SWFInputStream.getConstantPool(new ActionGraphSource(srcList, version, new HashMap(), new HashMap(), new HashMap()), 0, version);
+ List cps = SWFInputStream.getConstantPool(new ArrayList(), new ActionGraphSource(srcList, version, new HashMap(), new HashMap(), new HashMap()), 0, version);
if (!cps.isEmpty()) {
setConstantPool(list, cps.get(cps.size() - 1));
}
@@ -400,14 +400,20 @@ public class Action implements GraphSourceItem {
offset = address;
int pos = -1;
boolean lastPush = false;
+ StringBuilder ret = new StringBuilder();
for (GraphSourceItem s : srcList) {
+ for (DisassemblyListener l : listeners) {
+ l.progress("toString", pos + 2, srcList.size());
+ }
Action a = null;
if (s instanceof Action) {
a = (Action) s;
}
pos++;
if (hex) {
- ret += "" +/*"0x"+Helper.formatAddress(a.getFileAddress())+": "+*/ Helper.bytesToHexString(a.getBytes(version)) + "\r\n";
+ ret.append("");/* +"0x"+Helper.formatAddress(a.getFileAddress())+": "+*/;
+ ret.append(Helper.bytesToHexString(a.getBytes(version)));
+ ret.append("\r\n");
}
offset = a.getAddress();
@@ -430,10 +436,10 @@ public class Action implements GraphSourceItem {
if (containers.containsKey(offset)) {
for (int i = 0; i < containers.get(offset).size(); i++) {
- ret += "}\r\n";
+ ret.append("}\r\n");
GraphSourceItemContainer cnt = containers.get(offset).get(i);
int cntPos = containersPos.get(cnt);
- ret += cnt.getASMSourceBetween(cntPos);
+ ret.append(cnt.getASMSourceBetween(cntPos));
cntPos++;
containersPos.put(cnt, cntPos);
}
@@ -441,23 +447,27 @@ public class Action implements GraphSourceItem {
if (importantOffsets.contains(offset)) {
if (lastPush) {
- ret += "\r\n";
+ ret.append("\r\n");
lastPush = false;
}
- ret += "loc" + Helper.formatAddress(offset) + ":";
+ ret.append("loc");
+ ret.append(Helper.formatAddress(offset));
+ ret.append(":");
}
if (a.replaceWith != null) {
if (lastPush) {
- ret += "\r\n";
+ ret.append("\r\n");
lastPush = false;
}
- ret += Highlighting.hilighOffset("", offset) + a.replaceWith.getASMSource(list, importantOffsets, constantPool, version, hex) + "\r\n";
+ ret.append(Highlighting.hilighOffset("", offset));
+ ret.append(a.replaceWith.getASMSource(list, importantOffsets, constantPool, version, hex));
+ ret.append("\r\n");
} else if (a.ignored) {
if (lastPush) {
- ret += "\r\n";
+ ret.append("\r\n");
lastPush = false;
}
int len = 0;
@@ -467,11 +477,12 @@ public class Action implements GraphSourceItem {
len = a.getBytes(version).length;
}
for (int i = 0; i < len; i++) {
- ret += "Nop\r\n";
+ ret.append("Nop\r\n");
}
} else {
if (a.beforeInsert != null) {
- ret += a.beforeInsert.getASMSource(list, importantOffsets, constantPool, version, hex) + "\r\n";
+ ret.append(a.beforeInsert.getASMSource(list, importantOffsets, constantPool, version, hex));
+ ret.append("\r\n");
}
//if (!(a instanceof ActionNop)) {
String add = "";
@@ -484,12 +495,17 @@ public class Action implements GraphSourceItem {
add = "; ofs" + Helper.formatAddress(offset) + add;
add = "";
if ((a instanceof ActionPush) && lastPush) {
- ret += " " + ((ActionPush) a).paramsToStringReplaced(list, importantOffsets, constantPool, version, hex);
+ ret.append(" ");
+ ret.append(((ActionPush) a).paramsToStringReplaced(list, importantOffsets, constantPool, version, hex));
} else {
if (lastPush) {
- ret += "\r\n";
+ ret.append("\r\n");
}
- ret += Highlighting.hilighOffset("", offset) + a.getASMSourceReplaced(list, importantOffsets, constantPool, version, hex) + (a.ignored ? "; ignored" : "") + add + ((a instanceof ActionPush) ? "" : "\r\n");
+ ret.append(Highlighting.hilighOffset("", offset));
+ ret.append(a.getASMSourceReplaced(list, importantOffsets, constantPool, version, hex));
+ ret.append(a.ignored ? "; ignored" : "");
+ ret.append(add);
+ ret.append((a instanceof ActionPush) ? "" : "\r\n");
}
if (a instanceof ActionPush) {
lastPush = true;
@@ -498,28 +514,31 @@ public class Action implements GraphSourceItem {
}
//}
if (a.afterInsert != null) {
- ret += a.afterInsert.getASMSource(list, importantOffsets, constantPool, version, hex) + "\r\n";
+ ret.append(a.afterInsert.getASMSource(list, importantOffsets, constantPool, version, hex));
+ ret.append("\r\n");
}
}
offset += a.getBytes(version).length;
}
if (lastPush) {
- ret += "\r\n";
+ ret.append("\r\n");
}
if (containers.containsKey(offset)) {
for (int i = 0; i < containers.get(offset).size(); i++) {
- ret += "}\r\n";
+ ret.append("}\r\n");
GraphSourceItemContainer cnt = containers.get(offset).get(i);
int cntPos = containersPos.get(cnt);
- ret += cnt.getASMSourceBetween(cntPos);
+ ret.append(cnt.getASMSourceBetween(cntPos));
cntPos++;
containersPos.put(cnt, cntPos);
}
}
if (importantOffsets.contains(offset)) {
- ret += "loc" + Helper.formatAddress(offset) + ":\r\n";
+ ret.append("loc");
+ ret.append(Helper.formatAddress(offset));
+ ret.append(":\r\n");
}
- return ret;
+ return ret.toString();
}
/**
@@ -1216,7 +1235,7 @@ public class Action implements GraphSourceItem {
}
String s = null;
try {
- s = Highlighting.stripHilights(Action.actionsToString(address, ret, null, version, false, swfPos));
+ s = Highlighting.stripHilights(Action.actionsToString(new ArrayList(), address, ret, null, version, false, swfPos));
ret = ASMParser.parse(address, swfPos, true, new ByteArrayInputStream(s.getBytes()), SWF.DEFAULT_VERSION);
} catch (Exception ex) {
diff --git a/trunk/src/com/jpexs/decompiler/flash/action/gui/ActionPanel.java b/trunk/src/com/jpexs/decompiler/flash/action/gui/ActionPanel.java
index 56746b8af..0ae5e601e 100644
--- a/trunk/src/com/jpexs/decompiler/flash/action/gui/ActionPanel.java
+++ b/trunk/src/com/jpexs/decompiler/flash/action/gui/ActionPanel.java
@@ -16,6 +16,7 @@
*/
package com.jpexs.decompiler.flash.action.gui;
+import com.jpexs.decompiler.flash.DisassemblyListener;
import com.jpexs.decompiler.flash.Main;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.abc.gui.LineMarkedEditorPane;
@@ -93,8 +94,15 @@ public class ActionPanel extends JPanel implements ActionListener {
lastH = h;
}
long offset = lastH.offset;
+ editor.setText("; Getting hilights...");
disassembledHilights = Highlighting.getInstrHighlights(text);
- editor.setText(Highlighting.stripHilights(text));
+ String stripped = Highlighting.stripHilights(text);
+ /*if(stripped.length()>30000){
+ editor.setContentType("text/plain");
+ }else{
+ editor.setContentType("text/flasm");
+ }*/
+ editor.setText(stripped);
for (Highlighting h : disassembledHilights) {
if (h.offset == offset) {
editor.setCaretPosition(h.startPos);
@@ -117,13 +125,35 @@ public class ActionPanel extends JPanel implements ActionListener {
public void run() {
editor.setText("; Disassembling...");
if (Main.DO_DECOMPILE) {
- decompiledEditor.setText("//Decompiling...");
+ decompiledEditor.setText("//Waiting for dissasembly...");
}
+ DisassemblyListener listener = new DisassemblyListener() {
+ int percent = 0;
+ String phase = "";
+
+ @Override
+ public void progress(String phase, long pos, long total) {
+ if (total < 1) {
+ return;
+ }
+ int newpercent = (int) (pos * 100 / total);
+ if (((newpercent > percent) || (!this.phase.equals(phase))) && newpercent <= 100) {
+ percent = newpercent;
+ this.phase = phase;
+ editor.setText("; Disassembling - " + phase + " " + percent + "%...");
+ }
+ }
+ };
+ asm.addDisassemblyListener(listener);
lastDisasm = asm.getASMSource(SWF.DEFAULT_VERSION, true);
+ asm.removeDisassemblyListener(listener);
+ editor.setText("; Disassembled");
srcWithHex = Helper.hexToComments(lastDisasm);
srcNoHex = Helper.stripComments(lastDisasm);
+ editor.setText("; Disassembling - setting");
setHex(hexButton.isSelected());
if (Main.DO_DECOMPILE) {
+ decompiledEditor.setText("//Decompiling...");
List as = asm.getActions(SWF.DEFAULT_VERSION);
lastCode = as;
//com.jpexs.decompiler.flash.action.Action.setActionsAddresses(as, 0, SWF.DEFAULT_VERSION);
@@ -138,13 +168,19 @@ public class ActionPanel extends JPanel implements ActionListener {
} catch (IOException ex) {
Logger.getLogger(ActionPanel.class.getName()).log(Level.SEVERE, null, ex);
}*/
- decompiledEditor.setText(lastDecompiled = stripped);
+ lastDecompiled = stripped;
+ /*if(lastDecompiled.length()>30000){
+ decompiledEditor.setContentType("text/plain");
+ }else{
+ decompiledEditor.setContentType("text/actionscript");
+ }*/
+ decompiledEditor.setText(lastDecompiled);
if (debugRecompile) {
try {
ActionScriptParser ps = new ActionScriptParser();
- recompiledEditor.setText(Highlighting.stripHilights(com.jpexs.decompiler.flash.action.Action.actionsToString(0, ps.parse(stripped), null, SWF.DEFAULT_VERSION, false, 0)));
+ recompiledEditor.setText(Highlighting.stripHilights(com.jpexs.decompiler.flash.action.Action.actionsToString(new ArrayList(), 0, ps.parse(stripped), null, SWF.DEFAULT_VERSION, false, 0)));
} catch (ParseException ex) {
Logger.getLogger(ActionPanel.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/ModuloTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/ModuloTreeItem.java
index 2cc74eadb..d916e8405 100644
--- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/ModuloTreeItem.java
+++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/operations/ModuloTreeItem.java
@@ -28,6 +28,9 @@ public class ModuloTreeItem extends BinaryOpItem {
@Override
public double toNumber() {
+ if (Double.compare(rightSide.toNumber(), 0) == 0) {
+ return Double.NaN;
+ }
return ((int) leftSide.toNumber()) % ((int) rightSide.toNumber());
}
}
diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java b/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java
index b4bae6516..ff08cb88f 100644
--- a/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java
+++ b/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java
@@ -489,10 +489,24 @@ public class MainFrame extends JFrame implements ActionListener, TreeSelectionLi
List