diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/amf/amf0/Amf0OutputStream.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/amf/amf0/Amf0OutputStream.java index 7ba27e9b0..53a8879da 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/amf/amf0/Amf0OutputStream.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/amf/amf0/Amf0OutputStream.java @@ -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 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; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/amf/amf0/types/DateType.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/amf/amf0/types/DateType.java index 66b92ddac..41e1c6967 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/amf/amf0/types/DateType.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/amf/amf0/types/DateType.java @@ -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 getSubValues() { + return new ArrayList<>(); + } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/amf/amf0/types/XmlDocumentType.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/amf/amf0/types/XmlDocumentType.java index fd152857e..afe73b235 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/amf/amf0/types/XmlDocumentType.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/amf/amf0/types/XmlDocumentType.java @@ -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 getSubValues() { + return new ArrayList<>(); + } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/amf/amf0/Amf0Exporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/amf/amf0/Amf0Exporter.java index 9057ed854..e75d15ab5 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/amf/amf0/Amf0Exporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/amf/amf0/Amf0Exporter.java @@ -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 subvalues = ((ComplexObject) object).getSubValues(); for (Object o : subvalues) { populateObjects(o, referenceCount, objectList, objectAlias); } - } - objectList.add(object); - objectAlias.put(object, "obj" + objectList.size()); + } } } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/amf/amf0/Amf0Importer.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/amf/amf0/Amf0Importer.java index 96b8d0156..eefc0c520 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/amf/amf0/Amf0Importer.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/amf/amf0/Amf0Importer.java @@ -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 map(Map objectTable) throws IOException, AmfParseException { - Map result = new HashMap<>(); + Map 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 objectsTable = new HashMap<>(); + Map objectsTable = new LinkedHashMap<>(); List references = new ArrayList<>(); Object result = value(objectsTable); Object resultResolved = resolveObjects(result, objectsTable, true); @@ -564,7 +562,7 @@ public class Amf0Importer { */ public Map stringToAmfMap(String val) throws IOException, AmfParseException { lexer = new AmfLexer(new StringReader(val)); - Map objectsTable = new HashMap<>(); + Map objectsTable = new LinkedHashMap<>(); List references = new ArrayList<>(); Map result = map(objectsTable); for (String key : result.keySet()) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/amf/amf3/Amf3Importer.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/amf/amf3/Amf3Importer.java index efd240bb4..a79d72d80 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/amf/amf3/Amf3Importer.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/amf/amf3/Amf3Importer.java @@ -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 map(Map objectTable) throws IOException, AmfParseException { - Map result = new HashMap<>(); + Map 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 objectsTable = new HashMap<>(); + Map objectsTable = new LinkedHashMap<>(); List references = new ArrayList<>(); Object result = value(objectsTable); Object resultResolved = resolveObjects(result, objectsTable, true); @@ -615,7 +615,7 @@ public class Amf3Importer { */ public Map stringToAmfMap(String val) throws IOException, AmfParseException { lexer = new AmfLexer(new StringReader(val)); - Map objectsTable = new HashMap<>(); + Map objectsTable = new LinkedHashMap<>(); List references = new ArrayList<>(); Map result = map(objectsTable); for (String key: result.keySet()) { diff --git a/libsrc/ffdec_lib/testdata/sharedobjects/sharedobjects.swf b/libsrc/ffdec_lib/testdata/sharedobjects/sharedobjects.swf index 065c94ae0..240b876c9 100644 Binary files a/libsrc/ffdec_lib/testdata/sharedobjects/sharedobjects.swf and b/libsrc/ffdec_lib/testdata/sharedobjects/sharedobjects.swf differ diff --git a/libsrc/ffdec_lib/testdata/sharedobjects/sharedobjects/DOMDocument.xml b/libsrc/ffdec_lib/testdata/sharedobjects/sharedobjects/DOMDocument.xml index e9493ef95..561eeeaf4 100644 --- a/libsrc/ffdec_lib/testdata/sharedobjects/sharedobjects/DOMDocument.xml +++ b/libsrc/ffdec_lib/testdata/sharedobjects/sharedobjects/DOMDocument.xml @@ -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("
  • item
"); 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("
  • item
"), + myxml : xm, + myxml2 : xm, mytypedobject : new MyClass() }; @@ -130,6 +134,11 @@ function fonLoad(event:MouseEvent):void { + + + + + @@ -145,10 +154,5 @@ function fonLoad(event:MouseEvent):void { - - - - - \ No newline at end of file diff --git a/libsrc/ffdec_lib/testdata/sharedobjects/sharedobjects/bin/SymDepend.cache b/libsrc/ffdec_lib/testdata/sharedobjects/sharedobjects/bin/SymDepend.cache index 9a6c83f8f..59a20af60 100644 Binary files a/libsrc/ffdec_lib/testdata/sharedobjects/sharedobjects/bin/SymDepend.cache and b/libsrc/ffdec_lib/testdata/sharedobjects/sharedobjects/bin/SymDepend.cache differ diff --git a/src/com/jpexs/decompiler/flash/gui/PreviewPanel.java b/src/com/jpexs/decompiler/flash/gui/PreviewPanel.java index 5351c87de..5bb348be2 100644 --- a/src/com/jpexs/decompiler/flash/gui/PreviewPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/PreviewPanel.java @@ -1828,6 +1828,7 @@ public class PreviewPanel extends JPersistentSplitPane implements TagEditorPanel amfVersionLabel.setText("" + solFile.getAmfVersion()); } catch (Exception ex) { cookieEditor.setText("//Error: " + ex.getLocalizedMessage()); + ex.printStackTrace(); } }