From b52fff07a9aab0769fcad2997739e930cfd805d7 Mon Sep 17 00:00:00 2001 From: "honfika@gmail.com" Date: Sun, 18 Jan 2015 15:11:10 +0100 Subject: [PATCH] xml export/import of null objects fixed --- .../flash/exporters/swf/SwfXmlExporter.java | 31 ++++++++++--------- .../flash/importers/SwfXmlImporter.java | 17 ++++++++++ .../src/com/jpexs/helpers/Helper.java | 6 ++-- .../jpexs/decompiler/flash/gui/MainPanel.java | 2 ++ 4 files changed, 38 insertions(+), 18 deletions(-) diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/swf/SwfXmlExporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/swf/SwfXmlExporter.java index 313f6c1fe..a2e2bd802 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/swf/SwfXmlExporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/swf/SwfXmlExporter.java @@ -95,13 +95,8 @@ public class SwfXmlExporter { generateXml(doc, node, "swf", swf, false, 0); } - private static void generateXml(Document doc, Node node, String name, Object obj, boolean addAsChildNode, int level){ - if (obj == null) { - return; - } - - Class cls = obj.getClass(); - Object value = null; + private static void generateXml(Document doc, Node node, String name, Object obj, boolean isListItem, int level){ + Class cls = obj != null ? obj.getClass() : null; if (cls == Byte.class || cls == byte.class || cls == Short.class || cls == short.class || @@ -112,19 +107,19 @@ public class SwfXmlExporter { cls == Boolean.class || cls == boolean.class || cls == Character.class || cls == char.class || cls == String.class) { - value = obj; + Object value = obj; if (value instanceof String) { - value = Helper.escapeXML((String) value); + value = Helper.removeInvalidXMLCharacters((String) value); } - if (addAsChildNode) { + if (isListItem) { Element childNode = doc.createElement(name); childNode.setTextContent(value.toString()); node.appendChild(childNode); } else { ((Element) node).setAttribute(name, value.toString()); } - } else if (cls.isEnum()) { + } else if (cls != null && cls.isEnum()) { ((Element) node).setAttribute(name, obj.toString()); } else if (obj instanceof ByteArrayRange) { ByteArrayRange range = (ByteArrayRange) obj; @@ -135,22 +130,22 @@ public class SwfXmlExporter { } ((Element) node).setAttribute(name, sb.toString()); - } else if (List.class.isAssignableFrom(cls)) { + } else if (cls != null && List.class.isAssignableFrom(cls)) { List list = (List) obj; Element listNode = doc.createElement(name); node.appendChild(listNode); for (int i = 0; i < list.size(); i++) { generateXml(doc, listNode, "item", list.get(i), true, level + 1); } - } else if (cls.isArray()) { - String arrayType = cls.getComponentType().getSimpleName(); + } else if (cls != null && cls.isArray()) { + Class arrayType = cls.getComponentType(); Element arrayNode = doc.createElement(name); node.appendChild(arrayNode); int length = Array.getLength(obj); for (int i = 0; i < length; i++) { generateXml(doc, arrayNode, "item", Array.get(obj, i), true, level + 1); } - } else { + } else if (obj != null) { if (obj instanceof LazyObject) { ((LazyObject) obj).load(); } @@ -182,6 +177,12 @@ public class SwfXmlExporter { Logger.getLogger(SwfXmlExporter.class.getName()).log(Level.SEVERE, null, ex); } } + } else { + if (isListItem) { + Element childNode = doc.createElement(name); + childNode.setAttribute("isNull", Boolean.TRUE.toString()); + node.appendChild(childNode); + } } } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/SwfXmlImporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/SwfXmlImporter.java index 6dfa33141..36c83b54a 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/SwfXmlImporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/SwfXmlImporter.java @@ -81,6 +81,14 @@ import com.jpexs.decompiler.flash.types.SOUNDINFO; import com.jpexs.decompiler.flash.types.TEXTRECORD; import com.jpexs.decompiler.flash.types.ZONEDATA; import com.jpexs.decompiler.flash.types.ZONERECORD; +import com.jpexs.decompiler.flash.types.filters.BEVELFILTER; +import com.jpexs.decompiler.flash.types.filters.BLURFILTER; +import com.jpexs.decompiler.flash.types.filters.COLORMATRIXFILTER; +import com.jpexs.decompiler.flash.types.filters.CONVOLUTIONFILTER; +import com.jpexs.decompiler.flash.types.filters.DROPSHADOWFILTER; +import com.jpexs.decompiler.flash.types.filters.GLOWFILTER; +import com.jpexs.decompiler.flash.types.filters.GRADIENTBEVELFILTER; +import com.jpexs.decompiler.flash.types.filters.GRADIENTGLOWFILTER; import com.jpexs.decompiler.flash.types.shaperecords.CurvedEdgeRecord; import com.jpexs.decompiler.flash.types.shaperecords.EndShapeRecord; import com.jpexs.decompiler.flash.types.shaperecords.StraightEdgeRecord; @@ -213,6 +221,11 @@ public class SwfXmlImporter { processElement(element, childObj, swf); return childObj; } else { + String isNullAttr = element.getAttribute("isNull"); + if (Boolean.parseBoolean(isNullAttr)) { + return null; + } + return getAs(requiredType, element.getTextContent()); } } @@ -249,6 +262,10 @@ public class SwfXmlImporter { PIX24.class, RECT.class, RGB.class, RGBA.class, SHAPE.class, SHAPEWITHSTYLE.class, SOUNDENVELOPE.class, SOUNDINFO.class, TEXTRECORD.class, ZONEDATA.class, ZONERECORD.class, CurvedEdgeRecord.class, EndShapeRecord.class, StraightEdgeRecord.class, StyleChangeRecord.class, + + BEVELFILTER.class, BLURFILTER.class, COLORMATRIXFILTER.class, CONVOLUTIONFILTER.class, + DROPSHADOWFILTER.class, GLOWFILTER.class, GRADIENTBEVELFILTER.class, GRADIENTGLOWFILTER.class, + AVM2ConstantPool.class, Decimal.class, Namespace.class, NamespaceSet.class, Multiname.class, MethodInfo.class, ValueKind.class, InstanceInfo.class, Traits.class, TraitClass.class, TraitFunction.class, TraitMethodGetterSetter.class, TraitSlotConst.class, ClassInfo.class, ScriptInfo.class, MethodBody.class, diff --git a/libsrc/ffdec_lib/src/com/jpexs/helpers/Helper.java b/libsrc/ffdec_lib/src/com/jpexs/helpers/Helper.java index f52dd3da0..3755b979c 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/helpers/Helper.java +++ b/libsrc/ffdec_lib/src/com/jpexs/helpers/Helper.java @@ -869,7 +869,7 @@ public class Helper { return text; } - public static String escapeXML(String text) { + public static String removeInvalidXMLCharacters(String text) { StringBuilder sb = new StringBuilder(text.length()); for (int i = 0; i < text.length(); i++) { char ch = text.charAt(i); @@ -878,9 +878,9 @@ public class Helper { } } - return escapeHTML(sb.toString()); + return sb.toString(); } - + public static Shape imageToShape(BufferedImage image) { Area area = new Area(); Rectangle rectangle = new Rectangle(); diff --git a/src/com/jpexs/decompiler/flash/gui/MainPanel.java b/src/com/jpexs/decompiler/flash/gui/MainPanel.java index e3a6141fc..d1f488371 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/MainPanel.java @@ -1671,6 +1671,8 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec try { new SwfXmlImporter().importSwf(swf, xml); swf.clearAllCache(); + swf.assignExportNamesToSymbols(); + swf.assignClassesToSymbols(); refreshTree(); } catch (IOException ex) { logger.log(Level.SEVERE, null, ex);