From f6969d442aea403ce397addc17a14e40b590e171 Mon Sep 17 00:00:00 2001 From: honfika Date: Sun, 20 Jul 2014 18:15:36 +0200 Subject: [PATCH] Debug mode Do(Init)Action reading fixed --- .../flash/tags/DefineButtonTag.java | 30 ++++++++---------- .../decompiler/flash/tags/DoActionTag.java | 31 +++++++++---------- .../flash/tags/DoInitActionTag.java | 29 ++++++++--------- src/com/jpexs/helpers/ByteArrayRange.java | 11 +++++++ 4 files changed, 51 insertions(+), 50 deletions(-) diff --git a/src/com/jpexs/decompiler/flash/tags/DefineButtonTag.java b/src/com/jpexs/decompiler/flash/tags/DefineButtonTag.java index 93c307795..6f0b49e5a 100644 --- a/src/com/jpexs/decompiler/flash/tags/DefineButtonTag.java +++ b/src/com/jpexs/decompiler/flash/tags/DefineButtonTag.java @@ -73,14 +73,13 @@ public class DefineButtonTag extends ButtonTag implements ASMSource { */ //public List actions; @Internal - public byte[] actionBytes; + public ByteArrayRange actionBytes; public static final int ID = 7; @Override public int getCharacterId() { return buttonId; } - private final long hdrSize; private Timeline timeline; @@ -103,8 +102,9 @@ public class DefineButtonTag extends ButtonTag implements ASMSource { super(sis.getSwf(), ID, "DefineButton", data); buttonId = sis.readUI16("buttonId"); characters = sis.readBUTTONRECORDList(false, "characters"); - hdrSize = sis.getPos(); - actionBytes = sis.readBytesEx(sis.available(), "actionBytes"); + int pos = (int) sis.getPos(); + byte[] bytes = sis.readBytesEx(sis.available(), "actionBytes"); + actionBytes = new ByteArrayRange(data.array, pos, bytes.length); } /** @@ -123,7 +123,7 @@ public class DefineButtonTag extends ButtonTag implements ASMSource { try { sos.writeUI16(buttonId); sos.writeBUTTONRECORDList(characters, false); - sos.write(actionBytes); + sos.write(getActionBytes()); //sos.write(Action.actionsToBytes(actions, true, version)); sos.close(); } catch (IOException e) { @@ -166,15 +166,10 @@ public class DefineButtonTag extends ButtonTag implements ASMSource { @Override public List getActions() throws InterruptedException { try { - int prevLength; - SWFInputStream rri; - if (actionBytes == null) { - prevLength = (int) (getDataPos() + hdrSize); - rri = new SWFInputStream(swf, getOriginalRange().array); + int prevLength = actionBytes.pos; + SWFInputStream rri = new SWFInputStream(swf, actionBytes.array); + if (prevLength != 0) { rri.seek(prevLength); - } else { - prevLength = 0; - rri = new SWFInputStream(swf, actionBytes); } List list = ActionListReader.readActionListTimeout(listeners, rri, getVersion(), prevLength, -1, toString()/*FIXME?*/); return list; @@ -188,17 +183,18 @@ public class DefineButtonTag extends ButtonTag implements ASMSource { @Override public void setActions(List actions) { - actionBytes = Action.actionsToBytes(actions, true, swf.version); + byte[] bytes = Action.actionsToBytes(actions, true, swf.version); + actionBytes = new ByteArrayRange(bytes, 0, bytes.length); } @Override public byte[] getActionBytes() { - return actionBytes; + return actionBytes.getRangeData(); } @Override public void setActionBytes(byte[] actionBytes) { - this.actionBytes = actionBytes; + this.actionBytes = new ByteArrayRange(actionBytes); } @Override @@ -208,7 +204,7 @@ public class DefineButtonTag extends ButtonTag implements ASMSource { @Override public GraphTextWriter getActionBytesAsHex(GraphTextWriter writer) { - return Helper.byteArrayToHexWithHeader(writer, actionBytes); + return Helper.byteArrayToHexWithHeader(writer, actionBytes.getRangeData()); } @Override diff --git a/src/com/jpexs/decompiler/flash/tags/DoActionTag.java b/src/com/jpexs/decompiler/flash/tags/DoActionTag.java index 40d1e20f2..18933674d 100644 --- a/src/com/jpexs/decompiler/flash/tags/DoActionTag.java +++ b/src/com/jpexs/decompiler/flash/tags/DoActionTag.java @@ -44,7 +44,7 @@ public class DoActionTag extends Tag implements ASMSource { */ //public List actions = new ArrayList(); @Internal - public byte[] actionBytes; + public ByteArrayRange actionBytes; public static final int ID = 12; /** @@ -56,8 +56,9 @@ public class DoActionTag extends Tag implements ASMSource { */ public DoActionTag(SWFInputStream sis, ByteArrayRange data) throws IOException { super(sis.getSwf(), ID, "DoAction", data); - //do not store actionBytes. Disassebler will use the original SWF stream in this case - sis.readBytesEx(sis.available(), "actionBytes"); + int pos = (int) sis.getPos(); + byte[] bytes = sis.readBytesEx(sis.available(), "actionBytes"); + actionBytes = new ByteArrayRange(data.array, pos, bytes.length); } /** @@ -68,7 +69,7 @@ public class DoActionTag extends Tag implements ASMSource { */ public DoActionTag(SWF swf, ByteArrayRange data) { super(swf, ID, "DoAction", data); - actionBytes = new byte[0]; + actionBytes = new ByteArrayRange(new byte[0]); } /** @@ -78,7 +79,7 @@ public class DoActionTag extends Tag implements ASMSource { */ @Override public byte[] getData() { - return actionBytes;//Action.actionsToBytes(actions, true, version); + return getActionBytes(); } /** @@ -120,15 +121,10 @@ public class DoActionTag extends Tag implements ASMSource { @Override public List getActions() throws InterruptedException { try { - int prevLength; - SWFInputStream rri; - if (actionBytes == null) { - prevLength = (int) getDataPos(); - rri = new SWFInputStream(swf, getOriginalRange().array); + int prevLength = actionBytes.pos; + SWFInputStream rri = new SWFInputStream(swf, actionBytes.array); + if (prevLength != 0) { rri.seek(prevLength); - } else { - prevLength = 0; - rri = new SWFInputStream(swf, actionBytes); } List list = ActionListReader.readActionListTimeout(listeners, rri, getVersion(), prevLength, -1, toString()/*FIXME?*/); return list; @@ -142,17 +138,18 @@ public class DoActionTag extends Tag implements ASMSource { @Override public void setActions(List actions) { - actionBytes = Action.actionsToBytes(actions, true, swf.version); + byte[] bytes = Action.actionsToBytes(actions, true, swf.version); + actionBytes = new ByteArrayRange(bytes, 0, bytes.length); } @Override public byte[] getActionBytes() { - return actionBytes; + return actionBytes.getRangeData(); } @Override public void setActionBytes(byte[] actionBytes) { - this.actionBytes = actionBytes; + this.actionBytes = new ByteArrayRange(actionBytes); } @Override @@ -162,7 +159,7 @@ public class DoActionTag extends Tag implements ASMSource { @Override public GraphTextWriter getActionBytesAsHex(GraphTextWriter writer) { - return Helper.byteArrayToHexWithHeader(writer, actionBytes); + return Helper.byteArrayToHexWithHeader(writer, actionBytes.getRangeData()); } List listeners = new ArrayList<>(); diff --git a/src/com/jpexs/decompiler/flash/tags/DoInitActionTag.java b/src/com/jpexs/decompiler/flash/tags/DoInitActionTag.java index d04b22ccd..d52fcb01e 100644 --- a/src/com/jpexs/decompiler/flash/tags/DoInitActionTag.java +++ b/src/com/jpexs/decompiler/flash/tags/DoInitActionTag.java @@ -49,7 +49,7 @@ public class DoInitActionTag extends CharacterIdTag implements ASMSource { */ //public List actions = new ArrayList(); @Internal - public byte[] actionBytes; + public ByteArrayRange actionBytes; public static final int ID = 59; /** @@ -62,8 +62,9 @@ public class DoInitActionTag extends CharacterIdTag implements ASMSource { public DoInitActionTag(SWFInputStream sis, ByteArrayRange data) throws IOException { super(sis.getSwf(), ID, "DoInitAction", data); spriteId = sis.readUI16("spriteId"); - //do not store actionBytes. Disassebler will use the original SWF stream in this case - sis.readBytesEx(sis.available(), "actionBytes"); + int pos = (int) sis.getPos(); + byte[] bytes = sis.readBytesEx(sis.available(), "actionBytes"); + actionBytes = new ByteArrayRange(data.array, pos, bytes.length); } /** @@ -77,7 +78,7 @@ public class DoInitActionTag extends CharacterIdTag implements ASMSource { SWFOutputStream sos = new SWFOutputStream(baos, getVersion()); try { sos.writeUI16(spriteId); - sos.write(actionBytes); + sos.write(getActionBytes()); //sos.write(Action.actionsToBytes(actions, true, version)); sos.close(); } catch (IOException e) { @@ -114,15 +115,10 @@ public class DoInitActionTag extends CharacterIdTag implements ASMSource { @Override public List getActions() throws InterruptedException { try { - int prevLength; - SWFInputStream rri; - if (actionBytes == null) { - prevLength = (int) (getDataPos() + 2); - rri = new SWFInputStream(swf, getOriginalRange().array); + int prevLength = actionBytes.pos; + SWFInputStream rri = new SWFInputStream(swf, actionBytes.array); + if (prevLength != 0) { rri.seek(prevLength); - } else { - prevLength = 0; - rri = new SWFInputStream(swf, actionBytes); } List list = ActionListReader.readActionListTimeout(listeners, rri, getVersion(), prevLength, -1, toString()/*FIXME?*/); return list; @@ -136,17 +132,18 @@ public class DoInitActionTag extends CharacterIdTag implements ASMSource { @Override public void setActions(List actions) { - actionBytes = Action.actionsToBytes(actions, true, swf.version); + byte[] bytes = Action.actionsToBytes(actions, true, swf.version); + actionBytes = new ByteArrayRange(bytes, 0, bytes.length); } @Override public byte[] getActionBytes() { - return actionBytes; + return actionBytes.getRangeData(); } @Override public void setActionBytes(byte[] actionBytes) { - this.actionBytes = actionBytes; + this.actionBytes = new ByteArrayRange(actionBytes); } @Override @@ -156,7 +153,7 @@ public class DoInitActionTag extends CharacterIdTag implements ASMSource { @Override public GraphTextWriter getActionBytesAsHex(GraphTextWriter writer) { - return Helper.byteArrayToHexWithHeader(writer, actionBytes); + return Helper.byteArrayToHexWithHeader(writer, actionBytes.getRangeData()); } @Override diff --git a/src/com/jpexs/helpers/ByteArrayRange.java b/src/com/jpexs/helpers/ByteArrayRange.java index 082fe72f1..239357001 100644 --- a/src/com/jpexs/helpers/ByteArrayRange.java +++ b/src/com/jpexs/helpers/ByteArrayRange.java @@ -26,10 +26,21 @@ public class ByteArrayRange { public final int pos; public final int length; + public ByteArrayRange(byte[] array) { + this.array = array; + this.pos = 0; + this.length = array.length; + } + public ByteArrayRange(byte[] array, int pos, int length) { this.array = array; this.pos = pos; this.length = length; } + public byte[] getRangeData() { + byte[] data = new byte[length]; + System.arraycopy(array, pos, data, 0, length); + return data; + } }