diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyCharAdvances.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyCharAdvances.java index 6b4b4d73a..537e6be3b 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyCharAdvances.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyCharAdvances.java @@ -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)); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyCharIndices.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyCharIndices.java index 265539592..f4cfd4e3c 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyCharIndices.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyCharIndices.java @@ -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)); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyCharKerning.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyCharKerning.java index 67da2c29b..d1987d2b1 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyCharKerning.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyCharKerning.java @@ -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)); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyCharOffset.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyCharOffset.java index 46a27b722..3f2ab4ffd 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyCharOffset.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyCharOffset.java @@ -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); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyFile.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyFile.java index 5245301bc..eef892111 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyFile.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyFile.java @@ -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 subFileEntriesData = new ArrayList<>(); private List headers = new ArrayList<>(); - private List flashDataReaders = new ArrayList<>(); + private List flashDataReaders = new ArrayList<>(); public Set 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> indexTables = new ArrayList<>(); //TODO: use this for something ?? List> offsetTables = new ArrayList<>(); - List flashDataStreams = new ArrayList<>(); + List 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 indexTable = new ArrayList<>(); List 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); + } } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyFlashHeader32.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyFlashHeader32.java index 5cd77f11f..0c913fd0d 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyFlashHeader32.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyFlashHeader32.java @@ -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. } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyFlashHeader64.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyFlashHeader64.java index d9f4467f7..1cc8c1156 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyFlashHeader64.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyFlashHeader64.java @@ -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. } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyFont.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyFont.java index 86b61b103..e939b9c23 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyFont.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyFont.java @@ -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); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyHeader.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyHeader.java index 057ad0bd6..f6dff51f6 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyHeader.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyHeader.java @@ -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); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyIndexParser.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyIndexParser.java index 9e80df53f..7757d0772 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyIndexParser.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyIndexParser.java @@ -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 indexTableEntry, List offsets) throws IOException { + public static void parseIndex(boolean is64, ReadDataStreamInterface indexStream, List indexTableEntry, List offsets) throws IOException { int indexTableSize = indexStream.readUI8(); int[] indexTable = new int[indexTableSize]; for (int i = 0; i < indexTableSize; i++) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyShape.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyShape.java index c5f61ba2f..e7abed276 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyShape.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyShape.java @@ -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); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyShapeNode.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyShapeNode.java index eaae35f84..9507acd9e 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyShapeNode.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyShapeNode.java @@ -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); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggySubFileEntry.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggySubFileEntry.java index a4f7d4823..c87b3598b 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggySubFileEntry.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggySubFileEntry.java @@ -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); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyDataReader.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggySwf.java similarity index 78% rename from libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyDataReader.java rename to libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggySwf.java index 6d3b4e28b..ee54f21db 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyDataReader.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggySwf.java @@ -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 sizesOfOffsets; private List allOffsets; - public IggyDataReader(IggyFlashHeader64 header, AbstractDataStream stream, List offsets) throws IOException { + public IggySwf(IggyFlashHeader64 header, ReadDataStreamInterface stream, List 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 diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyText.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyText.java index b95f369b0..746919b1d 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyText.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyText.java @@ -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."); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/RawIggyTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/RawIggyTag.java index 132d57e4c..81b57474b 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/RawIggyTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/RawIggyTag.java @@ -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); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/streams/AbstractDataStream.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/streams/AbstractDataStream.java index bd075cfb5..b11de5655 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/streams/AbstractDataStream.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/streams/AbstractDataStream.java @@ -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++) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/streams/ByteArrayDataStream.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/streams/ByteArrayDataStream.java deleted file mode 100644 index af7dcc0c5..000000000 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/streams/ByteArrayDataStream.java +++ /dev/null @@ -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 - } - -} diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/streams/RandomAccessFileDataStream.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/streams/RandomAccessFileDataStream.java index d46efbe6f..b341fc015 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/streams/RandomAccessFileDataStream.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/streams/RandomAccessFileDataStream.java @@ -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); + } + } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/streams/ReadDataStreamInterface.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/streams/ReadDataStreamInterface.java index 0682218d8..b9049c124 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/streams/ReadDataStreamInterface.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/streams/ReadDataStreamInterface.java @@ -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(); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/streams/StructureInterface.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/streams/StructureInterface.java index f16952a86..526445ddd 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/streams/StructureInterface.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/streams/StructureInterface.java @@ -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; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/streams/TemporaryDataStream.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/streams/TemporaryDataStream.java new file mode 100644 index 000000000..adb99afdd --- /dev/null +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/streams/TemporaryDataStream.java @@ -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 + } + } +}