swf input stream fixes, javadoc parameters

This commit is contained in:
honfika
2014-06-19 23:42:15 +02:00
parent 52e6142fe5
commit 3cbf152b61
74 changed files with 2398 additions and 2492 deletions
+5 -3
View File
@@ -381,7 +381,9 @@ public final class SWF implements TreeItem, Timelined {
sos.writeUI8(frameRate);
sos.writeUI16(frameCount);
sos.writeTags(tags);
Map<Tag, Long> tagPositions = new HashMap<>();
Map<Tag, Integer> tagLengths = new HashMap<>();
sos.writeTags(tags, tagPositions, tagLengths);
if (hasEndTag) {
sos.writeUI16(0);
}
@@ -507,7 +509,7 @@ public final class SWF implements TreeItem, Timelined {
compression = header.compression;
uncompressedData = baos.toByteArray();
SWFInputStream sis = new SWFInputStream(uncompressedData, version);
SWFInputStream sis = new SWFInputStream(this, uncompressedData);
sis.read(new byte[8], 0, 8); // skip the header
if (listener != null) {
sis.addPercentListener(listener);
@@ -703,7 +705,7 @@ public final class SWF implements TreeItem, Timelined {
}
int version = hdr[3];
SWFInputStream sis = new SWFInputStream(Arrays.copyOfRange(hdr, 4, 8), version, 4);
SWFInputStream sis = new SWFInputStream(null, Arrays.copyOfRange(hdr, 4, 8), 4);
long fileSize = sis.readUI32();
SWFHeader header = new SWFHeader();
header.version = version;
@@ -291,14 +291,10 @@ public class SWFInputStream implements AutoCloseable {
private SeekableInputStream is;
private long pos;
private int version;
private static final Logger logger = Logger.getLogger(SWFInputStream.class.getName());
private final List<ProgressListener> listeners = new ArrayList<>();
private long percentMax;
public int getVersion() {
return version;
}
public SWF swf;
public void addPercentListener(ProgressListener listener) {
listeners.add(listener);
@@ -318,12 +314,12 @@ public class SWFInputStream implements AutoCloseable {
/**
* Constructor
*
* @param swf SWF to read
* @param data SWF data
* @param version Version of SWF to read
* @param startingPos
*/
public SWFInputStream(byte[] data, int version, long startingPos) {
this.version = version;
public SWFInputStream(SWF swf, byte[] data, long startingPos) {
this.swf = swf;
this.is = new MemoryInputStream(data);
pos = startingPos;
}
@@ -331,34 +327,11 @@ public class SWFInputStream implements AutoCloseable {
/**
* Constructor
*
* @param swf SWF to read
* @param data SWF data
* @param version Version of SWF to read
*/
public SWFInputStream(byte[] data, int version) {
this(data, version, 0L);
}
/**
* Constructor
*
* @param is Existing inputstream
* @param version Version of SWF to read
* @param startingPos
*/
public SWFInputStream(SeekableInputStream is, int version, long startingPos) {
this.version = version;
this.is = is;
pos = startingPos;
}
/**
* Constructor
*
* @param is Existing inputstream
* @param version Version of SWF to read
*/
public SWFInputStream(SeekableInputStream is, int version) {
this(is, version, 0L);
public SWFInputStream(SWF swf, byte[] data) {
this(swf, data, 0L);
}
/**
@@ -888,7 +861,7 @@ public class SWFInputStream implements AutoCloseable {
tags.add(tag);
}
if (Configuration.dumpTags.get() && level == 0) {
dumpTag(System.out, version, tag, level);
dumpTag(System.out, swf.version, tag, level);
}
boolean doParse;
@@ -970,7 +943,7 @@ public class SWFInputStream implements AutoCloseable {
byte[] data = tag.getData();
long pos = tag.getPos();
int length = tag.getOriginalLength();
SWFLimitedInputStream sis = new SWFLimitedInputStream(swf, new SWFInputStream(data, swf.version), length);
SWFLimitedInputStream sis = new SWFLimitedInputStream(swf, new SWFInputStream(swf, data, tag.getDataPos()), length);
try {
switch (tag.getId()) {
@@ -1354,7 +1327,7 @@ public class SWFInputStream implements AutoCloseable {
case 0x81:
return new ActionGotoFrame(actionLength, this);
case 0x83:
return new ActionGetURL(actionLength, this, version);
return new ActionGetURL(actionLength, this, swf.version);
case 0x04:
return new ActionNextFrame();
case 0x05:
@@ -1370,12 +1343,12 @@ public class SWFInputStream implements AutoCloseable {
case 0x8A:
return new ActionWaitForFrame(actionLength, this, cpool);
case 0x8B:
return new ActionSetTarget(actionLength, this, version);
return new ActionSetTarget(actionLength, this, swf.version);
case 0x8C:
return new ActionGoToLabel(actionLength, this, version);
return new ActionGoToLabel(actionLength, this, swf.version);
//SWF4 Actions
case 0x96:
return new ActionPush(actionLength, this, version);
return new ActionPush(actionLength, this, swf.version);
case 0x17:
return new ActionPop();
case 0x0A:
@@ -1462,9 +1435,9 @@ public class SWFInputStream implements AutoCloseable {
case 0x52:
return new ActionCallMethod();
case 0x88:
return new ActionConstantPool(actionLength, this, version);
return new ActionConstantPool(actionLength, this, swf.version);
case 0x9B:
return new ActionDefineFunction(actionLength, this, version);
return new ActionDefineFunction(actionLength, this, swf.version);
case 0x3C:
return new ActionDefineLocal();
case 0x41:
@@ -1492,7 +1465,7 @@ public class SWFInputStream implements AutoCloseable {
case 0x45:
return new ActionTargetPath();
case 0x94:
return new ActionWith(actionLength, this, version);
return new ActionWith(actionLength, this, swf.version);
case 0x4A:
return new ActionToNumber();
case 0x4B:
@@ -1542,7 +1515,7 @@ public class SWFInputStream implements AutoCloseable {
return new ActionStringGreater();
//SWF7 Actions
case 0x8E:
return new ActionDefineFunction2(actionLength, this, version);
return new ActionDefineFunction2(actionLength, this, swf.version);
case 0x69:
return new ActionExtends();
case 0x2B:
@@ -1550,7 +1523,7 @@ public class SWFInputStream implements AutoCloseable {
case 0x2C:
return new ActionImplementsOp();
case 0x8F:
return new ActionTry(actionLength, this, version);
return new ActionTry(actionLength, this, swf.version);
case 0x2A:
return new ActionThrow();
default:
@@ -1677,7 +1650,7 @@ public class SWFInputStream implements AutoCloseable {
ret.clipEventPress = readUB(1) == 1;
ret.clipEventInitialize = readUB(1) == 1;
ret.clipEventData = readUB(1) == 1;
if (version >= 6) {
if (swf.version >= 6) {
ret.reserved = (int) readUB(5);
ret.clipEventConstruct = readUB(1) == 1;
ret.clipEventKeyPress = readUB(1) == 1;
@@ -48,10 +48,12 @@ import java.util.List;
public class SWFLimitedInputStream {
private SWFInputStream sis;
private long limit;
public SWF swf;
public SWFLimitedInputStream(SWF swf, SWFInputStream sis, long limit) {
public SWFLimitedInputStream(SWF swf, SWFInputStream sis, long limit) {
this.swf = swf;
this.limit = limit;
this.sis = sis;
}
@@ -79,6 +79,7 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
import java.util.Map;
import java.util.zip.Deflater;
import java.util.zip.DeflaterOutputStream;
@@ -414,11 +415,17 @@ public class SWFOutputStream extends OutputStream {
* Writes list of Tag values to the stream
*
* @param tags List of tag values
* @param tagPositions
* @param tagLengths
* @throws IOException
*/
public void writeTags(List<Tag> tags) throws IOException {
public void writeTags(List<Tag> tags, Map<Tag, Long> tagPositions, Map<Tag, Integer> tagLengths) throws IOException {
for (Tag tag : tags) {
long pos = getPos();
tag.writeTag(this);
int length = (int) (getPos() - pos);
tagPositions.put(tag, pos);
tagLengths.put(tag, length);
}
}
File diff suppressed because it is too large Load Diff
@@ -77,7 +77,7 @@ public class ActionPush extends Action {
super(0x96, actionLength);
int type;
values = new ArrayList<>();
sis = new SWFInputStream(sis.readBytesEx(actionLength), version);
sis = new SWFInputStream(sis.swf, sis.readBytesEx(actionLength));
try {
while (sis.available() > 0) {
type = sis.readUI8();
@@ -101,7 +101,7 @@ public class MovieExporter {
if ((videoStream.codecID == DefineVideoStreamTag.CODEC_VP6)
|| (videoStream.codecID == DefineVideoStreamTag.CODEC_VP6_ALPHA)) {
SWFInputStream sis = new SWFInputStream(tag.videoData, swf.version);
SWFInputStream sis = new SWFInputStream(swf, tag.videoData);
if (videoStream.codecID == DefineVideoStreamTag.CODEC_VP6_ALPHA) {
sis.readUI24(); //offsetToAlpha
}
@@ -135,7 +135,7 @@ public class MovieExporter {
sos.writeUB(4, verticalAdjustment);
}
if (videoStream.codecID == DefineVideoStreamTag.CODEC_SORENSON_H263) {
SWFInputStream sis = new SWFInputStream(tag.videoData, swf.version);
SWFInputStream sis = new SWFInputStream(swf, tag.videoData);
sis.readUB(17);//pictureStartCode
sis.readUB(5); //version
sis.readUB(8); //temporalReference
File diff suppressed because it is too large Load Diff
@@ -83,10 +83,8 @@ public class CSMTextSettingsTag extends Tag {
/**
* Constructor
*
* @param swf
* @param headerData
* @param sis
* @param length
* @param data Data bytes
* @param pos
* @throws IOException
*/
@@ -56,10 +56,8 @@ public class DebugIDTag extends Tag {
/**
* Constructor
*
* @param swf
* @param headerData
* @param sis
* @param length
* @param data Data bytes
* @param pos
* @throws IOException
*/
@@ -132,10 +132,8 @@ public class DefineBitsJPEG4Tag extends ImageTag implements AloneTag {
/**
* Constructor
*
* @param swf
* @param headerData
* @param sis
* @param length
* @param data Data bytes
* @param pos
* @throws IOException
*/
@@ -16,7 +16,6 @@
*/
package com.jpexs.decompiler.flash.tags;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.SWFInputStream;
import com.jpexs.decompiler.flash.SWFLimitedInputStream;
import com.jpexs.decompiler.flash.SWFOutputStream;
@@ -140,7 +139,7 @@ public class DefineBitsLossless2Tag extends ImageTag implements AloneTag {
private void uncompressData() {
try {
SWFInputStream sis = new SWFInputStream(Helper.readStream(new InflaterInputStream(new ByteArrayInputStream(zlibBitmapData))), SWF.DEFAULT_VERSION);
SWFInputStream sis = new SWFInputStream(swf, Helper.readStream(new InflaterInputStream(new ByteArrayInputStream(zlibBitmapData))));
if (bitmapFormat == FORMAT_8BIT_COLORMAPPED) {
colorMapData = sis.readALPHACOLORMAPDATA(bitmapColorTableSize, bitmapWidth, bitmapHeight);
}
@@ -16,7 +16,6 @@
*/
package com.jpexs.decompiler.flash.tags;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.SWFInputStream;
import com.jpexs.decompiler.flash.SWFLimitedInputStream;
import com.jpexs.decompiler.flash.SWFOutputStream;
@@ -171,7 +170,7 @@ public class DefineBitsLosslessTag extends ImageTag implements AloneTag {
private void uncompressData() {
try {
SWFInputStream sis = new SWFInputStream(Helper.readStream(new InflaterInputStream(new ByteArrayInputStream(zlibBitmapData))), SWF.DEFAULT_VERSION);
SWFInputStream sis = new SWFInputStream(swf, Helper.readStream(new InflaterInputStream(new ByteArrayInputStream(zlibBitmapData))));
if (bitmapFormat == FORMAT_8BIT_COLORMAPPED) {
colorMapData = sis.readCOLORMAPDATA(bitmapColorTableSize, bitmapWidth, bitmapHeight);
}
@@ -96,10 +96,8 @@ public class DefineButton2Tag extends ButtonTag implements Container {
/**
* Constructor
*
* @param swf
* @param headerData
* @param sis
* @param length
* @param data Data bytes
* @param pos
* @throws IOException
*/
@@ -58,10 +58,8 @@ public class DefineButtonCxformTag extends Tag {
/**
* Constructor
*
* @param swf
* @param headerData
* @param sis
* @param length
* @param data Data bytes
* @param pos
* @throws IOException
*/
@@ -98,10 +98,8 @@ public class DefineButtonSoundTag extends CharacterIdTag {
/**
* Constructor
*
* @param swf
* @param headerData
* @param sis
* @param length
* @param data Data bytes
* @param pos
* @throws IOException
*/
@@ -17,6 +17,7 @@
package com.jpexs.decompiler.flash.tags;
import com.jpexs.decompiler.flash.DisassemblyListener;
import com.jpexs.decompiler.flash.SWFInputStream;
import com.jpexs.decompiler.flash.SWFLimitedInputStream;
import com.jpexs.decompiler.flash.SWFOutputStream;
import com.jpexs.decompiler.flash.abc.CopyOutputStream;
@@ -41,7 +42,6 @@ import com.jpexs.decompiler.flash.types.annotations.Internal;
import com.jpexs.decompiler.flash.types.annotations.SWFType;
import com.jpexs.helpers.Cache;
import com.jpexs.helpers.Helper;
import com.jpexs.helpers.MemoryInputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -95,10 +95,8 @@ public class DefineButtonTag extends ButtonTag implements ASMSource {
/**
* Constructor
*
* @param swf
* @param headerData
* @param sis
* @param length
* @param data Data bytes
* @param pos
* @throws IOException
*/
@@ -106,7 +104,6 @@ public class DefineButtonTag extends ButtonTag implements ASMSource {
super(sis.swf, ID, "DefineButton", pos, length);
buttonId = sis.readUI16();
characters = sis.readBUTTONRECORDList(false);
//actions = sis.readActionList();
hdrSize = sis.getPos();
actionBytes = sis.readBytesEx(sis.available());
}
@@ -148,7 +145,7 @@ public class DefineButtonTag extends ButtonTag implements ASMSource {
if (actions == null) {
actions = getActions();
}
return Action.actionsToString(listeners, 0, actions, null, swf.version, exportMode, writer, getPos() + hdrSize, toString()/*FIXME?*/);
return Action.actionsToString(listeners, 0, actions, null, swf.version, exportMode, writer, getDataPos() + hdrSize, toString()/*FIXME?*/);
}
/**
@@ -170,11 +167,17 @@ public class DefineButtonTag extends ButtonTag implements ASMSource {
@Override
public List<Action> getActions() throws InterruptedException {
try {
int prevLength = (int) (getPos() + hdrSize);
MemoryInputStream rri = new MemoryInputStream(swf.uncompressedData);
rri.seek(prevLength);
List<Action> list = ActionListReader.readActionListTimeout(listeners, getPos() + hdrSize - prevLength, rri, getVersion(), prevLength, -1, toString()/*FIXME?*/);
int prevLength;
SWFInputStream rri;
if (actionBytes == null) {
prevLength = (int) (getDataPos() + hdrSize);
rri = new SWFInputStream(swf, swf.uncompressedData);
rri.seek(prevLength);
} else {
prevLength = 0;
rri = new SWFInputStream(swf, actionBytes);
}
List<Action> list = ActionListReader.readActionListTimeout(listeners, getDataPos() + hdrSize - prevLength, rri, getVersion(), prevLength, -1, toString()/*FIXME?*/);
return list;
} catch (InterruptedException ex) {
throw ex;
@@ -694,10 +694,8 @@ public class DefineEditTextTag extends TextTag {
/**
* Constructor
*
* @param swf
* @param headerData
* @param sis
* @param length
* @param data Data bytes
* @param pos
* @throws IOException
*/
@@ -191,10 +191,8 @@ public class DefineFont2Tag extends FontTag {
/**
* Constructor
*
* @param swf
* @param headerData
* @param sis
* @param length
* @param data Data bytes
* @param pos
* @throws IOException
*/
@@ -87,10 +87,8 @@ public class DefineFontInfo2Tag extends Tag {
/**
* Constructor
*
* @param swf
* @param headerData
* @param sis
* @param length
* @param data Data bytes
* @param pos
* @throws IOException
*/
@@ -88,10 +88,8 @@ public class DefineFontInfoTag extends Tag {
/**
* Constructor
*
* @param swf
* @param headerData
* @param sis
* @param length
* @param data Data bytes
* @param pos
* @throws IOException
*/
@@ -135,10 +135,8 @@ public class DefineFontTag extends FontTag {
/**
* Constructor
*
* @param swf
* @param headerData
* @param sis
* @param length
* @param data Data bytes
* @param pos
* @throws IOException
*/
@@ -147,10 +147,8 @@ public class DefineMorphShape2Tag extends CharacterTag implements MorphShapeTag
/**
* Constructor
*
* @param swf
* @param headerData
* @param sis
* @param length
* @param data Data bytes
* @param pos
* @throws IOException
*/
@@ -125,10 +125,8 @@ public class DefineMorphShapeTag extends CharacterTag implements MorphShapeTag {
/**
* Constructor
*
* @param swf
* @param headerData
* @param sis
* @param length
* @param data Data bytes
* @param pos
* @throws IOException
*/
@@ -77,10 +77,8 @@ public class DefineSceneAndFrameLabelDataTag extends Tag {
/**
* Constructor
*
* @param swf
* @param headerData
* @param sis
* @param length
* @param data Data bytes
* @param pos
* @throws IOException
*/
@@ -95,10 +95,8 @@ public class DefineSoundTag extends CharacterTag implements SoundTag {
/**
* Constructor
*
* @param swf
* @param headerData
* @param sis
* @param length
* @param data Data bytes
* @param pos
* @throws IOException
*/
@@ -237,7 +235,7 @@ public class DefineSoundTag extends CharacterTag implements SoundTag {
}
}
try {
MP3SOUNDDATA snd = new MP3SOUNDDATA(mp3data, swf.version, true);
MP3SOUNDDATA snd = new MP3SOUNDDATA(swf, mp3data, true);
if (!snd.frames.isEmpty()) {
MP3FRAME fr = snd.frames.get(0);
newSoundRate = fr.getSamplingRate();
@@ -50,6 +50,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
@@ -191,9 +192,8 @@ public class DefineSpriteTag extends CharacterTag implements Container, Drawable
/**
* Constructor
*
* @param swf
* @param headerData
* @param data Data bytes
* @param sis
* @param length
* @param level
* @param pos
* @param parallel
@@ -230,7 +230,9 @@ public class DefineSpriteTag extends CharacterTag implements Container, Drawable
try {
sos.writeUI16(spriteId);
sos.writeUI16(frameCount);
sos.writeTags(subTags);
Map<Tag, Long> tagPositions = new HashMap<>();
Map<Tag, Integer> tagLengths = new HashMap<>();
sos.writeTags(subTags, tagPositions, tagLengths);
if (hasEndTag) {
sos.writeUI16(0);
}
@@ -459,10 +459,8 @@ public class DefineText2Tag extends TextTag {
/**
* Constructor
*
* @param swf
* @param headerData
* @param sis
* @param length
* @param data Data bytes
* @param pos
* @throws IOException
*/
@@ -470,10 +470,8 @@ public class DefineTextTag extends TextTag {
/**
* Constructor
*
* @param swf
* @param headerData
* @param sis
* @param length
* @param data Data bytes
* @param pos
* @throws IOException
*/
@@ -98,10 +98,8 @@ public class DefineVideoStreamTag extends CharacterTag implements BoundedTag {
/**
* Constructor
*
* @param swf
* @param headerData
* @param sis
* @param length
* @param data Data bytes
* @param pos
* @throws IOException
*/
@@ -65,10 +65,8 @@ public class DoABCDefineTag extends Tag implements ABCContainerTag {
/**
* Constructor
*
* @param swf
* @param headerData
* @param sis
* @param length
* @param data Data bytes
* @param pos
* @throws IOException
*/
@@ -52,10 +52,8 @@ public class DoABCTag extends Tag implements ABCContainerTag {
/**
* Constructor
*
* @param swf
* @param headerData
* @param sis
* @param length
* @param data Data bytes
* @param pos
* @throws IOException
*/
@@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.tags;
import com.jpexs.decompiler.flash.DisassemblyListener;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.SWFInputStream;
import com.jpexs.decompiler.flash.SWFLimitedInputStream;
import com.jpexs.decompiler.flash.action.Action;
import com.jpexs.decompiler.flash.action.ActionListReader;
@@ -26,7 +27,6 @@ import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.flash.tags.base.ASMSource;
import com.jpexs.decompiler.flash.types.annotations.Internal;
import com.jpexs.helpers.Helper;
import com.jpexs.helpers.MemoryInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@@ -50,22 +50,22 @@ public class DoActionTag extends Tag implements ASMSource {
/**
* Constructor
*
* @param swf
* @param headerData
* @param data Data bytes
* @param sis
* @param length
* @param pos
* @throws java.io.IOException
*/
public DoActionTag(SWFLimitedInputStream sis, long pos, int length) throws IOException {
super(sis.swf, ID, "DoAction", pos, length);
actionBytes = sis.readBytesEx(sis.available());
//do not load actionBytes. Disassebler will use the original SWF stream in this case
//actionBytes = sis.readBytesEx(sis.available());
}
/**
* Constructor
*
* @param swf
* @param headerData
* @param data Data bytes
* @param length
* @param pos
*/
public DoActionTag(SWF swf, long pos, int length) {
@@ -96,7 +96,7 @@ public class DoActionTag extends Tag implements ASMSource {
if (actions == null) {
actions = getActions();
}
return Action.actionsToString(listeners, 0, actions, null, swf.version, exportMode, writer, getPos(), toString()/*FIXME?*/);
return Action.actionsToString(listeners, 0, actions, null, swf.version, exportMode, writer, getDataPos(), toString()/*FIXME?*/);
}
/**
@@ -122,10 +122,17 @@ public class DoActionTag extends Tag implements ASMSource {
@Override
public List<Action> getActions() throws InterruptedException {
try {
int prevLength = (int) getPos();
MemoryInputStream rri = new MemoryInputStream(swf.uncompressedData);
rri.seek(prevLength);
List<Action> list = ActionListReader.readActionListTimeout(listeners, getPos() - prevLength, rri, getVersion(), prevLength, -1, toString()/*FIXME?*/);
int prevLength;
SWFInputStream rri;
if (actionBytes == null) {
prevLength = (int) getDataPos();
rri = new SWFInputStream(swf, swf.uncompressedData);
rri.seek(prevLength);
} else {
prevLength = 0;
rri = new SWFInputStream(swf, actionBytes);
}
List<Action> list = ActionListReader.readActionListTimeout(listeners, getDataPos() - prevLength, rri, getVersion(), prevLength, -1, toString()/*FIXME?*/);
return list;
} catch (InterruptedException ex) {
throw ex;
@@ -17,6 +17,7 @@
package com.jpexs.decompiler.flash.tags;
import com.jpexs.decompiler.flash.DisassemblyListener;
import com.jpexs.decompiler.flash.SWFInputStream;
import com.jpexs.decompiler.flash.SWFLimitedInputStream;
import com.jpexs.decompiler.flash.SWFOutputStream;
import com.jpexs.decompiler.flash.action.Action;
@@ -29,7 +30,6 @@ import com.jpexs.decompiler.flash.types.BasicType;
import com.jpexs.decompiler.flash.types.annotations.Internal;
import com.jpexs.decompiler.flash.types.annotations.SWFType;
import com.jpexs.helpers.Helper;
import com.jpexs.helpers.MemoryInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
@@ -55,10 +55,8 @@ public class DoInitActionTag extends CharacterIdTag implements ASMSource {
/**
* Constructor
*
* @param swf
* @param headerData
* @param sis
* @param length
* @param data Data bytes
* @param pos
* @throws IOException
*/
@@ -111,16 +109,23 @@ public class DoInitActionTag extends CharacterIdTag implements ASMSource {
if (actions == null) {
actions = getActions();
}
return Action.actionsToString(listeners, 0, actions, null, swf.version, exportMode, writer, getPos() + 2, toString()/*FIXME?*/);
return Action.actionsToString(listeners, 0, actions, null, swf.version, exportMode, writer, getDataPos() + 2, toString()/*FIXME?*/);
}
@Override
public List<Action> getActions() throws InterruptedException {
try {
int prevLength = (int) (getPos() + 2);
MemoryInputStream rri = new MemoryInputStream(swf.uncompressedData);
rri.seek(prevLength);
List<Action> list = ActionListReader.readActionListTimeout(listeners, getPos() + 2 - prevLength, rri, getVersion(), prevLength, -1, toString()/*FIXME?*/);
int prevLength;
SWFInputStream rri;
if (actionBytes == null) {
prevLength = (int) (getDataPos() + 2);
rri = new SWFInputStream(swf, swf.uncompressedData);
rri.seek(prevLength);
} else {
prevLength = 0;
rri = new SWFInputStream(swf, actionBytes);
}
List<Action> list = ActionListReader.readActionListTimeout(listeners, getDataPos() + 2 - prevLength, rri, getVersion(), prevLength, -1, toString()/*FIXME?*/);
return list;
} catch (InterruptedException ex) {
throw ex;
@@ -63,10 +63,8 @@ public class EnableDebugger2Tag extends Tag {
/**
* Constructor
*
* @param swf
* @param headerData
* @param sis
* @param length
* @param data Data bytes
* @param pos
* @throws IOException
*/
@@ -57,10 +57,8 @@ public class EnableDebuggerTag extends Tag {
/**
* Constructor
*
* @param swf
* @param headerData
* @param sis
* @param length
* @param data Data bytes
* @param pos
* @throws IOException
*/
@@ -66,10 +66,8 @@ public class EnableTelemetryTag extends Tag {
/**
* Constructor
*
* @param swf
* @param headerData
* @param sis
* @param length
* @param data Data bytes
* @param pos
* @throws IOException
*/
@@ -41,9 +41,7 @@ public class EndTag extends Tag {
* Constructor
*
* @param swf
* @param headerData
* @param length
* @param data Data bytes
* @param pos
* @throws IOException
*/
@@ -55,9 +55,8 @@ public class ExportAssetsTag extends Tag {
/**
* Constructor
*
* @param swf
* @param headerData
* @param data Data bytes
* @param sis
* @param length
* @param pos
* @throws IOException
*/
@@ -58,10 +58,8 @@ public class ImportAssets2Tag extends Tag implements ImportTag {
/**
* Constructor
*
* @param swf
* @param headerData
* @param sis
* @param length
* @param data Data bytes
* @param pos
* @throws IOException
*/
@@ -51,10 +51,8 @@ public class ImportAssetsTag extends Tag implements ImportTag {
/**
* Constructor
*
* @param swf
* @param headerData
* @param sis
* @param length
* @param data Data bytes
* @param pos
* @throws IOException
*/
@@ -213,10 +213,8 @@ public class PlaceObject2Tag extends CharacterIdTag implements Container, PlaceO
/**
* Constructor
*
* @param swf
* @param headerData
* @param sis
* @param length
* @param data Data bytes
* @param pos
* @throws IOException
*/
@@ -297,10 +297,8 @@ public class PlaceObject3Tag extends CharacterIdTag implements Container, PlaceO
/**
* Constructor
*
* @param swf
* @param headerData
* @param sis
* @param length
* @param data Data bytes
* @param pos
* @throws IOException
*/
@@ -298,10 +298,8 @@ public class PlaceObject4Tag extends CharacterIdTag implements Container, PlaceO
/**
* Constructor
*
* @param swf
* @param headerData
* @param sis
* @param length
* @param data Data bytes
* @param pos
* @throws IOException
*/
@@ -99,10 +99,8 @@ public class PlaceObjectTag extends CharacterIdTag implements PlaceObjectTypeTag
/**
* Constructor
*
* @param swf
* @param headerData
* @param sis
* @param length
* @param data Data bytes
* @param pos
* @throws IOException
*/
@@ -57,10 +57,8 @@ public class ProtectTag extends Tag {
/**
* Constructor
*
* @param swf
* @param headerData
* @param sis
* @param length
* @param data Data bytes
* @param pos
* @throws IOException
*/
@@ -66,10 +66,8 @@ public class RemoveObjectTag extends CharacterIdTag implements RemoveTag {
/**
* Constructor
*
* @param swf
* @param headerData
* @param sis
* @param length
* @param data Data bytes
* @param pos
* @throws IOException
*/
@@ -64,10 +64,8 @@ public class SetTabIndexTag extends Tag {
/**
* Constructor
*
* @param swf
* @param headerData
* @param sis
* @param length
* @param data Data bytes
* @param pos
* @throws IOException
*/
@@ -51,10 +51,8 @@ public class ShowFrameTag extends Tag {
* Constructor
*
* @param swf
* @param headerData
* @param length
* @param pos
* @param data
*/
public ShowFrameTag(SWF swf, long pos, int length) {
super(swf, ID, "ShowFrame", pos, length);
@@ -35,10 +35,8 @@ public class SoundStreamBlockTag extends Tag {
/**
* Constructor
*
* @param swf
* @param headerData
* @param sis
* @param length
* @param data Data bytes
* @param pos
* @throws IOException
*/
@@ -136,10 +136,8 @@ public class SoundStreamHead2Tag extends CharacterIdTag implements SoundStreamHe
/**
* Constructor
*
* @param swf
* @param headerData
* @param sis
* @param length
* @param data Data bytes
* @param pos
* @throws IOException
*/
@@ -129,10 +129,8 @@ public class SoundStreamHeadTag extends CharacterIdTag implements SoundStreamHea
/**
* Constructor
*
* @param swf
* @param headerData
* @param sis
* @param length
* @param data Data bytes
* @param pos
* @throws IOException
*/
@@ -54,10 +54,8 @@ public class StartSound2Tag extends Tag {
/**
* Constructor
*
* @param swf
* @param headerData
* @param sis
* @param length
* @param data Data bytes
* @param pos
* @throws IOException
*/
@@ -58,10 +58,8 @@ public class StartSoundTag extends Tag {
/**
* Constructor
*
* @param swf
* @param headerData
* @param sis
* @param length
* @param data Data bytes
* @param pos
* @throws IOException
*/
+12 -10
View File
@@ -331,16 +331,13 @@ public class Tag implements NeedsCharacters, Exportable, ContainerItem, Serializ
* @throws IOException
*/
public void writeTag(SWFOutputStream sos) throws IOException {
int newLength;
if (isModified()) {
byte[] newData = getData();
byte[] newHeaderData = getHeader(newData);
sos.write(newHeaderData);
sos.write(newData);
newLength = newData.length + newHeaderData.length;
} else {
sos.write(swf.uncompressedData, (int) pos, length);
newLength = length;
}
//todo: honfika: update pos and length during save
@@ -365,6 +362,10 @@ public class Tag implements NeedsCharacters, Exportable, ContainerItem, Serializ
return getOriginalData();
}
public final int getOriginalLength() {
return length;
}
public final byte[] getOriginalData() {
// todo honfika: do not copy data
int dataLength = getOriginalDataLength();
@@ -373,16 +374,13 @@ public class Tag implements NeedsCharacters, Exportable, ContainerItem, Serializ
return data;
}
public final int getOriginalLength() {
return length;
public final int getOriginalDataLength() {
return length - (isLongOriginal() ? 6 : 2);
}
public final int getOriginalDataLength() {
public final boolean isLongOriginal() {
int shortLength = swf.uncompressedData[(int) pos] & 0x003F;
if (shortLength == 0x3f) {
return length - 6;
}
return length - 2;
return shortLength == 0x3f;
}
public boolean hasSubTags() {
@@ -397,6 +395,10 @@ public class Tag implements NeedsCharacters, Exportable, ContainerItem, Serializ
return pos;
}
public long getDataPos() {
return pos + (isLongOriginal() ? 6 : 2);
}
public void setModified(boolean value) {
modified = value;
}
@@ -42,8 +42,7 @@ public class TagStub extends Tag {
* Constructor
*
* @param swf
* @param headerData
* @param data Data bytes
* @param length
* @param pos
* @throws IOException
*/
@@ -60,9 +60,8 @@ public class VideoFrameTag extends Tag {
/**
* Constructor
*
* @param swf
* @param headerData
* @param data Data bytes
* @param sis
* @param length
* @param pos
* @throws IOException
*/
@@ -83,9 +83,8 @@ public final class DefineCompactedFont extends FontTag implements DrawableTag {
/**
* Constructor
*
* @param swf
* @param headerData
* @param data Data bytes
* @param sis
* @param length
* @param pos
* @throws IOException
*/
@@ -64,10 +64,8 @@ public class DefineExternalGradient extends Tag {
/**
* Constructor
*
* @param swf
* @param headerData
* @param sis
* @param length
* @param data Data bytes
* @param pos
* @throws IOException
*/
@@ -66,10 +66,8 @@ public class DefineExternalImage extends Tag {
/**
* Constructor
*
* @param swf
* @param headerData
* @param sis
* @param length
* @param data Data bytes
* @param pos
* @throws IOException
*/
@@ -74,10 +74,8 @@ public class DefineExternalImage2 extends Tag {
/**
* Constructor
*
* @param swf
* @param headerData
* @param sis
* @param length
* @param data Data bytes
* @param pos
* @throws IOException
*/
@@ -74,10 +74,8 @@ public class DefineExternalSound extends Tag {
/**
* Constructor
*
* @param swf
* @param headerData
* @param sis
* @param length
* @param data Data bytes
* @param pos
* @throws IOException
*/
@@ -72,10 +72,8 @@ public class DefineExternalStreamSound extends Tag {
/**
* Constructor
*
* @param swf
* @param headerData
* @param sis
* @param length
* @param data Data bytes
* @param pos
* @throws IOException
*/
@@ -56,10 +56,8 @@ public class DefineGradientMap extends Tag {
/**
* Constructor
*
* @param swf
* @param headerData
* @param sis
* @param length
* @param data Data bytes
* @param pos
* @throws IOException
*/
@@ -63,10 +63,8 @@ public class DefineSubImage extends Tag {
/**
* Constructor
*
* @param swf
* @param headerData
* @param sis
* @param length
* @param data Data bytes
* @param pos
* @throws IOException
*/
@@ -82,10 +82,8 @@ public class ExporterInfoTag extends Tag {
/**
* Constructor
*
* @param swf
* @param headerData
* @param sis
* @param length
* @param data Data bytes
* @param pos
* @throws IOException
*/
@@ -84,10 +84,8 @@ public class FontTextureInfo extends Tag {
/**
* Constructor
*
* @param swf
* @param headerData
* @param sis
* @param length
* @param data Data bytes
* @param pos
* @throws IOException
*/
@@ -31,7 +31,6 @@ import com.jpexs.decompiler.flash.types.annotations.Conditional;
import com.jpexs.decompiler.flash.types.annotations.Internal;
import com.jpexs.decompiler.flash.types.annotations.SWFType;
import com.jpexs.helpers.Helper;
import com.jpexs.helpers.MemoryInputStream;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
@@ -192,7 +191,7 @@ public class BUTTONCONDACTION implements ASMSource, Exportable, ContainerItem, S
@Override
public List<Action> getActions() throws InterruptedException {
try {
List<Action> list = ActionListReader.readActionListTimeout(listeners, getPos() + 4, new MemoryInputStream(actionBytes), swf.version, 0, -1, toString()/*FIXME?*/);
List<Action> list = ActionListReader.readActionListTimeout(listeners, getPos() + 4, new SWFInputStream(swf, actionBytes), swf.version, 0, -1, toString()/*FIXME?*/);
return list;
} catch (InterruptedException ex) {
@@ -30,7 +30,6 @@ import com.jpexs.decompiler.flash.tags.base.Exportable;
import com.jpexs.decompiler.flash.types.annotations.Conditional;
import com.jpexs.decompiler.flash.types.annotations.Internal;
import com.jpexs.helpers.Helper;
import com.jpexs.helpers.MemoryInputStream;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
@@ -201,7 +200,7 @@ public class CLIPACTIONRECORD implements ASMSource, Exportable, ContainerItem, S
@Override
public List<Action> getActions() throws InterruptedException {
try {
List<Action> list = ActionListReader.readActionListTimeout(listeners, getPos() + hdrPos, new MemoryInputStream(actionBytes), swf.version, 0, -1, toString()/*FIXME?*/);
List<Action> list = ActionListReader.readActionListTimeout(listeners, getPos() + hdrPos, new SWFInputStream(swf, actionBytes, 0), swf.version, 0, -1, toString()/*FIXME?*/);
return list;
} catch (InterruptedException ex) {
throw ex;
@@ -77,6 +77,9 @@ public class FILLSTYLE implements NeedsCharacters, Serializable {
|| (fillStyleType == NON_SMOOTHED_REPEATING_BITMAP)
|| (fillStyleType == NON_SMOOTHED_CLIPPED_BITMAP)) {
fillStyleType = SOLID;
if (color == null) {
color = inShape3 ? new RGBA(0, 0, 0, 0) : new RGB(0, 0, 0);
}
}
bitmapId = 0;
return true;
@@ -204,7 +204,7 @@ public class AdpcmDecoder extends SoundDecoder {
@Override
public void decode(byte[] data, OutputStream os) throws IOException {
int adpcm_code_size;
SWFInputStream sis = new SWFInputStream(data, SWF.DEFAULT_VERSION);
SWFInputStream sis = new SWFInputStream(null, data);
SWFOutputStream sos = new SWFOutputStream(os, SWF.DEFAULT_VERSION);
adpcm_code_size = (int) sis.readUB(2);
int bits_per_code = adpcm_code_size + 2;
@@ -16,6 +16,7 @@
*/
package com.jpexs.decompiler.flash.types.sound;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.SWFInputStream;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@@ -33,8 +34,8 @@ public class MP3SOUNDDATA {
public int seekSamples;
public List<MP3FRAME> frames;
public MP3SOUNDDATA(byte[] data, int version, boolean raw) throws IOException {
SWFInputStream sis = new SWFInputStream(data, version);
public MP3SOUNDDATA(SWF swf, byte[] data, boolean raw) throws IOException {
SWFInputStream sis = new SWFInputStream(swf, data);
if (!raw) {
seekSamples = sis.readSI16();
}
@@ -1437,7 +1437,7 @@ public class XFLConverter {
bits = 18;
}
if (soundFormat == SoundFormat.FORMAT_ADPCM) {
SWFInputStream sis = new SWFInputStream(soundData, swf.version);
SWFInputStream sis = new SWFInputStream(swf, soundData);
exportFormat = "wav";
try {
int adpcmCodeSize = (int) sis.readUB(2);
@@ -1453,7 +1453,7 @@ public class XFLConverter {
}
format += 4; //quality best
try {
MP3SOUNDDATA s = new MP3SOUNDDATA(soundData, swf.version, false);
MP3SOUNDDATA s = new MP3SOUNDDATA(swf, soundData, false);
//sis.readSI16();
//MP3FRAME frame = new MP3FRAME(sis);
MP3FRAME frame = s.frames.get(0);