Debug mode Do(Init)Action reading fixed

This commit is contained in:
honfika
2014-07-20 18:15:36 +02:00
parent beddb0d48f
commit f6969d442a
4 changed files with 51 additions and 50 deletions
@@ -73,14 +73,13 @@ public class DefineButtonTag extends ButtonTag implements ASMSource {
*/
//public List<Action> 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<Action> 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<Action> 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<Action> 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
@@ -44,7 +44,7 @@ public class DoActionTag extends Tag implements ASMSource {
*/
//public List<Action> actions = new ArrayList<Action>();
@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<Action> 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<Action> 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<Action> 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<DisassemblyListener> listeners = new ArrayList<>();
@@ -49,7 +49,7 @@ public class DoInitActionTag extends CharacterIdTag implements ASMSource {
*/
//public List<Action> actions = new ArrayList<Action>();
@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<Action> 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<Action> 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<Action> 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
+11
View File
@@ -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;
}
}