AMF3 refactorings

AMF3 editor in GUI for PlaceObject4
This commit is contained in:
Jindra Petřík
2016-07-20 22:16:45 +02:00
parent 0d8e621a17
commit 1c9e485dca
23 changed files with 334 additions and 17 deletions

View File

@@ -119,6 +119,7 @@ import com.jpexs.decompiler.flash.action.swf7.ActionImplementsOp;
import com.jpexs.decompiler.flash.action.swf7.ActionThrow;
import com.jpexs.decompiler.flash.action.swf7.ActionTry;
import com.jpexs.decompiler.flash.amf.amf3.Amf3InputStream;
import com.jpexs.decompiler.flash.amf.amf3.Amf3Value;
import com.jpexs.decompiler.flash.amf.amf3.NoSerializerExistsException;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.dumpview.DumpInfo;
@@ -767,13 +768,13 @@ public class SWFInputStream implements AutoCloseable {
* @return
* @throws IOException
*/
public Object readAmf3Object(String name) throws IOException {
public Amf3Value readAmf3Object(String name) throws IOException {
Amf3InputStream ai = new Amf3InputStream(is);
ai.dumpInfo = this.dumpInfo;
try {
return ai.readValue("amfData");
return new Amf3Value(ai.readValue("amfData"));
} catch (NoSerializerExistsException nse) {
return nse.getIncompleteData();
return new Amf3Value(nse.getIncompleteData());
}
}

View File

@@ -17,6 +17,7 @@
package com.jpexs.decompiler.flash;
import com.jpexs.decompiler.flash.amf.amf3.Amf3OutputStream;
import com.jpexs.decompiler.flash.amf.amf3.Amf3Value;
import com.jpexs.decompiler.flash.amf.amf3.NoSerializerExistsException;
import com.jpexs.decompiler.flash.amf.amf3.ObjectTypeSerializeHandler;
import com.jpexs.decompiler.flash.configuration.Configuration;
@@ -1962,9 +1963,9 @@ public class SWFOutputStream extends OutputStream {
* @throws IOException
* @throws NoSerializerExistsException
*/
public void writeAmf3Object(Object value, Map<String, ObjectTypeSerializeHandler> serializers) throws IOException, NoSerializerExistsException {
public void writeAmf3Object(Amf3Value value, Map<String, ObjectTypeSerializeHandler> serializers) throws IOException, NoSerializerExistsException {
Amf3OutputStream ao = new Amf3OutputStream(os);
ao.writeValue(value, serializers);
ao.writeValue(value.getValue(), serializers);
}
/**
@@ -1975,7 +1976,7 @@ public class SWFOutputStream extends OutputStream {
* @throws IOException
* @throws NoSerializerExistsException
*/
public void writeAmf3Object(Object value) throws IOException, NoSerializerExistsException {
public void writeAmf3Object(Amf3Value value) throws IOException, NoSerializerExistsException {
writeAmf3Object(value, new HashMap<>());
}
}

View File

@@ -0,0 +1,48 @@
package com.jpexs.decompiler.flash.amf.amf3;
import com.jpexs.decompiler.flash.amf.amf3.types.Amf3ValueType;
import com.jpexs.decompiler.flash.exporters.amf.amf3.Amf3Exporter;
public class Amf3Value {
private Object value;
public Amf3Value(Object value) {
setValue(value);
}
public void setValue(Object value) {
if (!isValueValid(value)) {
throw new IllegalArgumentException("Invalid Amf value: " + value.getClass().getSimpleName());
}
this.value = value;
}
public static boolean isValueValid(Object value) {
if (value instanceof Long) {
return true;
}
if (value instanceof Double) {
return true;
}
if (value instanceof String) {
return true;
}
if (value instanceof Boolean) {
return true;
}
if (value instanceof Amf3ValueType) {
return true;
}
return false;
}
public Object getValue() {
return value;
}
@Override
public String toString() {
return Amf3Exporter.amfToString(value);
}
}

View File

@@ -5,7 +5,7 @@ import java.util.ArrayList;
import java.util.List;
import com.jpexs.decompiler.flash.amf.amf3.WithSubValues;
public abstract class AbstractVectorType<T> implements WithSubValues {
public abstract class AbstractVectorType<T> implements WithSubValues, Amf3ValueType {
private boolean fixed;
private List<T> values;

View File

@@ -0,0 +1,5 @@
package com.jpexs.decompiler.flash.amf.amf3.types;
public interface Amf3ValueType {
}

View File

@@ -7,7 +7,7 @@ import java.util.ArrayList;
import java.util.List;
import com.jpexs.decompiler.flash.amf.amf3.WithSubValues;
public class ArrayType implements WithSubValues {
public class ArrayType implements WithSubValues, Amf3ValueType {
private List<Object> denseValues;
private List<Pair<String, Object>> associativeValues;

View File

@@ -1,6 +1,6 @@
package com.jpexs.decompiler.flash.amf.amf3.types;
public enum BasicType {
public enum BasicType implements Amf3ValueType {
NULL {
@Override
public String toString() {

View File

@@ -3,7 +3,7 @@ package com.jpexs.decompiler.flash.amf.amf3.types;
import com.jpexs.decompiler.flash.exporters.amf.amf3.Amf3Exporter;
import java.util.Date;
public class DateType {
public class DateType implements Amf3ValueType {
private double val;

View File

@@ -6,7 +6,7 @@ import java.util.ArrayList;
import java.util.List;
import com.jpexs.decompiler.flash.amf.amf3.WithSubValues;
public class DictionaryType implements WithSubValues {
public class DictionaryType implements WithSubValues, Amf3ValueType {
private boolean weakKeys;
private List<Pair<Object, Object>> pairs;

View File

@@ -8,7 +8,7 @@ import java.util.ArrayList;
import java.util.List;
import com.jpexs.decompiler.flash.amf.amf3.WithSubValues;
public class ObjectType implements WithSubValues {
public class ObjectType implements WithSubValues, Amf3ValueType {
private List<Pair<String, Object>> sealedMembers;
private List<Pair<String, Object>> dynamicMembers;

View File

@@ -1,6 +1,6 @@
package com.jpexs.decompiler.flash.amf.amf3.types;
public class XmlDocType {
public class XmlDocType implements Amf3ValueType {
private String data;

View File

@@ -1,6 +1,6 @@
package com.jpexs.decompiler.flash.amf.amf3.types;
public class XmlType {
public class XmlType implements Amf3ValueType {
private String data;

View File

@@ -20,6 +20,7 @@ import com.jpexs.decompiler.flash.EndOfStreamException;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.SWFInputStream;
import com.jpexs.decompiler.flash.SWFOutputStream;
import com.jpexs.decompiler.flash.amf.amf3.Amf3Value;
import com.jpexs.decompiler.flash.amf.amf3.NoSerializerExistsException;
import com.jpexs.decompiler.flash.tags.base.ASMSourceContainer;
import com.jpexs.decompiler.flash.tags.base.PlaceObjectTypeTag;
@@ -234,8 +235,7 @@ public class PlaceObject4Tag extends PlaceObjectTypeTag implements ASMSourceCont
@Reserved
public boolean reserved;
//public byte[] amfData; //TODO: Parse AMF data?
public Object amfData;
public Amf3Value amfData;
/**
* Constructor
@@ -246,7 +246,7 @@ public class PlaceObject4Tag extends PlaceObjectTypeTag implements ASMSourceCont
super(swf, ID, NAME, null);
}
public PlaceObject4Tag(SWF swf, boolean placeFlagMove, int depth, String className, int characterId, MATRIX matrix, CXFORMWITHALPHA colorTransform, int ratio, String name, int clipDepth, List<FILTER> surfaceFilterList, int blendMode, int bitmapCache, int visible, RGBA backgroundColor, CLIPACTIONS clipActions, Object amfData) {
public PlaceObject4Tag(SWF swf, boolean placeFlagMove, int depth, String className, int characterId, MATRIX matrix, CXFORMWITHALPHA colorTransform, int ratio, String name, int clipDepth, List<FILTER> surfaceFilterList, int blendMode, int bitmapCache, int visible, RGBA backgroundColor, CLIPACTIONS clipActions, Amf3Value amfData) {
super(swf, ID, NAME, null);
this.placeFlagHasClassName = className != null;
this.placeFlagHasFilterList = surfaceFilterList != null;