small fixes

This commit is contained in:
honfika@gmail.com
2014-11-09 00:39:56 +01:00
parent 36d4628ae6
commit 6ce4c3d758
19 changed files with 81 additions and 61 deletions

View File

@@ -946,9 +946,9 @@ public class SWFInputStream implements AutoCloseable {
sb.append(" len=");
sb.append(Helper.formatInt(tag.getOriginalDataLength(), 8));
sb.append(" ");
sb.append(Helper.bytesToHexString(64, tag.getData(), 0));
sb.append(Helper.bytesToHexString(64, tag.getOriginalData(), 0));
out.println(sb.toString());
// out.println(Utils.formatHex((int)tag.getPos(), 8) + ": " + Utils.indent(level, "") + Utils.format(tag.toString(), 25 - 2*level) + " tagId="+tag.getId()+" len="+tag.getOrigDataLength()+": "+Utils.bytesToHexString(64, tag.getData(version), 0));
// out.println(Utils.formatHex((int)tag.getPos(), 8) + ": " + Utils.indent(level, "") + Utils.format(tag.toString(), 25 - 2*level) + " tagId="+tag.getId()+" len="+tag.getOrigDataLength()+": "+Utils.bytesToHexString(64, tag.getData(version), 0));
if (tag.hasSubTags()) {
for (Tag subTag : tag.getSubTags()) {
dumpTag(out, version, subTag, level + 1);
@@ -1430,7 +1430,7 @@ public class SWFInputStream implements AutoCloseable {
int tagIDTagLength = readUI16("tagIDTagLength");
int tagID = (tagIDTagLength) >> 6;
logger.log(Level.INFO, "Reading tag. ID={0}, position: {1}", new Object[]{tagID, pos});
logger.log(Level.FINE, "Reading tag. ID={0}, position: {1}", new Object[]{tagID, pos});
long tagLength = (tagIDTagLength & 0x003F);
boolean readLong = false;
@@ -1466,7 +1466,7 @@ public class SWFInputStream implements AutoCloseable {
}
if (Configuration.debugMode.get()) {
byte[] data = ret.getOriginalData().getRangeData();
byte[] data = ret.getOriginalData();
byte[] dataNew = ret.getData();
int ignoreFirst = 0;
for (int i = 0; i < data.length; i++) {
@@ -1886,7 +1886,7 @@ public class SWFInputStream implements AutoCloseable {
*/
public CLIPACTIONRECORD readCLIPACTIONRECORD(SWF swf, Tag tag, String name) throws IOException {
newDumpLevel(name, "CLIPACTIONRECORD");
CLIPACTIONRECORD ret = new CLIPACTIONRECORD(swf, this, getPos(), tag);
CLIPACTIONRECORD ret = new CLIPACTIONRECORD(swf, this, tag);
endDumpLevel();
if (ret.eventFlags.isClear()) {
return null;

View File

@@ -619,8 +619,10 @@ public class Configuration {
static {
setConfigurationFields();
if (useDetailedLogging.get() || debugMode.get()) {
logLevel = Level.CONFIG;
if (useDetailedLogging.get()) {
logLevel = Level.FINEST;
} else if (debugMode.get()) {
logLevel = Level.INFO;
} else {
logLevel = Level.WARNING;
}

View File

@@ -133,7 +133,7 @@ public class DefineButton2Tag extends ButtonTag implements Container {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
OutputStream os = baos;
if (Configuration.debugCopy.get()) {
ByteArrayInputStream bais = new ByteArrayInputStream(getOriginalData().getRangeData());
ByteArrayInputStream bais = new ByteArrayInputStream(getOriginalData());
os = new CopyOutputStream(os, bais);
}
SWFOutputStream sos = new SWFOutputStream(os, getVersion());

View File

@@ -102,7 +102,7 @@ public class DefineButtonTag extends ButtonTag implements ASMSource {
super(swf, ID, "DefineButton", null);
buttonId = swf.getNextCharacterId();
characters = new ArrayList<>();
actionBytes = new ByteArrayRange(new byte[] {0});
actionBytes = ByteArrayRange.EMPTY;
}
/**
@@ -119,7 +119,7 @@ public class DefineButtonTag extends ButtonTag implements ASMSource {
int pos = (int) sis.getPos();
byte[] bytes = sis.readBytesEx(sis.available(), "actionBytes");
if (data != null) {
actionBytes = new ByteArrayRange(data.array, pos, bytes.length);
actionBytes = new ByteArrayRange(data.getArray(), pos, bytes.length);
} else {
actionBytes = new ByteArrayRange(bytes, 0, bytes.length);
}
@@ -135,7 +135,7 @@ public class DefineButtonTag extends ButtonTag implements ASMSource {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
OutputStream os = baos;
if (Configuration.debugCopy.get()) {
os = new CopyOutputStream(os, new ByteArrayInputStream(getOriginalData().getRangeData()));
os = new CopyOutputStream(os, new ByteArrayInputStream(getOriginalData()));
}
SWFOutputStream sos = new SWFOutputStream(os, getVersion());
try {
@@ -186,12 +186,12 @@ public class DefineButtonTag extends ButtonTag implements ASMSource {
@Override
public ActionList getActions() throws InterruptedException {
try {
int prevLength = actionBytes.pos;
SWFInputStream rri = new SWFInputStream(swf, actionBytes.array);
int prevLength = actionBytes.getPos();
SWFInputStream rri = new SWFInputStream(swf, actionBytes.getArray());
if (prevLength != 0) {
rri.seek(prevLength);
}
ActionList list = ActionListReader.readActionListTimeout(listeners, rri, getVersion(), prevLength, prevLength + actionBytes.length, toString()/*FIXME?*/);
ActionList list = ActionListReader.readActionListTimeout(listeners, rri, getVersion(), prevLength, prevLength + actionBytes.getLength(), toString()/*FIXME?*/);
return list;
} catch (InterruptedException ex) {
throw ex;

View File

@@ -200,7 +200,7 @@ public class DefineFont3Tag extends FontTag {
OutputStream os = baos;
SWFOutputStream sos = new SWFOutputStream(os, getVersion());
if (Configuration.debugCopy.get()) {
sos = new SWFOutputStream(new CopyOutputStream(sos, new ByteArrayInputStream(getOriginalData().getRangeData())), getVersion());
sos = new SWFOutputStream(new CopyOutputStream(sos, new ByteArrayInputStream(getOriginalData())), getVersion());
}
try {
List<Long> offsetTable = new ArrayList<>();

View File

@@ -233,7 +233,7 @@ public class DefineSpriteTag extends CharacterTag implements Container, Drawable
ByteArrayOutputStream baos = new ByteArrayOutputStream();
OutputStream os = baos;
if (Configuration.debugCopy.get()) {
os = new CopyOutputStream(os, new ByteArrayInputStream(getOriginalData().getRangeData()));
os = new CopyOutputStream(os, new ByteArrayInputStream(getOriginalData()));
}
SWFOutputStream sos = new SWFOutputStream(os, getVersion());
try {

View File

@@ -112,7 +112,7 @@ public class DoABCDefineTag extends Tag implements ABCContainerTag {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
OutputStream os = bos;
if (Configuration.debugCopy.get()) {
os = new CopyOutputStream(os, new ByteArrayInputStream(getOriginalData().getRangeData()));
os = new CopyOutputStream(os, new ByteArrayInputStream(getOriginalData()));
}
try (SWFOutputStream sos = new SWFOutputStream(os, getVersion())) {
sos.writeUI32(flags);

View File

@@ -88,7 +88,7 @@ public class DoABCTag extends Tag implements ABCContainerTag {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
OutputStream os = bos;
if (Configuration.debugCopy.get()) {
os = new CopyOutputStream(os, new ByteArrayInputStream(getOriginalData().getRangeData()));
os = new CopyOutputStream(os, new ByteArrayInputStream(getOriginalData()));
}
try (SWFOutputStream sos = new SWFOutputStream(os, getVersion())) {
abc.saveToStream(sos);

View File

@@ -67,7 +67,7 @@ public class DoActionTag extends Tag implements ASMSource {
super(sis.getSwf(), ID, "DoAction", data);
int pos = (int) sis.getPos();
byte[] bytes = sis.readBytesEx(sis.available(), "actionBytes");
actionBytes = new ByteArrayRange(data.array, pos, bytes.length);
actionBytes = new ByteArrayRange(data.getArray(), pos, bytes.length);
}
/**
@@ -78,7 +78,7 @@ public class DoActionTag extends Tag implements ASMSource {
*/
public DoActionTag(SWF swf, ByteArrayRange data) {
super(swf, ID, "DoAction", data);
actionBytes = new ByteArrayRange();
actionBytes = ByteArrayRange.EMPTY;
}
/**
@@ -131,12 +131,12 @@ public class DoActionTag extends Tag implements ASMSource {
@Override
public ActionList getActions() throws InterruptedException {
try {
int prevLength = actionBytes.pos;
SWFInputStream rri = new SWFInputStream(swf, actionBytes.array);
int prevLength = actionBytes.getPos();
SWFInputStream rri = new SWFInputStream(swf, actionBytes.getArray());
if (prevLength != 0) {
rri.seek(prevLength);
}
ActionList list = ActionListReader.readActionListTimeout(listeners, rri, getVersion(), prevLength, prevLength + actionBytes.length, toString()/*FIXME?*/);
ActionList list = ActionListReader.readActionListTimeout(listeners, rri, getVersion(), prevLength, prevLength + actionBytes.getLength(), toString()/*FIXME?*/);
return list;
} catch (InterruptedException ex) {
throw ex;

View File

@@ -74,7 +74,7 @@ public class DoInitActionTag extends CharacterIdTag implements ASMSource {
spriteId = sis.readUI16("spriteId");
int pos = (int) sis.getPos();
byte[] bytes = sis.readBytesEx(sis.available(), "actionBytes");
actionBytes = new ByteArrayRange(data.array, pos, bytes.length);
actionBytes = new ByteArrayRange(data.getArray(), pos, bytes.length);
}
/**
@@ -127,12 +127,12 @@ public class DoInitActionTag extends CharacterIdTag implements ASMSource {
@Override
public ActionList getActions() throws InterruptedException {
try {
int prevLength = actionBytes.pos;
SWFInputStream rri = new SWFInputStream(swf, actionBytes.array);
int prevLength = actionBytes.getPos();
SWFInputStream rri = new SWFInputStream(swf, actionBytes.getArray());
if (prevLength != 0) {
rri.seek(prevLength);
}
ActionList list = ActionListReader.readActionListTimeout(listeners, rri, getVersion(), prevLength, prevLength + actionBytes.length, toString()/*FIXME?*/);
ActionList list = ActionListReader.readActionListTimeout(listeners, rri, getVersion(), prevLength, prevLength + actionBytes.getLength(), toString()/*FIXME?*/);
return list;
} catch (InterruptedException ex) {
throw ex;

View File

@@ -151,7 +151,7 @@ public class PlaceObject2Tag extends CharacterIdTag implements Container, PlaceO
ByteArrayOutputStream baos = new ByteArrayOutputStream();
OutputStream os = baos;
if (Configuration.debugCopy.get()) {
os = new CopyOutputStream(os, new ByteArrayInputStream(getOriginalData().getRangeData()));
os = new CopyOutputStream(os, new ByteArrayInputStream(getOriginalData()));
}
SWFOutputStream sos = new SWFOutputStream(os, getVersion());
try {

View File

@@ -227,7 +227,7 @@ public class PlaceObject3Tag extends CharacterIdTag implements Container, PlaceO
ByteArrayOutputStream baos = new ByteArrayOutputStream();
OutputStream os = baos;
if (Configuration.debugCopy.get()) {
os = new CopyOutputStream(os, new ByteArrayInputStream(getOriginalData().getRangeData()));
os = new CopyOutputStream(os, new ByteArrayInputStream(getOriginalData()));
}
SWFOutputStream sos = new SWFOutputStream(os, getVersion());
try {

View File

@@ -229,7 +229,7 @@ public class PlaceObject4Tag extends CharacterIdTag implements Container, PlaceO
ByteArrayOutputStream baos = new ByteArrayOutputStream();
OutputStream os = baos;
if (Configuration.debugCopy.get()) {
os = new CopyOutputStream(os, new ByteArrayInputStream(getOriginalData().getRangeData()));
os = new CopyOutputStream(os, new ByteArrayInputStream(getOriginalData()));
}
SWFOutputStream sos = new SWFOutputStream(os, getVersion());
try {

View File

@@ -332,7 +332,7 @@ public abstract class Tag implements NeedsCharacters, Exportable, ContainerItem,
sos.write(newHeaderData);
sos.write(newData);
} else {
sos.write(originalRange.array, originalRange.pos, originalRange.length);
sos.write(originalRange.getArray(), originalRange.getPos(), originalRange.getLength());
}
}
@@ -357,14 +357,22 @@ public abstract class Tag implements NeedsCharacters, Exportable, ContainerItem,
return originalRange;
}
public final ByteArrayRange getOriginalData() {
/**
* Returns the original inner data of the tag, without the 2-6 bytes length header
* Call this method only from debug codes
* @return The data
*/
public final byte[] getOriginalData() {
if (originalRange == null) {
return new ByteArrayRange();
return null;
}
int dataLength = getOriginalDataLength();
int pos = (int) (originalRange.pos + originalRange.length - dataLength);
return new ByteArrayRange(originalRange.array, pos, dataLength);
int pos = (int) (originalRange.getPos() + originalRange.getLength() - dataLength);
byte[] data = new byte[dataLength];
System.arraycopy(originalRange.getArray(), pos, data, 0, dataLength);
return data;
}
public final int getOriginalDataLength() {
@@ -372,11 +380,11 @@ public abstract class Tag implements NeedsCharacters, Exportable, ContainerItem,
return 0;
}
return originalRange.length - (isLongOriginal() ? 6 : 2);
return originalRange.getLength() - (isLongOriginal() ? 6 : 2);
}
private boolean isLongOriginal() {
int shortLength = originalRange.array[(int) originalRange.pos] & 0x003F;
int shortLength = originalRange.getArray()[(int) originalRange.getPos()] & 0x003F;
return shortLength == 0x3f;
}
@@ -389,11 +397,11 @@ public abstract class Tag implements NeedsCharacters, Exportable, ContainerItem,
}
public long getPos() {
return originalRange.pos;
return originalRange.getPos();
}
public long getDataPos() {
return originalRange.pos + (isLongOriginal() ? 6 : 2);
return originalRange.getPos() + (isLongOriginal() ? 6 : 2);
}
public void setModified(boolean value) {

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.SWF;
@@ -49,7 +50,7 @@ public class TagStub extends Tag {
*/
@Override
public byte[] getData() {
public byte[] getData() {
throw new Error("TagStub.getData call is not supported.");
}
public SWFInputStream getDataStream() {

View File

@@ -192,12 +192,12 @@ public class BUTTONCONDACTION implements ASMSource, Exportable, ContainerItem, S
@Override
public ActionList getActions() throws InterruptedException {
try {
int prevLength = actionBytes.pos;
SWFInputStream rri = new SWFInputStream(swf, actionBytes.array);
int prevLength = actionBytes.getPos();
SWFInputStream rri = new SWFInputStream(swf, actionBytes.getArray());
if (prevLength != 0) {
rri.seek(prevLength);
}
ActionList list = ActionListReader.readActionListTimeout(listeners, rri, swf.version, prevLength, prevLength + actionBytes.length, toString()/*FIXME?*/);
ActionList list = ActionListReader.readActionListTimeout(listeners, rri, swf.version, prevLength, prevLength + actionBytes.getLength(), toString()/*FIXME?*/);
return list;
} catch (InterruptedException ex) {

View File

@@ -93,18 +93,16 @@ public class CLIPACTIONRECORD implements ASMSource, Exportable, ContainerItem, S
private final SWF swf;
@Internal
private final Tag tag;
@Internal
private long pos;
//Constructor for Generic tag editor. TODO:Handle this somehow better
public CLIPACTIONRECORD() {
swf = null;
tag = null;
eventFlags = new CLIPEVENTFLAGS();
actionBytes = new ByteArrayRange(new byte[0]);
actionBytes = ByteArrayRange.EMPTY;
}
public CLIPACTIONRECORD(SWF swf, SWFInputStream sis, long pos, Tag tag) throws IOException {
public CLIPACTIONRECORD(SWF swf, SWFInputStream sis, Tag tag) throws IOException {
this.swf = swf;
this.tag = tag;
eventFlags = sis.readCLIPEVENTFLAGS("eventFlags");
@@ -119,7 +117,6 @@ public class CLIPACTIONRECORD implements ASMSource, Exportable, ContainerItem, S
int actionBytesPos = (int) sis.getPos();
byte[] bytes = sis.readBytesEx(actionRecordSize, "actionBytes");
actionBytes = new ByteArrayRange(swf.uncompressedData, actionBytesPos, bytes.length);
this.pos = pos;
}
@Override
@@ -197,12 +194,12 @@ public class CLIPACTIONRECORD implements ASMSource, Exportable, ContainerItem, S
@Override
public ActionList getActions() throws InterruptedException {
try {
int prevLength = actionBytes.pos;
SWFInputStream rri = new SWFInputStream(swf, actionBytes.array);
int prevLength = actionBytes.getPos();
SWFInputStream rri = new SWFInputStream(swf, actionBytes.getArray());
if (prevLength != 0) {
rri.seek(prevLength);
}
ActionList list = ActionListReader.readActionListTimeout(listeners, rri, swf.version, prevLength, prevLength + actionBytes.length, toString()/*FIXME?*/);
ActionList list = ActionListReader.readActionListTimeout(listeners, rri, swf.version, prevLength, prevLength + actionBytes.getLength(), toString()/*FIXME?*/);
return list;
} catch (InterruptedException ex) {
throw 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.helpers;
/**
@@ -21,13 +22,11 @@ package com.jpexs.helpers;
*/
public class ByteArrayRange {
public final byte[] array;
public final int pos;
public final int length;
public ByteArrayRange() {
this(new byte[0]);
public static final ByteArrayRange EMPTY = new ByteArrayRange(new byte[0]);
private final byte[] array;
private final int pos;
private final int length;
public ByteArrayRange(byte[] array) {
this.array = array;
@@ -41,6 +40,18 @@ public class ByteArrayRange {
this.length = length;
}
public byte[] getArray() {
return array;
}
public int getPos() {
return pos;
}
public int getLength() {
return length;
}
public byte[] getRangeData() {
byte[] data = new byte[length];
System.arraycopy(array, pos, data, 0, length);