mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-07-02 19:44:40 +00:00
Issue #449: process last partial (end of stream in the middle) tag
This commit is contained in:
@@ -192,7 +192,7 @@ public class SWFInputStream extends InputStream {
|
||||
bitPos = 0;
|
||||
try {
|
||||
return readNoBitReset();
|
||||
} catch (EndOfStreamException ex) {
|
||||
} catch (EOFException | EndOfStreamException ex) {
|
||||
Logger.getLogger(SWFInputStream.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
return -1;
|
||||
@@ -356,7 +356,7 @@ public class SWFInputStream extends InputStream {
|
||||
}
|
||||
|
||||
private long readLong() throws IOException {
|
||||
byte[] readBuffer = readBytes(8);
|
||||
byte[] readBuffer = readBytesEx(8);
|
||||
return (((long) readBuffer[3] << 56)
|
||||
+ ((long) (readBuffer[2] & 255) << 48)
|
||||
+ ((long) (readBuffer[1] & 255) << 40)
|
||||
@@ -419,7 +419,7 @@ public class SWFInputStream extends InputStream {
|
||||
* @return Array of read bytes
|
||||
* @throws IOException
|
||||
*/
|
||||
public byte[] readBytes(long count) throws IOException {
|
||||
public byte[] readBytesEx(long count) throws IOException {
|
||||
if (count <= 0) {
|
||||
return new byte[0];
|
||||
}
|
||||
@@ -430,8 +430,30 @@ public class SWFInputStream extends InputStream {
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads bytes from the stream
|
||||
*
|
||||
* @param count Number of bytes to read
|
||||
* @return Array of read bytes
|
||||
* @throws IOException
|
||||
*/
|
||||
public byte[] readBytes(long count) throws IOException {
|
||||
if (count <= 0) {
|
||||
return new byte[0];
|
||||
}
|
||||
byte[] ret = new byte[(int) count];
|
||||
try {
|
||||
for (int i = 0; i < count; i++) {
|
||||
ret[i] = (byte) readEx();
|
||||
}
|
||||
} catch (EOFException | EndOfStreamException ex) {
|
||||
Logger.getLogger(SWFInputStream.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public byte[] readBytesZlib(long count) throws IOException {
|
||||
byte[] data = readBytes(count);
|
||||
byte[] data = readBytesEx(count);
|
||||
InflaterInputStream dis = new InflaterInputStream(new ByteArrayInputStream(data));
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
byte[] buf = new byte[4096];
|
||||
@@ -2560,7 +2582,7 @@ public class SWFInputStream extends InputStream {
|
||||
x++;
|
||||
}
|
||||
}
|
||||
ret.colorMapPixelData = readBytes(dataLen);
|
||||
ret.colorMapPixelData = readBytesEx(dataLen);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -2649,7 +2671,7 @@ public class SWFInputStream extends InputStream {
|
||||
x++;
|
||||
}
|
||||
}
|
||||
ret.colorMapPixelData = readBytes(dataLen);
|
||||
ret.colorMapPixelData = readBytesEx(dataLen);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ public class ActionPush extends Action {
|
||||
super(0x96, actionLength);
|
||||
int type;
|
||||
values = new ArrayList<>();
|
||||
sis = new SWFInputStream(new ByteArrayInputStream(sis.readBytes(actionLength)), version);
|
||||
sis = new SWFInputStream(new ByteArrayInputStream(sis.readBytesEx(actionLength)), version);
|
||||
try {
|
||||
while (sis.available() > 0) {
|
||||
type = sis.readUI8();
|
||||
|
||||
@@ -63,6 +63,6 @@ public class DebugIDTag extends Tag {
|
||||
public DebugIDTag(SWF swf, byte[] data, int version, long pos) throws IOException {
|
||||
super(swf, ID, "DebugID", data, pos);
|
||||
SWFInputStream sis = new SWFInputStream(new ByteArrayInputStream(data), version);
|
||||
debugId = sis.readBytes(16);
|
||||
debugId = sis.readBytesEx(16);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ public class DefineBinaryDataTag extends CharacterTag {
|
||||
SWFInputStream sis = new SWFInputStream(new ByteArrayInputStream(data), version);
|
||||
tag = sis.readUI16();
|
||||
reserved = sis.readUI32();
|
||||
binaryData = sis.readBytes(sis.available());
|
||||
binaryData = sis.readBytesEx(sis.available());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -58,7 +58,7 @@ public class DefineBitsJPEG2Tag extends ImageTag implements AloneTag {
|
||||
super(swf, ID, "DefineBitsJPEG2", data, pos);
|
||||
SWFInputStream sis = new SWFInputStream(new ByteArrayInputStream(data), version);
|
||||
characterID = sis.readUI16();
|
||||
imageData = sis.readBytes(sis.available());
|
||||
imageData = sis.readBytesEx(sis.available());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -93,7 +93,7 @@ public class DefineBitsJPEG3Tag extends ImageTag implements AloneTag {
|
||||
SWFInputStream sis = new SWFInputStream(new ByteArrayInputStream(data), version);
|
||||
characterID = sis.readUI16();
|
||||
long alphaDataOffset = sis.readUI32();
|
||||
imageData = sis.readBytes(alphaDataOffset);
|
||||
imageData = sis.readBytesEx(alphaDataOffset);
|
||||
bitmapAlphaData = sis.readBytesZlib(sis.available());
|
||||
}
|
||||
|
||||
|
||||
@@ -131,7 +131,7 @@ public class DefineBitsJPEG4Tag extends ImageTag implements AloneTag {
|
||||
characterID = sis.readUI16();
|
||||
long alphaDataOffset = sis.readUI32();
|
||||
deblockParam = sis.readUI16();
|
||||
imageData = sis.readBytes(alphaDataOffset);
|
||||
bitmapAlphaData = sis.readBytes(sis.available());
|
||||
imageData = sis.readBytesEx(alphaDataOffset);
|
||||
bitmapAlphaData = sis.readBytesEx(sis.available());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ public class DefineBitsLossless2Tag extends ImageTag implements AloneTag {
|
||||
if (bitmapFormat == FORMAT_8BIT_COLORMAPPED) {
|
||||
bitmapColorTableSize = sis.readUI8();
|
||||
}
|
||||
zlibBitmapData = sis.readBytes(sis.available());
|
||||
zlibBitmapData = sis.readBytesEx(sis.available());
|
||||
}
|
||||
private ALPHACOLORMAPDATA colorMapData;
|
||||
private ALPHABITMAPDATA bitmapData;
|
||||
|
||||
@@ -165,7 +165,7 @@ public class DefineBitsLosslessTag extends ImageTag implements AloneTag {
|
||||
if (bitmapFormat == FORMAT_8BIT_COLORMAPPED) {
|
||||
bitmapColorTableSize = sis.readUI8();
|
||||
}
|
||||
zlibBitmapData = sis.readBytes(sis.available());
|
||||
zlibBitmapData = sis.readBytesEx(sis.available());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -49,7 +49,7 @@ public class DefineBitsTag extends ImageTag {
|
||||
super(swf, ID, "DefineBits", data, pos);
|
||||
SWFInputStream sis = new SWFInputStream(new ByteArrayInputStream(data), version);
|
||||
characterID = sis.readUI16();
|
||||
jpegData = sis.readBytes(sis.available());
|
||||
jpegData = sis.readBytesEx(sis.available());
|
||||
}
|
||||
|
||||
private void getJPEGTables(List<Tag> tags) {
|
||||
|
||||
@@ -137,7 +137,7 @@ public class DefineButton2Tag extends CharacterTag implements Container, Bounded
|
||||
SWFInputStream sis = new SWFInputStream(bais, version);
|
||||
int len = sis.readUI16();
|
||||
if (len != 0) {
|
||||
origbrdata = sis.readBytes(len - 2);
|
||||
origbrdata = sis.readBytesEx(len - 2);
|
||||
os2 = new CopyOutputStream(os2, new ByteArrayInputStream(origbrdata));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ public class DefineButtonTag extends CharacterTag implements ASMSource, BoundedT
|
||||
characters = sis.readBUTTONRECORDList(false);
|
||||
//actions = sis.readActionList();
|
||||
hdrSize = sis.getPos();
|
||||
actionBytes = sis.readBytes(sis.available());
|
||||
actionBytes = sis.readBytesEx(sis.available());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -190,7 +190,7 @@ public class DefineFont2Tag extends FontTag {
|
||||
fontFlagsBold = sis.readUB(1) == 1;
|
||||
languageCode = sis.readLANGCODE();
|
||||
int fontNameLen = sis.readUI8();
|
||||
fontName = new String(sis.readBytes(fontNameLen));
|
||||
fontName = new String(sis.readBytesEx(fontNameLen));
|
||||
numGlyphs = sis.readUI16();
|
||||
//offsetTable = new long[numGlyphs];
|
||||
for (int i = 0; i < numGlyphs; i++) { //offsetTable
|
||||
|
||||
@@ -105,7 +105,7 @@ public class DefineFont3Tag extends FontTag {
|
||||
fontFlagsBold = sis.readUB(1) == 1;
|
||||
languageCode = sis.readLANGCODE();
|
||||
int fontNameLen = sis.readUI8();
|
||||
fontName = new String(sis.readBytes(fontNameLen));
|
||||
fontName = new String(sis.readBytesEx(fontNameLen));
|
||||
numGlyphs = sis.readUI16();
|
||||
for (int i = 0; i < numGlyphs; i++) { //offsetTable
|
||||
if (fontFlagsWideOffsets) {
|
||||
|
||||
@@ -49,7 +49,7 @@ public class DefineFont4Tag extends CharacterTag {
|
||||
fontFlagsItalic = sis.readUB(1) == 1;
|
||||
fontFlagsBold = sis.readUB(1) == 1;
|
||||
fontName = sis.readString();
|
||||
fontData = sis.readBytes(sis.available());
|
||||
fontData = sis.readBytesEx(sis.available());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -91,7 +91,7 @@ public class DefineFontInfo2Tag extends Tag {
|
||||
SWFInputStream sis = new SWFInputStream(new ByteArrayInputStream(data), version);
|
||||
fontID = sis.readUI16();
|
||||
int fontNameLen = sis.readUI8();
|
||||
fontName = new String(sis.readBytes(fontNameLen));
|
||||
fontName = new String(sis.readBytesEx(fontNameLen));
|
||||
sis.readUB(2);//reserved
|
||||
fontFlagsSmallText = sis.readUB(1) == 1;
|
||||
fontFlagsShiftJIS = sis.readUB(1) == 1;
|
||||
|
||||
@@ -93,7 +93,7 @@ public class DefineFontInfoTag extends Tag {
|
||||
SWFInputStream sis = new SWFInputStream(new ByteArrayInputStream(data), version);
|
||||
fontId = sis.readUI16();
|
||||
int fontNameLen = sis.readUI8();
|
||||
fontName = new String(sis.readBytes(fontNameLen));
|
||||
fontName = new String(sis.readBytesEx(fontNameLen));
|
||||
sis.readUB(2); //reserved
|
||||
fontFlagsSmallText = sis.readUB(1) == 1;
|
||||
fontFlagsShiftJIS = sis.readUB(1) == 1;
|
||||
|
||||
@@ -94,7 +94,7 @@ public class DefineSoundTag extends CharacterTag {
|
||||
soundSize = (int) sis.readUB(1);
|
||||
soundType = (int) sis.readUB(1);
|
||||
soundSampleCount = sis.readUI32();
|
||||
soundData = sis.readBytes(sis.available());
|
||||
soundData = sis.readBytesEx(sis.available());
|
||||
}
|
||||
|
||||
public String getExportFormat() {
|
||||
|
||||
@@ -63,7 +63,7 @@ public class DoInitActionTag extends CharacterIdTag implements ASMSource {
|
||||
SWFInputStream sis = new SWFInputStream(new ByteArrayInputStream(data), version);
|
||||
spriteId = sis.readUI16();
|
||||
//actions = sis.readActionList();
|
||||
actionBytes = sis.readBytes(sis.available());
|
||||
actionBytes = sis.readBytesEx(sis.available());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -70,7 +70,7 @@ public class EnableTelemetryTag extends Tag {
|
||||
SWFInputStream sis = new SWFInputStream(new ByteArrayInputStream(data), version);
|
||||
reserved = (int) sis.readUB(16);
|
||||
if (sis.available() > 0) {
|
||||
passwordHash = sis.readBytes(32);
|
||||
passwordHash = sis.readBytesEx(32);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -350,7 +350,7 @@ public class PlaceObject4Tag extends CharacterIdTag implements Container, PlaceO
|
||||
if (placeFlagHasClipActions) {
|
||||
clipActions = sis.readCLIPACTIONS(swf);
|
||||
}
|
||||
amfData = sis.readBytes(sis.available());
|
||||
amfData = sis.readBytesEx(sis.available());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -68,6 +68,6 @@ public class VideoFrameTag extends Tag {
|
||||
SWFInputStream sis = new SWFInputStream(new ByteArrayInputStream(data), version);
|
||||
streamID = sis.readUI16();
|
||||
frameNum = sis.readUI16();
|
||||
videoData = sis.readBytes(sis.available()); //TODO: Parse video packets
|
||||
videoData = sis.readBytesEx(sis.available()); //TODO: Parse video packets
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,6 +80,6 @@ public class DefineExternalGradient extends Tag {
|
||||
bitmapsFormat = sis.readUI16();
|
||||
gradientSize = sis.readUI16();
|
||||
int fileNameLen = sis.readUI8();
|
||||
fileName = new String(sis.readBytes(fileNameLen));
|
||||
fileName = new String(sis.readBytesEx(fileNameLen));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ public class DefineExternalImage extends Tag {
|
||||
targetWidth = sis.readUI16();
|
||||
targetHeight = sis.readUI16();
|
||||
int fileNameLen = sis.readUI8();
|
||||
fileName = new String(sis.readBytes(fileNameLen));
|
||||
fileName = new String(sis.readBytesEx(fileNameLen));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,11 +91,11 @@ public class DefineExternalImage2 extends Tag {
|
||||
targetWidth = sis.readUI16();
|
||||
targetHeight = sis.readUI16();
|
||||
int exportNameLen = sis.readUI8();
|
||||
exportName = new String(sis.readBytes(exportNameLen));
|
||||
exportName = new String(sis.readBytesEx(exportNameLen));
|
||||
int fileNameLen = sis.readUI8();
|
||||
fileName = new String(sis.readBytes(fileNameLen));
|
||||
fileName = new String(sis.readBytesEx(fileNameLen));
|
||||
if (sis.available() > 0) { //there is usually one zero byte, bod knows why
|
||||
extraData = sis.readBytes(sis.available());
|
||||
extraData = sis.readBytesEx(sis.available());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,9 +94,9 @@ public class DefineExternalSound extends Tag {
|
||||
sampleCount = sis.readUI32();
|
||||
seekSample = sis.readUI32();
|
||||
int exportNameLen = sis.readUI8();
|
||||
exportName = new String(sis.readBytes(exportNameLen));
|
||||
exportName = new String(sis.readBytesEx(exportNameLen));
|
||||
int fileNameLen = sis.readUI8();
|
||||
fileName = new String(sis.readBytes(fileNameLen));
|
||||
fileName = new String(sis.readBytesEx(fileNameLen));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ public class DefineExternalStreamSound extends Tag {
|
||||
startFrame = sis.readUI32();
|
||||
lastFrame = sis.readUI32();
|
||||
int fileNameLen = sis.readUI8();
|
||||
fileName = new String(sis.readBytes(fileNameLen));
|
||||
fileName = new String(sis.readBytesEx(fileNameLen));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,9 +100,9 @@ public class ExporterInfoTag extends Tag {
|
||||
}
|
||||
bitmapFormat = sis.readUI16();
|
||||
int prefixLen = sis.readUI8();
|
||||
prefix = sis.readBytes(prefixLen);
|
||||
prefix = sis.readBytesEx(prefixLen);
|
||||
int swfNameLen = sis.readUI8();
|
||||
swfName = new String(sis.readBytes(swfNameLen));
|
||||
swfName = new String(sis.readBytesEx(swfNameLen));
|
||||
if (sis.available() > 0) // (version >= 0x401) //?
|
||||
{
|
||||
codeOffsets = new ArrayList<>();
|
||||
|
||||
@@ -99,7 +99,7 @@ public class FontTextureInfo extends Tag {
|
||||
textureID = sis.readUI32();
|
||||
textureFormat = sis.readUI16();
|
||||
int fileNameLen = sis.readUI8();
|
||||
fileName = new String(sis.readBytes(fileNameLen));
|
||||
fileName = new String(sis.readBytesEx(fileNameLen));
|
||||
textureWidth = sis.readUI16();
|
||||
textureHeight = sis.readUI16();
|
||||
padPixels = sis.readUI8();
|
||||
|
||||
@@ -73,9 +73,9 @@ public class BUTTONCONDACTION implements ASMSource, Exportable, ContainerItem {
|
||||
condKeyPress = (int) sis.readUB(7);
|
||||
condOverDownToIddle = sis.readUB(1) == 1;
|
||||
if (condActionSize <= 0) {
|
||||
actionBytes = sis.readBytes(sis.available());
|
||||
actionBytes = sis.readBytesEx(sis.available());
|
||||
} else {
|
||||
actionBytes = sis.readBytes(condActionSize - 4);
|
||||
actionBytes = sis.readBytesEx(condActionSize - 4);
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
||||
@@ -103,7 +103,7 @@ public class CLIPACTIONRECORD implements ASMSource, Exportable, ContainerItem {
|
||||
actionRecordSize--;
|
||||
}
|
||||
hdrPos = sis.getPos();
|
||||
actionBytes = sis.readBytes(actionRecordSize);
|
||||
actionBytes = sis.readBytesEx(actionRecordSize);
|
||||
this.pos = pos;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user