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()) {

View File

@@ -19,7 +19,13 @@ import flash.net.ObjectEncoding;
import flash.xml.XMLDocument;
import flash.net.registerClassAlias;
var s:String = "";
for (var i = 0; i < 70000; i++) {
s += "A";
}
var dt = new Date(2024,12-1,3,23,16);
var xm = new XMLDocument("<ul><li>item</li></ul>");
var amf0test:SharedObject = SharedObject.getLocal("amf0test");
amf0test.objectEncoding = ObjectEncoding.AMF0;
@@ -33,10 +39,6 @@ var reftest = {a:refobj, b:refobj};
reftest["c"] = reftest;
var s:String = "";
for (var i = 0; i < 70000; i++) {
s += "A";
}
registerClassAlias("MyClassAlias", MyClass);
var data = {
@@ -47,10 +49,12 @@ var data = {
mynull : null,
myundefined : undefined,
myarray : ["a","b","c"],
mydate : new Date(2024,12-1,3,23,16),
mydate : dt,
mydate2 : dt,
myref: reftest,
mylongstring : s,
myxml : new XMLDocument("<ul><li>item</li></ul>"),
myxml : xm,
myxml2 : xm,
mytypedobject : new MyClass()
};
@@ -130,6 +134,11 @@ function fonLoad(event:MouseEvent):void {
</timelines>
<PrinterSettings/>
<publishHistory>
<PublishItem publishSize="21715" publishTime="1731055062"/>
<PublishItem publishSize="21697" publishTime="1731054903"/>
<PublishItem publishSize="21636" publishTime="1731052148"/>
<PublishItem publishSize="21602" publishTime="1731051747"/>
<PublishItem publishSize="21507" publishTime="1730740224"/>
<PublishItem publishSize="21508" publishTime="1730740069"/>
<PublishItem publishSize="21505" publishTime="1730740015"/>
<PublishItem publishSize="21520" publishTime="1730739945"/>
@@ -145,10 +154,5 @@ function fonLoad(event:MouseEvent):void {
<PublishItem publishSize="20794" publishTime="1730676730"/>
<PublishItem publishSize="20793" publishTime="1730676669"/>
<PublishItem publishSize="20792" publishTime="1730676587"/>
<PublishItem publishSize="20407" publishTime="1730676575"/>
<PublishItem publishSize="20409" publishTime="1730676542"/>
<PublishItem publishSize="20409" publishTime="1730676533"/>
<PublishItem publishSize="20251" publishTime="1730676524"/>
<PublishItem publishSize="20251" publishTime="1730676504"/>
</publishHistory>
</DOMDocument>