From 1fcc9c6ba006e169b348bb4e2c6bbdd52a46343f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Sun, 28 Aug 2016 23:39:47 +0200 Subject: [PATCH] AS3 p-code Popup docs for other items than instructions --- .../flash/abc/types/traits/Trait.java | 12 +- .../abc/types/traits/TraitSlotConst.java | 6 +- .../decompiler/flash/docs/AbstractDocs.java | 64 ++++++++++ .../decompiler/flash/docs/As3PCodeDocs.java | 115 ++++++------------ .../flash/docs/As3PCodeOtherDocs.java | 102 ++++++++++++++++ .../com/jpexs/decompiler/flash/docs/docs.css | 1 + .../locales/docs/pcode/AS3other.properties | 92 ++++++++++++++ 7 files changed, 306 insertions(+), 86 deletions(-) create mode 100644 libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/docs/AbstractDocs.java create mode 100644 libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/docs/As3PCodeOtherDocs.java create mode 100644 libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/locales/docs/pcode/AS3other.properties diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/Trait.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/Trait.java index bc95e296d..0406b3c87 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/Trait.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/Trait.java @@ -393,19 +393,23 @@ public abstract class Trait implements Cloneable, Serializable { writer.hilightSpecial(abc.constants.multinameToString(name_index), HighlightSpecialType.TRAIT_NAME); if ((kindFlags & ATTR_Final) > 0) { - writer.append(" flag "); + writer.newLine(); + writer.append("flag "); writer.hilightSpecial("FINAL", HighlightSpecialType.ATTR_FINAL); } if ((kindFlags & ATTR_Override) > 0) { - writer.append(" flag "); + writer.newLine(); + writer.append("flag "); writer.hilightSpecial("OVERRIDE", HighlightSpecialType.ATTR_OVERRIDE); } if ((kindFlags & ATTR_Metadata) > 0) { - writer.append(" flag "); + writer.newLine(); + writer.append("flag "); writer.hilightSpecial("METADATA", HighlightSpecialType.ATTR_METADATA); } if ((kindFlags & ATTR_0x8) > 0) { - writer.append(" flag "); + writer.newLine(); + writer.append("flag "); writer.hilightSpecial("0x8", HighlightSpecialType.ATTR_0x8); } if ((kindFlags & ATTR_Metadata) > 0) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitSlotConst.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitSlotConst.java index d7e325066..0da163cc9 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitSlotConst.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/TraitSlotConst.java @@ -235,9 +235,11 @@ public class TraitSlotConst extends Trait implements TraitWithSlot { writer.newLine(); writer.appendNoHilight("slotid "); writer.hilightSpecial(Integer.toString(slot_id), HighlightSpecialType.SLOT_ID); - writer.appendNoHilight(" type "); + writer.newLine(); + writer.appendNoHilight("type "); writer.hilightSpecial(abc.constants.multinameToString(type_index), HighlightSpecialType.TRAIT_TYPE_NAME); - writer.appendNoHilight(" value "); + writer.newLine(); + writer.appendNoHilight("value "); writer.hilightSpecial((new ValueKind(value_index, value_kind).toASMString(abc.constants)), HighlightSpecialType.TRAIT_VALUE); writer.newLine(); return writer; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/docs/AbstractDocs.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/docs/AbstractDocs.java new file mode 100644 index 000000000..cc7539ec5 --- /dev/null +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/docs/AbstractDocs.java @@ -0,0 +1,64 @@ +package com.jpexs.decompiler.flash.docs; + +import com.jpexs.decompiler.flash.ApplicationInfo; +import static com.jpexs.decompiler.flash.docs.As3PCodeOtherDocs.NEWLINE; +import com.jpexs.helpers.Cache; +import com.jpexs.helpers.Helper; +import com.jpexs.helpers.utf8.Utf8Helper; +import java.io.InputStream; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Locale; +import java.util.ResourceBundle; +import java.util.TimeZone; +import java.util.logging.Level; +import java.util.logging.Logger; + +public class AbstractDocs { + + protected static Cache docsCache = Cache.getInstance(false, true, "abstractDocsCache"); + + protected static String htmlFooter() { + StringBuilder sb = new StringBuilder(); + + sb.append(""); + return sb.toString(); + } + + public static String getStyle() { + String cached = docsCache.get("__style"); + if (cached != null) { + return cached; + } + String style = ""; + InputStream is = As3PCodeDocs.class.getResourceAsStream("/com/jpexs/decompiler/flash/docs/docs.css"); + if (is == null) { + Logger.getLogger(As3PCodeDocs.class.getName()).log(Level.SEVERE, "docs.css needed for documentation not found"); + } else { + style = new String(Helper.readStream(is), Utf8Helper.charset); + } + + docsCache.put("__style", style); + return style; + } + + protected static String meta(String name, String content) { + return "\t\t" + NEWLINE; + } + + protected static String metaProp(String name, String content) { + return "\t\t" + NEWLINE; + } + + protected static String meta(String name, Date content) { + return "\t\t" + NEWLINE; + } + + protected static String getISO8601StringForDate(Date date) { + DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US); + dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); + return dateFormat.format(date); + } + +} diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/docs/As3PCodeDocs.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/docs/As3PCodeDocs.java index eafdcf770..8350b8927 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/docs/As3PCodeDocs.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/docs/As3PCodeDocs.java @@ -28,15 +28,12 @@ import java.util.logging.Logger; * * @author JPEXS */ -public class As3PCodeDocs { +public class As3PCodeDocs extends AbstractDocs { - private static ResourceBundle prop; + static ResourceBundle prop; + private static final Map flagDescriptions = new HashMap<>(); - private static Map flagDescriptions = new HashMap<>(); - - private static Cache docsCache = Cache.getInstance(false, true, "as3DocsCache"); - - private static Map nameToDef = new HashMap<>(); + private final static Map nameToDef = new HashMap<>(); static final String NEWLINE = "\r\n"; @@ -82,56 +79,6 @@ public class As3PCodeDocs { return getDocsForIns(nameToDef.get(insName), showDataSize, ui, withStyle); } - private static String getProperty(String name) { - if (prop.containsKey(name)) { - return Helper.escapeHTML(prop.getString(name)); - } - return null; - } - - private static String htmlFooter() { - StringBuilder sb = new StringBuilder(); - - sb.append(""); - return sb.toString(); - } - - private static String meta(String name, String content) { - return "\t\t" + NEWLINE; - } - - private static String metaProp(String name, String content) { - return "\t\t" + NEWLINE; - } - - private static String meta(String name, Date content) { - return "\t\t" + NEWLINE; - } - - private static String htmlHeader(String js, String style) { - Date dateGenerated = new Date(); - StringBuilder sb = new StringBuilder(); - sb.append("").append(NEWLINE). - append("").append(NEWLINE). - append("\t").append(NEWLINE); - if (style != null && !style.isEmpty()) { - sb.append("\t\t").append(NEWLINE); - } - if (js != null && !js.isEmpty()) { - sb.append("\t\t").append(NEWLINE); - } - sb.append("\t\t").append(NEWLINE). - append(meta("generator", ApplicationInfo.applicationVerName)). - append(meta("description", getProperty("ui.list.pageDescription"))). - append(metaProp("og:title", getProperty("ui.list.pageTitle"))). - append(metaProp("og:type", "article")). - append(metaProp("og:description", getProperty("ui.list.pageDescription"))). - append(meta("date", dateGenerated)). - append("\t\t").append(getProperty("ui.list.documentTitle")).append("").append(NEWLINE). - append("\t").append(NEWLINE); - return sb.toString(); - } - public static String getDocsForIns(InstructionDefinition def, boolean showDataSize, boolean ui, boolean standalone) { final String cacheKey = def.instructionName + "|" + (showDataSize ? 1 : 0) + "|" + (ui ? 1 : 0) + "|" + (standalone ? 1 : 0); String v = docsCache.get(cacheKey); @@ -267,23 +214,6 @@ public class As3PCodeDocs { return r; } - public static String getStyle() { - String cached = docsCache.get("__style"); - if (cached != null) { - return cached; - } - String style = ""; - InputStream is = As3PCodeDocs.class.getResourceAsStream("/com/jpexs/decompiler/flash/docs/docs.css"); - if (is == null) { - Logger.getLogger(As3PCodeDocs.class.getName()).log(Level.SEVERE, "docs.css needed for documentation not found"); - } else { - style = new String(Helper.readStream(is), Utf8Helper.charset); - } - - docsCache.put("__style", style); - return style; - } - public static String getJs() { String cached = docsCache.get("__js"); if (cached != null) { @@ -301,12 +231,6 @@ public class As3PCodeDocs { return js; } - private static String getISO8601StringForDate(Date date) { - DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US); - dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); - return dateFormat.format(date); - } - public static String getAllInstructionDocs() { String jsData = ""; @@ -353,4 +277,35 @@ public class As3PCodeDocs { public static void main(String[] args) throws UnsupportedEncodingException { System.out.println(getAllInstructionDocs()); } + + protected static String htmlHeader(String js, String style) { + Date dateGenerated = new Date(); + StringBuilder sb = new StringBuilder(); + sb.append("").append(NEWLINE). + append("").append(NEWLINE). + append("\t").append(NEWLINE); + if (style != null && !style.isEmpty()) { + sb.append("\t\t").append(NEWLINE); + } + if (js != null && !js.isEmpty()) { + sb.append("\t\t").append(NEWLINE); + } + sb.append("\t\t").append(NEWLINE). + append(meta("generator", ApplicationInfo.applicationVerName)). + append(meta("description", getProperty("ui.list.pageDescription"))). + append(metaProp("og:title", getProperty("ui.list.pageTitle"))). + append(metaProp("og:type", "article")). + append(metaProp("og:description", getProperty("ui.list.pageDescription"))). + append(meta("date", dateGenerated)). + append("\t\t").append(getProperty("ui.list.documentTitle")).append("").append(NEWLINE). + append("\t").append(NEWLINE); + return sb.toString(); + } + + protected static String getProperty(String name) { + if (prop.containsKey(name)) { + return Helper.escapeHTML(prop.getString(name)); + } + return null; + } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/docs/As3PCodeOtherDocs.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/docs/As3PCodeOtherDocs.java new file mode 100644 index 000000000..358fbad60 --- /dev/null +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/docs/As3PCodeOtherDocs.java @@ -0,0 +1,102 @@ +package com.jpexs.decompiler.flash.docs; + +import com.jpexs.decompiler.flash.ApplicationInfo; +import static com.jpexs.decompiler.flash.docs.As3PCodeDocs.NEWLINE; +import com.jpexs.helpers.Cache; +import com.jpexs.helpers.Helper; +import com.jpexs.helpers.utf8.Utf8Helper; +import java.io.InputStream; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Locale; +import java.util.ResourceBundle; +import java.util.TimeZone; +import java.util.logging.Level; +import java.util.logging.Logger; + +public class As3PCodeOtherDocs extends AbstractDocs { + + static ResourceBundle prop; + static final String NEWLINE = "\r\n"; + + static { + prop = ResourceBundle.getBundle("com.jpexs.decompiler.flash.locales.docs.pcode.AS3other"); + } + + public static String getDocsForPath(String path) { + + return getDocsForPath(path, true); + } + + private static String getDocsForPath(String path, boolean standalone) { + + final String cacheKey = path + "|" + (standalone ? 1 : 0); + String v = docsCache.get(cacheKey); + if (v != null) { + return v; + } + + String docStr = ""; + String pathNoTrait = path; + if (path.startsWith("trait.method")) { + pathNoTrait = path.substring("trait.".length()); + } + if (prop.containsKey(pathNoTrait)) { + docStr = prop.getString(pathNoTrait); + } + + StringBuilder sb = new StringBuilder(); + if (standalone) { + sb.append(htmlHeader("", getStyle())); + } + + sb.append("<"); + sb.append(standalone ? "body" : "div"); + sb.append(" class=\"otherdoc\""); + sb.append(">"); + + sb.append(docStr); + + sb.append("").append(NEWLINE); + if (standalone) { + sb.append(htmlFooter()); + } + String r = sb.toString(); + docsCache.put(cacheKey, r); + return r; + } + + protected static String htmlHeader(String js, String style) { + Date dateGenerated = new Date(); + StringBuilder sb = new StringBuilder(); + sb.append("").append(NEWLINE). + append("").append(NEWLINE). + append("\t").append(NEWLINE); + if (style != null && !style.isEmpty()) { + sb.append("\t\t").append(NEWLINE); + } + if (js != null && !js.isEmpty()) { + sb.append("\t\t").append(NEWLINE); + } + sb.append("\t\t").append(NEWLINE). + append(meta("generator", ApplicationInfo.applicationVerName)). + append(meta("description", getProperty("ui.list.pageDescription"))). + append(metaProp("og:title", getProperty("ui.list.pageTitle"))). + append(metaProp("og:type", "article")). + append(metaProp("og:description", getProperty("ui.list.pageDescription"))). + append(meta("date", dateGenerated)). + append("\t\t").append(getProperty("ui.list.documentTitle")).append("").append(NEWLINE). + append("\t").append(NEWLINE); + return sb.toString(); + } + + protected static String getProperty(String name) { + if (prop.containsKey(name)) { + return Helper.escapeHTML(prop.getString(name)); + } + return null; + } +} diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/docs/docs.css b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/docs/docs.css index 807075899..6c5e5dabc 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/docs/docs.css +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/docs/docs.css @@ -1,5 +1,6 @@ html, body {margin:0px; padding: 0px;} .instruction {background-color: #f5f5b5; color:black;} +.otherdoc {background-color: #f5f5b5; color:black;} li.instruction-item {list-style:none; padding:0px;border:1px solid black; border-bottom:none; border-collapse:collapse; } ul.instruction-list {padding-left:0; display:table; border-bottom:1px solid black;} strong.instruction-name {font-weight: bold; color: blue;} diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/locales/docs/pcode/AS3other.properties b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/locales/docs/pcode/AS3other.properties new file mode 100644 index 000000000..26347b3b1 --- /dev/null +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/locales/docs/pcode/AS3other.properties @@ -0,0 +1,92 @@ +# Copyright (C) 2010-2016 JPEXS, All rights reserved. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 3.0 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library. +ui.list.heading = AVM2 p-code +ui.list.pageTitle = AVM2 p-code +ui.list.documentTitle = AVM2 p-code +ui.list.pageDescription = List of p-code settings + + +name.QName = Qualified Name +name.QNameA = Qualified Name of Attribute +name.RTQName = Runtime Qualified Name +name.RTQNameA = Runtime Qualified Name of Attribute +name.RTQNameL = Runtime Qualified Name Late +name.RTQNameLA = Runtime Qualified Name Late of Attribute +name.Multiname = Multiple Namespace Name +name.MultinameA = Multiple Namespace Name of Attribute +name.MultinameL = Multiple Namespace Name Late +name.MultinameLA = Multiple Namespace Name Late of Attribute +name.TypeName = Type Name + +namespacekind.Namespace = Namespace +namespacekind.PrivateNamespace = Private Namespace +namespacekind.PackageNamespace = Package Namespace +namespacekind.PackageInternalNs = Package Internal Namespace +namespacekind.ProtectedNamespace = Protected Namespace +namespacekind.ExplicitNamespace = Explicit Namespace +namespacekind.StaticProtectedNs = Static Protected Namespace + +trait = Trait +#types: +trait.method = Trait of type method +trait.slot = Trait of type slot +trait.const = Trait of type const +trait.method = Trait of type method +trait.setter = Trait of type setter +trait.getter = Trait of type getter +trait.class = Trait of type class +trait.function = Trait of type function + +trait.metadata = Metadata +trait.metadata.item = One metadata item +trait.metadata.end = End of metadata + +trait.flag = Trait flag +trait.flag.METADATA = Trait has metadata attached +trait.flag.FINAL = Trais if final +trait.flag.OVERRIDE = Trait overrides parent + +#method/getter/setter +trait.dispid = Dispatch id +#slot/const/class/function +trait.slotid = Slot id + +method = Method +method.name = Name of the method +method.flag = Method flag +method.flag.NEED_ARGUMENTS = Create "arguments" object in register method_info.param_count+1 +method.flag.NEED_ACTIVATION = This method uses newactivation instruction +method.flag.NEED_REST = Create rest arguments array in register method_info.param_count+1 +method.flag.HAS_OPTIONAL = This method has optional arguments +method.flag.IGNORE_REST = ?? +method.flag.EXPLICIT = ?? +method.flag.SETSDXNS = This method uses dxns or dxnslate instructions +method.flag.HAS_PARAMNAMES = This method has parameter names in method_info +method.param = Type of parameter +method.paramname = Name of parameter +method.optional = Default value for optional parameter +method.returns = Return type of method +method.body = Body of method +method.body.maxstack = Maximum number of stack slots at any point of execution +method.body.localcount = Index of highest-numbered local register plus one +method.body.initscopedepth = Minimum scope depth (relative to maxscopedepth) that may be accessed +method.body.maxscopedepth = Maximum scope depth that may be accessed +method.body.try = Exception block +method.body.try.from = Starting position from which exception is enabled +method.body.try.to = Ending position after which the exception is disabled +method.body.try.target = Position to which control should jump if exception of this type is thrown +method.body.try.type = Type of catched exception +method.body.try.name = Name of the exception object +method.body.code = Code of the method body