Decl strings, sequence, fonttypeinfo.

Read/Write IggySWF is complete. TODO: Apply in GUI. Make index.
This commit is contained in:
Jindra Petřík
2016-12-01 22:05:39 +01:00
parent 94d12bfe4c
commit c498ebfaf4
9 changed files with 251 additions and 10 deletions

View File

@@ -5,5 +5,5 @@ package com.jpexs.decompiler.flash.iggy;
*/
public enum DataType {
ubits, uint8_t, uint16_t, uint32_t, uint64_t, float_t, unknown, int64_t,
widechar_t //or maybe just "string"? It has two bytes per character and is null terminated
wchar_t //or maybe just "string"? It has two bytes per character and is null terminated
}

View File

@@ -14,7 +14,7 @@ import java.util.List;
*/
public class IggyCharIndices implements StructureInterface {
@IggyFieldType(value = DataType.widechar_t)
@IggyFieldType(value = DataType.wchar_t)
List<Character> chars;
@IggyFieldType(DataType.uint32_t)
long padd;

View File

@@ -0,0 +1,63 @@
package com.jpexs.decompiler.flash.iggy;
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.StructureInterface;
import com.jpexs.decompiler.flash.iggy.streams.WriteDataStreamInterface;
import java.io.IOException;
/**
*
* @author JPEXS
*/
public class IggyDeclStrings implements StructureInterface {
@IggyFieldType(DataType.uint64_t)
long one;
@IggyFieldType(DataType.uint32_t)
long size;
@IggyArrayFieldType(value = DataType.uint8_t, count = 3)
byte xxx[];
@IggyArrayFieldType(value = DataType.uint8_t, countField = "size")
byte data[];
byte padd[];
@IggyFieldType(DataType.uint64_t)
long one2;
@IggyFieldType(DataType.uint64_t)
long zero;
public IggyDeclStrings(ReadDataStreamInterface stream) throws IOException {
readFromDataStream(stream);
}
@Override
public void readFromDataStream(ReadDataStreamInterface s) throws IOException {
one = s.readUI64();
size = s.readUI32();
xxx = s.readBytes(3);
data = s.readBytes((int) size);
if ((15 + size) % 8 != 0) {
padd = s.readBytes((int) (((15 + size) / 8 + 1) * 8 - 15 - size));
} else {
padd = new byte[0];
}
one = s.readUI64();
if (one != 1) {
throw new IOException("Wrong iggy font format (declend)!");
}
zero = s.readUI64();
}
@Override
public void writeToDataStream(WriteDataStreamInterface s) throws IOException {
s.writeUI64(one);
s.writeUI32(size);
s.writeBytes(xxx);
s.writeBytes(data);
s.writeBytes(padd);
s.writeUI64(one);
s.writeUI64(zero);
}
}

View File

@@ -73,7 +73,7 @@ public class IggyFont extends IggyTag {
long zero_padd_4;
@IggyFieldType(DataType.uint64_t)
long what_3;
@IggyFieldType(value = DataType.widechar_t, count = 40)
@IggyFieldType(value = DataType.wchar_t, count = 40)
String subName = "";
@IggyFieldType(value = DataType.uint8_t, count = 48)
byte[] zeroes48a;
@@ -98,7 +98,7 @@ public class IggyFont extends IggyTag {
@IggyFieldType(DataType.uint32_t)
long one_padd5;
@IggyFieldType(value = DataType.widechar_t, count = 16)
@IggyFieldType(value = DataType.wchar_t, count = 16)
String name;
List<IggyCharOffset> charOffsets;

View File

@@ -0,0 +1,73 @@
package com.jpexs.decompiler.flash.iggy;
import com.jpexs.decompiler.flash.iggy.annotations.IggyFieldType;
import com.jpexs.decompiler.flash.iggy.streams.ReadDataStreamInterface;
import com.jpexs.decompiler.flash.iggy.streams.SeekMode;
import com.jpexs.decompiler.flash.iggy.streams.StructureInterface;
import com.jpexs.decompiler.flash.iggy.streams.WriteDataStreamInterface;
import java.io.IOException;
/**
*
* @author JPEXS
*/
public class IggyFontTypeInfo implements StructureInterface {
@IggyFieldType(DataType.uint64_t)
long zero;
@IggyFieldType(DataType.uint64_t)
long ofs_local_name;
@IggyFieldType(DataType.uint64_t)
long font_info_num;
private long local_name_address;
public long getLocal_name_address() {
return local_name_address;
}
public IggyFontTypeInfo(ReadDataStreamInterface s) throws IOException {
readFromDataStream(s);
}
@Override
public void readFromDataStream(ReadDataStreamInterface s) throws IOException {
zero = s.readUI64();
ofs_local_name = s.readUI64();
local_name_address = ofs_local_name + s.position() - 8;
font_info_num = s.readUI64();
}
public String readFontInfo(ReadDataStreamInterface s) throws IOException {
long pos = s.position();
s.seek(local_name_address, SeekMode.SET);
StringBuilder inf_font_builder = new StringBuilder();
while (true) {
char c = (char) s.readUI16();
if (c == '\0') {
break;
}
inf_font_builder.append(c);
}
s.seek(pos, SeekMode.SET);
return inf_font_builder.toString();
}
public void writeFontInfo(String info_name, WriteDataStreamInterface s) throws IOException {
long pos = s.position();
s.seek(local_name_address, SeekMode.SET);
for (int i = 0; i < info_name.length(); i++) {
s.writeUI16(info_name.charAt(i));
}
s.writeUI16(0);
s.seek(pos, SeekMode.SET);
}
@Override
public void writeToDataStream(WriteDataStreamInterface s) throws IOException {
s.writeUI64(zero);
s.writeUI64(ofs_local_name);
s.writeUI64(font_info_num);
}
}

View File

@@ -0,0 +1,75 @@
package com.jpexs.decompiler.flash.iggy;
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.StructureInterface;
import com.jpexs.decompiler.flash.iggy.streams.WriteDataStreamInterface;
import java.io.IOException;
/**
*
* @author JPEXS
*/
public class IggySequence implements StructureInterface {
@IggyArrayFieldType(value = DataType.uint64_t, count = 2)
public long onepadd[];
@IggyFieldType(DataType.uint64_t)
public long local_seq_offset;
@IggyFieldType(DataType.uint64_t)
public long zero;
@IggyFieldType(DataType.wchar_t)
public String sequence_name;
@IggyArrayFieldType(DataType.uint8_t)
byte pad[];
@IggyFieldType(DataType.uint64_t)
public long zero2;
// wchar_t sequencname[(sequenceendaddress-sequencestartaddress-localseqoffset)/2];
// if((sequenceendaddress-sequencestartaddress)%8!=0) byte padd[((sequenceendaddress-sequencestartaddress)/8+1)*8-(sequenceendaddress-sequencestartaddress)];
public IggySequence(ReadDataStreamInterface stream) throws IOException {
readFromDataStream(stream);
}
@Override
public void readFromDataStream(ReadDataStreamInterface s) throws IOException {
onepadd = new long[2];
for (int i = 0; i < onepadd.length; i++) {
onepadd[i] = s.readUI64();
}
local_seq_offset = s.readUI64();
zero = s.readUI64();
StringBuilder sequence_name_builder = new StringBuilder();
for (int i = 0; i < local_seq_offset; i++) {
sequence_name_builder.append((char) s.readUI16());
}
sequence_name = sequence_name_builder.toString();
int pad8 = 8 - (int) (s.position() % 8);
if (pad8 < 8) {
pad = s.readBytes(pad8);
} else {
pad = new byte[0];
}
zero2 = s.readUI64(); //zero2
}
@Override
public void writeToDataStream(WriteDataStreamInterface s) throws IOException {
for (int i = 0; i < onepadd.length; i++) {
s.writeUI64(onepadd[i]);
}
s.writeUI64(local_seq_offset);
s.writeUI64(zero);
for (int i = 0; i < sequence_name.length(); i++) {
s.writeUI16(sequence_name.charAt(i));
}
s.writeBytes(pad);
s.writeUI64(zero2);
}
}

View File

@@ -23,7 +23,7 @@ public class IggySwf implements StructureInterface {
final static int NO_OFFSET = 1;
@IggyFieldType(value = DataType.widechar_t, count = 48)
@IggyFieldType(value = DataType.wchar_t, count = 48)
String name;
Map<Integer, IggyFont> fonts;
@@ -45,6 +45,10 @@ public class IggySwf implements StructureInterface {
private List<Long> font_add_off = new ArrayList<>();
private List<Long> font_add_size = new ArrayList<>();
private FontBinInfo font_bin_info[];
private IggySequence sequence;
private IggyFontTypeInfo type_info[];
private String type_info_name[];
private IggyDeclStrings decl_strings;
public IggyFlashHeader64 getHdr() {
return hdr;
@@ -177,8 +181,20 @@ public class IggySwf implements StructureInterface {
font_bin_info[i] = new FontBinInfo(s);
}
s.seek(hdr.getSequenceStartAddress1(), SeekMode.SET);
sequence = new IggySequence(s);
s.seek(hdr.getTypeFontsAddress(), SeekMode.SET);
type_info = new IggyFontTypeInfo[(int) hdr.font_count];
type_info_name = new String[(int) hdr.font_count];
for (int i = 0; i < hdr.font_count; i++) {
type_info[i] = new IggyFontTypeInfo(s);
}
for (int i = 0; i < hdr.font_count; i++) {
type_info_name[i] = type_info[i].readFontInfo(s);
}
//TODO: sequence,typeoffonts,declstrings,binarydata
s.seek(hdr.getDeclStringsAddress(), SeekMode.SET);
decl_strings = new IggyDeclStrings(s);
//TODO: binarydata
/*WriteDataStreamInterface outs = new TemporaryDataStream();
writeToDataStream(outs);
Helper.writeFile("d:\\Dropbox\\jpexs-laptop\\iggi\\parts\\swf_out.bin", outs.getAllBytes());*/
@@ -235,7 +251,21 @@ public class IggySwf implements StructureInterface {
for (int i = 0; i < hdr.font_count; i++) {
font_bin_info[i].writeToDataStream(s);
}
//TODO: sequence,typeoffonts,declstrings,binarydata
s.seek(hdr.getSequenceStartAddress1(), SeekMode.SET);
sequence.writeToDataStream(s);
s.seek(hdr.getTypeFontsAddress(), SeekMode.SET);
for (int i = 0; i < hdr.font_count; i++) {
type_info[i].writeToDataStream(s);
}
for (int i = 0; i < hdr.font_count; i++) {
type_info[i].writeFontInfo(type_info_name[i], s);
}
s.seek(hdr.getDeclStringsAddress(), SeekMode.SET);
decl_strings.writeToDataStream(s);
//TODO: binarydata
}
@Override

View File

@@ -58,7 +58,7 @@ public class IggyText implements StructureInterface {
long one;
@IggyArrayFieldType(value = DataType.uint8_t, count = 32)
byte[] some; // same for different fonts
@IggyArrayFieldType(value = DataType.widechar_t)
@IggyArrayFieldType(value = DataType.wchar_t)
String initialText; //till end of info file?
public IggyText(int type, int order_in_iggy_file, byte[] zeroone, float par1, float par2, float par3, float par4, int enum_hex, int for_which_font_order_in_iggyfile, long zero, long one, byte[] some, long offset_of_name, String name) {

View File

@@ -29,7 +29,7 @@ public class FieldPrinter {
case uint64_t:
sb.append(f.getLong(val));
break;
case widechar_t:
case wchar_t:
sb.append("\"").append(f.get(val)).append("\"");
break;
}
@@ -65,7 +65,7 @@ public class FieldPrinter {
case uint64_t:
sb.append("UI64");
break;
case widechar_t:
case wchar_t:
sb.append("//FIXME");
break;
}