Iggy converter stub (not working yet)

This commit is contained in:
Jindra Petřík
2016-11-23 19:24:25 +01:00
parent 589227fc80
commit 810ddca7e8
4 changed files with 73 additions and 56 deletions

View File

@@ -62,16 +62,19 @@ public class IggyFile extends AbstractDataStream implements AutoCloseable {
} else {
hdr = new IggyFlashHeader32(dataStream);
}
//System.out.println("hdr=" + hdr);
IggyNameAndTagList nameTagList = new IggyNameAndTagList(dataStream);
//System.out.println("nameTagList=" + nameTagList);
headers.add(hdr);
namesAndTagLists.add(new IggyNameAndTagList(dataStream));
namesAndTagLists.add(nameTagList);
flashStreams.add(dataStream);
}
}
for (int i = 0; i < flashStreams.size(); i++) {
ByteArrayDataStream flashStream = flashStreams.get(i);
List<Long> offsets = offsetTables.get(i);
List<Integer> tagIds = namesAndTagLists.get(i).getTagIds();
List<Long> tagExtended = namesAndTagLists.get(i).getTagIdsExtraInfo();
List<Long> tagIds = namesAndTagLists.get(i).getTagIds();
List<Long> tagExtraInfo = namesAndTagLists.get(i).getTagIdsExtraInfo();
int offsetIndex = 3; //0 = SWF name, 1 = UI16 zero, 2 = tag list
List<ByteArrayDataStream> tagDataStreams = new ArrayList<>();
@@ -80,6 +83,7 @@ public class IggyFile extends AbstractDataStream implements AutoCloseable {
long startOffset = offsets.get(offsetIndex);
long endOffset = offsets.get(offsetIndex + 1);
long dataLength = endOffset - startOffset;
long extraInfo = tagExtraInfo.get(t); //TODO: What's this for?
flashStream.seek(startOffset, SeekMode.SET);
long remLength = dataLength;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -90,6 +94,7 @@ public class IggyFile extends AbstractDataStream implements AutoCloseable {
remLength -= readCount;
} while (remLength > 0);
byte tagBytes[] = baos.toByteArray(); //TODO: optimize speed - without ByteArrayOutputStream
ByteArrayDataStream tagDataStream = new ByteArrayDataStream(tagBytes, is64());
tagDataStreams.add(tagDataStream);
offsetIndex++;
@@ -691,11 +696,11 @@ public class IggyFile extends AbstractDataStream implements AutoCloseable {
return namesAndTagLists.get(swfIndex).getName();
}
public List<Integer> getSwfTagIds(int swfIndex) {
public List<Long> getSwfTagIds(int swfIndex) {
return namesAndTagLists.get(swfIndex).getTagIds();
}
public Integer getSwfTagId(int swfIndex, int tagIndex) {
public Long getSwfTagId(int swfIndex, int tagIndex) {
return namesAndTagLists.get(swfIndex).getTagIds().get(tagIndex);
}

View File

@@ -78,10 +78,6 @@ public class IggyFlashHeader64 implements IggyFlashHeaderInterface {
@IggyFieldType(DataType.uint32_t)
long unk_B4;
/*@IggyArrayFieldType(value = DataType.uint32_t, count = 20)
long unk_offsets_a[] = new long[20];
@IggyArrayFieldType(value = DataType.uint32_t, count = 20)
long unk_offsets_b[] = new long[20];*/
// Offset 0xB8 (outside header): there are *unk_40* relative offsets that point to flash objects.
// The flash objects are in a format different to swf but there is probably a way to convert between them.
// After the offsets, the bodies of objects pointed above, which apparently have a code like 0xFFXX to identify the type of object, followed by a (unique?) identifier
@@ -92,13 +88,6 @@ public class IggyFlashHeader64 implements IggyFlashHeaderInterface {
readFromDataStream(stream);
}
private int ofs = 0;
private List<Long> offsets;
private String currentOffset() {
return String.format(" [offset: %d]", offsets.get(ofs++));
}
/*
offsets:
name (UI16 chars, zero terminated)
@@ -110,7 +99,6 @@ public class IggyFlashHeader64 implements IggyFlashHeaderInterface {
*/
@Override
public void readFromDataStream(AbstractDataStream stream) throws IOException {
this.offsets = offsets;
main_offset = stream.readUI64();
as3_section_offset = stream.readUI64();
unk_offset = stream.readUI64();
@@ -153,18 +141,36 @@ public class IggyFlashHeader64 implements IggyFlashHeaderInterface {
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("[\r\n");
sb.append("main_offset ").append(main_offset).append(currentOffset()).append("\r\n");
sb.append("as3_section_offset ").append(as3_section_offset).append(currentOffset()).append("\r\n");
sb.append("unk_offset ").append(unk_offset).append(currentOffset()).append("\r\n");
sb.append("unk_offset2 ").append(unk_offset2).append(currentOffset()).append("\r\n");
sb.append("unk_offset3 ").append(unk_offset3).append(currentOffset()).append("\r\n");
sb.append("unk_offset4 ").append(unk_offset4).append(currentOffset()).append("\r\n");
sb.append("xmin ").append(xmin).append(currentOffset()).append("\r\n");
sb.append("ymin ").append(ymin).append(currentOffset()).append("\r\n");
sb.append("xmax ").append(ymax).append(currentOffset()).append("\r\n");
sb.append("ymax ").append(ymax).append(currentOffset()).append("\r\n");
sb.append("unk_40 ").append(unk_40).append(currentOffset()).append("\r\n");
sb.append("unk_44 ").append(unk_44).append(currentOffset()).append("\r\n");
sb.append("main_offset ").append(main_offset).append("\r\n");
sb.append("as3_section_offset ").append(as3_section_offset);
sb.append(" global: ").append(main_offset + as3_section_offset);
sb.append("\r\n");
sb.append("unk_offset ").append(unk_offset);
if (unk_offset != 1) {
sb.append(" global: ").append(main_offset + unk_offset);
}
sb.append("\r\n");
sb.append("unk_offset2 ").append(unk_offset2);
if (unk_offset2 != 1) {
sb.append(" global: ").append(main_offset + unk_offset2);
}
sb.append("\r\n");
sb.append("unk_offset3 ").append(unk_offset3);
if (unk_offset3 != 1) {
sb.append(" global: ").append(main_offset + unk_offset3);
}
sb.append("\r\n");
sb.append("unk_offset4 ").append(unk_offset4);
if (unk_offset4 != 1) {
sb.append(" global: ").append(main_offset + unk_offset4);
}
sb.append("\r\n");
sb.append("xmin ").append(xmin).append("\r\n");
sb.append("ymin ").append(ymin).append("\r\n");
sb.append("xmax ").append(ymax).append("\r\n");
sb.append("ymax ").append(ymax).append("\r\n");
sb.append("unk_40 ").append(unk_40).append("\r\n");
sb.append("unk_44 ").append(unk_44).append("\r\n");
sb.append("unk_48 ").append(unk_48).append("\r\n");
sb.append("unk_4C ").append(unk_4C).append("\r\n");
sb.append("unk_50 ").append(unk_50).append("\r\n");

View File

@@ -16,12 +16,12 @@ public class IggyNameAndTagList implements StructureInterface {
private String name;
@IggyArrayFieldType(value = DataType.ubits, count = 10)
private List<Integer> tagIds;
private List<Long> tagIds;
@IggyArrayFieldType(value = DataType.uint16_t)
private List<Long> tagIdsExtraInfo;
public IggyNameAndTagList(String name, List<Integer> tagIds, List<Long> tagIdsExtendedInfo) {
public IggyNameAndTagList(String name, List<Long> tagIds, List<Long> tagIdsExtendedInfo) {
this.name = name;
this.tagIds = tagIds;
this.tagIdsExtraInfo = tagIdsExtendedInfo;
@@ -46,12 +46,11 @@ public class IggyNameAndTagList implements StructureInterface {
tagIds = new ArrayList<>();
tagIdsExtraInfo = new ArrayList<>();
while (true) {
long typeLen = stream.readUI32();
if (typeLen == 0) {
long tagType = stream.readUI32() & 0xffffffffL;
if (tagType == 0) {
break;
}
long tagLength = stream.readUI32();
int tagType = (int) ((typeLen >>> 6) + 10) & 0x3FF;
tagIds.add(tagType);
tagIdsExtraInfo.add(tagLength);
}
@@ -61,7 +60,7 @@ public class IggyNameAndTagList implements StructureInterface {
return name;
}
public List<Integer> getTagIds() {
public List<Long> getTagIds() {
return tagIds;
}
@@ -74,4 +73,17 @@ public class IggyNameAndTagList implements StructureInterface {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("[\r\n");
sb.append("name ").append(name).append("\r\n");
sb.append("tags:").append("\r\n");
for (int i = 0; i < tagIds.size(); i++) {
sb.append("tag ").append(String.format("%08X", tagIds.get(i))).append(" extra ").append(tagIdsExtraInfo.get(i)).append("\r\n");
}
sb.append("]");
return sb.toString();
}
}

View File

@@ -4,12 +4,15 @@ import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.SWFCompression;
import com.jpexs.decompiler.flash.SWFInputStream;
import com.jpexs.decompiler.flash.SWFOutputStream;
import com.jpexs.decompiler.flash.iggy.AbstractDataStream;
import com.jpexs.decompiler.flash.iggy.IggyFile;
import com.jpexs.decompiler.flash.iggy.IggyFlashHeaderInterface;
import com.jpexs.decompiler.flash.iggy.SeekMode;
import com.jpexs.decompiler.flash.tags.Tag;
import com.jpexs.decompiler.flash.tags.UnknownTag;
import com.jpexs.decompiler.flash.types.RECT;
import com.jpexs.helpers.ByteArrayRange;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -17,13 +20,13 @@ import java.io.OutputStream;
/**
*
* TODO: TEST!!!
* Unfinished WIP!
*
* @author JPEXS
*/
public class IggyToSwfConvertor {
public SWF[] getAllSwfs(IggyFile file) {
public static SWF[] getAllSwfs(IggyFile file) {
SWF[] ret = new SWF[file.getSwfCount()];
for (int i = 0; i < ret.length; i++) {
ret[i] = getSwf(file, i);
@@ -31,33 +34,34 @@ public class IggyToSwfConvertor {
return ret;
}
public void exportAllSwfsToDir(IggyFile file, File outputDir) throws IOException {
public static void exportAllSwfsToDir(IggyFile file, File outputDir) throws IOException {
for (int swfIndex = 0; swfIndex < file.getSwfCount(); swfIndex++) {
exportSwfToDir(file, swfIndex, outputDir);
}
}
public void exportSwfToDir(IggyFile file, int swfIndex, File outputDir) throws IOException {
public static void exportSwfToDir(IggyFile file, int swfIndex, File outputDir) throws IOException {
try (FileOutputStream fos = new FileOutputStream(new File(outputDir, file.getSwfName(swfIndex)))) {
exportSwf(file, swfIndex, fos);
}
}
public void exportSwfToFile(IggyFile file, int swfIndex, File outputFile) throws IOException {
public static void exportSwfToFile(IggyFile file, int swfIndex, File outputFile) throws IOException {
try (FileOutputStream fos = new FileOutputStream(outputFile)) {
exportSwf(file, swfIndex, fos);
}
}
public void exportSwf(IggyFile file, int swfIndex, OutputStream output) throws IOException {
public static void exportSwf(IggyFile file, int swfIndex, OutputStream output) throws IOException {
SWF swf = getSwf(file, swfIndex);
swf.saveTo(output);
}
public SWF getSwf(IggyFile file, int swfIndex) {
public static SWF getSwf(IggyFile file, int swfIndex) {
SWF swf = new SWF();
swf.compression = SWFCompression.NONE;
swf.frameCount = 1; //FIXME!!
swf.frameCount = 1; //FIXME!!
swf.frameRate = file.getSwfFrameRate(swfIndex);
swf.gfx = false;
swf.displayRect = new RECT(
(int) (file.getSwfXMin(swfIndex) * SWF.unitDivisor),
@@ -65,18 +69,8 @@ public class IggyToSwfConvertor {
(int) (file.getSwfYMin(swfIndex) * SWF.unitDivisor),
(int) (file.getSwfYMax(swfIndex) * SWF.unitDivisor));
swf.version = 9; //FIXME
for (int tagIndex = 0; tagIndex < file.getSwfTagCount(swfIndex); tagIndex++) {
byte[] data = file.getSwfTagData(swfIndex, tagIndex);
int dataLength = data.length;
int tagLength = dataLength;
int tagID = file.getSwfTagId(swfIndex, tagIndex);
long tagExtra = file.getSwfTagExtraInfo(swfIndex, tagIndex);
try {
swf.addTag(new UnknownTag(new SWFInputStream(swf, data), tagID, new ByteArrayRange(data)));
} catch (IOException ex) {
//ignored
}
}
return swf;
//TODO: Convert tags
throw new UnsupportedOperationException("Not implemented yet");
}
}