More documentation.

This commit is contained in:
Jindra Petřík
2024-08-08 19:27:14 +02:00
parent 5c1811582a
commit f219b49372
394 changed files with 13018 additions and 552 deletions
@@ -85,6 +85,12 @@ public class BMPFile extends Component {
private BMPFile() {
}
/**
* Save bitmap to file.
* @param image Image to save
* @param file File to save to
* @throws IOException On I/O error
*/
public static void saveBitmap(Image image, File file) throws IOException {
BMPFile b = new BMPFile();
try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(file))) {
@@ -23,52 +23,136 @@ package com.jpexs.decompiler.flash.helpers;
*/
public class CodeFormatting {
/**
* New line characters
*/
public String newLineChars = "\r\n";
/**
* Indent string
*/
public String indentString = " ";
/**
* Begin block on new line
*/
public boolean beginBlockOnNewLine = true;
// spaces
// before parentheses
/**
* Spaces before parentheses in method call
*/
public boolean spaceBeforeParenthesesMethodCallParentheses = false;
/**
* Spaces before parentheses in method call with empty parentheses
*/
public boolean spaceBeforeParenthesesMethodCallEmptyParentheses = false;
/**
* Spaces before array access brackets
*/
public boolean spaceBeforeArrayAccessBrackets = false;
/**
* Spaces before parentheses in method declaration
*/
public boolean spaceBeforeParenthesesMethodDeclarationParentheses = false;
/**
* Spaces before parentheses in method declaration with empty parentheses
*/
public boolean spaceBeforeParenthesesMethodDeclarationEmptyParentheses = false;
/**
* Spaces before parentheses in if parentheses
*/
public boolean spaceBeforeParenthesesIfParentheses = false;
/**
* Spaces before parentheses in with parentheses
*/
public boolean spaceBeforeParenthesesWithParentheses = false;
/**
* Spaces before parentheses in while parentheses
*/
public boolean spaceBeforeParenthesesWhileParentheses = false;
/**
* Spaces before parentheses in catch parentheses
*/
public boolean spaceBeforeParenthesesCatchParentheses = false;
/**
* Spaces before parentheses in switch parentheses
*/
public boolean spaceBeforeParenthesesSwitchParentheses = false;
/**
* Spaces before parentheses in for parentheses
*/
public boolean spaceBeforeParenthesesForParentheses = false;
/**
* Spaces before parentheses in foreach parentheses
*/
public boolean spaceBeforeParenthesesForEachParentheses = false;
// around operators
public boolean spaceAroundOperatorsAssignmentOperators = false; // =, +=,...
/**
* Spaces around assignment operators.
* =, +=, ...
*/
public boolean spaceAroundOperatorsAssignmentOperators = false;
public boolean spaceAroundOperatorsLogicalOperators = false; // &&, ||
/**
* Spaces around logical operators.
* &&, ||
*/
public boolean spaceAroundOperatorsLogicalOperators = false;
public boolean spaceAroundOperatorsEqualityOperators = false; // ==, !=
/**
* Spaces around equality operators.
* ==, !=
*/
public boolean spaceAroundOperatorsEqualityOperators = false;
public boolean spaceAroundOperatorsRelationalOperator = false; // <, >, <=, >=
/**
* Spaces around relational operators.
* &lt;, &gt;, &lt;=, &gt;=
*/
public boolean spaceAroundOperatorsRelationalOperator = false;
public boolean spaceAroundOperatorsBitwiseOperator = false; // &, |, ^
/**
* Spaces around bitwise operators.
* &amp;, |, ^
*/
public boolean spaceAroundOperatorsBitwiseOperator = false;
public boolean spaceAroundOperatorsAdditiveOperator = false; // +, -
/**
* Spaces around additive operators.
* +, -
*/
public boolean spaceAroundOperatorsAdditiveOperator = false;
public boolean spaceAroundOperatorsMultiplicativeOperator = false; // *, /, %
/**
* Spaces around multiplicative operators.
* *, /, %
*/
public boolean spaceAroundOperatorsMultiplicativeOperator = false;
public boolean spaceAroundOperatorsShiftOperator = false; // <<, >>
/**
* Spaces around shift operators.
* &lt;&lt;, &gt;&gt;
*/
public boolean spaceAroundOperatorsShiftOperator = false;
/**
* Constructor.
*/
public CodeFormatting() {
}
}
@@ -25,6 +25,11 @@ import java.io.FileOutputStream;
*/
public class FileTextWriter extends StreamTextWriter implements AutoCloseable {
/**
* Constructor.
* @param formatting Code formatting
* @param os Output stream
*/
public FileTextWriter(CodeFormatting formatting, FileOutputStream os) {
super(formatting, os);
}
@@ -49,7 +49,7 @@ public class FontHelper {
return clFmFactory.getDeclaredMethod("getInstance").invoke(null);
}*/
/**
* Gets all available fonts in the system
* Gets all available fonts in the system.
*
* @return Map of FamilyName to Map FontName to Font
*/
@@ -107,6 +107,11 @@ public class FontHelper {
return ret;
}
/**
* Converts font to string.
* @param font Font
* @return String
*/
public static String fontToString(Font font) {
int style = font.getStyle();
String styleString;
@@ -128,12 +133,17 @@ public class FontHelper {
return font.getName() + "-" + styleString + "-" + font.getSize();
}
/**
* Converts string to font.
* @param fontString String
* @return Font
*/
public static Font stringToFont(String fontString) {
return Font.decode(fontString);
}
/**
* Gets kerning offset for two characters of the font
* Gets kerning offset for two characters of the font.
*
* @param font Font
* @param char1 First character
@@ -159,6 +169,12 @@ public class FontHelper {
return withKerningX - noKerningX;
}
/**
* Gets kerning pairs for the font.
* @param fontFile Font file
* @param size Size
* @return List of kerning pairs
*/
public static List<KerningPair> getFontKerningPairs(File fontFile, int size) {
KerningLoader k = new KerningLoader();
@@ -219,14 +235,32 @@ public class FontHelper {
return ret;
}
/**
* Kerning pair.
*/
public static class KerningPair {
/**
* First character
*/
public final char char1;
/**
* Second character
*/
public final char char2;
/**
* Kerning
*/
public int kerning;
/**
* Constructor.
* @param char1 First character
* @param char2 Second character
* @param kerning Kerning
*/
public KerningPair(char char1, char char2, int kerning) {
this.char1 = char1;
this.char2 = char2;
@@ -288,6 +322,10 @@ public class FontHelper {
}
}*/
/**
* Gets installed font files.
* @return Map of FamilyName to Map FontName to File
*/
public static Map<String, Map<String, File>> getInstalledFontFiles() {
Map<String, Map<String, File>> ret = new HashMap<>();
@@ -23,7 +23,15 @@ package com.jpexs.decompiler.flash.helpers;
*/
public interface Freed {
/**
* Returns true if the object is being freed.
*
* @return true if the object is being freed
*/
public boolean isFreeing();
/**
* Frees the object.
*/
public void free();
}
@@ -26,11 +26,23 @@ import com.jpexs.decompiler.graph.GraphSourceItem;
*/
public class GraphSourceItemPosition {
/**
* Graph source item.
*/
public GraphSourceItem graphSourceItem;
/**
* Position
*/
public int position;
/**
* Start line item
*/
public GraphSourceItem startLineItem;
/**
* Data
*/
public HighlightData data;
}
@@ -27,29 +27,62 @@ import com.jpexs.decompiler.graph.GraphSourceItem;
*/
public abstract class GraphTextWriter {
/**
* Start time
*/
protected long startTime;
/**
* Suspend time
*/
protected long suspendTime;
/**
* Code formatting
*/
protected CodeFormatting formatting;
/**
* Trait index - instance initializer
*/
public static final int TRAIT_INSTANCE_INITIALIZER = -1;
/**
* Trait index - class initializer
*/
public static final int TRAIT_CLASS_INITIALIZER = -2;
/**
* Trait index - script initializer
*/
public static final int TRAIT_SCRIPT_INITIALIZER = -3;
/**
* Trait index - unknown
*/
public static final int TRAIT_UNKNOWN = -4;
/**
* Gets code formatting
* @return Code formatting
*/
public CodeFormatting getFormatting() {
return formatting;
}
/**
* Constructor.
* @param formatting Code formatting
*/
public GraphTextWriter(CodeFormatting formatting) {
startTime = System.currentTimeMillis();
this.formatting = formatting;
}
/**
* Gets is highlighted.
* @return Is highlighted
*/
public boolean getIsHighlighted() {
return false;
}
@@ -57,16 +90,20 @@ public abstract class GraphTextWriter {
/**
* Highlights specified text as instruction
*
* @param src
* @param startLineItem
* @param src Graph source item
* @param startLineItem Start line item
* @param pos Offset of instruction
* @param data
* @param data Highlight data
* @return GraphTextWriter
*/
public GraphTextWriter startOffset(GraphSourceItem src, GraphSourceItem startLineItem, int pos, HighlightData data) {
return this;
}
/**
* Ends offset.
* @return GraphTextWriter
*/
public GraphTextWriter endOffset() {
return this;
}
@@ -75,7 +112,7 @@ public abstract class GraphTextWriter {
* Highlights specified text as method
*
* @param index MethodInfo index
* @param name
* @param name Method name
* @return GraphTextWriter
*/
public GraphTextWriter startMethod(long index, String name) {
@@ -92,10 +129,18 @@ public abstract class GraphTextWriter {
return this;
}
/**
* Ends method.
* @return
*/
public GraphTextWriter endMethod() {
return this;
}
/**
* Ends function.
* @return
*/
public GraphTextWriter endFunction() {
return this;
}
@@ -110,10 +155,19 @@ public abstract class GraphTextWriter {
return this;
}
/**
* Highlights specified text as class
* @param className Class name
* @return GraphTextWriter
*/
public GraphTextWriter startClass(String className) {
return this;
}
/**
* Ends class.
* @return GraphTextWriter
*/
public GraphTextWriter endClass() {
return this;
}
@@ -128,84 +182,203 @@ public abstract class GraphTextWriter {
return this;
}
/**
* Ends trait.
* @return GraphTextWriter
*/
public GraphTextWriter endTrait() {
return this;
}
/**
* Hilights special type.
* @param text Text
* @param type Highlight special type
* @return GraphTextWriter
*/
public final GraphTextWriter hilightSpecial(String text, HighlightSpecialType type) {
return hilightSpecial(text, type, "");
}
/**
* Hilights special type.
* @param text Text
* @param type Highlight special type
* @param specialValue Special value
* @return GraphTextWriter
*/
public final GraphTextWriter hilightSpecial(String text, HighlightSpecialType type, int specialValue) {
return hilightSpecial(text, type, Integer.toString(specialValue), null);
}
/**
* Hilights special type.
* @param text Text
* @param type Highlight special type
* @param specialValue Special value
* @return GraphTextWriter
*/
public final GraphTextWriter hilightSpecial(String text, HighlightSpecialType type, int specialValue, HighlightData data) {
return hilightSpecial(text, type, Integer.toString(specialValue), data);
}
/**
* Hilights special type.
* @param text Text
* @param type Highlight special type
* @param specialValue Special value
* @return GraphTextWriter
*/
public final GraphTextWriter hilightSpecial(String text, HighlightSpecialType type, String specialValue) {
return hilightSpecial(text, type, specialValue, null);
}
/**
* Hilights special type.
* @param text Text
* @param type Highlight special type
* @param specialValue Special value
* @param data Highlight data
* @return GraphTextWriter
*/
protected GraphTextWriter hilightSpecial(String text, HighlightSpecialType type, String specialValue, HighlightData data) {
return this;
}
/**
* Hilights offset.
* @param text Text
* @param offset Offset
* @return GraphTextWriter
*/
public static String hilighOffset(String text, long offset) {
return "";
}
/**
* Appends text with data.
* @param str Text
* @param data Highlight data
* @return GraphTextWriter
*/
public abstract GraphTextWriter appendWithData(String str, HighlightData data);
/**
* Appends text.
* @param value Value
* @return GraphTextWriter
*/
public GraphTextWriter append(char value) {
return append(Character.toString(value));
}
/**
* Appends text.
* @param value Value
* @return GraphTextWriter
*/
public GraphTextWriter append(int value) {
return append(Integer.toString(value));
}
/**
* Appends text.
* @param value Value
* @return GraphTextWriter
*/
public GraphTextWriter append(long value) {
return append(Long.toString(value));
}
/**
* Appends text.
* @param value Value
* @return GraphTextWriter
*/
public GraphTextWriter append(double value) {
return append(Double.toString(value));
}
/**
* Appends text.
* @param str Text
* @return GraphTextWriter
*/
public abstract GraphTextWriter append(String str);
/**
* Appends text.
* @param str Text
* @param offset Offset
* @param fileOffset File offset
* @return GraphTextWriter
*/
public abstract GraphTextWriter append(String str, long offset, long fileOffset);
/**
* Appends text without highlight.
* @param i Text
* @return GraphTextWriter
*/
public abstract GraphTextWriter appendNoHilight(int i);
/**
* Appends text without highlight.
* @param str Text
* @return GraphTextWriter
*/
public abstract GraphTextWriter appendNoHilight(String str);
/**
* Indents text.
* @return GraphTextWriter
*/
public GraphTextWriter indent() {
return this;
}
/**
* Unindents text.
* @return GraphTextWriter
*/
public GraphTextWriter unindent() {
return this;
}
/**
* New line.
* @return GraphTextWriter
*/
public GraphTextWriter newLine() {
return this;
}
/**
* Gets length.
* @return Length
*/
public int getLength() {
return 0;
}
/**
* Gets indent.
* @return Indent
*/
public int getIndent() {
return 0;
}
/**
* Suspends measure.
*/
public void suspendMeasure() {
suspendTime = System.currentTimeMillis();
}
/**
* Continues measure.
*/
public void continueMeasure() {
long time = System.currentTimeMillis();
startTime += time - suspendTime;
@@ -225,22 +398,44 @@ public abstract class GraphTextWriter {
return append(opening).newLine().indent();
}
/**
* Starts block.
* @return GraphTextWriter
*/
public GraphTextWriter startBlock() {
return startBlock("{");
}
/**
* Ends block.
* @param closing Closing
* @return GraphTextWriter
*/
private GraphTextWriter endBlock(String closing) {
return unindent().append(closing);
}
/**
* Ends block.
* @return GraphTextWriter
*/
public GraphTextWriter endBlock() {
return endBlock("}");
}
/**
* Space
* @return GraphTextWriter
*/
public GraphTextWriter space() {
return append(" ");
}
/**
* Space before call parenthesies.
* @param argCount Argument count
* @return GraphTextWriter
*/
public GraphTextWriter spaceBeforeCallParenthesies(int argCount) {
if (argCount > 0) {
if (formatting.spaceBeforeParenthesesMethodCallParentheses) {
@@ -252,6 +447,11 @@ public abstract class GraphTextWriter {
return this;
}
/**
* Adds current method data.
* @param data Highlight data
* @return GraphTextWriter
*/
public GraphTextWriter addCurrentMethodData(HighlightData data) {
return this;
}
@@ -26,8 +26,14 @@ import java.io.Serializable;
*/
public class HighlightedText implements Serializable {
/**
* Empty highlighted text
*/
public static HighlightedText EMPTY = new HighlightedText();
/**
* Text
*/
public String text;
private final HighlightingList traitHighlights;
@@ -40,26 +46,50 @@ public class HighlightedText implements Serializable {
private final HighlightingList specialHighlights;
/**
* Gets trait highlights
* @return Trait highlights
*/
public HighlightingList getTraitHighlights() {
return traitHighlights;
}
/**
* Gets method highlights
* @return Method highlights
*/
public HighlightingList getMethodHighlights() {
return methodHighlights;
}
/**
* Gets class highlights
* @return Class highlights
*/
public HighlightingList getClassHighlights() {
return classHighlights;
}
/**
* Gets instruction highlights
* @return Instruction highlights
*/
public HighlightingList getInstructionHighlights() {
return instructionHighlights;
}
/**
* Gets special highlights
* @return Special highlights
*/
public HighlightingList getSpecialHighlights() {
return specialHighlights;
}
/**
* Constructor.
* @param writer Writer
*/
public HighlightedText(HighlightedTextWriter writer) {
this.text = writer.toString();
this.traitHighlights = writer.traitHilights;
@@ -73,6 +103,10 @@ public class HighlightedText implements Serializable {
this("");
}
/**
* Constructor.
* @param text Text
*/
public HighlightedText(String text) {
this.text = text;
this.traitHighlights = new HighlightingList();
@@ -49,16 +49,34 @@ public class HighlightedTextWriter extends GraphTextWriter {
private final Stack<Highlighting> hilightStack = new Stack<>();
/**
* Trait hilights
*/
public HighlightingList traitHilights = new HighlightingList();
/**
* Class hilights
*/
public HighlightingList classHilights = new HighlightingList();
/**
* Method hilights
*/
public HighlightingList methodHilights = new HighlightingList();
/**
* Instruction hilights
*/
public HighlightingList instructionHilights = new HighlightingList();
/**
* Special hilights
*/
public HighlightingList specialHilights = new HighlightingList();
/**
* Finish hilights.
*/
public void finishHilights() {
traitHilights.finish();
classHilights.finish();
@@ -67,11 +85,22 @@ public class HighlightedTextWriter extends GraphTextWriter {
specialHilights.finish();
}
/**
* Constructor.
* @param formatting Code formatting
* @param hilight If true, text will be highlighted
*/
public HighlightedTextWriter(CodeFormatting formatting, boolean hilight) {
super(formatting);
this.hilight = hilight;
}
/**
* Constructor.
* @param formatting Code formatting
* @param hilight If true, text will be highlighted
* @param indent Indent
*/
public HighlightedTextWriter(CodeFormatting formatting, boolean hilight, int indent) {
super(formatting);
this.hilight = hilight;
@@ -51,10 +51,21 @@ public class ImageHelper {
ImageIO.setUseCache(false);
}
/**
* Reads image from byte array.
* @param data Image data
* @return Image
*/
public static BufferedImage read(byte[] data) throws IOException {
return read(new ByteArrayInputStream(data));
}
/**
* Reads image from input stream.
* @param input Input stream
* @return Image
* @throws IOException On I/O error
*/
public static BufferedImage read(InputStream input) throws IOException {
BufferedImage in;
byte[] data = Helper.readStream(input);
@@ -92,6 +103,13 @@ public class ImageHelper {
return in;
}
/**
* Writes image to file.
* @param image Image
* @param format Image format
* @param output Output file
* @throws IOException On I/O error
*/
public static void write(BufferedImage image, ImageFormat format, File output) throws IOException {
String formatName = getImageFormatString(format).toUpperCase(Locale.ENGLISH);
if (format == ImageFormat.JPEG) {
@@ -101,6 +119,13 @@ public class ImageHelper {
ImageIO.write(image, formatName, output);
}
/**
* Writes image to output stream.
* @param image Image
* @param format Image format
* @param output Output stream
* @throws IOException On I/O error
*/
public static void write(BufferedImage image, ImageFormat format, OutputStream output) throws IOException {
String formatName = getImageFormatString(format).toUpperCase(Locale.ENGLISH);
if (format == ImageFormat.JPEG) {
@@ -110,6 +135,12 @@ public class ImageHelper {
ImageIO.write(image, formatName, output);
}
/**
* Writes image to byte array.
* @param image Image
* @param format Image format
* @param output Output byte array
*/
public static void write(BufferedImage image, ImageFormat format, ByteArrayOutputStream output) {
String formatName = getImageFormatString(format).toUpperCase(Locale.ENGLISH);
if (format == ImageFormat.JPEG) {
@@ -178,6 +209,11 @@ public class ImageHelper {
return image;
}
/**
* Gets image format string.
* @param format Image format
* @return Image format string
*/
public static String getImageFormatString(ImageFormat format) {
switch (format) {
case UNKNOWN:
@@ -195,7 +231,13 @@ public class ImageHelper {
throw new Error("Unsuported image format: " + format);
}
public static Dimension getDimesion(InputStream input) throws IOException {
/**
* Gets image dimension.
* @param input Input stream
* @return Image dimension
* @throws IOException On I/O error
*/
public static Dimension getDimension(InputStream input) throws IOException {
try (ImageInputStream in = ImageIO.createImageInputStream(input)) {
final Iterator<ImageReader> readers = ImageIO.getImageReaders(in);
if (readers.hasNext()) {
@@ -23,5 +23,8 @@ package com.jpexs.decompiler.flash.helpers;
*/
public interface LazyObject {
/**
* Loads the object.
*/
public void load();
}
@@ -23,13 +23,28 @@ package com.jpexs.decompiler.flash.helpers;
*/
public class LoopWithType {
/**
* Loop type - loop
*/
public static int LOOP_TYPE_LOOP = 0;
/**
* Loop type - switch
*/
public static int LOOP_TYPE_SWITCH = 1;
/**
* Loop id
*/
public long loopId;
/**
* Loop type
*/
public int type;
/**
* Used flag
*/
public boolean used;
}
@@ -37,6 +37,11 @@ public class NulWriter extends GraphTextWriter {
super(new CodeFormatting());
}
/**
* Starts a new loop.
* @param loopId Loop id
* @param loopType Loop type
*/
public void startLoop(long loopId, int loopType) {
LoopWithType loop = new LoopWithType();
loop.loopId = loopId;
@@ -44,6 +49,11 @@ public class NulWriter extends GraphTextWriter {
loopStack.add(loop);
}
/**
* Ends a loop.
* @param loopId Loop id
* @return LoopWithType
*/
public LoopWithType endLoop(long loopId) {
LoopWithType loopIdInStack = loopStack.pop();
if (loopId != loopIdInStack.loopId) {
@@ -52,6 +62,10 @@ public class NulWriter extends GraphTextWriter {
return loopIdInStack;
}
/**
* Gets the current loop id.
* @return Loop id
*/
public long getLoop() {
if (loopStack.isEmpty()) {
return -1;
@@ -59,6 +73,10 @@ public class NulWriter extends GraphTextWriter {
return loopStack.peek().loopId;
}
/**
* Gets the current non-switch loop id.
* @return Loop id
*/
public long getNonSwitchLoop() {
if (loopStack.isEmpty()) {
return -1;
@@ -78,6 +96,10 @@ public class NulWriter extends GraphTextWriter {
return loop.loopId;
}
/**
* Sets the loop as used.
* @param loopId Loop id
*/
public void setLoopUsed(long loopId) {
if (loopStack.isEmpty()) {
return;
@@ -149,11 +171,18 @@ public class NulWriter extends GraphTextWriter {
return this;
}
/**
* Creates mark.
*/
public void mark() {
stringAddedStack.add(stringAdded);
stringAdded = false;
}
/**
* Gets the mark.
* @return Mark
*/
public boolean getMark() {
boolean result = stringAdded;
stringAdded = stringAddedStack.pop() || result;
@@ -56,6 +56,10 @@ public class SWFDecompilerPlugin {
public static String[] customParameters = new String[0];
/**
* Get plugins directory.
* @return Plugins directory
*/
public static File getPluginsDir() {
File pluginPath = null;
@@ -76,6 +80,9 @@ public class SWFDecompilerPlugin {
return pluginPath;
}
/**
* Load plugins
*/
public static void loadPlugins() {
File pluginPath = getPluginsDir();
if (pluginPath != null && pluginPath.exists()) {
@@ -91,6 +98,10 @@ public class SWFDecompilerPlugin {
}
/**
* Load plugin from path.
* @param path Path to plugin
*/
public static void loadPlugin(String path) {
if (".class".equals(Path.getExtension(path))) {
loadPluginCompiled(path);
@@ -176,6 +187,11 @@ public class SWFDecompilerPlugin {
}
}
/**
* Fire plugin method proxyFileCatched.
* @param data Data
* @return Result
*/
public static byte[] fireProxyFileCatched(byte[] data) {
byte[] result = null;
for (SWFDecompilerListener listener : listeners) {
@@ -194,6 +210,11 @@ public class SWFDecompilerPlugin {
return result;
}
/**
* Fire plugin method swfParsed.
* @param swf SWF
* @return Result
*/
public static boolean fireSwfParsed(SWF swf) {
for (SWFDecompilerListener listener : listeners) {
try {
@@ -207,6 +228,13 @@ public class SWFDecompilerPlugin {
return !listeners.isEmpty();
}
/**
* Fire plugin method actionListParsed.
* @param actions Action list
* @param swf SWF
* @return Result
* @throws InterruptedException On interrupt
*/
public static boolean fireActionListParsed(ActionList actions, SWF swf) throws InterruptedException {
for (SWFDecompilerListener listener : listeners) {
try {
@@ -220,6 +248,13 @@ public class SWFDecompilerPlugin {
return !listeners.isEmpty();
}
/**
* Fire plugin method actionTreeCreated.
* @param tree Tree
* @param swf SWF
* @return Result
* @throws InterruptedException On interrupt
*/
public static boolean fireActionTreeCreated(List<GraphTargetItem> tree, SWF swf) throws InterruptedException {
for (SWFDecompilerListener listener : listeners) {
try {
@@ -233,6 +268,12 @@ public class SWFDecompilerPlugin {
return !listeners.isEmpty();
}
/**
* Fire plugin method abcParsed.
* @param abc ABC
* @param swf SWF
* @return Result
*/
public static boolean fireAbcParsed(ABC abc, SWF swf) {
for (SWFDecompilerListener listener : listeners) {
try {
@@ -246,6 +287,13 @@ public class SWFDecompilerPlugin {
return !listeners.isEmpty();
}
/**
* Fire plugin method methodBodyParsed.
* @param abc ABC
* @param body Method body
* @param swf SWF
* @return Result
*/
public static boolean fireMethodBodyParsed(ABC abc, MethodBody body, SWF swf) {
for (SWFDecompilerListener listener : listeners) {
try {
@@ -259,6 +307,19 @@ public class SWFDecompilerPlugin {
return !listeners.isEmpty();
}
/**
* Fire plugin method avm2CodeRemoveTraps.
* @param path Path
* @param classIndex Class index
* @param isStatic Is static
* @param scriptIndex Script index
* @param abc ABC
* @param trait Trait
* @param methodInfo Method info
* @param body Method body
* @return Result
* @throws InterruptedException On interrupt
*/
public static boolean fireAvm2CodeRemoveTraps(String path, int classIndex, boolean isStatic, int scriptIndex, ABC abc, Trait trait, int methodInfo, MethodBody body) throws InterruptedException {
for (SWFDecompilerListener listener : listeners) {
try {
@@ -41,6 +41,11 @@ public class StreamTextWriter extends GraphTextWriter implements AutoCloseable {
private int writtenBytes;
/**
* Constructor.
* @param formatting Code formatting
* @param os Output stream
*/
public StreamTextWriter(CodeFormatting formatting, OutputStream os) {
super(formatting);
this.writer = new Utf8OutputStreamWriter(new BufferedOutputStream(os));
@@ -34,6 +34,11 @@ public class StringBuilderTextWriter extends GraphTextWriter {
private int writtenBytes;
/**
* Constructor.
* @param formatting Code formatting
* @param writer StringBuilder to write to
*/
public StringBuilderTextWriter(CodeFormatting formatting, StringBuilder writer) {
super(formatting);
this.writer = writer;
@@ -27,9 +27,17 @@ public class FixItemCounterStack extends Stack<Object> {
private int fixItemCount = Integer.MAX_VALUE;
/**
* Constructor.
*/
public FixItemCounterStack() {
}
/**
* Peeks the item at the specified index.
* @param index Index
* @return Item
*/
public Object peek(int index) {
return super.get(size() - index);
}
@@ -52,10 +60,18 @@ public class FixItemCounterStack extends Stack<Object> {
return super.remove(index);
}
/**
* Returns true if all items are fixed.
* @return True if all items are fixed
*/
public boolean allItemsFixed() {
return size() <= fixItemCount;
}
/**
* Returns the fixed item count.
* @return Fixed item count
*/
public int getFixItemCount() {
return fixItemCount;
}
@@ -33,6 +33,12 @@ public class MyEntry<K, V> implements Entry<K, V>, Serializable {
private V value;
/**
* Constructor.
*
* @param key Key
* @param value Value
*/
public MyEntry(K key, V value) {
this.key = key;
this.value = value;
@@ -31,6 +31,9 @@ import java.util.Set;
*/
public class MyMap<K, V> implements Map<K, V> {
/**
* List of key-value pairs.
*/
List<MyEntry<K, V>> values = new ArrayList<>();
@Override
@@ -30,6 +30,9 @@ import java.util.Set;
*/
public class MySet<T> implements Set<T> {
/**
* List of items.
*/
List<T> items = new ArrayList<>();
@Override
@@ -26,36 +26,85 @@ import java.io.Serializable;
*/
public class HighlightData implements Cloneable, Serializable {
/**
* Declaration flag
*/
public boolean declaration;
/**
* Declared type
*/
public DottedChain declaredType;
/**
* Local name
*/
public String localName;
/**
* Subtype
*/
public HighlightSpecialType subtype;
/**
* Special value
*/
public String specialValue;
/**
* Index
*/
public long index;
/**
* Offset
*/
public long offset;
/**
* File offset
*/
public long fileOffset = -1;
/**
* First line offset
*/
public long firstLineOffset = -1;
/**
* Register index
*/
public int regIndex = -1;
/**
* Namespace index
*/
public int namespaceIndex = -1;
/**
* Activation register index
*/
public int activationRegIndex = -1;
/**
* Is static
*/
public boolean isStatic = false;
/**
* Property type
*/
public String propertyType;
/**
* Property subtype
*/
public String propertySubType;
/**
* Checks if the data is empty.
* @return True if the data is empty, false otherwise.
*/
public boolean isEmpty() {
return !declaration && declaredType == null && localName == null
&& subtype == null && specialValue == null
@@ -67,6 +116,10 @@ public class HighlightData implements Cloneable, Serializable {
&& activationRegIndex == -1;
}
/**
* Merges the data.
* @param data Data to merge.
*/
public void merge(HighlightData data) {
if (data == null) {
return;
@@ -23,14 +23,136 @@ package com.jpexs.decompiler.flash.helpers.hilight;
*/
public enum HighlightSpecialType {
PARAM_NAME, PARAM, OPTIONAL, RETURNS,
TYPE_NAME, CLASS_NAME, METHOD_NAME,
TRAIT_TYPE, TRAIT_NAME, TRAIT_TYPE_NAME, TRAIT_VALUE,
SLOT_ID, DISP_ID,
FLAG_NEED_REST, FLAG_NATIVE, FLAG_HAS_OPTIONAL, FLAG_HAS_PARAM_NAMES,
FLAG_IGNORE_REST, FLAG_NEED_ACTIVATION, FLAG_NEED_ARGUMENTS, FLAG_SET_DXNS,
TRY_TYPE, TRY_NAME,
/**
* Parameter name
*/
PARAM_NAME,
/**
* Parameter
*/
PARAM,
/**
* Optional
*/
OPTIONAL,
/**
* Returns
*/
RETURNS,
/**
* Type name
*/
TYPE_NAME,
/**
* Class name
*/
CLASS_NAME,
/**
* Method name
*/
METHOD_NAME,
/**
* Trait type
*/
TRAIT_TYPE,
/**
* Trait name
*/
TRAIT_NAME,
/**
* Trait type name
*/
TRAIT_TYPE_NAME,
/**
* Trait value
*/
TRAIT_VALUE,
/**
* Slot id
*/
SLOT_ID,
/**
* Dispatch id
*/
DISP_ID,
/**
* Flag need rest
*/
FLAG_NEED_REST,
/**
* Flag native
*/
FLAG_NATIVE,
/**
* Flag has optional
*/
FLAG_HAS_OPTIONAL,
/**
* Flag has param names
*/
FLAG_HAS_PARAM_NAMES,
/**
* Flag ignore rest
*/
FLAG_IGNORE_REST,
/**
* Flag need activation
*/
FLAG_NEED_ACTIVATION,
/**
* Flag need arguments
*/
FLAG_NEED_ARGUMENTS,
/**
* Flag set dxns
*/
FLAG_SET_DXNS,
/**
* Try type
*/
TRY_TYPE,
/**
* Try name
*/
TRY_NAME,
/**
* Text
*/
TEXT,
ATTR_METADATA, ATTR_FINAL, ATTR_OVERRIDE, ATTR_0x8,
PROPERTY_TYPE, INSTANCE_NAME, IMPLEMENTS, EXTENDS, PROTECTEDNS
/**
* Attr metadata
*/
ATTR_METADATA,
/**
* Attr final
*/
ATTR_FINAL,
/**
* Attr override
*/
ATTR_OVERRIDE,
/**
* Attr 0x8
*/
ATTR_0x8,
/**
* Property type
*/
PROPERTY_TYPE,
/**
* Instance name
*/
INSTANCE_NAME,
/**
* Implements
*/
IMPLEMENTS,
/**
* Extends
*/
EXTENDS,
/**
* Protected namespace
*/
PROTECTEDNS
}
@@ -23,5 +23,24 @@ package com.jpexs.decompiler.flash.helpers.hilight;
*/
public enum HighlightType {
TRAIT, CLASS, METHOD, OFFSET, SPECIAL
/**
* Trait
*/
TRAIT,
/**
* Class
*/
CLASS,
/**
* Method
*/
METHOD,
/**
* Offset
*/
OFFSET,
/**
* Special
*/
SPECIAL
}
@@ -18,9 +18,6 @@ package com.jpexs.decompiler.flash.helpers.hilight;
import com.jpexs.decompiler.flash.configuration.Configuration;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;
@@ -31,8 +28,14 @@ import java.util.WeakHashMap;
*/
public class Highlighting implements Serializable {
/**
* Type
*/
public HighlightType type;
/**
* Highlighted text
*/
public String HighlightedText;
/**
@@ -47,10 +50,22 @@ public class Highlighting implements Serializable {
private final HighlightData properties;
/**
* Gets properties.
* @return Properties
*/
public HighlightData getProperties() {
return properties;
}
/**
* Searches for a highlighting with the specified properties.
* @param list List of highlightings
* @param properties Highlighting properties
* @param from Starting position
* @param to Ending position
* @return Highlighting
*/
public static Highlighting search(HighlightingList list, HighlightData properties, long from, long to) {
Highlighting ret = null;
looph:
@@ -85,14 +100,36 @@ public class Highlighting implements Serializable {
return null;
}
/**
* Searches for a highlighting with the specified position.
* @param list List of highlightings
* @param pos Position
* @return Highlighting
*/
public static Highlighting searchPos(HighlightingList list, long pos) {
return searchPos(list, pos, -1, -1);
}
/**
* Searches for a highlighting with the specified position.
* @param list List of highlightings
* @param pos Position
* @param from Starting position
* @param to Ending position
* @return Highlighting
*/
public static Highlighting searchPos(HighlightingList list, long pos, long from, long to) {
return searchPosNew(list, pos, from, to);
}
/**
* Searches for a highlighting with the specified position. New version.
* @param list List of highlightings
* @param pos Position
* @param from Starting position
* @param to Ending position
* @return Highlighting
*/
public static Highlighting searchPosNew(HighlightingList list, long pos, long from, long to) {
Highlighting[] hmap = posToHighlightMap(list);
if (pos > -1) {
@@ -143,6 +180,7 @@ public class Highlighting implements Serializable {
return ret;
}*/
private static final Map<HighlightingList, Highlighting[]> listToPosMap = new WeakHashMap<>();
private static Highlighting[] posToHighlightMap(HighlightingList list) {
@@ -171,10 +209,24 @@ public class Highlighting implements Serializable {
return map;
}
/**
* Searches for a highlighting with the specified offset.
* @param list List of highlightings
* @param offset Offset
* @return Highlighting
*/
public static Highlighting searchOffset(HighlightingList list, long offset) {
return searchOffset(list, offset, -1, -1);
}
/**
* Searches for a highlighting with the specified offset.
* @param list List of highlightings
* @param offset Offset
* @param from Starting position
* @param to Ending position
* @return Highlighting
*/
public static Highlighting searchOffset(HighlightingList list, long offset, long from, long to) {
looph:
for (Highlighting h : list) {
@@ -198,10 +250,24 @@ public class Highlighting implements Serializable {
return null;
}
/**
* Searches for a highlighting with the specified index.
* @param list List of highlightings
* @param index Index
* @return Highlighting
*/
public static Highlighting searchIndex(HighlightingList list, long index) {
return searchIndex(list, index, -1, -1);
}
/**
* Searches for a highlighting with the specified index.
* @param list List of highlightings
* @param index Index
* @param from Starting position
* @param to Ending position
* @return Highlighting
*/
public static Highlighting searchIndex(HighlightingList list, long index, long from, long to) {
looph:
for (Highlighting h : list) {
@@ -225,6 +291,12 @@ public class Highlighting implements Serializable {
return null;
}
/**
* Searche all highlightings with the specified position.
* @param list List of highlightings
* @param pos Position
* @return List of highlightings
*/
public static HighlightingList searchAllPos(HighlightingList list, long pos) {
HighlightingList ret = new HighlightingList();
for (Highlighting h : list) {
@@ -236,6 +308,12 @@ public class Highlighting implements Serializable {
return ret;
}
/**
* Searche all highlightings with the specified index.
* @param list List of highlightings
* @param index Index
* @return List of highlightings
*/
public static HighlightingList searchAllIndexes(HighlightingList list, long index) {
HighlightingList ret = new HighlightingList();
for (Highlighting h : list) {
@@ -248,6 +326,13 @@ public class Highlighting implements Serializable {
return ret;
}
/**
* Searche all highlightings with the specified local name.
* @param list List of highlightings
* @param localName Local name
* @return List of highlightings
*/
public static HighlightingList searchAllLocalNames(HighlightingList list, String localName) {
HighlightingList ret = new HighlightingList();
for (Highlighting h : list) {
@@ -259,11 +344,6 @@ public class Highlighting implements Serializable {
return ret;
}
/**
* Returns a string representation of the object
*
* @return a string representation of the object.
*/
@Override
public String toString() {
return startPos + "-" + (startPos + len) + " type:" + type;
@@ -273,7 +353,7 @@ public class Highlighting implements Serializable {
* @param startPos Starting position
* @param data Highlighting data
* @param type Highlighting type
* @param text
* @param text Highlighted text
*/
public Highlighting(int startPos, HighlightData data, HighlightType type, String text) {
this.startPos = startPos;
@@ -30,10 +30,18 @@ public class HighlightingList extends ArrayList<Highlighting> {
private boolean finished = false;
/**
* Marks this list as finished, so no more elements can be added.
*/
public void finish() {
this.finished = true;
}
/**
* Returns true if this list is finished.
*
* @return true if this list is finished
*/
public boolean isFinished() {
return finished;
}