Streams refactoring.

Replace Iggy Swf stub
This commit is contained in:
Jindra Petřík
2016-11-27 11:34:27 +01:00
parent 7fcb962809
commit 4dfcef525f
22 changed files with 196 additions and 184 deletions

View File

@@ -1,7 +1,8 @@
package com.jpexs.decompiler.flash.iggy;
import com.jpexs.decompiler.flash.iggy.streams.StructureInterface;
import com.jpexs.decompiler.flash.iggy.streams.AbstractDataStream;
import com.jpexs.decompiler.flash.iggy.streams.ReadDataStreamInterface;
import com.jpexs.decompiler.flash.iggy.streams.WriteDataStreamInterface;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@@ -19,13 +20,13 @@ public class IggyCharAdvances implements StructureInterface {
return advances;
}
public IggyCharAdvances(AbstractDataStream stream, long charCount) throws IOException {
public IggyCharAdvances(ReadDataStreamInterface stream, long charCount) throws IOException {
this.charCount = charCount;
readFromDataStream(stream);
}
@Override
public void readFromDataStream(AbstractDataStream stream) throws IOException {
public void readFromDataStream(ReadDataStreamInterface stream) throws IOException {
advances = new ArrayList<>();
for (int i = 0; i < charCount; i++) {
advances.add(stream.readFloat());
@@ -33,7 +34,7 @@ public class IggyCharAdvances implements StructureInterface {
}
@Override
public void writeToDataStream(AbstractDataStream stream) throws IOException {
public void writeToDataStream(WriteDataStreamInterface stream) throws IOException {
for (int i = 0; i < advances.size(); i++) {
stream.writeFloat(advances.get(i));
}

View File

@@ -1,7 +1,8 @@
package com.jpexs.decompiler.flash.iggy;
import com.jpexs.decompiler.flash.iggy.streams.StructureInterface;
import com.jpexs.decompiler.flash.iggy.streams.AbstractDataStream;
import com.jpexs.decompiler.flash.iggy.streams.ReadDataStreamInterface;
import com.jpexs.decompiler.flash.iggy.streams.WriteDataStreamInterface;
import com.jpexs.decompiler.flash.iggy.annotations.IggyFieldType;
import java.io.IOException;
import java.util.ArrayList;
@@ -24,13 +25,13 @@ public class IggyCharIndices implements StructureInterface {
private long charCount;
public IggyCharIndices(AbstractDataStream stream, long charCount) throws IOException {
public IggyCharIndices(ReadDataStreamInterface stream, long charCount) throws IOException {
this.charCount = charCount;
readFromDataStream(stream);
}
@Override
public void readFromDataStream(AbstractDataStream stream) throws IOException {
public void readFromDataStream(ReadDataStreamInterface stream) throws IOException {
chars = new ArrayList<>();
for (int i = 0; i < charCount; i++) {
chars.add((char) stream.readUI16());
@@ -39,7 +40,7 @@ public class IggyCharIndices implements StructureInterface {
}
@Override
public void writeToDataStream(AbstractDataStream stream) throws IOException {
public void writeToDataStream(WriteDataStreamInterface stream) throws IOException {
for (int i = 0; i < chars.size(); i++) {
stream.writeUI16(chars.get(i));
}

View File

@@ -1,7 +1,8 @@
package com.jpexs.decompiler.flash.iggy;
import com.jpexs.decompiler.flash.iggy.streams.StructureInterface;
import com.jpexs.decompiler.flash.iggy.streams.AbstractDataStream;
import com.jpexs.decompiler.flash.iggy.streams.ReadDataStreamInterface;
import com.jpexs.decompiler.flash.iggy.streams.WriteDataStreamInterface;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@@ -34,13 +35,13 @@ public class IggyCharKerning implements StructureInterface {
return kerningOffsets;
}
public IggyCharKerning(AbstractDataStream stream, long kernCount) throws IOException {
public IggyCharKerning(ReadDataStreamInterface stream, long kernCount) throws IOException {
this.kernCount = kernCount;
readFromDataStream(stream);
}
@Override
public void readFromDataStream(AbstractDataStream stream) throws IOException {
public void readFromDataStream(ReadDataStreamInterface stream) throws IOException {
charsA = new ArrayList<>();
charsB = new ArrayList<>();
kerningOffsets = new ArrayList<>();
@@ -53,7 +54,7 @@ public class IggyCharKerning implements StructureInterface {
}
@Override
public void writeToDataStream(AbstractDataStream stream) throws IOException {
public void writeToDataStream(WriteDataStreamInterface stream) throws IOException {
for (int i = 0; i < kernCount; i++) {
stream.writeUI16(charsA.get(i));
stream.writeUI16(charsB.get(i));

View File

@@ -1,7 +1,8 @@
package com.jpexs.decompiler.flash.iggy;
import com.jpexs.decompiler.flash.iggy.streams.StructureInterface;
import com.jpexs.decompiler.flash.iggy.streams.AbstractDataStream;
import com.jpexs.decompiler.flash.iggy.streams.ReadDataStreamInterface;
import com.jpexs.decompiler.flash.iggy.streams.WriteDataStreamInterface;
import com.jpexs.decompiler.flash.iggy.annotations.IggyFieldType;
import java.io.IOException;
import java.util.logging.Logger;
@@ -31,7 +32,7 @@ public class IggyCharOffset implements StructureInterface {
@IggyFieldType(DataType.uint64_t)
long offset;
public IggyCharOffset(AbstractDataStream stream) throws IOException {
public IggyCharOffset(ReadDataStreamInterface stream) throws IOException {
readFromDataStream(stream);
}
@@ -47,7 +48,7 @@ public class IggyCharOffset implements StructureInterface {
}
@Override
public void readFromDataStream(AbstractDataStream stream) throws IOException {
public void readFromDataStream(ReadDataStreamInterface stream) throws IOException {
zero = stream.readUI64();
ischar1 = stream.readUI16();
ischar2 = stream.readUI16();
@@ -66,7 +67,7 @@ public class IggyCharOffset implements StructureInterface {
}
@Override
public void writeToDataStream(AbstractDataStream stream) throws IOException {
public void writeToDataStream(WriteDataStreamInterface stream) throws IOException {
stream.writeUI64(zero);
stream.writeUI16(ischar1);
stream.writeUI16(ischar2);

View File

@@ -3,11 +3,10 @@ package com.jpexs.decompiler.flash.iggy;
import com.jpexs.decompiler.flash.iggy.streams.StructureInterface;
import com.jpexs.decompiler.flash.iggy.streams.SeekMode;
import com.jpexs.decompiler.flash.iggy.streams.RandomAccessFileDataStream;
import com.jpexs.decompiler.flash.iggy.streams.AbstractDataStream;
import com.jpexs.decompiler.flash.iggy.streams.ByteArrayDataStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.EOFException;
import com.jpexs.decompiler.flash.iggy.streams.ReadDataStreamInterface;
import com.jpexs.decompiler.flash.iggy.streams.WriteDataStreamInterface;
import com.jpexs.decompiler.flash.iggy.streams.DataStreamInterface;
import com.jpexs.decompiler.flash.iggy.streams.TemporaryDataStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FilenameFilter;
@@ -37,7 +36,7 @@ public class IggyFile implements StructureInterface {
private List<byte[]> subFileEntriesData = new ArrayList<>();
private List<IggyFlashHeaderInterface> headers = new ArrayList<>();
private List<IggyDataReader> flashDataReaders = new ArrayList<>();
private List<IggySwf> flashDataReaders = new ArrayList<>();
public Set<Integer> getFontIds(int swfIndex) {
return flashDataReaders.get(swfIndex).fonts.keySet();
@@ -55,14 +54,12 @@ public class IggyFile implements StructureInterface {
return flashDataReaders.get(swfIndex).texts.keySet();
}
public IggyFile(File file) throws IOException {
try (AbstractDataStream stream = new RandomAccessFileDataStream(file)) {
readFromDataStream(stream);
}
public IggyFile(String filePath) throws IOException {
this(new File(filePath));
}
public IggyFile(RandomAccessFile rafile) throws IOException {
try (AbstractDataStream stream = new RandomAccessFileDataStream(rafile)) {
public IggyFile(File file) throws IOException {
try (ReadDataStreamInterface stream = new RandomAccessFileDataStream(file)) {
readFromDataStream(stream);
}
}
@@ -141,22 +138,15 @@ public class IggyFile implements StructureInterface {
}
public static void main(String[] args) throws IOException {
System.out.println("Iggy file splitter");
if (args.length == 0) {
System.err.println("No file specified");
System.exit(1);
}
for (String s : args) {
File f = new File(s);
if (!f.exists()) {
System.err.println("File " + f + " does not exists");
System.exit(1);
}
processFile(f);
String inFileName = "d:\\Dropbox\\jpexs-laptop\\iggi\\lib_loc_english_font.iggy";
String outFileName = "d:\\Dropbox\\jpexs-laptop\\iggi\\lib_loc_english_font2.iggy";
File inFile = new File(inFileName);
File outFile = new File(outFileName);
IggyFile iggyFile = new IggyFile(inFile);
try (RandomAccessFileDataStream outputStream = new RandomAccessFileDataStream(outFile)) {
iggyFile.writeToDataStream(outputStream);
}
System.exit(0);
}
private static void copyStream(InputStream is, OutputStream os) {
@@ -173,7 +163,7 @@ public class IggyFile implements StructureInterface {
}
private static boolean updateIndex(long item_offset /*uint32_t*/, boolean is_64, byte index_bytes[], long item_size_change /*int32_t*/) throws IOException {
ByteArrayDataStream stream = new ByteArrayDataStream(index_bytes);
TemporaryDataStream stream = new TemporaryDataStream(index_bytes);
/*
index_table:
@@ -389,7 +379,7 @@ public class IggyFile implements StructureInterface {
* @throws IOException
*/
private static Long itemLength(long item_offset /*uint32_t*/, boolean is_64, byte index_bytes[], Long newValue) throws IOException {
ByteArrayDataStream stream = new ByteArrayDataStream(index_bytes);
TemporaryDataStream stream = new TemporaryDataStream(index_bytes);
/*
index_table:
@@ -597,14 +587,47 @@ public class IggyFile implements StructureInterface {
return headers.get(swfIndex).getFrameRate();
}
//WIP
public boolean replaceSwf(int targetSwfIndex, IggySwf iggySwf) {
if (targetSwfIndex < 0 || targetSwfIndex >= getSwfCount()) {
throw new ArrayIndexOutOfBoundsException("No such SWF file index");
}
byte replacementData[];
try (DataStreamInterface stream = new TemporaryDataStream()) {
iggySwf.writeToDataStream(stream);
replacementData = stream.getAllBytes();
} catch (IOException ex) {
Logger.getLogger(IggyFile.class.getName()).log(Level.SEVERE, "Error during updating SWF", ex);
return false;
}
int swfIndex = 0;
long offsetsChange = 0;
for (int i = 0; i < subFileEntries.size(); i++) {
IggySubFileEntry entry = subFileEntries.get(i);
entry.offset += offsetsChange;
if (entry.type == IggySubFileEntry.TYPE_FLASH) {
if (swfIndex == targetSwfIndex) {
long oldSize = entry.size;
long newSize = replacementData.length;
offsetsChange = offsetsChange + (newSize - oldSize);
//entries after this one will have modified offsets
}
swfIndex++;
}
}
subFileEntriesData.set(targetSwfIndex, replacementData);
return true;
}
private void parseEntries() throws IOException {
List<List<Integer>> indexTables = new ArrayList<>(); //TODO: use this for something ??
List<List<Long>> offsetTables = new ArrayList<>();
List<AbstractDataStream> flashDataStreams = new ArrayList<>();
List<DataStreamInterface> flashDataStreams = new ArrayList<>();
for (int i = 0; i < subFileEntries.size(); i++) {
IggySubFileEntry entry = subFileEntries.get(i);
AbstractDataStream dataStream = new ByteArrayDataStream(getEntryData(i));
DataStreamInterface dataStream = new TemporaryDataStream(getEntryData(i));
if (entry.type == IggySubFileEntry.TYPE_INDEX) {
List<Integer> indexTable = new ArrayList<>();
List<Long> offsets = new ArrayList<>();
@@ -626,13 +649,13 @@ public class IggyFile implements StructureInterface {
for (int swfIndex = 0; swfIndex < headers.size(); swfIndex++) {
IggyFlashHeaderInterface hdr = headers.get(swfIndex);
IggyDataReader dataReader = new IggyDataReader((IggyFlashHeader64) hdr, flashDataStreams.get(swfIndex), offsetTables.get(swfIndex));
IggySwf dataReader = new IggySwf((IggyFlashHeader64) hdr, flashDataStreams.get(swfIndex), offsetTables.get(swfIndex));
flashDataReaders.add(dataReader);
}
}
@Override
public void readFromDataStream(AbstractDataStream stream) throws IOException {
public void readFromDataStream(ReadDataStreamInterface stream) throws IOException {
header = new IggyHeader(stream);
for (int i = 0; i < header.getNumSubfiles(); i++) {
subFileEntries.add(new IggySubFileEntry(stream));
@@ -646,11 +669,18 @@ public class IggyFile implements StructureInterface {
}
@Override
public void writeToDataStream(AbstractDataStream stream) throws IOException {
public void writeToDataStream(WriteDataStreamInterface stream) throws IOException {
header.writeToDataStream(stream);
for (IggySubFileEntry entry : subFileEntries) {
entry.writeToDataStream(stream);
}
for (int i = 0; i < subFileEntries.size(); i++) {
IggySubFileEntry entry = subFileEntries.get(i);
byte[] entryData = subFileEntriesData.get(i);
stream.seek(entry.offset, SeekMode.SET);
stream.writeBytes(entryData);
}
}
}

View File

@@ -1,6 +1,7 @@
package com.jpexs.decompiler.flash.iggy;
import com.jpexs.decompiler.flash.iggy.streams.AbstractDataStream;
import com.jpexs.decompiler.flash.iggy.streams.ReadDataStreamInterface;
import com.jpexs.decompiler.flash.iggy.streams.WriteDataStreamInterface;
import com.jpexs.decompiler.flash.iggy.annotations.IggyFieldType;
import java.io.IOException;
@@ -84,12 +85,12 @@ public class IggyFlashHeader32 implements IggyFlashHeaderInterface {
// for the object.
// A DefineEditText-like object can be easily spotted and apparently uses type code 0x06 (or 0xFF06) but as stated above,
// it is written in a different way.
public IggyFlashHeader32(AbstractDataStream stream) throws IOException {
public IggyFlashHeader32(ReadDataStreamInterface stream) throws IOException {
readFromDataStream(stream);
}
@Override
public void readFromDataStream(AbstractDataStream stream) throws IOException {
public void readFromDataStream(ReadDataStreamInterface stream) throws IOException {
main_offset = stream.readUI32();
as3_section_offset = stream.readUI32();
unk_offset = stream.readUI32();
@@ -125,7 +126,7 @@ public class IggyFlashHeader32 implements IggyFlashHeaderInterface {
}
@Override
public void writeToDataStream(AbstractDataStream stream) throws IOException {
public void writeToDataStream(WriteDataStreamInterface stream) throws IOException {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

View File

@@ -1,6 +1,7 @@
package com.jpexs.decompiler.flash.iggy;
import com.jpexs.decompiler.flash.iggy.streams.AbstractDataStream;
import com.jpexs.decompiler.flash.iggy.streams.ReadDataStreamInterface;
import com.jpexs.decompiler.flash.iggy.streams.WriteDataStreamInterface;
import com.jpexs.decompiler.flash.iggy.annotations.IggyFieldType;
import java.io.IOException;
@@ -81,12 +82,12 @@ public class IggyFlashHeader64 implements IggyFlashHeaderInterface {
// for the object.
// A DefineEditText-like object can be easily spotted and apparently uses type code 0x06 (or 0xFF06) but as stated above,
// it is written in a different way.
public IggyFlashHeader64(AbstractDataStream stream) throws IOException {
public IggyFlashHeader64(ReadDataStreamInterface stream) throws IOException {
readFromDataStream(stream);
}
@Override
public void readFromDataStream(AbstractDataStream stream) throws IOException {
public void readFromDataStream(ReadDataStreamInterface stream) throws IOException {
main_offset = stream.readUI64();
as3_section_offset = stream.readUI64();
unk_offset = stream.readUI64();
@@ -122,7 +123,7 @@ public class IggyFlashHeader64 implements IggyFlashHeaderInterface {
}
@Override
public void writeToDataStream(AbstractDataStream stream) throws IOException {
public void writeToDataStream(WriteDataStreamInterface stream) throws IOException {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

View File

@@ -1,8 +1,9 @@
package com.jpexs.decompiler.flash.iggy;
import com.jpexs.decompiler.flash.iggy.streams.SeekMode;
import com.jpexs.decompiler.flash.iggy.streams.AbstractDataStream;
import com.jpexs.decompiler.flash.iggy.streams.ByteArrayDataStream;
import com.jpexs.decompiler.flash.iggy.streams.ReadDataStreamInterface;
import com.jpexs.decompiler.flash.iggy.streams.WriteDataStreamInterface;
import com.jpexs.decompiler.flash.iggy.streams.TemporaryDataStream;
import com.jpexs.decompiler.flash.iggy.annotations.IggyArrayFieldType;
import com.jpexs.decompiler.flash.iggy.annotations.IggyFieldType;
import java.io.IOException;
@@ -147,11 +148,11 @@ public class IggyFont extends IggyTag {
this.padTo4byteBoundary = padTo4byteBoundary;
}
public IggyFont(AbstractDataStream stream) throws IOException {
public IggyFont(ReadDataStreamInterface stream) throws IOException {
readFromDataStream(stream);
}
private long readAbsoluteOffset(AbstractDataStream stream) throws IOException {
private long readAbsoluteOffset(ReadDataStreamInterface stream) throws IOException {
long offset = stream.readUI64();
if (offset == 1) {
return 0;
@@ -159,7 +160,7 @@ public class IggyFont extends IggyTag {
return stream.position() - 8 + offset;
}
private void writeAbsoluteOffset(AbstractDataStream stream, long offset) throws IOException {
private void writeAbsoluteOffset(WriteDataStreamInterface stream, long offset) throws IOException {
if (offset == 0) {
stream.writeUI64(1);
} else {
@@ -167,7 +168,7 @@ public class IggyFont extends IggyTag {
}
}
private void writeRelativeOffset(AbstractDataStream stream, long offset) throws IOException {
private void writeRelativeOffset(WriteDataStreamInterface stream, long offset) throws IOException {
if (offset == 0) {
stream.writeUI64(1);
} else {
@@ -176,8 +177,8 @@ public class IggyFont extends IggyTag {
}
@Override
public void readFromDataStream(AbstractDataStream stream) throws IOException {
ByteArrayDataStream s = new ByteArrayDataStream(stream.readBytes((int) (long) stream.available()));
public void readFromDataStream(ReadDataStreamInterface stream) throws IOException {
TemporaryDataStream s = new TemporaryDataStream(stream.readBytes((int) (long) stream.available()));
type = s.readUI16();
fontId = s.readUI16();
zeroone = s.readBytes(28);
@@ -260,7 +261,7 @@ public class IggyFont extends IggyTag {
}
@Override
public void writeToDataStream(AbstractDataStream s) throws IOException {
public void writeToDataStream(WriteDataStreamInterface s) throws IOException {
s.writeUI16(type);
s.writeUI16(fontId);
s.writeBytes(zeroone);

View File

@@ -1,7 +1,8 @@
package com.jpexs.decompiler.flash.iggy;
import com.jpexs.decompiler.flash.iggy.streams.StructureInterface;
import com.jpexs.decompiler.flash.iggy.streams.AbstractDataStream;
import com.jpexs.decompiler.flash.iggy.streams.ReadDataStreamInterface;
import com.jpexs.decompiler.flash.iggy.streams.WriteDataStreamInterface;
import com.jpexs.decompiler.flash.iggy.annotations.IggyArrayFieldType;
import com.jpexs.decompiler.flash.iggy.annotations.IggyFieldType;
import java.io.IOException;
@@ -52,7 +53,7 @@ public class IggyHeader implements StructureInterface {
@IggyFieldType(value = DataType.uint32_t)
private long numSubfiles;
public IggyHeader(AbstractDataStream stream) throws IOException {
public IggyHeader(ReadDataStreamInterface stream) throws IOException {
readFromDataStream(stream);
}
@@ -92,7 +93,7 @@ public class IggyHeader implements StructureInterface {
}
@Override
public void readFromDataStream(AbstractDataStream stream) throws IOException {
public void readFromDataStream(ReadDataStreamInterface stream) throws IOException {
magic = stream.readUI32();
if (magic != IggyHeader.MAGIC) {
throw new IOException("Invalid Iggy file");
@@ -108,7 +109,7 @@ public class IggyHeader implements StructureInterface {
}
@Override
public void writeToDataStream(AbstractDataStream s) throws IOException {
public void writeToDataStream(WriteDataStreamInterface s) throws IOException {
s.writeUI32(magic);
s.writeUI32(version);
s.writeUI8(platform1);

View File

@@ -2,6 +2,7 @@ package com.jpexs.decompiler.flash.iggy;
import com.jpexs.decompiler.flash.iggy.streams.SeekMode;
import com.jpexs.decompiler.flash.iggy.streams.AbstractDataStream;
import com.jpexs.decompiler.flash.iggy.streams.ReadDataStreamInterface;
import java.io.IOException;
import java.util.List;
import java.util.logging.Logger;
@@ -30,7 +31,7 @@ public class IggyIndexParser {
* @param offsets Output list of offsets
* @throws IOException on error
*/
public static void parseIndex(boolean is64, AbstractDataStream indexStream, List<Integer> indexTableEntry, List<Long> offsets) throws IOException {
public static void parseIndex(boolean is64, ReadDataStreamInterface indexStream, List<Integer> indexTableEntry, List<Long> offsets) throws IOException {
int indexTableSize = indexStream.readUI8();
int[] indexTable = new int[indexTableSize];
for (int i = 0; i < indexTableSize; i++) {

View File

@@ -4,6 +4,8 @@ import com.jpexs.decompiler.flash.iggy.streams.StructureInterface;
import com.jpexs.decompiler.flash.iggy.streams.SeekMode;
import com.jpexs.decompiler.flash.iggy.streams.AbstractDataStream;
import com.jpexs.decompiler.flash.iggy.annotations.IggyFieldType;
import com.jpexs.decompiler.flash.iggy.streams.ReadDataStreamInterface;
import com.jpexs.decompiler.flash.iggy.streams.WriteDataStreamInterface;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@@ -81,7 +83,7 @@ public class IggyShape implements StructureInterface {
}
@Override
public void readFromDataStream(AbstractDataStream s) throws IOException {
public void readFromDataStream(ReadDataStreamInterface s) throws IOException {
s.seek(offset, SeekMode.SET);
minx = s.readFloat();
miny = s.readFloat();
@@ -107,7 +109,7 @@ public class IggyShape implements StructureInterface {
}
@Override
public void writeToDataStream(AbstractDataStream s) throws IOException {
public void writeToDataStream(WriteDataStreamInterface s) throws IOException {
s.writeFloat(minx);
s.writeFloat(miny);
s.writeFloat(maxx);

View File

@@ -3,6 +3,8 @@ package com.jpexs.decompiler.flash.iggy;
import com.jpexs.decompiler.flash.iggy.streams.StructureInterface;
import com.jpexs.decompiler.flash.iggy.streams.AbstractDataStream;
import com.jpexs.decompiler.flash.iggy.annotations.IggyFieldType;
import com.jpexs.decompiler.flash.iggy.streams.ReadDataStreamInterface;
import com.jpexs.decompiler.flash.iggy.streams.WriteDataStreamInterface;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -52,13 +54,13 @@ public class IggyShapeNode implements StructureInterface {
this.isstart = isstart;
}
public IggyShapeNode(AbstractDataStream s, boolean first) throws IOException {
public IggyShapeNode(ReadDataStreamInterface s, boolean first) throws IOException {
this.first = first;
readFromDataStream(s);
}
@Override
public void readFromDataStream(AbstractDataStream s) throws IOException {
public void readFromDataStream(ReadDataStreamInterface s) throws IOException {
targetX = s.readFloat();
targetY = s.readFloat();
controlX = s.readFloat();
@@ -81,7 +83,7 @@ public class IggyShapeNode implements StructureInterface {
}
@Override
public void writeToDataStream(AbstractDataStream s) throws IOException {
public void writeToDataStream(WriteDataStreamInterface s) throws IOException {
s.writeFloat(targetX);
s.writeFloat(targetY);
s.writeFloat(controlX);

View File

@@ -1,7 +1,8 @@
package com.jpexs.decompiler.flash.iggy;
import com.jpexs.decompiler.flash.iggy.streams.StructureInterface;
import com.jpexs.decompiler.flash.iggy.streams.AbstractDataStream;
import com.jpexs.decompiler.flash.iggy.streams.ReadDataStreamInterface;
import com.jpexs.decompiler.flash.iggy.streams.WriteDataStreamInterface;
import com.jpexs.decompiler.flash.types.BasicType;
import com.jpexs.decompiler.flash.types.annotations.SWFType;
import java.io.IOException;
@@ -33,7 +34,7 @@ public class IggySubFileEntry implements StructureInterface {
@SWFType(BasicType.UI32)
long offset;
public IggySubFileEntry(AbstractDataStream stream) throws IOException {
public IggySubFileEntry(ReadDataStreamInterface stream) throws IOException {
readFromDataStream(stream);
}
@@ -57,7 +58,7 @@ public class IggySubFileEntry implements StructureInterface {
}
@Override
public void readFromDataStream(AbstractDataStream stream) throws IOException {
public void readFromDataStream(ReadDataStreamInterface stream) throws IOException {
type = stream.readUI32();
size = stream.readUI32();
size2 = stream.readUI32();
@@ -65,7 +66,7 @@ public class IggySubFileEntry implements StructureInterface {
}
@Override
public void writeToDataStream(AbstractDataStream stream) throws IOException {
public void writeToDataStream(WriteDataStreamInterface stream) throws IOException {
stream.writeUI32(type);
stream.writeUI32(size);
stream.writeUI32(size2);

View File

@@ -2,8 +2,10 @@ package com.jpexs.decompiler.flash.iggy;
import com.jpexs.decompiler.flash.iggy.streams.StructureInterface;
import com.jpexs.decompiler.flash.iggy.streams.SeekMode;
import com.jpexs.decompiler.flash.iggy.streams.AbstractDataStream;
import com.jpexs.decompiler.flash.iggy.streams.ReadDataStreamInterface;
import com.jpexs.decompiler.flash.iggy.streams.WriteDataStreamInterface;
import com.jpexs.decompiler.flash.iggy.annotations.IggyFieldType;
import com.jpexs.decompiler.flash.iggy.streams.DataStreamInterface;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
@@ -13,7 +15,7 @@ import java.util.Map;
*
* @author JPEXS
*/
public class IggyDataReader implements StructureInterface {
public class IggySwf implements StructureInterface {
final static int NO_OFFSET = 1;
@@ -28,7 +30,7 @@ public class IggyDataReader implements StructureInterface {
private Map<Long, Long> sizesOfOffsets;
private List<Long> allOffsets;
public IggyDataReader(IggyFlashHeader64 header, AbstractDataStream stream, List<Long> offsets) throws IOException {
public IggySwf(IggyFlashHeader64 header, ReadDataStreamInterface stream, List<Long> offsets) throws IOException {
this.header = header;
sizesOfOffsets = new HashMap<>();
for (int i = 0; i < offsets.size() - 1; i++) {
@@ -40,7 +42,7 @@ public class IggyDataReader implements StructureInterface {
}
@Override
public void readFromDataStream(AbstractDataStream stream) throws IOException {
public void readFromDataStream(ReadDataStreamInterface stream) throws IOException {
//here is offset[0]
StringBuilder nameBuilder = new StringBuilder();
do {
@@ -77,8 +79,8 @@ public class IggyDataReader implements StructureInterface {
}
@Override
public void writeToDataStream(AbstractDataStream stream) throws IOException {
throw new UnsupportedOperationException("Not supported yet.");
public void writeToDataStream(WriteDataStreamInterface stream) throws IOException {
throw new UnsupportedOperationException("Not supported yet."); //TODO!!!
}
@Override

View File

@@ -1,9 +1,10 @@
package com.jpexs.decompiler.flash.iggy;
import com.jpexs.decompiler.flash.iggy.streams.StructureInterface;
import com.jpexs.decompiler.flash.iggy.streams.AbstractDataStream;
import com.jpexs.decompiler.flash.iggy.annotations.IggyArrayFieldType;
import com.jpexs.decompiler.flash.iggy.annotations.IggyFieldType;
import com.jpexs.decompiler.flash.iggy.streams.ReadDataStreamInterface;
import com.jpexs.decompiler.flash.iggy.streams.WriteDataStreamInterface;
import java.io.IOException;
/**
@@ -76,12 +77,12 @@ public class IggyText implements StructureInterface {
this.initialText = name;
}
public IggyText(AbstractDataStream stream) throws IOException {
public IggyText(ReadDataStreamInterface stream) throws IOException {
this.readFromDataStream(stream);
}
@Override
public void readFromDataStream(AbstractDataStream s) throws IOException {
public void readFromDataStream(ReadDataStreamInterface s) throws IOException {
type = s.readUI16();
//characterId - iggy Id
@@ -137,7 +138,7 @@ public class IggyText implements StructureInterface {
}
@Override
public void writeToDataStream(AbstractDataStream stream) throws IOException {
public void writeToDataStream(WriteDataStreamInterface stream) throws IOException {
throw new UnsupportedOperationException("Not supported yet.");
}

View File

@@ -1,6 +1,7 @@
package com.jpexs.decompiler.flash.iggy;
import com.jpexs.decompiler.flash.iggy.streams.AbstractDataStream;
import com.jpexs.decompiler.flash.iggy.streams.ReadDataStreamInterface;
import com.jpexs.decompiler.flash.iggy.streams.WriteDataStreamInterface;
import java.io.IOException;
/**
@@ -13,7 +14,7 @@ public class RawIggyTag extends IggyTag {
int tagType;
private int length;
public RawIggyTag(int tagType, AbstractDataStream stream, int length) throws IOException {
public RawIggyTag(int tagType, ReadDataStreamInterface stream, int length) throws IOException {
this.length = length;
this.tagType = tagType;
readFromDataStream(stream);
@@ -25,12 +26,12 @@ public class RawIggyTag extends IggyTag {
}
@Override
public void readFromDataStream(AbstractDataStream stream) throws IOException {
public void readFromDataStream(ReadDataStreamInterface stream) throws IOException {
rawData = stream.readBytes(length);
}
@Override
public void writeToDataStream(AbstractDataStream stream) throws IOException {
public void writeToDataStream(WriteDataStreamInterface stream) throws IOException {
stream.writeBytes(rawData);
}

View File

@@ -111,6 +111,14 @@ public abstract class AbstractDataStream implements DataStreamInterface {
return ret;
}
public byte[] getAllBytes() throws IOException {
long oldPos = position();
seek(0, SeekMode.SET);
byte[] ret = readBytes((int) (long) available());
seek(oldPos, SeekMode.SET);
return ret;
}
@Override
public void writeBytes(byte[] data) throws IOException {
for (int i = 0; i < data.length; i++) {

View File

@@ -1,83 +0,0 @@
package com.jpexs.decompiler.flash.iggy.streams;
import java.io.EOFException;
import java.io.IOException;
import java.util.Arrays;
/**
*
* @author JPEXS
*/
public class ByteArrayDataStream extends AbstractDataStream {
private byte[] data;
private long pos;
public ByteArrayDataStream(int initialSize) {
this(new byte[initialSize]);
}
@Override
public long position() {
return pos;
}
public ByteArrayDataStream(byte data[]) {
this.data = data;
pos = 0;
}
@Override
public int read() throws IOException {
if (pos >= data.length) {
throw new EOFException("End of stream reached");
}
int ret = data[(int) pos] & 0xff;
pos++;
return ret;
}
public void resize(int newsize) {
data = Arrays.copyOf(data, newsize);
if (pos > data.length) {
pos = data.length;
}
}
@Override
public void write(int val) throws IOException {
if (pos >= data.length) {
throw new EOFException("End of stream reached");
}
data[(int) pos] = (byte) val;
pos++;
}
@Override
public void seek(long pos, SeekMode mode) throws IOException {
long newpos = pos;
if (mode == SeekMode.CUR) {
newpos = this.pos + pos;
} else if (mode == SeekMode.END) {
newpos = data.length - pos;
}
if (newpos > data.length) {
throw new ArrayIndexOutOfBoundsException("Position outside bounds accessed: " + pos + ". Size: " + data.length);
} else if (newpos < 0) {
throw new ArrayIndexOutOfBoundsException("Negative position accessed: " + pos);
} else {
this.pos = (int) newpos;
}
}
@Override
public Long available() {
return (long) (data.length - pos);
}
@Override
public void close() {
//nothing
}
}

View File

@@ -12,15 +12,16 @@ import java.io.RandomAccessFile;
*/
public class RandomAccessFileDataStream extends AbstractDataStream {
private File file;
private RandomAccessFile raf;
private boolean is64;
public RandomAccessFileDataStream(File file) throws FileNotFoundException {
this(new RandomAccessFile(file, "rw"));
protected File getFile() {
return file;
}
public RandomAccessFileDataStream(RandomAccessFile rafile) {
this.raf = rafile;
public RandomAccessFileDataStream(File file) throws FileNotFoundException {
this.file = file;
raf = new RandomAccessFile(file, "rw");
}
@Override
@@ -76,4 +77,9 @@ public class RandomAccessFileDataStream extends AbstractDataStream {
}
}
@Override
public void write(int val) throws IOException {
raf.write(val);
}
}

View File

@@ -33,6 +33,8 @@ public interface ReadDataStreamInterface extends AutoCloseable {
public void seek(long pos, SeekMode mode) throws IOException;
public byte[] getAllBytes() throws IOException;
@Override
public void close();
}

View File

@@ -10,7 +10,7 @@ import java.util.List;
*/
public interface StructureInterface {
public void readFromDataStream(AbstractDataStream stream) throws IOException;
public void readFromDataStream(ReadDataStreamInterface stream) throws IOException;
public void writeToDataStream(AbstractDataStream stream) throws IOException;
public void writeToDataStream(WriteDataStreamInterface stream) throws IOException;
}

View File

@@ -0,0 +1,31 @@
package com.jpexs.decompiler.flash.iggy.streams;
import java.io.File;
import java.io.IOException;
/**
*
* @author JPEXS
*/
public class TemporaryDataStream extends RandomAccessFileDataStream {
public TemporaryDataStream() throws IOException {
this(new byte[0]);
}
public TemporaryDataStream(byte[] data) throws IOException {
super(File.createTempFile("tempdatastream", ".bin"));
this.getFile().deleteOnExit();
writeBytes(data);
seek(0, SeekMode.SET);
}
@Override
public void close() {
try {
this.getFile().delete();
} catch (Exception ex) {
//ignore
}
}
}