Fixed: AMF0 - DateType and XMLType can also be referenced.

Fixed: Maintain AMF key order
This commit is contained in:
Jindra Petřík
2024-11-08 09:56:39 +01:00
parent cf6f8edc40
commit 497b5b5018
10 changed files with 51 additions and 33 deletions

View File

@@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.amf.amf0;
import com.jpexs.decompiler.flash.amf.amf0.types.ArrayType;
import com.jpexs.decompiler.flash.amf.amf0.types.BasicType;
import com.jpexs.decompiler.flash.amf.amf0.types.ComplexObject;
import com.jpexs.decompiler.flash.amf.amf0.types.DateType;
import com.jpexs.decompiler.flash.amf.amf0.types.EcmaArrayType;
import com.jpexs.decompiler.flash.amf.amf0.types.ObjectType;
@@ -167,13 +168,9 @@ public class Amf0OutputStream extends OutputStream {
public void writeValue(Object value, List<Object> complexObjectsList) throws IOException {
if ((value instanceof ObjectType)
|| (value instanceof TypedObjectType)
|| (value instanceof ArrayType)
|| (value instanceof EcmaArrayType)
) {
if (value instanceof ComplexObject) {
int index = complexObjectsList.indexOf(value);
if (index != -1 && index <= 65535 ) {
if (index != -1 && index <= 65535) {
write(Marker.REFERENCE);
writeU16(index);
return;

View File

@@ -19,12 +19,14 @@ package com.jpexs.decompiler.flash.amf.amf0.types;
import com.jpexs.decompiler.flash.amf.amf3.types.*;
import com.jpexs.decompiler.flash.exporters.amf.amf3.Amf3Exporter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* AMF0 date type.
*/
public class DateType implements Amf3ValueType {
public class DateType implements Amf3ValueType, ComplexObject {
private int timezone;
@@ -77,6 +79,10 @@ public class DateType implements Amf3ValueType {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SS");
return sdf.format(toDate()) + " timezone " + timezone;
}
@Override
public List<Object> getSubValues() {
return new ArrayList<>();
}
}

View File

@@ -17,11 +17,13 @@
package com.jpexs.decompiler.flash.amf.amf0.types;
import com.jpexs.decompiler.flash.amf.amf3.types.*;
import java.util.ArrayList;
import java.util.List;
/**
* AMF0 XML document type.
*/
public class XmlDocumentType implements Amf3ValueType {
public class XmlDocumentType implements Amf3ValueType, ComplexObject {
/**
* Data
@@ -57,4 +59,8 @@ public class XmlDocumentType implements Amf3ValueType {
return data;
}
@Override
public List<Object> getSubValues() {
return new ArrayList<>();
}
}

View File

@@ -31,6 +31,7 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import com.jpexs.decompiler.flash.amf.amf0.types.ComplexObject;
import com.jpexs.decompiler.flash.amf.amf0.types.ReferenceType;
import com.jpexs.decompiler.flash.ecma.EcmaScript;
/**
@@ -91,7 +92,10 @@ public class Amf0Exporter {
processedObjects.add(value);
}
if (value instanceof ReferenceType) {
ReferenceType rt = (ReferenceType) value;
return "#obj" + rt.referenceIndex;
}
if (value instanceof Double) {
return EcmaScript.toString(value);
@@ -166,6 +170,7 @@ public class Amf0Exporter {
StringBuilder sb = new StringBuilder();
sb.append("{").append(newLine);
sb.append(indent(level + 1)).append("\"type\": \"Date\",").append(newLine);
sb.append(addId);
sb.append(indent(level + 1)).append("\"value\": \"").append(sdf.format(dt.toDate())).append("\",").append(newLine);
sb.append(indent(level + 1)).append("\"timezone\": ").append(dt.getTimezone()).append(newLine);
sb.append(indent(level)).append("}");
@@ -177,6 +182,7 @@ public class Amf0Exporter {
StringBuilder sb = new StringBuilder();
sb.append("{").append(newLine);
sb.append(indent(level + 1)).append("\"type\": \"XMLDocument\",").append(newLine);
sb.append(addId);
sb.append(indent(level + 1)).append("\"data\": \"").append(Helper.escapeActionScriptString(xdt.getData())).append("\"").append(newLine);
sb.append(indent(level)).append("}");
return sb.toString();
@@ -238,13 +244,13 @@ public class Amf0Exporter {
referenceCount.put(object, prevRef + 1);
if (prevRef == 0) {
if (object instanceof ComplexObject) {
objectAlias.put(object, "obj" + objectList.size());
objectList.add(object);
List<Object> subvalues = ((ComplexObject) object).getSubValues();
for (Object o : subvalues) {
populateObjects(o, referenceCount, objectList, objectAlias);
}
}
objectList.add(object);
objectAlias.put(object, "obj" + objectList.size());
}
}
}
}

View File

@@ -27,13 +27,11 @@ import com.jpexs.decompiler.flash.importers.amf.ParsedSymbol;
import com.jpexs.decompiler.flash.importers.amf.AmfLexer;
import com.jpexs.decompiler.flash.importers.amf.AmfParseException;
import com.jpexs.decompiler.flash.importers.amf.SymbolType;
import com.jpexs.helpers.Helper;
import java.io.IOException;
import java.io.StringReader;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -429,7 +427,7 @@ public class Amf0Importer {
}
private Map<String, Object> map(Map<String, Object> objectTable) throws IOException, AmfParseException {
Map<String, Object> result = new HashMap<>();
Map<String, Object> result = new LinkedHashMap<>();
expectedType(SymbolType.CURLY_OPEN);
ParsedSymbol s;
do {
@@ -546,7 +544,7 @@ public class Amf0Importer {
*/
public Object stringToAmf(String val) throws IOException, AmfParseException {
lexer = new AmfLexer(new StringReader(val));
Map<String, Object> objectsTable = new HashMap<>();
Map<String, Object> objectsTable = new LinkedHashMap<>();
List<ReferencedObjectType> references = new ArrayList<>();
Object result = value(objectsTable);
Object resultResolved = resolveObjects(result, objectsTable, true);
@@ -564,7 +562,7 @@ public class Amf0Importer {
*/
public Map<String, Object> stringToAmfMap(String val) throws IOException, AmfParseException {
lexer = new AmfLexer(new StringReader(val));
Map<String, Object> objectsTable = new HashMap<>();
Map<String, Object> objectsTable = new LinkedHashMap<>();
List<ReferencedObjectType> references = new ArrayList<>();
Map<String, Object> result = map(objectsTable);
for (String key : result.keySet()) {

View File

@@ -40,7 +40,7 @@ import java.io.StringReader;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -467,7 +467,7 @@ public class Amf3Importer {
}
private Map<String, Object> map(Map<String, Object> objectTable) throws IOException, AmfParseException {
Map<String, Object> result = new HashMap<>();
Map<String, Object> result = new LinkedHashMap<>();
expectedType(SymbolType.CURLY_OPEN);
ParsedSymbol s;
do {
@@ -597,7 +597,7 @@ public class Amf3Importer {
*/
public Object stringToAmf(String val) throws IOException, AmfParseException {
lexer = new AmfLexer(new StringReader(val));
Map<String, Object> objectsTable = new HashMap<>();
Map<String, Object> objectsTable = new LinkedHashMap<>();
List<ReferencedObjectType> references = new ArrayList<>();
Object result = value(objectsTable);
Object resultResolved = resolveObjects(result, objectsTable, true);
@@ -615,7 +615,7 @@ public class Amf3Importer {
*/
public Map<String, Object> stringToAmfMap(String val) throws IOException, AmfParseException {
lexer = new AmfLexer(new StringReader(val));
Map<String, Object> objectsTable = new HashMap<>();
Map<String, Object> objectsTable = new LinkedHashMap<>();
List<ReferencedObjectType> references = new ArrayList<>();
Map<String, Object> result = map(objectsTable);
for (String key: result.keySet()) {