diff --git a/src/com/jpexs/decompiler/flash/SWF.java b/src/com/jpexs/decompiler/flash/SWF.java index 778768942..182c48888 100644 --- a/src/com/jpexs/decompiler/flash/SWF.java +++ b/src/com/jpexs/decompiler/flash/SWF.java @@ -236,8 +236,8 @@ public final class SWF implements TreeItem, Timelined { */ public int version; /** - * Uncompressed size of the file - */ + * Uncompressed size of the file + */ public long fileSize; /** * Used compression mode @@ -270,7 +270,7 @@ public final class SWF implements TreeItem, Timelined { public static final double unitDivisor = 20; private Timeline timeline; - + public DumpInfo dumpInfo; public void updateCharacters() { @@ -368,7 +368,7 @@ public final class SWF implements TreeItem, Timelined { public void saveTo(OutputStream os) throws IOException { saveTo(os, compression); } - + /** * Saves this SWF into new file * @@ -691,7 +691,7 @@ public final class SWF implements TreeItem, Timelined { return false; } } - + private static SWFHeader decompress(InputStream is, OutputStream os, boolean allowUncompressed) throws IOException { byte[] hdr = new byte[8]; @@ -735,7 +735,7 @@ public final class SWF implements TreeItem, Timelined { } case 'Z': { // ZWS sis.readUI32("LZMAsize"); // compressed LZMA data size = compressed SWF - 17 byte, - // where 17 = 8 byte header + this 4 byte + 5 bytes decoder properties + // where 17 = 8 byte header + this 4 byte + 5 bytes decoder properties int propertiesSize = 5; byte[] lzmaProperties = sis.readBytes(propertiesSize, "lzmaproperties"); if (lzmaProperties.length != propertiesSize) { @@ -760,7 +760,7 @@ public final class SWF implements TreeItem, Timelined { } } } - + return header; } } @@ -789,13 +789,13 @@ public final class SWF implements TreeItem, Timelined { abcTags.add(cnt); } } - + boolean exported = false; - + for (int i = 0; i < abcTags.size(); i++) { ABC abc = abcTags.get(i).getABC(); List scrs = abc.findScriptPacksByPath(className); - for(ScriptPack scr:scrs) { + for (ScriptPack scr : scrs) { String cnt = ""; if (abc.script_info.size() > 1) { cnt = "script " + (i + 1) + "/" + abc.script_info.size() + " "; @@ -804,11 +804,11 @@ public final class SWF implements TreeItem, Timelined { informListeners("exporting", exStr); scr.export(outdir, abcTags, exportMode, parallel); exStr = "Exported " + "tag " + (i + 1) + "/" + abcTags.size() + " " + cnt + scr.getPath() + " ..."; - informListeners("exported", exStr); + informListeners("exported", exStr); exported = true; - } + } } - return exported; + return exported; } private List> uniqueAS3Packs(List> packs) { @@ -1281,10 +1281,10 @@ public final class SWF implements TreeItem, Timelined { return; } try (ImageOutputStream output = new FileImageOutputStream(file)) { - BufferedImage img0=images.next(); + BufferedImage img0 = images.next(); GifSequenceWriter writer = new GifSequenceWriter(output, img0.getType(), 1000 / frameRate, true); writer.writeToSequence(img0); - + while (images.hasNext()) { writer.writeToSequence(images.next()); } @@ -1521,24 +1521,24 @@ public final class SWF implements TreeItem, Timelined { return ret; } - - final Timeline ftim=tim; - final Color fbackgroundColor=backgroundColor; + + final Timeline ftim = tim; + final Color fbackgroundColor = backgroundColor; final Iterator frameImages = new Iterator() { - private final int pos=0; - + private final int pos = 0; + @Override public boolean hasNext() { - return fframes.size()>pos; + return fframes.size() > pos; } @Override public BufferedImage next() { - if(!hasNext()){ + if (!hasNext()) { return null; } - return frameToImageGet(ftim, fframes.get(pos), 0, null, 0, ftim.displayRect, new Matrix(), new ColorTransform(), fbackgroundColor,false).getBufferedImage(); + return frameToImageGet(ftim, fframes.get(pos), 0, null, 0, ftim.displayRect, new Matrix(), new ColorTransform(), fbackgroundColor, false).getBufferedImage(); } }; @@ -2519,7 +2519,7 @@ public final class SWF implements TreeItem, Timelined { public static SerializableImage frameToImageGet(Timeline timeline, int frame, int time, DepthState stateUnderCursor, int mouseButton, RECT displayRect, Matrix transformation, ColorTransform colorTransform, Color backGroundColor, boolean useCache) { String key = "frame_" + frame + "_" + timeline.id + "_" + timeline.swf.hashCode(); SerializableImage image; - if(useCache){ + if (useCache) { image = getFromCache(key); if (image != null) { return image; @@ -2882,8 +2882,8 @@ public final class SWF implements TreeItem, Timelined { i--; continue; } - - if (toRemove instanceof CharacterTag){ + + if (toRemove instanceof CharacterTag) { if (t.removeCharacter(characterId)) { modified = true; i = -1; @@ -2902,7 +2902,7 @@ public final class SWF implements TreeItem, Timelined { } return modified; } - + public void removeTag(Tag t, boolean removeDependencies) { Timelined timelined = t.getTimelined(); if (t instanceof ShowFrameTag || ShowFrameTag.isNestedTagType(t.getId())) { @@ -2926,4 +2926,4 @@ public final class SWF implements TreeItem, Timelined { updateCharacters(); clearImageCache(); } -} \ No newline at end of file +} diff --git a/src/com/jpexs/decompiler/flash/SWFCompression.java b/src/com/jpexs/decompiler/flash/SWFCompression.java index 8b1530d15..96f625fa7 100644 --- a/src/com/jpexs/decompiler/flash/SWFCompression.java +++ b/src/com/jpexs/decompiler/flash/SWFCompression.java @@ -21,6 +21,6 @@ package com.jpexs.decompiler.flash; * @author JPEXS */ public enum SWFCompression { - + NONE, ZLIB, LZMA } diff --git a/src/com/jpexs/decompiler/flash/SWFHeader.java b/src/com/jpexs/decompiler/flash/SWFHeader.java index 889778223..8f5754154 100644 --- a/src/com/jpexs/decompiler/flash/SWFHeader.java +++ b/src/com/jpexs/decompiler/flash/SWFHeader.java @@ -21,12 +21,12 @@ package com.jpexs.decompiler.flash; * @author JPEXS */ public class SWFHeader { - + /** * Version of SWF */ public int version; - + /** * Uncompressed size of the file */ diff --git a/src/com/jpexs/decompiler/flash/SWFInputStream.java b/src/com/jpexs/decompiler/flash/SWFInputStream.java index cba8513a9..deadb555a 100644 --- a/src/com/jpexs/decompiler/flash/SWFInputStream.java +++ b/src/com/jpexs/decompiler/flash/SWFInputStream.java @@ -370,11 +370,11 @@ public class SWFInputStream implements AutoCloseable { dumpInfo = di; } } - + private void endDumpLevel() { endDumpLevel(null); } - + private void endDumpLevel(Object value) { if (dumpInfo != null) { if (dumpInfo.startBit == 0 && bitPos == 0) { @@ -386,7 +386,7 @@ public class SWFInputStream implements AutoCloseable { dumpInfo = dumpInfo.parent; } } - + /** * Reads one byte from the stream * @@ -401,7 +401,7 @@ public class SWFInputStream implements AutoCloseable { private void alignByte() { bitPos = 0; } - + private int lastPercent = -1; private int readNoBitReset() throws IOException, EndOfStreamException { @@ -695,6 +695,7 @@ public class SWFInputStream implements AutoCloseable { } return ret; } + /** * Skip bytes from the stream * @@ -806,7 +807,7 @@ public class SWFInputStream implements AutoCloseable { endDumpLevel(ret); return ret; } - + /** * Reads UB[nBits] (Unsigned-bit value) value from the stream * @@ -850,7 +851,7 @@ public class SWFInputStream implements AutoCloseable { endDumpLevel(ret); return ret; } - + /** * Reads SB[nBits] (Signed-bit value) value from the stream * @@ -1086,13 +1087,13 @@ public class SWFInputStream implements AutoCloseable { if (!(tag instanceof TagStub)) { return tag; } - + long pos = tag.getPos(); int length = tag.getOriginalLength(); SWF swf = tag.getSwf(); TagStub tagStub = (TagStub) tag; SWFInputStream sis = tagStub.getDataStream(); - + try { switch (tag.getId()) { case 0: @@ -3238,7 +3239,7 @@ public class SWFInputStream implements AutoCloseable { } return available() * 8; } - + public MemoryInputStream getBaseStream() throws IOException { int pos = (int) is.getPos(); return new MemoryInputStream(is.getAllRead(), pos, pos + is.available()); diff --git a/src/com/jpexs/decompiler/flash/SWFOutputStream.java b/src/com/jpexs/decompiler/flash/SWFOutputStream.java index 0e183bbaf..e660f16b2 100644 --- a/src/com/jpexs/decompiler/flash/SWFOutputStream.java +++ b/src/com/jpexs/decompiler/flash/SWFOutputStream.java @@ -427,7 +427,7 @@ public class SWFOutputStream extends OutputStream { tagPositions.put(tag, pos); tagLengths.put(tag, length); } - + // todo: honfika: update tag position and lengths. Currently the 2nd save fails } diff --git a/src/com/jpexs/decompiler/flash/abc/ABC.java b/src/com/jpexs/decompiler/flash/abc/ABC.java index 4bb36ca8e..eaf80995c 100644 --- a/src/com/jpexs/decompiler/flash/abc/ABC.java +++ b/src/com/jpexs/decompiler/flash/abc/ABC.java @@ -803,22 +803,22 @@ public class ABC { } } - private void checkMultinameUsedInMethod(List abcTags,int multinameIndex, int methodInfo, List ret, int classIndex, int traitIndex, boolean isStatic, boolean isInitializer, Traits traits, int parentTraitIndex) { + private void checkMultinameUsedInMethod(List abcTags, int multinameIndex, int methodInfo, List ret, int classIndex, int traitIndex, boolean isStatic, boolean isInitializer, Traits traits, int parentTraitIndex) { for (int p = 0; p < method_info.get(methodInfo).param_types.length; p++) { if (method_info.get(methodInfo).param_types[p] == multinameIndex) { - ret.add(new MethodParamsMultinameUsage(abcTags,this,multinameIndex, classIndex, traitIndex, isStatic, isInitializer, traits, parentTraitIndex)); + ret.add(new MethodParamsMultinameUsage(abcTags, this, multinameIndex, classIndex, traitIndex, isStatic, isInitializer, traits, parentTraitIndex)); break; } } if (method_info.get(methodInfo).ret_type == multinameIndex) { - ret.add(new MethodReturnTypeMultinameUsage(abcTags,this,multinameIndex, classIndex, traitIndex, isStatic, isInitializer, traits, parentTraitIndex)); + ret.add(new MethodReturnTypeMultinameUsage(abcTags, this, multinameIndex, classIndex, traitIndex, isStatic, isInitializer, traits, parentTraitIndex)); } MethodBody body = findBody(methodInfo); if (body != null) { - findMultinameUsageInTraits(abcTags,body.traits, multinameIndex, isStatic, classIndex, ret, traitIndex); + findMultinameUsageInTraits(abcTags, body.traits, multinameIndex, isStatic, classIndex, ret, traitIndex); for (ABCException e : body.exceptions) { if ((e.name_index == multinameIndex) || (e.type_index == multinameIndex)) { - ret.add(new MethodBodyMultinameUsage(abcTags,this,multinameIndex, classIndex, traitIndex, isStatic, isInitializer, traits, parentTraitIndex)); + ret.add(new MethodBodyMultinameUsage(abcTags, this, multinameIndex, classIndex, traitIndex, isStatic, isInitializer, traits, parentTraitIndex)); return; } } @@ -826,7 +826,7 @@ public class ABC { for (int o = 0; o < ins.definition.operands.length; o++) { if (ins.definition.operands[o] == AVM2Code.DAT_MULTINAME_INDEX) { if (ins.operands[o] == multinameIndex) { - ret.add(new MethodBodyMultinameUsage(abcTags,this,multinameIndex, classIndex, traitIndex, isStatic, isInitializer, traits, parentTraitIndex)); + ret.add(new MethodBodyMultinameUsage(abcTags, this, multinameIndex, classIndex, traitIndex, isStatic, isInitializer, traits, parentTraitIndex)); return; } } @@ -835,70 +835,70 @@ public class ABC { } } - private void findMultinameUsageInTraits(List abcTags,Traits traits, int multinameIndex, boolean isStatic, int classIndex, List ret, int parentTraitIndex) { + private void findMultinameUsageInTraits(List abcTags, Traits traits, int multinameIndex, boolean isStatic, int classIndex, List ret, int parentTraitIndex) { for (int t = 0; t < traits.traits.size(); t++) { if (traits.traits.get(t) instanceof TraitSlotConst) { TraitSlotConst tsc = (TraitSlotConst) traits.traits.get(t); if (tsc.name_index == multinameIndex) { - ret.add(new ConstVarNameMultinameUsage(abcTags,this,multinameIndex, classIndex, t, isStatic, traits, parentTraitIndex)); + ret.add(new ConstVarNameMultinameUsage(abcTags, this, multinameIndex, classIndex, t, isStatic, traits, parentTraitIndex)); } if (tsc.type_index == multinameIndex) { - ret.add(new ConstVarTypeMultinameUsage(abcTags,this,multinameIndex, classIndex, t, isStatic, traits, parentTraitIndex)); + ret.add(new ConstVarTypeMultinameUsage(abcTags, this, multinameIndex, classIndex, t, isStatic, traits, parentTraitIndex)); } } if (traits.traits.get(t) instanceof TraitMethodGetterSetter) { TraitMethodGetterSetter tmgs = (TraitMethodGetterSetter) traits.traits.get(t); if (tmgs.name_index == multinameIndex) { - ret.add(new MethodNameMultinameUsage(abcTags,this,multinameIndex, classIndex, t, isStatic, false, traits, parentTraitIndex)); + ret.add(new MethodNameMultinameUsage(abcTags, this, multinameIndex, classIndex, t, isStatic, false, traits, parentTraitIndex)); } - checkMultinameUsedInMethod(abcTags,multinameIndex, tmgs.method_info, ret, classIndex, t, isStatic, false, traits, parentTraitIndex); + checkMultinameUsedInMethod(abcTags, multinameIndex, tmgs.method_info, ret, classIndex, t, isStatic, false, traits, parentTraitIndex); } } } - public List findMultinameDefinition(List abcTags,int multinameIndex){ - List usages = findMultinameUsage(abcTags,multinameIndex); + public List findMultinameDefinition(List abcTags, int multinameIndex) { + List usages = findMultinameUsage(abcTags, multinameIndex); List ret = new ArrayList<>(); - for(MultinameUsage u:usages){ - if(u instanceof DefinitionUsage){ + for (MultinameUsage u : usages) { + if (u instanceof DefinitionUsage) { ret.add(u); } } return ret; } - - public List findMultinameUsage(List abcTags,int multinameIndex) { + + public List findMultinameUsage(List abcTags, int multinameIndex) { List ret = new ArrayList<>(); if (multinameIndex == 0) { return ret; } for (int c = 0; c < instance_info.size(); c++) { if (instance_info.get(c).name_index == multinameIndex) { - ret.add(new ClassNameMultinameUsage(abcTags,this,multinameIndex, c)); + ret.add(new ClassNameMultinameUsage(abcTags, this, multinameIndex, c)); } if (instance_info.get(c).super_index == multinameIndex) { - ret.add(new ExtendsMultinameUsage(abcTags,this,multinameIndex, c)); + ret.add(new ExtendsMultinameUsage(abcTags, this, multinameIndex, c)); } for (int i = 0; i < instance_info.get(c).interfaces.length; i++) { if (instance_info.get(c).interfaces[i] == multinameIndex) { - ret.add(new ImplementsMultinameUsage(abcTags,this,multinameIndex, c)); + ret.add(new ImplementsMultinameUsage(abcTags, this, multinameIndex, c)); } } - checkMultinameUsedInMethod(abcTags,multinameIndex, instance_info.get(c).iinit_index, ret, c, 0, false, true, null, -1); - checkMultinameUsedInMethod(abcTags,multinameIndex, class_info.get(c).cinit_index, ret, c, 0, true, true, null, -1); - findMultinameUsageInTraits(abcTags,instance_info.get(c).instance_traits, multinameIndex, false, c, ret, -1); - findMultinameUsageInTraits(abcTags,class_info.get(c).static_traits, multinameIndex, true, c, ret, -1); + checkMultinameUsedInMethod(abcTags, multinameIndex, instance_info.get(c).iinit_index, ret, c, 0, false, true, null, -1); + checkMultinameUsedInMethod(abcTags, multinameIndex, class_info.get(c).cinit_index, ret, c, 0, true, true, null, -1); + findMultinameUsageInTraits(abcTags, instance_info.get(c).instance_traits, multinameIndex, false, c, ret, -1); + findMultinameUsageInTraits(abcTags, class_info.get(c).static_traits, multinameIndex, true, c, ret, -1); } loopm: for (int m = 1; m < constants.getMultinameCount(); m++) { if (constants.getMultiname(m).kind == Multiname.TYPENAME) { if (constants.getMultiname(m).qname_index == multinameIndex) { - ret.add(new TypeNameMultinameUsage(abcTags,this,m)); + ret.add(new TypeNameMultinameUsage(abcTags, this, m)); continue; } for (int mp : constants.getMultiname(m).params) { if (mp == multinameIndex) { - ret.add(new TypeNameMultinameUsage(abcTags,this,m)); + ret.add(new TypeNameMultinameUsage(abcTags, this, m)); continue loopm; } } @@ -947,36 +947,36 @@ public class ABC { } return -1; } - + public List findScriptPacksByPath(String name) { List ret = new ArrayList<>(); List> allPacks = getScriptPacks(); - if(name.endsWith(".**")||name.equals("**")||name.endsWith(".++") || name.equals("++")){ - name = name.substring(0,name.length()-2); - + if (name.endsWith(".**") || name.equals("**") || name.endsWith(".++") || name.equals("++")) { + name = name.substring(0, name.length() - 2); + for (MyEntry en : allPacks) { if (en.key.toString().startsWith(name)) { ret.add(en.value); } } - } else if(name.endsWith(".*")||name.equals("*")||name.endsWith(".+")||name.equals("+")){ - name = name.substring(0,name.length()-1); + } else if (name.endsWith(".*") || name.equals("*") || name.endsWith(".+") || name.equals("+")) { + name = name.substring(0, name.length() - 1); for (MyEntry en : allPacks) { if (en.key.toString().startsWith(name)) { - String rem = name.isEmpty()?en.key.toString():en.key.toString().substring(name.length()); - if(!rem.contains(".")){ + String rem = name.isEmpty() ? en.key.toString() : en.key.toString().substring(name.length()); + if (!rem.contains(".")) { ret.add(en.value); } } } } else { ScriptPack p = findScriptPackByPath(name); - if(p!=null){ + if (p != null) { ret.add(p); - } + } } return ret; - + } public ScriptPack findScriptPackByPath(String name) { diff --git a/src/com/jpexs/decompiler/flash/abc/avm2/instructions/stack/PopIns.java b/src/com/jpexs/decompiler/flash/abc/avm2/instructions/stack/PopIns.java index 6f05aa7f8..85aff86d0 100644 --- a/src/com/jpexs/decompiler/flash/abc/avm2/instructions/stack/PopIns.java +++ b/src/com/jpexs/decompiler/flash/abc/avm2/instructions/stack/PopIns.java @@ -1,74 +1,74 @@ -/* - * Copyright (C) 2010-2014 JPEXS - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.jpexs.decompiler.flash.abc.avm2.instructions.stack; - -import com.jpexs.decompiler.flash.abc.ABC; -import com.jpexs.decompiler.flash.abc.avm2.AVM2Code; -import com.jpexs.decompiler.flash.abc.avm2.ConstantPool; -import com.jpexs.decompiler.flash.abc.avm2.LocalDataArea; -import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; -import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition; -import com.jpexs.decompiler.flash.abc.avm2.model.CallAVM2Item; -import com.jpexs.decompiler.flash.abc.avm2.model.CallMethodAVM2Item; -import com.jpexs.decompiler.flash.abc.avm2.model.CallPropertyAVM2Item; -import com.jpexs.decompiler.flash.abc.avm2.model.CallStaticAVM2Item; -import com.jpexs.decompiler.flash.abc.avm2.model.CallSuperAVM2Item; -import com.jpexs.decompiler.flash.abc.avm2.model.clauses.AssignmentAVM2Item; -import com.jpexs.decompiler.flash.abc.types.MethodBody; -import com.jpexs.decompiler.flash.abc.types.MethodInfo; -import com.jpexs.decompiler.graph.GraphTargetItem; -import java.util.HashMap; -import java.util.List; -import java.util.Stack; - -public class PopIns extends InstructionDefinition { - - public PopIns() { - super(0x29, "pop", new int[]{}); - } - - @Override - public void execute(LocalDataArea lda, ConstantPool constants, List arguments) { - lda.operandStack.pop(); - } - - @Override - public void translate(boolean isStatic, int scriptIndex, int classIndex, java.util.HashMap localRegs, Stack stack, java.util.Stack scopeStack, ConstantPool constants, AVM2Instruction ins, List method_info, List output, MethodBody body, ABC abc, HashMap localRegNames, List fullyQualifiedNames, String path, HashMap localRegsAssignmentIps, int ip, HashMap> refs, AVM2Code code) { - if (stack.size() > 0) { - GraphTargetItem top = stack.pop(); - //TODO: handle all values (#585) - beware collision with return inside finally block - if (top instanceof CallPropertyAVM2Item) { - output.add(top); - } else if (top instanceof CallSuperAVM2Item) { - output.add(top); - } else if (top instanceof CallStaticAVM2Item) { - output.add(top); - } else if (top instanceof CallMethodAVM2Item) { - output.add(top); - } else if (top instanceof CallAVM2Item) { - output.add(top); - } else if (top instanceof AssignmentAVM2Item) { - output.add(top); - } - } - } - - @Override - public int getStackDelta(AVM2Instruction ins, ABC abc) { - return -1; - } -} +/* + * Copyright (C) 2010-2014 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.decompiler.flash.abc.avm2.instructions.stack; + +import com.jpexs.decompiler.flash.abc.ABC; +import com.jpexs.decompiler.flash.abc.avm2.AVM2Code; +import com.jpexs.decompiler.flash.abc.avm2.ConstantPool; +import com.jpexs.decompiler.flash.abc.avm2.LocalDataArea; +import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; +import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition; +import com.jpexs.decompiler.flash.abc.avm2.model.CallAVM2Item; +import com.jpexs.decompiler.flash.abc.avm2.model.CallMethodAVM2Item; +import com.jpexs.decompiler.flash.abc.avm2.model.CallPropertyAVM2Item; +import com.jpexs.decompiler.flash.abc.avm2.model.CallStaticAVM2Item; +import com.jpexs.decompiler.flash.abc.avm2.model.CallSuperAVM2Item; +import com.jpexs.decompiler.flash.abc.avm2.model.clauses.AssignmentAVM2Item; +import com.jpexs.decompiler.flash.abc.types.MethodBody; +import com.jpexs.decompiler.flash.abc.types.MethodInfo; +import com.jpexs.decompiler.graph.GraphTargetItem; +import java.util.HashMap; +import java.util.List; +import java.util.Stack; + +public class PopIns extends InstructionDefinition { + + public PopIns() { + super(0x29, "pop", new int[]{}); + } + + @Override + public void execute(LocalDataArea lda, ConstantPool constants, List arguments) { + lda.operandStack.pop(); + } + + @Override + public void translate(boolean isStatic, int scriptIndex, int classIndex, java.util.HashMap localRegs, Stack stack, java.util.Stack scopeStack, ConstantPool constants, AVM2Instruction ins, List method_info, List output, MethodBody body, ABC abc, HashMap localRegNames, List fullyQualifiedNames, String path, HashMap localRegsAssignmentIps, int ip, HashMap> refs, AVM2Code code) { + if (stack.size() > 0) { + GraphTargetItem top = stack.pop(); + //TODO: handle all values (#585) - beware collision with return inside finally block + if (top instanceof CallPropertyAVM2Item) { + output.add(top); + } else if (top instanceof CallSuperAVM2Item) { + output.add(top); + } else if (top instanceof CallStaticAVM2Item) { + output.add(top); + } else if (top instanceof CallMethodAVM2Item) { + output.add(top); + } else if (top instanceof CallAVM2Item) { + output.add(top); + } else if (top instanceof AssignmentAVM2Item) { + output.add(top); + } + } + } + + @Override + public int getStackDelta(AVM2Instruction ins, ABC abc) { + return -1; + } +} diff --git a/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AVM2SourceGenerator.java b/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AVM2SourceGenerator.java index 3305ab6b5..c68f3aaf5 100644 --- a/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AVM2SourceGenerator.java +++ b/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AVM2SourceGenerator.java @@ -2424,10 +2424,9 @@ public class AVM2SourceGenerator implements SourceGenerator { @Override public List generateDiscardValue(SourceGeneratorLocalData localData, GraphTargetItem item) throws CompilationException { - List ret=item.toSource(localData, this); + List ret = item.toSource(localData, this); ret.add(ins(new PopIns())); return ret; } - - + } diff --git a/src/com/jpexs/decompiler/flash/abc/usages/ClassNameMultinameUsage.java b/src/com/jpexs/decompiler/flash/abc/usages/ClassNameMultinameUsage.java index 7b103abc9..308b228c7 100644 --- a/src/com/jpexs/decompiler/flash/abc/usages/ClassNameMultinameUsage.java +++ b/src/com/jpexs/decompiler/flash/abc/usages/ClassNameMultinameUsage.java @@ -1,37 +1,37 @@ -/* - * Copyright (C) 2010-2014 JPEXS - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.jpexs.decompiler.flash.abc.usages; - -import com.jpexs.decompiler.flash.abc.ABC; -import com.jpexs.decompiler.flash.tags.ABCContainerTag; -import java.util.List; - -/** - * - * @author JPEXS - */ -public class ClassNameMultinameUsage extends InsideClassMultinameUsage implements DefinitionUsage { - - public ClassNameMultinameUsage(List abcTags, ABC abc, int multinameIndex, int classIndex) { - super(abcTags,abc,multinameIndex, classIndex); - } - - @Override - public String toString() { - return "class " + abc.constants.getMultiname(abc.instance_info.get(classIndex).name_index).getNameWithNamespace(abc.constants); - } -} +/* + * Copyright (C) 2010-2014 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.decompiler.flash.abc.usages; + +import com.jpexs.decompiler.flash.abc.ABC; +import com.jpexs.decompiler.flash.tags.ABCContainerTag; +import java.util.List; + +/** + * + * @author JPEXS + */ +public class ClassNameMultinameUsage extends InsideClassMultinameUsage implements DefinitionUsage { + + public ClassNameMultinameUsage(List abcTags, ABC abc, int multinameIndex, int classIndex) { + super(abcTags, abc, multinameIndex, classIndex); + } + + @Override + public String toString() { + return "class " + abc.constants.getMultiname(abc.instance_info.get(classIndex).name_index).getNameWithNamespace(abc.constants); + } +} diff --git a/src/com/jpexs/decompiler/flash/abc/usages/ConstVarMultinameUsage.java b/src/com/jpexs/decompiler/flash/abc/usages/ConstVarMultinameUsage.java index 7cd58a207..c4f1b90a1 100644 --- a/src/com/jpexs/decompiler/flash/abc/usages/ConstVarMultinameUsage.java +++ b/src/com/jpexs/decompiler/flash/abc/usages/ConstVarMultinameUsage.java @@ -35,7 +35,7 @@ import java.util.List; public abstract class ConstVarMultinameUsage extends TraitMultinameUsage { public ConstVarMultinameUsage(List abcTags, ABC abc, int multinameIndex, int classIndex, int traitIndex, boolean isStatic, Traits traits, int parentTraitIndex) { - super(abcTags,abc,multinameIndex, classIndex, traitIndex, isStatic, traits, parentTraitIndex); + super(abcTags, abc, multinameIndex, classIndex, traitIndex, isStatic, traits, parentTraitIndex); } @Override @@ -66,7 +66,7 @@ public abstract class ConstVarMultinameUsage extends TraitMultinameUsage { try { ((TraitSlotConst) traits.traits.get(traitIndex)).toStringHeader(null, "", abcTags, abc, isStatic, ScriptExportMode.AS, -1/*FIXME*/, classIndex, writer, new ArrayList(), false); } catch (InterruptedException ex) { - //ignore + //ignore } return writer.toString(); } diff --git a/src/com/jpexs/decompiler/flash/abc/usages/ConstVarNameMultinameUsage.java b/src/com/jpexs/decompiler/flash/abc/usages/ConstVarNameMultinameUsage.java index 42dbd7eac..dea931cbe 100644 --- a/src/com/jpexs/decompiler/flash/abc/usages/ConstVarNameMultinameUsage.java +++ b/src/com/jpexs/decompiler/flash/abc/usages/ConstVarNameMultinameUsage.java @@ -1,38 +1,38 @@ -/* - * Copyright (C) 2010-2014 JPEXS - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.jpexs.decompiler.flash.abc.usages; - -import com.jpexs.decompiler.flash.abc.ABC; -import com.jpexs.decompiler.flash.abc.types.traits.Traits; -import com.jpexs.decompiler.flash.tags.ABCContainerTag; -import java.util.List; - -/** - * - * @author JPEXS - */ -public class ConstVarNameMultinameUsage extends ConstVarMultinameUsage implements DefinitionUsage { - - public ConstVarNameMultinameUsage(List abcTags, ABC abc, int multinameIndex, int classIndex, int traitIndex, boolean isStatic, Traits traits, int parentTraitIndex) { - super(abcTags,abc,multinameIndex, classIndex, traitIndex, isStatic, traits, parentTraitIndex); - } - - @Override - public String toString() { - return super.toString() + " name"; - } -} +/* + * Copyright (C) 2010-2014 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.decompiler.flash.abc.usages; + +import com.jpexs.decompiler.flash.abc.ABC; +import com.jpexs.decompiler.flash.abc.types.traits.Traits; +import com.jpexs.decompiler.flash.tags.ABCContainerTag; +import java.util.List; + +/** + * + * @author JPEXS + */ +public class ConstVarNameMultinameUsage extends ConstVarMultinameUsage implements DefinitionUsage { + + public ConstVarNameMultinameUsage(List abcTags, ABC abc, int multinameIndex, int classIndex, int traitIndex, boolean isStatic, Traits traits, int parentTraitIndex) { + super(abcTags, abc, multinameIndex, classIndex, traitIndex, isStatic, traits, parentTraitIndex); + } + + @Override + public String toString() { + return super.toString() + " name"; + } +} diff --git a/src/com/jpexs/decompiler/flash/abc/usages/ConstVarTypeMultinameUsage.java b/src/com/jpexs/decompiler/flash/abc/usages/ConstVarTypeMultinameUsage.java index 6107f1db0..83dc34bf5 100644 --- a/src/com/jpexs/decompiler/flash/abc/usages/ConstVarTypeMultinameUsage.java +++ b/src/com/jpexs/decompiler/flash/abc/usages/ConstVarTypeMultinameUsage.java @@ -1,38 +1,38 @@ -/* - * Copyright (C) 2010-2014 JPEXS - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.jpexs.decompiler.flash.abc.usages; - -import com.jpexs.decompiler.flash.abc.ABC; -import com.jpexs.decompiler.flash.abc.types.traits.Traits; -import com.jpexs.decompiler.flash.tags.ABCContainerTag; -import java.util.List; - -/** - * - * @author JPEXS - */ -public class ConstVarTypeMultinameUsage extends ConstVarMultinameUsage { - - public ConstVarTypeMultinameUsage(List abcTags, ABC abc, int multinameIndex, int classIndex, int traitIndex, boolean isStatic, Traits traits, int parentTraitIndex) { - super(abcTags,abc,multinameIndex, classIndex, traitIndex, isStatic, traits, parentTraitIndex); - } - - @Override - public String toString() { - return super.toString() + " type"; - } -} +/* + * Copyright (C) 2010-2014 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.decompiler.flash.abc.usages; + +import com.jpexs.decompiler.flash.abc.ABC; +import com.jpexs.decompiler.flash.abc.types.traits.Traits; +import com.jpexs.decompiler.flash.tags.ABCContainerTag; +import java.util.List; + +/** + * + * @author JPEXS + */ +public class ConstVarTypeMultinameUsage extends ConstVarMultinameUsage { + + public ConstVarTypeMultinameUsage(List abcTags, ABC abc, int multinameIndex, int classIndex, int traitIndex, boolean isStatic, Traits traits, int parentTraitIndex) { + super(abcTags, abc, multinameIndex, classIndex, traitIndex, isStatic, traits, parentTraitIndex); + } + + @Override + public String toString() { + return super.toString() + " type"; + } +} diff --git a/src/com/jpexs/decompiler/flash/abc/usages/DefinitionUsage.java b/src/com/jpexs/decompiler/flash/abc/usages/DefinitionUsage.java index fdb82eca2..52c525326 100644 --- a/src/com/jpexs/decompiler/flash/abc/usages/DefinitionUsage.java +++ b/src/com/jpexs/decompiler/flash/abc/usages/DefinitionUsage.java @@ -1,26 +1,25 @@ -/* - * Copyright (C) 2014 JPEXS - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.jpexs.decompiler.flash.abc.usages; - -/** - * - * @author JPEXS - */ -public interface DefinitionUsage { - -} +/* + * Copyright (C) 2014 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.decompiler.flash.abc.usages; + +/** + * + * @author JPEXS + */ +public interface DefinitionUsage { + +} diff --git a/src/com/jpexs/decompiler/flash/abc/usages/ExtendsMultinameUsage.java b/src/com/jpexs/decompiler/flash/abc/usages/ExtendsMultinameUsage.java index 68ad092f4..5e18097d4 100644 --- a/src/com/jpexs/decompiler/flash/abc/usages/ExtendsMultinameUsage.java +++ b/src/com/jpexs/decompiler/flash/abc/usages/ExtendsMultinameUsage.java @@ -1,37 +1,37 @@ -/* - * Copyright (C) 2010-2014 JPEXS - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.jpexs.decompiler.flash.abc.usages; - -import com.jpexs.decompiler.flash.abc.ABC; -import com.jpexs.decompiler.flash.tags.ABCContainerTag; -import java.util.List; - -/** - * - * @author JPEXS - */ -public class ExtendsMultinameUsage extends InsideClassMultinameUsage { - - public ExtendsMultinameUsage(List abcTags, ABC abc, int multinameIndex, int classIndex) { - super(abcTags,abc,multinameIndex, classIndex); - } - - @Override - public String toString() { - return super.toString() + " extends"; - } -} +/* + * Copyright (C) 2010-2014 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.decompiler.flash.abc.usages; + +import com.jpexs.decompiler.flash.abc.ABC; +import com.jpexs.decompiler.flash.tags.ABCContainerTag; +import java.util.List; + +/** + * + * @author JPEXS + */ +public class ExtendsMultinameUsage extends InsideClassMultinameUsage { + + public ExtendsMultinameUsage(List abcTags, ABC abc, int multinameIndex, int classIndex) { + super(abcTags, abc, multinameIndex, classIndex); + } + + @Override + public String toString() { + return super.toString() + " extends"; + } +} diff --git a/src/com/jpexs/decompiler/flash/abc/usages/ImplementsMultinameUsage.java b/src/com/jpexs/decompiler/flash/abc/usages/ImplementsMultinameUsage.java index 0b5104e00..d2f364255 100644 --- a/src/com/jpexs/decompiler/flash/abc/usages/ImplementsMultinameUsage.java +++ b/src/com/jpexs/decompiler/flash/abc/usages/ImplementsMultinameUsage.java @@ -1,37 +1,37 @@ -/* - * Copyright (C) 2010-2014 JPEXS - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.jpexs.decompiler.flash.abc.usages; - -import com.jpexs.decompiler.flash.abc.ABC; -import com.jpexs.decompiler.flash.tags.ABCContainerTag; -import java.util.List; - -/** - * - * @author JPEXS - */ -public class ImplementsMultinameUsage extends InsideClassMultinameUsage { - - public ImplementsMultinameUsage(List abcTags, ABC abc, int multinameIndex, int classIndex) { - super(abcTags,abc,multinameIndex, classIndex); - } - - @Override - public String toString() { - return super.toString() + " implements"; - } -} +/* + * Copyright (C) 2010-2014 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.decompiler.flash.abc.usages; + +import com.jpexs.decompiler.flash.abc.ABC; +import com.jpexs.decompiler.flash.tags.ABCContainerTag; +import java.util.List; + +/** + * + * @author JPEXS + */ +public class ImplementsMultinameUsage extends InsideClassMultinameUsage { + + public ImplementsMultinameUsage(List abcTags, ABC abc, int multinameIndex, int classIndex) { + super(abcTags, abc, multinameIndex, classIndex); + } + + @Override + public String toString() { + return super.toString() + " implements"; + } +} diff --git a/src/com/jpexs/decompiler/flash/abc/usages/InsideClassMultinameUsage.java b/src/com/jpexs/decompiler/flash/abc/usages/InsideClassMultinameUsage.java index f6673d135..840c6c13c 100644 --- a/src/com/jpexs/decompiler/flash/abc/usages/InsideClassMultinameUsage.java +++ b/src/com/jpexs/decompiler/flash/abc/usages/InsideClassMultinameUsage.java @@ -1,50 +1,50 @@ -/* - * Copyright (C) 2010-2014 JPEXS - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.jpexs.decompiler.flash.abc.usages; - -import com.jpexs.decompiler.flash.abc.ABC; -import com.jpexs.decompiler.flash.tags.ABCContainerTag; -import java.util.List; - -/** - * - * @author JPEXS - */ -public abstract class InsideClassMultinameUsage extends MultinameUsage { - - public int multinameIndex; - public int classIndex; - - public InsideClassMultinameUsage(List abcTags, ABC abc,int multinameIndex, int classIndex) { - super(abcTags, abc); - this.multinameIndex = multinameIndex; - this.classIndex = classIndex; - } - - @Override - public String toString(){ - return "class " + abc.constants.getMultiname(abc.instance_info.get(classIndex).name_index).getNameWithNamespace(abc.constants); - } - - public int getMultinameIndex() { - return multinameIndex; - } - - public int getClassIndex() { - return classIndex; - } -} +/* + * Copyright (C) 2010-2014 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.decompiler.flash.abc.usages; + +import com.jpexs.decompiler.flash.abc.ABC; +import com.jpexs.decompiler.flash.tags.ABCContainerTag; +import java.util.List; + +/** + * + * @author JPEXS + */ +public abstract class InsideClassMultinameUsage extends MultinameUsage { + + public int multinameIndex; + public int classIndex; + + public InsideClassMultinameUsage(List abcTags, ABC abc, int multinameIndex, int classIndex) { + super(abcTags, abc); + this.multinameIndex = multinameIndex; + this.classIndex = classIndex; + } + + @Override + public String toString() { + return "class " + abc.constants.getMultiname(abc.instance_info.get(classIndex).name_index).getNameWithNamespace(abc.constants); + } + + public int getMultinameIndex() { + return multinameIndex; + } + + public int getClassIndex() { + return classIndex; + } +} diff --git a/src/com/jpexs/decompiler/flash/abc/usages/MethodBodyMultinameUsage.java b/src/com/jpexs/decompiler/flash/abc/usages/MethodBodyMultinameUsage.java index b168b3206..e167a89a2 100644 --- a/src/com/jpexs/decompiler/flash/abc/usages/MethodBodyMultinameUsage.java +++ b/src/com/jpexs/decompiler/flash/abc/usages/MethodBodyMultinameUsage.java @@ -1,38 +1,38 @@ -/* - * Copyright (C) 2010-2014 JPEXS - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.jpexs.decompiler.flash.abc.usages; - -import com.jpexs.decompiler.flash.abc.ABC; -import com.jpexs.decompiler.flash.abc.types.traits.Traits; -import com.jpexs.decompiler.flash.tags.ABCContainerTag; -import java.util.List; - -/** - * - * @author JPEXS - */ -public class MethodBodyMultinameUsage extends MethodMultinameUsage { - - public MethodBodyMultinameUsage(List abcTags, ABC abc, int multinameIndex, int classIndex, int traitIndex, boolean isStatic, boolean isInitializer, Traits traits, int parentTraitIndex) { - super(abcTags,abc,multinameIndex, classIndex, traitIndex, isStatic, isInitializer, traits, parentTraitIndex); - } - - @Override - public String toString() { - return super.toString() + " body"; - } -} +/* + * Copyright (C) 2010-2014 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.decompiler.flash.abc.usages; + +import com.jpexs.decompiler.flash.abc.ABC; +import com.jpexs.decompiler.flash.abc.types.traits.Traits; +import com.jpexs.decompiler.flash.tags.ABCContainerTag; +import java.util.List; + +/** + * + * @author JPEXS + */ +public class MethodBodyMultinameUsage extends MethodMultinameUsage { + + public MethodBodyMultinameUsage(List abcTags, ABC abc, int multinameIndex, int classIndex, int traitIndex, boolean isStatic, boolean isInitializer, Traits traits, int parentTraitIndex) { + super(abcTags, abc, multinameIndex, classIndex, traitIndex, isStatic, isInitializer, traits, parentTraitIndex); + } + + @Override + public String toString() { + return super.toString() + " body"; + } +} diff --git a/src/com/jpexs/decompiler/flash/abc/usages/MethodMultinameUsage.java b/src/com/jpexs/decompiler/flash/abc/usages/MethodMultinameUsage.java index 7be4e0cf2..247276456 100644 --- a/src/com/jpexs/decompiler/flash/abc/usages/MethodMultinameUsage.java +++ b/src/com/jpexs/decompiler/flash/abc/usages/MethodMultinameUsage.java @@ -1,91 +1,91 @@ -/* - * Copyright (C) 2010-2014 JPEXS - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.jpexs.decompiler.flash.abc.usages; - -import com.jpexs.decompiler.flash.abc.ABC; -import com.jpexs.decompiler.flash.abc.types.traits.TraitMethodGetterSetter; -import com.jpexs.decompiler.flash.abc.types.traits.Traits; -import com.jpexs.decompiler.flash.configuration.Configuration; -import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode; -import com.jpexs.decompiler.flash.helpers.HilightedTextWriter; -import com.jpexs.decompiler.flash.helpers.NulWriter; -import com.jpexs.decompiler.flash.tags.ABCContainerTag; -import java.util.ArrayList; -import java.util.List; - -/** - * - * @author JPEXS - */ -public abstract class MethodMultinameUsage extends TraitMultinameUsage { - - public boolean isInitializer; - - public MethodMultinameUsage(List abcTags, ABC abc,int multinameIndex, int classIndex, int traitIndex, boolean isStatic, boolean isInitializer, Traits traits, int parentTraitIndex) { - super(abcTags,abc,multinameIndex, classIndex, traitIndex, isStatic, traits, parentTraitIndex); - this.isInitializer = isInitializer; - } - - public boolean isInitializer() { - return isInitializer; - } - - @Override - public String toString() { - NulWriter nulWriter = new NulWriter(); - if (!isInitializer) { - if (parentTraitIndex > -1) { - if (isStatic) { - ((TraitMethodGetterSetter) abc.class_info.get(classIndex).static_traits.traits.get(parentTraitIndex)).convertHeader(null, "", abcTags, abc, isStatic, ScriptExportMode.AS, -1/*FIXME*/, classIndex, nulWriter, new ArrayList(), false); - } else { - ((TraitMethodGetterSetter) abc.instance_info.get(classIndex).instance_traits.traits.get(parentTraitIndex)).convertHeader(null, "", abcTags, abc, isStatic, ScriptExportMode.AS, -1/*FIXME*/, classIndex, nulWriter, new ArrayList(), false); - } - } - ((TraitMethodGetterSetter) traits.traits.get(traitIndex)).convertHeader(null, "", abcTags, abc, isStatic, ScriptExportMode.AS, -1/*FIXME*/, classIndex, nulWriter, new ArrayList(), false); - } - - HilightedTextWriter writer = new HilightedTextWriter(Configuration.getCodeFormatting(), false); - writer.appendNoHilight(super.toString()); - writer.appendNoHilight(" "); - if (isInitializer) { - if (isStatic) { - writer.appendNoHilight("class initializer"); - } else { - writer.appendNoHilight("instance initializer"); - } - } else { - if (parentTraitIndex > -1) { - if (isStatic) { - ((TraitMethodGetterSetter) abc.class_info.get(classIndex).static_traits.traits.get(parentTraitIndex)).toStringHeader(null, "", abcTags, abc, isStatic, ScriptExportMode.AS, -1/*FIXME*/, classIndex, writer, new ArrayList(), false); - } else { - ((TraitMethodGetterSetter) abc.instance_info.get(classIndex).instance_traits.traits.get(parentTraitIndex)).toStringHeader(null, "", abcTags, abc, isStatic, ScriptExportMode.AS, -1/*FIXME*/, classIndex, writer, new ArrayList(), false); - } - writer.appendNoHilight(" "); - } - ((TraitMethodGetterSetter) traits.traits.get(traitIndex)).toStringHeader(null, "", abcTags, abc, isStatic, ScriptExportMode.AS, -1/*FIXME*/, classIndex, writer, new ArrayList(), false); - } - return writer.toString(); - } - - public int getTraitIndex() { - return traitIndex; - } - - public boolean isStatic() { - return isStatic; - } -} +/* + * Copyright (C) 2010-2014 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.decompiler.flash.abc.usages; + +import com.jpexs.decompiler.flash.abc.ABC; +import com.jpexs.decompiler.flash.abc.types.traits.TraitMethodGetterSetter; +import com.jpexs.decompiler.flash.abc.types.traits.Traits; +import com.jpexs.decompiler.flash.configuration.Configuration; +import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode; +import com.jpexs.decompiler.flash.helpers.HilightedTextWriter; +import com.jpexs.decompiler.flash.helpers.NulWriter; +import com.jpexs.decompiler.flash.tags.ABCContainerTag; +import java.util.ArrayList; +import java.util.List; + +/** + * + * @author JPEXS + */ +public abstract class MethodMultinameUsage extends TraitMultinameUsage { + + public boolean isInitializer; + + public MethodMultinameUsage(List abcTags, ABC abc, int multinameIndex, int classIndex, int traitIndex, boolean isStatic, boolean isInitializer, Traits traits, int parentTraitIndex) { + super(abcTags, abc, multinameIndex, classIndex, traitIndex, isStatic, traits, parentTraitIndex); + this.isInitializer = isInitializer; + } + + public boolean isInitializer() { + return isInitializer; + } + + @Override + public String toString() { + NulWriter nulWriter = new NulWriter(); + if (!isInitializer) { + if (parentTraitIndex > -1) { + if (isStatic) { + ((TraitMethodGetterSetter) abc.class_info.get(classIndex).static_traits.traits.get(parentTraitIndex)).convertHeader(null, "", abcTags, abc, isStatic, ScriptExportMode.AS, -1/*FIXME*/, classIndex, nulWriter, new ArrayList(), false); + } else { + ((TraitMethodGetterSetter) abc.instance_info.get(classIndex).instance_traits.traits.get(parentTraitIndex)).convertHeader(null, "", abcTags, abc, isStatic, ScriptExportMode.AS, -1/*FIXME*/, classIndex, nulWriter, new ArrayList(), false); + } + } + ((TraitMethodGetterSetter) traits.traits.get(traitIndex)).convertHeader(null, "", abcTags, abc, isStatic, ScriptExportMode.AS, -1/*FIXME*/, classIndex, nulWriter, new ArrayList(), false); + } + + HilightedTextWriter writer = new HilightedTextWriter(Configuration.getCodeFormatting(), false); + writer.appendNoHilight(super.toString()); + writer.appendNoHilight(" "); + if (isInitializer) { + if (isStatic) { + writer.appendNoHilight("class initializer"); + } else { + writer.appendNoHilight("instance initializer"); + } + } else { + if (parentTraitIndex > -1) { + if (isStatic) { + ((TraitMethodGetterSetter) abc.class_info.get(classIndex).static_traits.traits.get(parentTraitIndex)).toStringHeader(null, "", abcTags, abc, isStatic, ScriptExportMode.AS, -1/*FIXME*/, classIndex, writer, new ArrayList(), false); + } else { + ((TraitMethodGetterSetter) abc.instance_info.get(classIndex).instance_traits.traits.get(parentTraitIndex)).toStringHeader(null, "", abcTags, abc, isStatic, ScriptExportMode.AS, -1/*FIXME*/, classIndex, writer, new ArrayList(), false); + } + writer.appendNoHilight(" "); + } + ((TraitMethodGetterSetter) traits.traits.get(traitIndex)).toStringHeader(null, "", abcTags, abc, isStatic, ScriptExportMode.AS, -1/*FIXME*/, classIndex, writer, new ArrayList(), false); + } + return writer.toString(); + } + + public int getTraitIndex() { + return traitIndex; + } + + public boolean isStatic() { + return isStatic; + } +} diff --git a/src/com/jpexs/decompiler/flash/abc/usages/MethodNameMultinameUsage.java b/src/com/jpexs/decompiler/flash/abc/usages/MethodNameMultinameUsage.java index 16d464fc5..cea5241ba 100644 --- a/src/com/jpexs/decompiler/flash/abc/usages/MethodNameMultinameUsage.java +++ b/src/com/jpexs/decompiler/flash/abc/usages/MethodNameMultinameUsage.java @@ -1,38 +1,38 @@ -/* - * Copyright (C) 2010-2014 JPEXS - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.jpexs.decompiler.flash.abc.usages; - -import com.jpexs.decompiler.flash.abc.ABC; -import com.jpexs.decompiler.flash.abc.types.traits.Traits; -import com.jpexs.decompiler.flash.tags.ABCContainerTag; -import java.util.List; - -/** - * - * @author JPEXS - */ -public class MethodNameMultinameUsage extends MethodMultinameUsage implements DefinitionUsage { - - public MethodNameMultinameUsage(List abcTags, ABC abc, int multinameIndex, int classIndex, int traitIndex, boolean isStatic, boolean isInitializer, Traits traits, int parentTraitIndex) { - super(abcTags,abc, multinameIndex, classIndex, traitIndex, isStatic, isInitializer, traits, parentTraitIndex); - } - - @Override - public String toString() { - return super.toString() + " name"; - } -} +/* + * Copyright (C) 2010-2014 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.decompiler.flash.abc.usages; + +import com.jpexs.decompiler.flash.abc.ABC; +import com.jpexs.decompiler.flash.abc.types.traits.Traits; +import com.jpexs.decompiler.flash.tags.ABCContainerTag; +import java.util.List; + +/** + * + * @author JPEXS + */ +public class MethodNameMultinameUsage extends MethodMultinameUsage implements DefinitionUsage { + + public MethodNameMultinameUsage(List abcTags, ABC abc, int multinameIndex, int classIndex, int traitIndex, boolean isStatic, boolean isInitializer, Traits traits, int parentTraitIndex) { + super(abcTags, abc, multinameIndex, classIndex, traitIndex, isStatic, isInitializer, traits, parentTraitIndex); + } + + @Override + public String toString() { + return super.toString() + " name"; + } +} diff --git a/src/com/jpexs/decompiler/flash/abc/usages/MethodParamsMultinameUsage.java b/src/com/jpexs/decompiler/flash/abc/usages/MethodParamsMultinameUsage.java index 900d45c2d..e839894a6 100644 --- a/src/com/jpexs/decompiler/flash/abc/usages/MethodParamsMultinameUsage.java +++ b/src/com/jpexs/decompiler/flash/abc/usages/MethodParamsMultinameUsage.java @@ -1,38 +1,38 @@ -/* - * Copyright (C) 2010-2014 JPEXS - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.jpexs.decompiler.flash.abc.usages; - -import com.jpexs.decompiler.flash.abc.ABC; -import com.jpexs.decompiler.flash.abc.types.traits.Traits; -import com.jpexs.decompiler.flash.tags.ABCContainerTag; -import java.util.List; - -/** - * - * @author JPEXS - */ -public class MethodParamsMultinameUsage extends MethodMultinameUsage { - - public MethodParamsMultinameUsage(List abcTags, ABC abc, int multinameIndex, int classIndex, int traitIndex, boolean isStatic, boolean isInitializer, Traits traits, int parentTraitIndex) { - super(abcTags,abc,multinameIndex, classIndex, traitIndex, isStatic, isInitializer, traits, parentTraitIndex); - } - - @Override - public String toString() { - return super.toString() + " params"; - } -} +/* + * Copyright (C) 2010-2014 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.decompiler.flash.abc.usages; + +import com.jpexs.decompiler.flash.abc.ABC; +import com.jpexs.decompiler.flash.abc.types.traits.Traits; +import com.jpexs.decompiler.flash.tags.ABCContainerTag; +import java.util.List; + +/** + * + * @author JPEXS + */ +public class MethodParamsMultinameUsage extends MethodMultinameUsage { + + public MethodParamsMultinameUsage(List abcTags, ABC abc, int multinameIndex, int classIndex, int traitIndex, boolean isStatic, boolean isInitializer, Traits traits, int parentTraitIndex) { + super(abcTags, abc, multinameIndex, classIndex, traitIndex, isStatic, isInitializer, traits, parentTraitIndex); + } + + @Override + public String toString() { + return super.toString() + " params"; + } +} diff --git a/src/com/jpexs/decompiler/flash/abc/usages/MethodReturnTypeMultinameUsage.java b/src/com/jpexs/decompiler/flash/abc/usages/MethodReturnTypeMultinameUsage.java index 96ccccead..7be4f5c80 100644 --- a/src/com/jpexs/decompiler/flash/abc/usages/MethodReturnTypeMultinameUsage.java +++ b/src/com/jpexs/decompiler/flash/abc/usages/MethodReturnTypeMultinameUsage.java @@ -1,38 +1,38 @@ -/* - * Copyright (C) 2010-2014 JPEXS - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.jpexs.decompiler.flash.abc.usages; - -import com.jpexs.decompiler.flash.abc.ABC; -import com.jpexs.decompiler.flash.abc.types.traits.Traits; -import com.jpexs.decompiler.flash.tags.ABCContainerTag; -import java.util.List; - -/** - * - * @author JPEXS - */ -public class MethodReturnTypeMultinameUsage extends MethodMultinameUsage { - - public MethodReturnTypeMultinameUsage(List abcTags, ABC abc, int multinameIndex, int classIndex, int traitIndex, boolean isStatic, boolean isInitializer, Traits traits, int parentTraitIndex) { - super(abcTags,abc,multinameIndex, classIndex, traitIndex, isStatic, isInitializer, traits, parentTraitIndex); - } - - @Override - public String toString() { - return super.toString() + " return type"; - } -} +/* + * Copyright (C) 2010-2014 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.decompiler.flash.abc.usages; + +import com.jpexs.decompiler.flash.abc.ABC; +import com.jpexs.decompiler.flash.abc.types.traits.Traits; +import com.jpexs.decompiler.flash.tags.ABCContainerTag; +import java.util.List; + +/** + * + * @author JPEXS + */ +public class MethodReturnTypeMultinameUsage extends MethodMultinameUsage { + + public MethodReturnTypeMultinameUsage(List abcTags, ABC abc, int multinameIndex, int classIndex, int traitIndex, boolean isStatic, boolean isInitializer, Traits traits, int parentTraitIndex) { + super(abcTags, abc, multinameIndex, classIndex, traitIndex, isStatic, isInitializer, traits, parentTraitIndex); + } + + @Override + public String toString() { + return super.toString() + " return type"; + } +} diff --git a/src/com/jpexs/decompiler/flash/abc/usages/MultinameUsage.java b/src/com/jpexs/decompiler/flash/abc/usages/MultinameUsage.java index 3eaa81713..f6ded4225 100644 --- a/src/com/jpexs/decompiler/flash/abc/usages/MultinameUsage.java +++ b/src/com/jpexs/decompiler/flash/abc/usages/MultinameUsage.java @@ -1,36 +1,37 @@ -/* - * Copyright (C) 2010-2014 JPEXS - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.jpexs.decompiler.flash.abc.usages; - -import com.jpexs.decompiler.flash.abc.ABC; -import com.jpexs.decompiler.flash.tags.ABCContainerTag; -import java.util.List; - -/** - * - * @author JPEXS - */ -public abstract class MultinameUsage { - public List abcTags; - public ABC abc; - - public MultinameUsage(List abcTags, ABC abc) { - this.abcTags = abcTags; - this.abc = abc; - } - -} +/* + * Copyright (C) 2010-2014 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.decompiler.flash.abc.usages; + +import com.jpexs.decompiler.flash.abc.ABC; +import com.jpexs.decompiler.flash.tags.ABCContainerTag; +import java.util.List; + +/** + * + * @author JPEXS + */ +public abstract class MultinameUsage { + + public List abcTags; + public ABC abc; + + public MultinameUsage(List abcTags, ABC abc) { + this.abcTags = abcTags; + this.abc = abc; + } + +} diff --git a/src/com/jpexs/decompiler/flash/abc/usages/TraitMultinameUsage.java b/src/com/jpexs/decompiler/flash/abc/usages/TraitMultinameUsage.java index 89ffc2068..00f05914d 100644 --- a/src/com/jpexs/decompiler/flash/abc/usages/TraitMultinameUsage.java +++ b/src/com/jpexs/decompiler/flash/abc/usages/TraitMultinameUsage.java @@ -1,42 +1,42 @@ -/* - * Copyright (C) 2010-2014 JPEXS - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.jpexs.decompiler.flash.abc.usages; - -import com.jpexs.decompiler.flash.abc.ABC; -import com.jpexs.decompiler.flash.abc.types.traits.Traits; -import com.jpexs.decompiler.flash.tags.ABCContainerTag; -import java.util.List; - -/** - * - * @author JPEXS - */ -public abstract class TraitMultinameUsage extends InsideClassMultinameUsage { - - public int traitIndex; - public boolean isStatic; - public Traits traits; - public int parentTraitIndex; - - public TraitMultinameUsage(List abcTags, ABC abc, int multinameIndex, int classIndex, int traitIndex, boolean isStatic, Traits traits, int parentTraitIndex) { - super(abcTags,abc,multinameIndex, classIndex); - this.traitIndex = traitIndex; - this.isStatic = isStatic; - this.traits = traits; - this.parentTraitIndex = parentTraitIndex; - } -} +/* + * Copyright (C) 2010-2014 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.decompiler.flash.abc.usages; + +import com.jpexs.decompiler.flash.abc.ABC; +import com.jpexs.decompiler.flash.abc.types.traits.Traits; +import com.jpexs.decompiler.flash.tags.ABCContainerTag; +import java.util.List; + +/** + * + * @author JPEXS + */ +public abstract class TraitMultinameUsage extends InsideClassMultinameUsage { + + public int traitIndex; + public boolean isStatic; + public Traits traits; + public int parentTraitIndex; + + public TraitMultinameUsage(List abcTags, ABC abc, int multinameIndex, int classIndex, int traitIndex, boolean isStatic, Traits traits, int parentTraitIndex) { + super(abcTags, abc, multinameIndex, classIndex); + this.traitIndex = traitIndex; + this.isStatic = isStatic; + this.traits = traits; + this.parentTraitIndex = parentTraitIndex; + } +} diff --git a/src/com/jpexs/decompiler/flash/action/model/clauses/TellTargetActionItem.java b/src/com/jpexs/decompiler/flash/action/model/clauses/TellTargetActionItem.java index c38799f63..57f672370 100644 --- a/src/com/jpexs/decompiler/flash/action/model/clauses/TellTargetActionItem.java +++ b/src/com/jpexs/decompiler/flash/action/model/clauses/TellTargetActionItem.java @@ -84,7 +84,7 @@ public class TellTargetActionItem extends ActionItem { public boolean needsSemicolon() { return false; } - + @Override public boolean hasReturnValue() { return false; diff --git a/src/com/jpexs/decompiler/flash/action/parser/script/ActionSourceGenerator.java b/src/com/jpexs/decompiler/flash/action/parser/script/ActionSourceGenerator.java index 23cdc722c..9062dba31 100644 --- a/src/com/jpexs/decompiler/flash/action/parser/script/ActionSourceGenerator.java +++ b/src/com/jpexs/decompiler/flash/action/parser/script/ActionSourceGenerator.java @@ -779,11 +779,9 @@ public class ActionSourceGenerator implements SourceGenerator { @Override public List generateDiscardValue(SourceGeneratorLocalData localData, GraphTargetItem item) throws CompilationException { - List ret=item.toSource(localData, this); + List ret = item.toSource(localData, this); ret.add(new ActionPop()); return ret; } - - } diff --git a/src/com/jpexs/decompiler/flash/configuration/Configuration.java b/src/com/jpexs/decompiler/flash/configuration/Configuration.java index 07a9da360..c260b9066 100644 --- a/src/com/jpexs/decompiler/flash/configuration/Configuration.java +++ b/src/com/jpexs/decompiler/flash/configuration/Configuration.java @@ -384,16 +384,16 @@ public class Configuration { String path = "." + applicationId + "/"; directory = new File(userHome, path); } - }else{ + } else { //no home, then use application directory directory = new File("."); } } if (!directory.exists()) { if (!directory.mkdirs()) { - if (!directory.exists()) { - directory = new File("."); //fallback to current directory - } + if (!directory.exists()) { + directory = new File("."); //fallback to current directory + } } } String ret = directory.getAbsolutePath(); @@ -520,7 +520,7 @@ public class Configuration { @SuppressWarnings("unchecked") HashMap cfg = (HashMap) ois.readObject(); - config = cfg; + config = cfg; } catch (ClassNotFoundException | IOException ex) { //ignore } diff --git a/src/com/jpexs/decompiler/flash/dumpview/DumpInfo.java b/src/com/jpexs/decompiler/flash/dumpview/DumpInfo.java index a72566631..eababc219 100644 --- a/src/com/jpexs/decompiler/flash/dumpview/DumpInfo.java +++ b/src/com/jpexs/decompiler/flash/dumpview/DumpInfo.java @@ -33,17 +33,17 @@ public class DumpInfo { public long startByte; public int startBit; - + public long lengthBytes; public int lengthBits; - + public DumpInfo parent; - + public List childInfos = new ArrayList<>(); - + public DumpInfo(String name, String type, Object value, long startByte, int lengthBytes) { - + this.name = name; this.type = type; this.previewValue = value; @@ -52,7 +52,7 @@ public class DumpInfo { } public DumpInfo(String name, String type, Object value, long startByte, int startBit, long lengthBytes, int lengthBits) { - + this.name = name; this.type = type; this.previewValue = value; diff --git a/src/com/jpexs/decompiler/flash/gui/AppDialog.java b/src/com/jpexs/decompiler/flash/gui/AppDialog.java index 0e6fea342..b1c53b135 100644 --- a/src/com/jpexs/decompiler/flash/gui/AppDialog.java +++ b/src/com/jpexs/decompiler/flash/gui/AppDialog.java @@ -1,57 +1,56 @@ -/* - * Copyright (C) 2010-2014 JPEXS - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.jpexs.decompiler.flash.gui; - -import com.jpexs.decompiler.flash.AppStrings; -import com.jpexs.decompiler.flash.configuration.Configuration; -import java.awt.Window; -import java.util.ResourceBundle; -import javax.swing.JDialog; -import javax.swing.JRootPane; - -/** - * - * @author JPEXS - */ -public abstract class AppDialog extends JDialog { - - private ResourceBundle resourceBundle = ResourceBundle.getBundle(AppStrings.getResourcePath(getClass())); - - public AppDialog() { - View.installEscapeCloseOperation(this); - if (Configuration.useRibbonInterface.get()) { - getRootPane().setWindowDecorationStyle(JRootPane.FRAME); - } - } - - public AppDialog(Window owner) { - super(owner); - View.installEscapeCloseOperation(this); - if (Configuration.useRibbonInterface.get()) { - getRootPane().setWindowDecorationStyle(JRootPane.FRAME); - } - } - - - public String translate(String key) { - return resourceBundle.getString(key); - } - - public void updateLanguage() { - resourceBundle = ResourceBundle.getBundle(AppStrings.getResourcePath(getClass())); - } -} +/* + * Copyright (C) 2010-2014 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.decompiler.flash.gui; + +import com.jpexs.decompiler.flash.AppStrings; +import com.jpexs.decompiler.flash.configuration.Configuration; +import java.awt.Window; +import java.util.ResourceBundle; +import javax.swing.JDialog; +import javax.swing.JRootPane; + +/** + * + * @author JPEXS + */ +public abstract class AppDialog extends JDialog { + + private ResourceBundle resourceBundle = ResourceBundle.getBundle(AppStrings.getResourcePath(getClass())); + + public AppDialog() { + View.installEscapeCloseOperation(this); + if (Configuration.useRibbonInterface.get()) { + getRootPane().setWindowDecorationStyle(JRootPane.FRAME); + } + } + + public AppDialog(Window owner) { + super(owner); + View.installEscapeCloseOperation(this); + if (Configuration.useRibbonInterface.get()) { + getRootPane().setWindowDecorationStyle(JRootPane.FRAME); + } + } + + public String translate(String key) { + return resourceBundle.getString(key); + } + + public void updateLanguage() { + resourceBundle = ResourceBundle.getBundle(AppStrings.getResourcePath(getClass())); + } +} diff --git a/src/com/jpexs/decompiler/flash/gui/DumpTree.java b/src/com/jpexs/decompiler/flash/gui/DumpTree.java index bae0dfac0..21e335ca5 100644 --- a/src/com/jpexs/decompiler/flash/gui/DumpTree.java +++ b/src/com/jpexs/decompiler/flash/gui/DumpTree.java @@ -31,7 +31,7 @@ import javax.swing.tree.TreeModel; * @author JPEXS */ public class DumpTree extends JTree { - + public class DumpTreeCellRenderer extends DefaultTreeCellRenderer { @Override @@ -50,7 +50,6 @@ public class DumpTree extends JTree { hasFocus); //DumpInfo dumpInfo = (DumpInfo) value; - setUI(new BasicLabelUI()); setOpaque(false); setBackgroundNonSelectionColor(Color.white); @@ -83,7 +82,5 @@ public class DumpTree extends JTree { } } } - - } diff --git a/src/com/jpexs/decompiler/flash/gui/DumpTreeModel.java b/src/com/jpexs/decompiler/flash/gui/DumpTreeModel.java index 625601d80..877998a98 100644 --- a/src/com/jpexs/decompiler/flash/gui/DumpTreeModel.java +++ b/src/com/jpexs/decompiler/flash/gui/DumpTreeModel.java @@ -31,7 +31,7 @@ import javax.swing.tree.TreePath; public class DumpTreeModel implements TreeModel { private final DumpInfo root; - + public DumpTreeModel(List swfs) { DumpInfo root = new DumpInfo("root", "", null, 0, 0); for (SWFList swfList : swfs) { @@ -42,7 +42,7 @@ public class DumpTreeModel implements TreeModel { } this.root = root; } - + @Override public Object getRoot() { return root; @@ -80,5 +80,5 @@ public class DumpTreeModel implements TreeModel { @Override public void removeTreeModelListener(TreeModelListener tl) { } - + } diff --git a/src/com/jpexs/decompiler/flash/gui/DumpViewPanel.java b/src/com/jpexs/decompiler/flash/gui/DumpViewPanel.java index 77585f7d1..144e0689c 100644 --- a/src/com/jpexs/decompiler/flash/gui/DumpViewPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/DumpViewPanel.java @@ -34,19 +34,19 @@ import javax.swing.table.TableColumnModel; * @author JPEXS */ public class DumpViewPanel extends JPanel { - + private final int bytesInRow = 16; private final JLabel dumpViewLabel; private final JTable dumpViewHexTable; private byte[] data; - + public DumpViewPanel() { super(new BorderLayout()); dumpViewLabel = new JLabel(); dumpViewLabel.setMinimumSize(new Dimension(100, 20)); add(dumpViewLabel, BorderLayout.SOUTH); - + dumpViewHexTable = new JTable(); dumpViewHexTable.setBackground(Color.white); dumpViewHexTable.setFont(new Font("Monospaced", Font.PLAIN, 12)); @@ -81,7 +81,7 @@ public class DumpViewPanel extends JPanel { @Override public int getColumnCount() { - return 2*bytesInRow + 1; + return 2 * bytesInRow + 1; } @Override @@ -93,7 +93,7 @@ public class DumpViewPanel extends JPanel { } return ""; } - + @Override public Object getValueAt(int row, int column) { if (column == 0) { @@ -107,7 +107,7 @@ public class DumpViewPanel extends JPanel { } else { int pos = row * bytesInRow + column - bytesInRow - 1; if (pos < data.length) { - return (char)data[pos]; + return (char) data[pos]; } return null; } @@ -115,11 +115,11 @@ public class DumpViewPanel extends JPanel { }); add(new JScrollPane(dumpViewHexTable), BorderLayout.CENTER); } - + public void setData(byte[] data) { this.data = data; } - + public void setLabelText(String text) { dumpViewLabel.setText(text); } diff --git a/src/com/jpexs/decompiler/flash/gui/GraphDialog.java b/src/com/jpexs/decompiler/flash/gui/GraphDialog.java index 5c39e66fd..54efed695 100644 --- a/src/com/jpexs/decompiler/flash/gui/GraphDialog.java +++ b/src/com/jpexs/decompiler/flash/gui/GraphDialog.java @@ -1,336 +1,336 @@ -/* - * Copyright (C) 2010-2014 JPEXS - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.jpexs.decompiler.flash.gui; - -import com.jpexs.decompiler.graph.Graph; -import com.jpexs.decompiler.graph.GraphPart; -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Container; -import java.awt.Dimension; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.Point; -import java.awt.Polygon; -import java.awt.Window; -import java.awt.geom.AffineTransform; -import java.awt.geom.Line2D; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import javax.swing.JPanel; -import javax.swing.JScrollPane; - -/** - * - * @author JPEXS - */ -public class GraphDialog extends AppDialog { - - private class GraphPanel extends JPanel { - - private static final int SPACE_VERTICAL = 16; - private static final int SPACE_HORIZONTAL = 10; - private static final int SPACE_BACKLINKS = 5; - private static final int BLOCK_WIDTH = 200; - private static final int BLOCK_HEIGHT = 20; - private final HashMap partPos = new HashMap<>(); - private final Point size; - private int backLinksLeft = 0; - private int backLinksRight = 0; - private final GraphPart head; - - public GraphPanel(Graph graph) throws InterruptedException { - graph.init(null); - size = getPartPositions(head = graph.heads.get(0), SPACE_VERTICAL + SPACE_VERTICAL + BLOCK_HEIGHT / 2, getPartWidth(graph.heads.get(0), new HashSet()) * (BLOCK_WIDTH + SPACE_HORIZONTAL) / 2 - SPACE_HORIZONTAL, partPos, true); - backLinksLeft = 1; - backLinksRight = 1; - for (GraphPart part : partPos.keySet()) { - Point p = partPos.get(part); - for (GraphPart n : part.nextParts) { - Point npos = partPos.get(n); - if (npos.y < p.y) { - if (p.x > size.x / 2) { - backLinksRight++; - } else { - backLinksLeft++; - } - } - } - } - size.x += 2 * SPACE_BACKLINKS + backLinksLeft * SPACE_BACKLINKS + backLinksRight * SPACE_BACKLINKS; - setPreferredSize(new Dimension(size.x, size.y)); - } - - @Override - protected void paintComponent(Graphics g) { - super.paintComponent(g); - - Graphics2D g2 = (Graphics2D) g; - /*g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, - RenderingHints.VALUE_ANTIALIAS_ON);*/ - g2.setColor(Color.black); - int startX = SPACE_BACKLINKS + backLinksLeft * SPACE_BACKLINKS; - int blLeft = 0; - int blRight = 0; - for (GraphPart part : partPos.keySet()) { - Point p = partPos.get(part); - g2.setColor(Color.white); - g2.fillRect(startX + p.x - BLOCK_WIDTH / 2, p.y - BLOCK_HEIGHT / 2, BLOCK_WIDTH, BLOCK_HEIGHT); - g2.setColor(Color.black); - g2.drawRect(startX + p.x - BLOCK_WIDTH / 2, p.y - BLOCK_HEIGHT / 2, BLOCK_WIDTH, BLOCK_HEIGHT); - g2.drawString(part.toString(), startX + p.x - g2.getFontMetrics().stringWidth(part.toString()) / 2, p.y + g2.getFontMetrics().getHeight() / 2); - } - - Point hp = partPos.get(head); - drawArrow(g2, startX + hp.x, hp.y - BLOCK_HEIGHT / 2 - SPACE_VERTICAL, startX + hp.x, hp.y - BLOCK_HEIGHT / 2); - - for (GraphPart part : partPos.keySet()) { - Point p = partPos.get(part); - - for (int n = 0; n < part.nextParts.size(); n++) { - boolean isIf = part.nextParts.size() == 2; - if (isIf) { - if (n == 0) { - g2.setColor(new Color(0, 0x80, 0)); - } else { - g2.setColor(Color.red); - } - } else { - g2.setColor(Color.black); - } - Point npos = partPos.get(part.nextParts.get(n)); - if (npos.y < p.y) { - int sidex = startX; - if (p.x > size.x / 2) { - blRight++; - sidex = size.x - backLinksRight * SPACE_BACKLINKS; - sidex += SPACE_BACKLINKS + SPACE_BACKLINKS * blRight; - } else { - blLeft++; - sidex -= SPACE_BACKLINKS + SPACE_BACKLINKS * blLeft; - } - g2.drawLine(startX + p.x, p.y + BLOCK_HEIGHT / 2, startX + p.x, p.y + BLOCK_HEIGHT / 2 + SPACE_VERTICAL / 2); - g2.drawLine(startX + p.x, p.y + BLOCK_HEIGHT / 2 + SPACE_VERTICAL / 2, sidex, p.y + BLOCK_HEIGHT / 2 + SPACE_VERTICAL / 2); - g2.drawLine(sidex, npos.y - BLOCK_HEIGHT / 2 - SPACE_VERTICAL / 2, sidex, p.y + BLOCK_HEIGHT / 2 + SPACE_VERTICAL / 2); - drawArrow(g2, sidex, npos.y - BLOCK_HEIGHT / 2 - SPACE_VERTICAL / 2, startX + npos.x, npos.y - BLOCK_HEIGHT / 2 - SPACE_VERTICAL / 2); - g2.drawLine(startX + npos.x, npos.y - BLOCK_HEIGHT / 2 - SPACE_VERTICAL / 2, startX + npos.x, npos.y - BLOCK_HEIGHT / 2); - } else { - drawArrow(g2, startX + p.x, p.y + BLOCK_HEIGHT / 2, startX + npos.x, npos.y - BLOCK_HEIGHT / 2 - SPACE_VERTICAL / 2); - g2.drawLine(startX + npos.x, npos.y - BLOCK_HEIGHT / 2 - SPACE_VERTICAL / 2, startX + npos.x, npos.y - BLOCK_HEIGHT / 2); - } - } - } - } - - private Point getPartSubPositions(Point ret, int totalWidth, GraphPart part, int y, int x, HashMap used) { - if (used.containsKey(part)) { - Point p = used.get(part); - return new Point(x, y); - } - used.put(part, new Point(x, y)); - if (part.nextParts.size() > 0) { - int cx = x - totalWidth / 2; - for (int p = 0; p < part.nextParts.size(); p++) { - HashSet k = new HashSet<>(); - k.addAll(used.keySet()); - int partWidth = getPartWidth(part.nextParts.get(p), k); - int cellWidth = partWidth * (BLOCK_WIDTH + SPACE_HORIZONTAL); - Point pt = getPartPositions(part.nextParts.get(p), y + BLOCK_HEIGHT + SPACE_VERTICAL, cx + cellWidth / 2, used, false); - if (pt.x > ret.x) { - ret.x = pt.x; - } - if (pt.y > ret.y) { - ret.y = pt.y; - } - cx += cellWidth; - - } - cx = x - totalWidth / 2; - for (int p = 0; p < part.nextParts.size(); p++) { - HashSet k = new HashSet<>(); - k.addAll(used.keySet()); - int cellWidth = getPartWidth(part.nextParts.get(p), k) * (BLOCK_WIDTH + SPACE_HORIZONTAL); - - HashSet hs = new HashSet<>(); - hs.addAll(used.keySet()); - int totalWidthParts2 = getPartWidth(part.nextParts.get(p), hs); - int totalWidth2 = totalWidthParts2 * (BLOCK_WIDTH + SPACE_HORIZONTAL); - - Point pt = getPartSubPositions(ret, totalWidth2, part.nextParts.get(p), y + BLOCK_HEIGHT + SPACE_VERTICAL, cx + cellWidth / 2, used); - if (pt.x > ret.x) { - ret.x = pt.x; - } - if (pt.y > ret.y) { - ret.y = pt.y; - } - cx += cellWidth; - } - - } - return ret; - } - - private Point getPartPositions(GraphPart part, int y, int x, HashMap used, boolean goSub) { - HashMap l = new HashMap<>(); - l.putAll(used); - HashSet hs = new HashSet<>(); - hs.addAll(l.keySet()); - int totalWidthParts = getPartWidth(part, hs); - int totalWidth = totalWidthParts * (BLOCK_WIDTH + SPACE_HORIZONTAL); - - if (used.containsKey(part)) { - Point p = used.get(part); - return new Point(x, y); - } - Point ret = new Point(x - BLOCK_WIDTH / 2 - SPACE_HORIZONTAL / 2 + BLOCK_WIDTH, y + BLOCK_HEIGHT); - if (goSub) { - Point p2 = getPartSubPositions(ret, totalWidth, part, y, x, used); - if (p2.x > ret.x) { - ret.x = p2.x; - } - if (p2.y > ret.y) { - ret.y = p2.y; - } - } - return ret; - } - - private int getPartHeight(GraphPart part, List used) { - if (used.contains(part)) { - return 1; - } - used.add(part); - int maxH = 0; - for (int p = 0; p < part.nextParts.size(); p++) { - int h = getPartHeight(part.nextParts.get(p), used); - if (h > maxH) { - maxH = h; - } - } - return 1 + maxH; - } - - private int getPartWidth(GraphPart part, HashSet used) { - - if (used.contains(part)) { - return 1; - } - used.add(part); - if (part.nextParts.isEmpty()) { - return 1; - } - int w = 0; - for (GraphPart subpart : part.nextParts) { - w += getPartWidth(subpart, used); - } - return w; - } - } - GraphPanel gp; - int scrollBarWidth; - int scrollBarHeight; - int frameWidthDiff; - int frameHeightDiff; - - public GraphDialog(Window owner,Graph graph, String name) throws InterruptedException { - super(owner); - setSize(500, 500); - Container cnt = getContentPane(); - cnt.setLayout(new BorderLayout()); - gp = new GraphPanel(graph); - setTitle(translate("graph") + " " + name); - JScrollPane scrollPane = new JScrollPane(gp); - scrollBarWidth = scrollPane.getVerticalScrollBar().getPreferredSize().width; - scrollBarHeight = scrollPane.getHorizontalScrollBar().getPreferredSize().height; - cnt.add(scrollPane, BorderLayout.CENTER); - pack(); - - Dimension size = getSize(); - Dimension innerSize = getContentPane().getSize(); - - frameWidthDiff = size.width - innerSize.width; - frameHeightDiff = size.height - innerSize.height; - - View.setWindowIcon(this); - - } - - @Override - public void setVisible(boolean b) { - - super.setVisible(b); - Dimension screen = getToolkit().getScreenSize(); - Dimension dim = new Dimension(0, 0); - Dimension panDim = gp.getPreferredSize(); - // add some magic constants - panDim = new Dimension(panDim.width + 3, panDim.height + 2); - - boolean tooHigh = false; - boolean tooWide = false; - - if (panDim.width + frameWidthDiff < screen.width) { - dim.width = panDim.width; - } else { - dim.width = screen.width; - tooWide = true; - } - if (panDim.height + frameHeightDiff < screen.height) { - dim.height = panDim.height; - } else { - dim.height = screen.height; - tooHigh = true; - } - - if (tooWide) { - dim.height += scrollBarHeight; - dim.height = Math.min(dim.height, screen.height); - } - if (tooHigh) { - dim.width += scrollBarWidth; - dim.width = Math.min(dim.width, screen.width); - } - - setVisibleSize(dim); - View.centerScreen(this); - } - - private void setVisibleSize(Dimension dim) { - setSize(new Dimension(dim.width + frameWidthDiff, dim.height + frameHeightDiff)); - } - - private void drawArrow(Graphics g, int x1, int y1, int x2, int y2) { - Polygon arrowHead = new Polygon(); - arrowHead.addPoint(0, 0); - arrowHead.addPoint(-3, -8); - arrowHead.addPoint(3, -8); - Line2D.Double line = new Line2D.Double(x1, y1, x2, y2); - AffineTransform tx = new AffineTransform(); - tx.setToIdentity(); - double angle = Math.atan2(line.y2 - line.y1, line.x2 - line.x1); - tx.translate(line.x2, line.y2); - tx.rotate((angle - Math.PI / 2d)); - - Graphics2D g2d = (Graphics2D) g; - AffineTransform oldTransform = g2d.getTransform(); - g2d.draw(line); - tx.preConcatenate(oldTransform); - g2d.setTransform(tx); - g2d.fill(arrowHead); - g2d.setTransform(oldTransform); - } -} +/* + * Copyright (C) 2010-2014 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.decompiler.flash.gui; + +import com.jpexs.decompiler.graph.Graph; +import com.jpexs.decompiler.graph.GraphPart; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Point; +import java.awt.Polygon; +import java.awt.Window; +import java.awt.geom.AffineTransform; +import java.awt.geom.Line2D; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import javax.swing.JPanel; +import javax.swing.JScrollPane; + +/** + * + * @author JPEXS + */ +public class GraphDialog extends AppDialog { + + private class GraphPanel extends JPanel { + + private static final int SPACE_VERTICAL = 16; + private static final int SPACE_HORIZONTAL = 10; + private static final int SPACE_BACKLINKS = 5; + private static final int BLOCK_WIDTH = 200; + private static final int BLOCK_HEIGHT = 20; + private final HashMap partPos = new HashMap<>(); + private final Point size; + private int backLinksLeft = 0; + private int backLinksRight = 0; + private final GraphPart head; + + public GraphPanel(Graph graph) throws InterruptedException { + graph.init(null); + size = getPartPositions(head = graph.heads.get(0), SPACE_VERTICAL + SPACE_VERTICAL + BLOCK_HEIGHT / 2, getPartWidth(graph.heads.get(0), new HashSet()) * (BLOCK_WIDTH + SPACE_HORIZONTAL) / 2 - SPACE_HORIZONTAL, partPos, true); + backLinksLeft = 1; + backLinksRight = 1; + for (GraphPart part : partPos.keySet()) { + Point p = partPos.get(part); + for (GraphPart n : part.nextParts) { + Point npos = partPos.get(n); + if (npos.y < p.y) { + if (p.x > size.x / 2) { + backLinksRight++; + } else { + backLinksLeft++; + } + } + } + } + size.x += 2 * SPACE_BACKLINKS + backLinksLeft * SPACE_BACKLINKS + backLinksRight * SPACE_BACKLINKS; + setPreferredSize(new Dimension(size.x, size.y)); + } + + @Override + protected void paintComponent(Graphics g) { + super.paintComponent(g); + + Graphics2D g2 = (Graphics2D) g; + /*g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON);*/ + g2.setColor(Color.black); + int startX = SPACE_BACKLINKS + backLinksLeft * SPACE_BACKLINKS; + int blLeft = 0; + int blRight = 0; + for (GraphPart part : partPos.keySet()) { + Point p = partPos.get(part); + g2.setColor(Color.white); + g2.fillRect(startX + p.x - BLOCK_WIDTH / 2, p.y - BLOCK_HEIGHT / 2, BLOCK_WIDTH, BLOCK_HEIGHT); + g2.setColor(Color.black); + g2.drawRect(startX + p.x - BLOCK_WIDTH / 2, p.y - BLOCK_HEIGHT / 2, BLOCK_WIDTH, BLOCK_HEIGHT); + g2.drawString(part.toString(), startX + p.x - g2.getFontMetrics().stringWidth(part.toString()) / 2, p.y + g2.getFontMetrics().getHeight() / 2); + } + + Point hp = partPos.get(head); + drawArrow(g2, startX + hp.x, hp.y - BLOCK_HEIGHT / 2 - SPACE_VERTICAL, startX + hp.x, hp.y - BLOCK_HEIGHT / 2); + + for (GraphPart part : partPos.keySet()) { + Point p = partPos.get(part); + + for (int n = 0; n < part.nextParts.size(); n++) { + boolean isIf = part.nextParts.size() == 2; + if (isIf) { + if (n == 0) { + g2.setColor(new Color(0, 0x80, 0)); + } else { + g2.setColor(Color.red); + } + } else { + g2.setColor(Color.black); + } + Point npos = partPos.get(part.nextParts.get(n)); + if (npos.y < p.y) { + int sidex = startX; + if (p.x > size.x / 2) { + blRight++; + sidex = size.x - backLinksRight * SPACE_BACKLINKS; + sidex += SPACE_BACKLINKS + SPACE_BACKLINKS * blRight; + } else { + blLeft++; + sidex -= SPACE_BACKLINKS + SPACE_BACKLINKS * blLeft; + } + g2.drawLine(startX + p.x, p.y + BLOCK_HEIGHT / 2, startX + p.x, p.y + BLOCK_HEIGHT / 2 + SPACE_VERTICAL / 2); + g2.drawLine(startX + p.x, p.y + BLOCK_HEIGHT / 2 + SPACE_VERTICAL / 2, sidex, p.y + BLOCK_HEIGHT / 2 + SPACE_VERTICAL / 2); + g2.drawLine(sidex, npos.y - BLOCK_HEIGHT / 2 - SPACE_VERTICAL / 2, sidex, p.y + BLOCK_HEIGHT / 2 + SPACE_VERTICAL / 2); + drawArrow(g2, sidex, npos.y - BLOCK_HEIGHT / 2 - SPACE_VERTICAL / 2, startX + npos.x, npos.y - BLOCK_HEIGHT / 2 - SPACE_VERTICAL / 2); + g2.drawLine(startX + npos.x, npos.y - BLOCK_HEIGHT / 2 - SPACE_VERTICAL / 2, startX + npos.x, npos.y - BLOCK_HEIGHT / 2); + } else { + drawArrow(g2, startX + p.x, p.y + BLOCK_HEIGHT / 2, startX + npos.x, npos.y - BLOCK_HEIGHT / 2 - SPACE_VERTICAL / 2); + g2.drawLine(startX + npos.x, npos.y - BLOCK_HEIGHT / 2 - SPACE_VERTICAL / 2, startX + npos.x, npos.y - BLOCK_HEIGHT / 2); + } + } + } + } + + private Point getPartSubPositions(Point ret, int totalWidth, GraphPart part, int y, int x, HashMap used) { + if (used.containsKey(part)) { + Point p = used.get(part); + return new Point(x, y); + } + used.put(part, new Point(x, y)); + if (part.nextParts.size() > 0) { + int cx = x - totalWidth / 2; + for (int p = 0; p < part.nextParts.size(); p++) { + HashSet k = new HashSet<>(); + k.addAll(used.keySet()); + int partWidth = getPartWidth(part.nextParts.get(p), k); + int cellWidth = partWidth * (BLOCK_WIDTH + SPACE_HORIZONTAL); + Point pt = getPartPositions(part.nextParts.get(p), y + BLOCK_HEIGHT + SPACE_VERTICAL, cx + cellWidth / 2, used, false); + if (pt.x > ret.x) { + ret.x = pt.x; + } + if (pt.y > ret.y) { + ret.y = pt.y; + } + cx += cellWidth; + + } + cx = x - totalWidth / 2; + for (int p = 0; p < part.nextParts.size(); p++) { + HashSet k = new HashSet<>(); + k.addAll(used.keySet()); + int cellWidth = getPartWidth(part.nextParts.get(p), k) * (BLOCK_WIDTH + SPACE_HORIZONTAL); + + HashSet hs = new HashSet<>(); + hs.addAll(used.keySet()); + int totalWidthParts2 = getPartWidth(part.nextParts.get(p), hs); + int totalWidth2 = totalWidthParts2 * (BLOCK_WIDTH + SPACE_HORIZONTAL); + + Point pt = getPartSubPositions(ret, totalWidth2, part.nextParts.get(p), y + BLOCK_HEIGHT + SPACE_VERTICAL, cx + cellWidth / 2, used); + if (pt.x > ret.x) { + ret.x = pt.x; + } + if (pt.y > ret.y) { + ret.y = pt.y; + } + cx += cellWidth; + } + + } + return ret; + } + + private Point getPartPositions(GraphPart part, int y, int x, HashMap used, boolean goSub) { + HashMap l = new HashMap<>(); + l.putAll(used); + HashSet hs = new HashSet<>(); + hs.addAll(l.keySet()); + int totalWidthParts = getPartWidth(part, hs); + int totalWidth = totalWidthParts * (BLOCK_WIDTH + SPACE_HORIZONTAL); + + if (used.containsKey(part)) { + Point p = used.get(part); + return new Point(x, y); + } + Point ret = new Point(x - BLOCK_WIDTH / 2 - SPACE_HORIZONTAL / 2 + BLOCK_WIDTH, y + BLOCK_HEIGHT); + if (goSub) { + Point p2 = getPartSubPositions(ret, totalWidth, part, y, x, used); + if (p2.x > ret.x) { + ret.x = p2.x; + } + if (p2.y > ret.y) { + ret.y = p2.y; + } + } + return ret; + } + + private int getPartHeight(GraphPart part, List used) { + if (used.contains(part)) { + return 1; + } + used.add(part); + int maxH = 0; + for (int p = 0; p < part.nextParts.size(); p++) { + int h = getPartHeight(part.nextParts.get(p), used); + if (h > maxH) { + maxH = h; + } + } + return 1 + maxH; + } + + private int getPartWidth(GraphPart part, HashSet used) { + + if (used.contains(part)) { + return 1; + } + used.add(part); + if (part.nextParts.isEmpty()) { + return 1; + } + int w = 0; + for (GraphPart subpart : part.nextParts) { + w += getPartWidth(subpart, used); + } + return w; + } + } + GraphPanel gp; + int scrollBarWidth; + int scrollBarHeight; + int frameWidthDiff; + int frameHeightDiff; + + public GraphDialog(Window owner, Graph graph, String name) throws InterruptedException { + super(owner); + setSize(500, 500); + Container cnt = getContentPane(); + cnt.setLayout(new BorderLayout()); + gp = new GraphPanel(graph); + setTitle(translate("graph") + " " + name); + JScrollPane scrollPane = new JScrollPane(gp); + scrollBarWidth = scrollPane.getVerticalScrollBar().getPreferredSize().width; + scrollBarHeight = scrollPane.getHorizontalScrollBar().getPreferredSize().height; + cnt.add(scrollPane, BorderLayout.CENTER); + pack(); + + Dimension size = getSize(); + Dimension innerSize = getContentPane().getSize(); + + frameWidthDiff = size.width - innerSize.width; + frameHeightDiff = size.height - innerSize.height; + + View.setWindowIcon(this); + + } + + @Override + public void setVisible(boolean b) { + + super.setVisible(b); + Dimension screen = getToolkit().getScreenSize(); + Dimension dim = new Dimension(0, 0); + Dimension panDim = gp.getPreferredSize(); + // add some magic constants + panDim = new Dimension(panDim.width + 3, panDim.height + 2); + + boolean tooHigh = false; + boolean tooWide = false; + + if (panDim.width + frameWidthDiff < screen.width) { + dim.width = panDim.width; + } else { + dim.width = screen.width; + tooWide = true; + } + if (panDim.height + frameHeightDiff < screen.height) { + dim.height = panDim.height; + } else { + dim.height = screen.height; + tooHigh = true; + } + + if (tooWide) { + dim.height += scrollBarHeight; + dim.height = Math.min(dim.height, screen.height); + } + if (tooHigh) { + dim.width += scrollBarWidth; + dim.width = Math.min(dim.width, screen.width); + } + + setVisibleSize(dim); + View.centerScreen(this); + } + + private void setVisibleSize(Dimension dim) { + setSize(new Dimension(dim.width + frameWidthDiff, dim.height + frameHeightDiff)); + } + + private void drawArrow(Graphics g, int x1, int y1, int x2, int y2) { + Polygon arrowHead = new Polygon(); + arrowHead.addPoint(0, 0); + arrowHead.addPoint(-3, -8); + arrowHead.addPoint(3, -8); + Line2D.Double line = new Line2D.Double(x1, y1, x2, y2); + AffineTransform tx = new AffineTransform(); + tx.setToIdentity(); + double angle = Math.atan2(line.y2 - line.y1, line.x2 - line.x1); + tx.translate(line.x2, line.y2); + tx.rotate((angle - Math.PI / 2d)); + + Graphics2D g2d = (Graphics2D) g; + AffineTransform oldTransform = g2d.getTransform(); + g2d.draw(line); + tx.preConcatenate(oldTransform); + g2d.setTransform(tx); + g2d.fill(arrowHead); + g2d.setTransform(oldTransform); + } +} diff --git a/src/com/jpexs/decompiler/flash/gui/Main.java b/src/com/jpexs/decompiler/flash/gui/Main.java index 54dbb18ac..ba19e9921 100644 --- a/src/com/jpexs/decompiler/flash/gui/Main.java +++ b/src/com/jpexs/decompiler/flash/gui/Main.java @@ -1051,7 +1051,7 @@ public class Main { // sometimes during development the version information is not available return false; } - + List accepted = new ArrayList<>(); if (Configuration.checkForUpdatesStable.get()) { accepted.add("stable"); diff --git a/src/com/jpexs/decompiler/flash/gui/MainFrame.java b/src/com/jpexs/decompiler/flash/gui/MainFrame.java index b19e6fef9..7040fb0af 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainFrame.java +++ b/src/com/jpexs/decompiler/flash/gui/MainFrame.java @@ -1,38 +1,38 @@ -/* - * Copyright (C) 2010-2014 JPEXS - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.jpexs.decompiler.flash.gui; - -import java.awt.Window; - -/** - * - * @author JPEXS - */ -public interface MainFrame { - - public void setTitle(String string); - - public String translate(String key); - - public MainPanel getPanel(); - - public boolean isVisible(); - - public void setVisible(boolean b); - - public Window getWindow(); -} +/* + * Copyright (C) 2010-2014 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.decompiler.flash.gui; + +import java.awt.Window; + +/** + * + * @author JPEXS + */ +public interface MainFrame { + + public void setTitle(String string); + + public String translate(String key); + + public MainPanel getPanel(); + + public boolean isVisible(); + + public void setVisible(boolean b); + + public Window getWindow(); +} diff --git a/src/com/jpexs/decompiler/flash/gui/MainFrameClassic.java b/src/com/jpexs/decompiler/flash/gui/MainFrameClassic.java index 3591c139e..4cb2eed53 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainFrameClassic.java +++ b/src/com/jpexs/decompiler/flash/gui/MainFrameClassic.java @@ -124,6 +124,5 @@ public final class MainFrameClassic extends AppFrame implements MainFrame { public Window getWindow() { return this; } - - + } diff --git a/src/com/jpexs/decompiler/flash/gui/MainFrameRibbon.java b/src/com/jpexs/decompiler/flash/gui/MainFrameRibbon.java index 100148b21..5f7a5d08f 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainFrameRibbon.java +++ b/src/com/jpexs/decompiler/flash/gui/MainFrameRibbon.java @@ -116,8 +116,7 @@ public final class MainFrameRibbon extends AppRibbonFrame implements MainFrame { }); View.centerScreen(this); - - + } private static void getApplicationMenuButtons(Component comp, List ret) { @@ -220,9 +219,8 @@ public final class MainFrameRibbon extends AppRibbonFrame implements MainFrame { } @Override - public Window getWindow() { + public Window getWindow() { return this; } - - + } diff --git a/src/com/jpexs/decompiler/flash/gui/MainPanel.java b/src/com/jpexs/decompiler/flash/gui/MainPanel.java index 6f4bad5fb..7b6b829df 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/MainPanel.java @@ -283,8 +283,6 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec public MainFrame getMainFrame() { return mainFrame; } - - static { try { @@ -441,7 +439,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec expandRecursiveMenuItem.setVisible(model.getChildCount(treeNode) > 0); jumpToCharacterMenuItem.setVisible(item instanceof CharacterIdTag && !(item instanceof CharacterTag)); - + rawEditMenuItem.setVisible(item instanceof Tag); } @@ -2281,7 +2279,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec if (item == null) { return; } - + showCard(CARDPREVIEWPANEL); previewPanel.showGenericTagPanel((Tag) item); } @@ -2291,7 +2289,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec if (item == null || !(item instanceof CharacterIdTag)) { return; } - + CharacterIdTag characterIdTag = (CharacterIdTag) item; setTreeItem(item.getSwf().characters.get(characterIdTag.getCharacterId())); } @@ -2385,10 +2383,10 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec DumpInfo dumpInfo = (DumpInfo) e.getPath().getLastPathComponent(); if (dumpInfo.lengthBytes != 0 || dumpInfo.lengthBits != 0) { // todo - dumpViewPanel.setLabelText("startByte: " + dumpInfo.startByte + - " startBit: " + dumpInfo.startBit + - " lengthBytes: " + dumpInfo.lengthBytes + - " lengthBits: " + dumpInfo.lengthBits); + dumpViewPanel.setLabelText("startByte: " + dumpInfo.startByte + + " startBit: " + dumpInfo.startBit + + " lengthBytes: " + dumpInfo.lengthBytes + + " lengthBits: " + dumpInfo.lengthBits); } // todo honfika: support multiple swf @@ -2396,7 +2394,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec dumpViewPanel.revalidate(); showCard(CARDDUMPVIEW); } - + @Override public void valueChanged(TreeSelectionEvent e) { Object source = e.getSource(); diff --git a/src/com/jpexs/decompiler/flash/gui/PreviewImage.java b/src/com/jpexs/decompiler/flash/gui/PreviewImage.java index 47106f36c..3200a497f 100644 --- a/src/com/jpexs/decompiler/flash/gui/PreviewImage.java +++ b/src/com/jpexs/decompiler/flash/gui/PreviewImage.java @@ -93,7 +93,7 @@ public class PreviewImage extends JPanel { @Override public void actionPerformed(ActionEvent e) { - Tag tag = (Tag) treeItem; + Tag tag = (Tag) treeItem; tag.getSwf().removeTag(tag, false); mainPanel.refreshTree(); } @@ -104,7 +104,7 @@ public class PreviewImage extends JPanel { @Override public void actionPerformed(ActionEvent e) { - Tag tag = (Tag) treeItem; + Tag tag = (Tag) treeItem; tag.getSwf().removeTag(tag, true); mainPanel.refreshTree(); } diff --git a/src/com/jpexs/decompiler/flash/gui/QuickFindPanel.java b/src/com/jpexs/decompiler/flash/gui/QuickFindPanel.java index 58a027e31..5c41ea3be 100644 --- a/src/com/jpexs/decompiler/flash/gui/QuickFindPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/QuickFindPanel.java @@ -14,7 +14,6 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - package com.jpexs.decompiler.flash.gui; import java.awt.Color; @@ -46,30 +45,29 @@ import jsyntaxpane.components.Markers; * @author JPEXS */ public class QuickFindPanel extends JPanel implements ActionListener, jsyntaxpane.actions.QuickFindHandler { + public JTextField findTextField; - public JButton prevButton,nextButton; - public JCheckBox ignoreCaseCheckbox,regExpCheckbox,wrapCheckbox; + public JButton prevButton, nextButton; + public JCheckBox ignoreCaseCheckbox, regExpCheckbox, wrapCheckbox; public JLabel statusLabel; - + private final Markers.SimpleMarker marker = new Markers.SimpleMarker(Color.PINK); - private WeakReference target; - private WeakReference dsd; - private int oldCaretPosition; - - public QuickFindPanel(){ - setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); - - + private WeakReference target; + private WeakReference dsd; + private int oldCaretPosition; + + public QuickFindPanel() { + setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); + setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED)); - + JPanel pan1 = new JPanel(new WrapLayout()); JPanel pan2 = new JPanel(new WrapLayout()); pan1.setAlignmentX(0); pan2.setAlignmentX(0); pan1.setAlignmentY(0); pan2.setAlignmentY(0); - - + JLabel jLabel1 = new javax.swing.JLabel(); findTextField = new javax.swing.JTextField(); prevButton = new javax.swing.JButton(); @@ -78,21 +76,20 @@ public class QuickFindPanel extends JPanel implements ActionListener, jsyntaxpan regExpCheckbox = new javax.swing.JCheckBox(); wrapCheckbox = new javax.swing.JCheckBox(); statusLabel = new javax.swing.JLabel(); - + setName("QuickFindDialog"); // NOI18N - jLabel1.setLabelFor(findTextField); java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("jsyntaxpane/Bundle"); // NOI18N jLabel1.setText(bundle.getString("QuickFindDialog.jLabel1.text")); // NOI18N pan1.add(jLabel1); - + findTextField.setColumns(30); findTextField.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); findTextField.setMaximumSize(new java.awt.Dimension(200, 24)); findTextField.setMinimumSize(new java.awt.Dimension(60, 24)); pan1.add(findTextField); - + prevButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/META-INF/images/small-icons/go-up.png"))); // NOI18N prevButton.setFocusable(false); prevButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); @@ -136,124 +133,117 @@ public class QuickFindPanel extends JPanel implements ActionListener, jsyntaxpan pan2.add(wrapCheckbox); wrapCheckbox.addActionListener(this); - - statusLabel.setFont(statusLabel.getFont().deriveFont(statusLabel.getFont().getStyle() | java.awt.Font.BOLD, statusLabel.getFont().getSize()-2)); + statusLabel.setFont(statusLabel.getFont().deriveFont(statusLabel.getFont().getStyle() | java.awt.Font.BOLD, statusLabel.getFont().getSize() - 2)); statusLabel.setForeground(java.awt.Color.red); pan2.add(statusLabel); - + add(pan1); add(pan2); setPreferredSize(getMinimumSize()); - setVisible(false); + setVisible(false); } @Override public void actionPerformed(ActionEvent e) { - switch(e.getActionCommand()){ + switch (e.getActionCommand()) { case "PREVIOUS": if (dsd.get().doFindPrev(target.get())) { - statusLabel.setText(null); - } else { - statusLabel.setText(java.util.ResourceBundle.getBundle("jsyntaxpane/Bundle").getString("QuickFindDialog.NotFound")); - } + statusLabel.setText(null); + } else { + statusLabel.setText(java.util.ResourceBundle.getBundle("jsyntaxpane/Bundle").getString("QuickFindDialog.NotFound")); + } break; case "NEXT": if (dsd.get().doFindNext(target.get())) { - statusLabel.setText(null); - } else { - statusLabel.setText(java.util.ResourceBundle.getBundle("jsyntaxpane/Bundle").getString("QuickFindDialog.NotFound")); - } + statusLabel.setText(null); + } else { + statusLabel.setText(java.util.ResourceBundle.getBundle("jsyntaxpane/Bundle").getString("QuickFindDialog.NotFound")); + } break; } } - - @Override - public void showQuickFind(final JTextComponent t,DocumentSearchData ds) { + public void showQuickFind(final JTextComponent t, DocumentSearchData ds) { dsd = new WeakReference(ds); oldCaretPosition = t.getCaretPosition(); - Container view = t.getParent(); - Dimension wd = getSize(); - wd.width = t.getVisibleRect().width; - Point loc = new Point(0, view.getHeight()); - setSize(wd); - SwingUtilities.convertPointToScreen(loc, view); - setLocation(loc); - findTextField.setFont(t.getFont()); - final DocumentListener dl; - findTextField.getDocument().addDocumentListener(dl = new DocumentListener() { + Container view = t.getParent(); + Dimension wd = getSize(); + wd.width = t.getVisibleRect().width; + Point loc = new Point(0, view.getHeight()); + setSize(wd); + SwingUtilities.convertPointToScreen(loc, view); + setLocation(loc); + findTextField.setFont(t.getFont()); + final DocumentListener dl; + findTextField.getDocument().addDocumentListener(dl = new DocumentListener() { @Override - public void insertUpdate(DocumentEvent e) { - updateFind(); - } + public void insertUpdate(DocumentEvent e) { + updateFind(); + } - @Override - public void removeUpdate(DocumentEvent e) { - updateFind(); - } + @Override + public void removeUpdate(DocumentEvent e) { + updateFind(); + } - @Override - public void changedUpdate(DocumentEvent e) { - updateFind(); - } + @Override + public void changedUpdate(DocumentEvent e) { + updateFind(); + } - private void updateFind() { - JTextComponent t = target.get(); - DocumentSearchData d = dsd.get(); - String toFind = findTextField.getText(); - if (toFind == null || toFind.isEmpty()) { - statusLabel.setText(null); - return; - } - try { - d.setWrap(wrapCheckbox.isSelected()); - d.setPattern(toFind, - regExpCheckbox.isSelected(), - ignoreCaseCheckbox.isSelected()); - // The dsd doFindNext will always find from current pos, - // so we need to relocate to our saved pos before we call doFindNext - statusLabel.setText(null); - t.setCaretPosition(oldCaretPosition); - if (!d.doFindNext(t)) { - statusLabel.setText(java.util.ResourceBundle.getBundle("jsyntaxpane/Bundle").getString("QuickFindDialog.NotFound")); - } else { - statusLabel.setText(null); - } - } catch (PatternSyntaxException e) { - statusLabel.setText(e.getDescription()); - } + private void updateFind() { + JTextComponent t = target.get(); + DocumentSearchData d = dsd.get(); + String toFind = findTextField.getText(); + if (toFind == null || toFind.isEmpty()) { + statusLabel.setText(null); + return; + } + try { + d.setWrap(wrapCheckbox.isSelected()); + d.setPattern(toFind, + regExpCheckbox.isSelected(), + ignoreCaseCheckbox.isSelected()); + // The dsd doFindNext will always find from current pos, + // so we need to relocate to our saved pos before we call doFindNext + statusLabel.setText(null); + t.setCaretPosition(oldCaretPosition); + if (!d.doFindNext(t)) { + statusLabel.setText(java.util.ResourceBundle.getBundle("jsyntaxpane/Bundle").getString("QuickFindDialog.NotFound")); + } else { + statusLabel.setText(null); + } + } catch (PatternSyntaxException e) { + statusLabel.setText(e.getDescription()); + } + } + }); + this.target = new WeakReference<>(t); + Pattern p = dsd.get().getPattern(); + if (p != null) { + findTextField.setText(p.pattern()); } - }); - this.target = new WeakReference<>(t); - Pattern p = dsd.get().getPattern(); - if (p != null) { - findTextField.setText(p.pattern()); - } - wrapCheckbox.setSelected(dsd.get().isWrap()); - - - setVisible(true); + wrapCheckbox.setSelected(dsd.get().isWrap()); + + setVisible(true); getParent().revalidate(); - getParent().repaint(); + getParent().repaint(); findTextField.requestFocusInWindow(); } -/* - @Override - public void focusGained(FocusEvent e) { + /* + @Override + public void focusGained(FocusEvent e) { - } + } + + @Override + public void focusLost(FocusEvent e) { + removeFocusListener(this); + setVisible(false); + getParent().revalidate(); + getParent().repaint(); + }*/ - @Override - public void focusLost(FocusEvent e) { - removeFocusListener(this); - setVisible(false); - getParent().revalidate(); - getParent().repaint(); - }*/ - - - - } diff --git a/src/com/jpexs/decompiler/flash/gui/SearchResultsDialog.java b/src/com/jpexs/decompiler/flash/gui/SearchResultsDialog.java index 56ce1b0b7..c43b032bd 100644 --- a/src/com/jpexs/decompiler/flash/gui/SearchResultsDialog.java +++ b/src/com/jpexs/decompiler/flash/gui/SearchResultsDialog.java @@ -14,7 +14,6 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - package com.jpexs.decompiler.flash.gui; import java.awt.BorderLayout; @@ -39,25 +38,26 @@ import javax.swing.SwingUtilities; * @author JPEXS * @param */ -public class SearchResultsDialog extends AppDialog implements ActionListener{ +public class SearchResultsDialog extends AppDialog implements ActionListener { + private final JList resultsList; private final DefaultListModel model; private final SearchListener listener; - + static final String ACTION_GOTO = "GOTO"; static final String ACTION_CANCEL = "CLOSE"; private final JButton gotoButton = new JButton(translate("button.goto")); private final JButton closeButton = new JButton(translate("button.close")); - - public SearchResultsDialog(Window owner,String text,SearchListener listener) { + + public SearchResultsDialog(Window owner, String text, SearchListener listener) { super(owner); setTitle(translate("dialog.title").replace("%text%", text)); - Container cnt=getContentPane(); + Container cnt = getContentPane(); model = new DefaultListModel<>(); - resultsList = new JList<>(model); + resultsList = new JList<>(model); this.listener = listener; - + gotoButton.setActionCommand(ACTION_GOTO); gotoButton.addActionListener(this); closeButton.setActionCommand(ACTION_CANCEL); @@ -74,24 +74,24 @@ public class SearchResultsDialog extends AppDialog implements ActionListener{ gotoElement(); } } - - }); - + + }); + cnt.setLayout(new BorderLayout()); JScrollPane sp = new JScrollPane(resultsList); - sp.setPreferredSize(new Dimension(300,300)); - cnt.add(sp,BorderLayout.CENTER); - cnt.add(buttonsPanel,BorderLayout.SOUTH); + sp.setPreferredSize(new Dimension(300, 300)); + cnt.add(sp, BorderLayout.CENTER); + cnt.add(buttonsPanel, BorderLayout.SOUTH); pack(); View.centerScreen(this); View.setWindowIcon(this); } - - public void setResults(List results){ + + public void setResults(List results) { model.clear(); - for(E e:results){ + for (E e : results) { model.addElement(e); - } + } } @Override @@ -106,18 +106,18 @@ public class SearchResultsDialog extends AppDialog implements ActionListener{ break; } } - - private void gotoElement(){ + + private void gotoElement() { if (resultsList.getSelectedIndex() != -1) { SwingUtilities.invokeLater(new Runnable() { @Override - public void run() { + public void run() { listener.updateSearchPos(resultsList.getSelectedValue()); } - + }); } } - + } diff --git a/src/com/jpexs/decompiler/flash/gui/TextPanel.java b/src/com/jpexs/decompiler/flash/gui/TextPanel.java index eda739e73..e1a6e274f 100644 --- a/src/com/jpexs/decompiler/flash/gui/TextPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/TextPanel.java @@ -1,139 +1,139 @@ -/* - * Copyright (C) 2010-2014 JPEXS - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.jpexs.decompiler.flash.gui; - -import com.jpexs.decompiler.flash.SWF; -import com.jpexs.decompiler.flash.gui.abc.LineMarkedEditorPane; -import com.jpexs.decompiler.flash.tags.base.TextTag; -import com.jpexs.decompiler.flash.treeitems.TreeItem; -import java.awt.BorderLayout; -import java.awt.FlowLayout; -import java.awt.Insets; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import javax.swing.JButton; -import javax.swing.JPanel; -import javax.swing.JScrollPane; - -/** - * - * @author JPEXS - */ -public class TextPanel extends JPanel implements ActionListener { - - private static final String ACTION_EDIT_TEXT = "EDITTEXT"; - private static final String ACTION_CANCEL_TEXT = "CANCELTEXT"; - private static final String ACTION_SAVE_TEXT = "SAVETEXT"; - - private final MainPanel mainPanel; - private final SearchPanel textSearchPanel; - private final LineMarkedEditorPane textValue; - private final JButton textSaveButton; - private final JButton textEditButton; - private final JButton textCancelButton; - - public TextPanel(MainPanel mainPanel) { - super(new BorderLayout()); - - this.mainPanel = mainPanel; - textSearchPanel = new SearchPanel<>(new FlowLayout(), mainPanel); - add(textSearchPanel, BorderLayout.NORTH); - textValue = new LineMarkedEditorPane(); - add(new JScrollPane(textValue), BorderLayout.CENTER); - textValue.setEditable(false); - - JPanel textButtonsPanel = new JPanel(); - textButtonsPanel.setLayout(new FlowLayout()); - - textSaveButton = new JButton(mainPanel.translate("button.save"), View.getIcon("save16")); - textSaveButton.setMargin(new Insets(3, 3, 3, 10)); - textSaveButton.setActionCommand(ACTION_SAVE_TEXT); - textSaveButton.addActionListener(this); - - textEditButton = new JButton(mainPanel.translate("button.edit"), View.getIcon("edit16")); - textEditButton.setMargin(new Insets(3, 3, 3, 10)); - textEditButton.setActionCommand(ACTION_EDIT_TEXT); - textEditButton.addActionListener(this); - - textCancelButton = new JButton(mainPanel.translate("button.cancel"), View.getIcon("cancel16")); - textCancelButton.setMargin(new Insets(3, 3, 3, 10)); - textCancelButton.setActionCommand(ACTION_CANCEL_TEXT); - textCancelButton.addActionListener(this); - - textButtonsPanel.add(textEditButton); - textButtonsPanel.add(textSaveButton); - textButtonsPanel.add(textCancelButton); - - textSaveButton.setVisible(false); - textCancelButton.setVisible(false); - - add(textButtonsPanel, BorderLayout.SOUTH); - } - - public SearchPanel getSearchPanel() { - return textSearchPanel; - } - - public void setText(String text) { - textValue.setContentType("text/swf_text"); - // textValue.setFont(new Font("Monospaced", Font.PLAIN, 13)); - textValue.setText(text); - textValue.setCaretPosition(0); - } - - public void setEditText(boolean edit) { - textValue.setEditable(edit); - textSaveButton.setVisible(edit); - textEditButton.setVisible(!edit); - textCancelButton.setVisible(edit); - } - - public void updateSearchPos() { - textValue.setCaretPosition(0); - View.execInEventDispatchLater(new Runnable() { - - @Override - public void run() { - textSearchPanel.showQuickFindDialog(textValue); - } - }); - } - - @Override - public void actionPerformed(ActionEvent e) { - switch (e.getActionCommand()) { - case ACTION_EDIT_TEXT: - setEditText(true); - break; - case ACTION_CANCEL_TEXT: - setEditText(false); - mainPanel.reload(true); - break; - case ACTION_SAVE_TEXT: - TreeItem item = mainPanel.tagTree.getCurrentTreeItem(); - if (item instanceof TextTag) { - TextTag textTag = (TextTag) item; - if (mainPanel.saveText(textTag, textValue.getText(), null)) { - setEditText(false); - mainPanel.reload(true); - } - SWF.clearImageCache(); - } - break; - } - } -} +/* + * Copyright (C) 2010-2014 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.decompiler.flash.gui; + +import com.jpexs.decompiler.flash.SWF; +import com.jpexs.decompiler.flash.gui.abc.LineMarkedEditorPane; +import com.jpexs.decompiler.flash.tags.base.TextTag; +import com.jpexs.decompiler.flash.treeitems.TreeItem; +import java.awt.BorderLayout; +import java.awt.FlowLayout; +import java.awt.Insets; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javax.swing.JButton; +import javax.swing.JPanel; +import javax.swing.JScrollPane; + +/** + * + * @author JPEXS + */ +public class TextPanel extends JPanel implements ActionListener { + + private static final String ACTION_EDIT_TEXT = "EDITTEXT"; + private static final String ACTION_CANCEL_TEXT = "CANCELTEXT"; + private static final String ACTION_SAVE_TEXT = "SAVETEXT"; + + private final MainPanel mainPanel; + private final SearchPanel textSearchPanel; + private final LineMarkedEditorPane textValue; + private final JButton textSaveButton; + private final JButton textEditButton; + private final JButton textCancelButton; + + public TextPanel(MainPanel mainPanel) { + super(new BorderLayout()); + + this.mainPanel = mainPanel; + textSearchPanel = new SearchPanel<>(new FlowLayout(), mainPanel); + add(textSearchPanel, BorderLayout.NORTH); + textValue = new LineMarkedEditorPane(); + add(new JScrollPane(textValue), BorderLayout.CENTER); + textValue.setEditable(false); + + JPanel textButtonsPanel = new JPanel(); + textButtonsPanel.setLayout(new FlowLayout()); + + textSaveButton = new JButton(mainPanel.translate("button.save"), View.getIcon("save16")); + textSaveButton.setMargin(new Insets(3, 3, 3, 10)); + textSaveButton.setActionCommand(ACTION_SAVE_TEXT); + textSaveButton.addActionListener(this); + + textEditButton = new JButton(mainPanel.translate("button.edit"), View.getIcon("edit16")); + textEditButton.setMargin(new Insets(3, 3, 3, 10)); + textEditButton.setActionCommand(ACTION_EDIT_TEXT); + textEditButton.addActionListener(this); + + textCancelButton = new JButton(mainPanel.translate("button.cancel"), View.getIcon("cancel16")); + textCancelButton.setMargin(new Insets(3, 3, 3, 10)); + textCancelButton.setActionCommand(ACTION_CANCEL_TEXT); + textCancelButton.addActionListener(this); + + textButtonsPanel.add(textEditButton); + textButtonsPanel.add(textSaveButton); + textButtonsPanel.add(textCancelButton); + + textSaveButton.setVisible(false); + textCancelButton.setVisible(false); + + add(textButtonsPanel, BorderLayout.SOUTH); + } + + public SearchPanel getSearchPanel() { + return textSearchPanel; + } + + public void setText(String text) { + textValue.setContentType("text/swf_text"); + // textValue.setFont(new Font("Monospaced", Font.PLAIN, 13)); + textValue.setText(text); + textValue.setCaretPosition(0); + } + + public void setEditText(boolean edit) { + textValue.setEditable(edit); + textSaveButton.setVisible(edit); + textEditButton.setVisible(!edit); + textCancelButton.setVisible(edit); + } + + public void updateSearchPos() { + textValue.setCaretPosition(0); + View.execInEventDispatchLater(new Runnable() { + + @Override + public void run() { + textSearchPanel.showQuickFindDialog(textValue); + } + }); + } + + @Override + public void actionPerformed(ActionEvent e) { + switch (e.getActionCommand()) { + case ACTION_EDIT_TEXT: + setEditText(true); + break; + case ACTION_CANCEL_TEXT: + setEditText(false); + mainPanel.reload(true); + break; + case ACTION_SAVE_TEXT: + TreeItem item = mainPanel.tagTree.getCurrentTreeItem(); + if (item instanceof TextTag) { + TextTag textTag = (TextTag) item; + if (mainPanel.saveText(textTag, textValue.getText(), null)) { + setEditText(false); + mainPanel.reload(true); + } + SWF.clearImageCache(); + } + break; + } + } +} diff --git a/src/com/jpexs/decompiler/flash/gui/View.java b/src/com/jpexs/decompiler/flash/gui/View.java index 4e77d55c9..ce679d15b 100644 --- a/src/com/jpexs/decompiler/flash/gui/View.java +++ b/src/com/jpexs/decompiler/flash/gui/View.java @@ -504,18 +504,18 @@ public class View { tree.collapsePath(parent); } } - - public static void addEditorAction(JEditorPane editor,AbstractAction a,String key, String name, String keyStroke){ + + public static void addEditorAction(JEditorPane editor, AbstractAction a, String key, String name, String keyStroke) { KeyStroke ks = KeyStroke.getKeyStroke(keyStroke); a.putValue(Action.ACCELERATOR_KEY, ks); a.putValue(Action.NAME, name); - + String actionName = key; ActionMap amap = editor.getActionMap(); InputMap imap = editor.getInputMap(JTextComponent.WHEN_FOCUSED); imap.put(ks, actionName); amap.put(actionName, a); - + JPopupMenu pmenu = editor.getComponentPopupMenu(); JMenuItem findUsagesMenu = new JMenuItem(a); pmenu.add(findUsagesMenu); diff --git a/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java b/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java index 017a21654..eaf70060c 100644 --- a/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java @@ -136,7 +136,7 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se public DetailPanel detailPanel; public JPanel navPanel; public JTabbedPane tabbedPane; - public SearchPanel searchPanel; + public SearchPanel searchPanel; private NewTraitDialog newTraitDialog; public JLabel scriptNameLabel; @@ -155,9 +155,6 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se return mainPanel; } - - - public boolean search(final String txt, boolean ignoreCase, boolean regexp) { if ((txt != null) && (!txt.isEmpty())) { searchPanel.setOptions(ignoreCase, regexp); @@ -207,23 +204,21 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se System.gc(); Main.stopWork(); - + searchPanel.setSearchText(txt); - + View.execInEventDispatch(new Runnable() { @Override public void run() { - SearchResultsDialog sr=new SearchResultsDialog<>(ABCPanel.this.mainPanel.getMainFrame().getWindow(),txt,ABCPanel.this); + SearchResultsDialog sr = new SearchResultsDialog<>(ABCPanel.this.mainPanel.getMainFrame().getWindow(), txt, ABCPanel.this); sr.setResults(found); - sr.setVisible(true); + sr.setVisible(true); } }); - - - + return true; - + //return searchPanel.setResults(found); } return false; @@ -410,7 +405,7 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se iconDecPanel.add(scriptNameLabel); iconDecPanel.add(iconsPanel); iconDecPanel.add(decompiledScrollPane); - + JPanel decButtonsPan = new JPanel(new FlowLayout()); decButtonsPan.setBorder(new BevelBorder(BevelBorder.RAISED)); decButtonsPan.add(editDecompiledButton); @@ -459,32 +454,30 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se }); decompiledTextArea.setContentType("text/actionscript"); decompiledTextArea.setFont(new Font("Monospaced", Font.PLAIN, decompiledTextArea.getFont().getSize())); - - - + View.addEditorAction(decompiledTextArea, new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { - int multinameIndex = decompiledTextArea.getMultinameUnderCursor(); - if(multinameIndex>-1){ - UsageFrame usageFrame = new UsageFrame(swf.abcList, abc, multinameIndex, ABCPanel.this,false); + int multinameIndex = decompiledTextArea.getMultinameUnderCursor(); + if (multinameIndex > -1) { + UsageFrame usageFrame = new UsageFrame(swf.abcList, abc, multinameIndex, ABCPanel.this, false); usageFrame.setVisible(true); } } }, "find-usages", AppStrings.translate("abc.action.find-usages"), "control U"); - + View.addEditorAction(decompiledTextArea, new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { - gotoDeclaration(); + gotoDeclaration(); } - }, "find-declaration", AppStrings.translate("abc.action.find-declaration"), "control B"); - + }, "find-declaration", AppStrings.translate("abc.action.find-declaration"), "control B"); + CtrlClickHandler cch = new CtrlClickHandler(); decompiledTextArea.addKeyListener(cch); decompiledTextArea.addMouseListener(cch); decompiledTextArea.addMouseMotionListener(cch); - + JPanel pan2 = new JPanel(); pan2.setLayout(new BorderLayout()); pan2.add((abcComboBox = new JComboBox<>(new ABCComboBoxModel(new ArrayList()))), BorderLayout.NORTH); @@ -508,7 +501,7 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se }); Main.startWork(AppStrings.translate("work.buildingscripttree") + "..."); - + tabbedPane = new JTabbedPane(); tabbedPane.addTab(AppStrings.translate("traits"), navPanel); abcComboBox.addItemListener(this); @@ -548,45 +541,44 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se panConstants.add(new JScrollPane(constantTable), BorderLayout.CENTER); tabbedPane.addTab(AppStrings.translate("constants"), panConstants); } - - private void gotoDeclaration(){ + + private void gotoDeclaration() { int multinameIndex = decompiledTextArea.getMultinameUnderCursor(); - if(multinameIndex>-1){ - List usages = abc.findMultinameDefinition(swf.abcList,multinameIndex); - + if (multinameIndex > -1) { + List usages = abc.findMultinameDefinition(swf.abcList, multinameIndex); + Multiname m = abc.constants.constant_multiname.get(multinameIndex); //search other ABC tags if this is not private multiname - if(m.namespace_index>0 && abc.constants.constant_namespace.get(m.namespace_index).kind != Namespace.KIND_PRIVATE) - { - for(ABCContainerTag at:swf.abcList){ + if (m.namespace_index > 0 && abc.constants.constant_namespace.get(m.namespace_index).kind != Namespace.KIND_PRIVATE) { + for (ABCContainerTag at : swf.abcList) { ABC a = at.getABC(); - if(a == abc){ + if (a == abc) { continue; - } - int mid=a.constants.getMultinameId(m,false); - if(mid>0){ + } + int mid = a.constants.getMultinameId(m, false); + if (mid > 0) { usages.addAll(a.findMultinameDefinition(swf.abcList, mid)); } } } - + //more than one? display list - if(usages.size()>1){ - UsageFrame usageFrame = new UsageFrame(swf.abcList, abc, multinameIndex, ABCPanel.this,true); + if (usages.size() > 1) { + UsageFrame usageFrame = new UsageFrame(swf.abcList, abc, multinameIndex, ABCPanel.this, true); usageFrame.setVisible(true); - }else if(!usages.isEmpty()){ //one + } else if (!usages.isEmpty()) { //one UsageFrame.gotoUsage(ABCPanel.this, usages.get(0)); } } } - + private class CtrlClickHandler extends KeyAdapter implements MouseListener, MouseMotionListener { private boolean ctrlDown = false; - + @Override - public void keyPressed(KeyEvent e) { - if(e.getKeyCode() == 17 && !decompiledTextArea.isEditable()){ + public void keyPressed(KeyEvent e) { + if (e.getKeyCode() == 17 && !decompiledTextArea.isEditable()) { ctrlDown = true; decompiledTextArea.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); } @@ -594,24 +586,24 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se @Override public void keyReleased(KeyEvent e) { - if(e.getKeyCode() == 17){ + if (e.getKeyCode() == 17) { ctrlDown = false; decompiledTextArea.setCursor(Cursor.getDefaultCursor()); } } - + @Override public void mouseClicked(MouseEvent e) { - if(ctrlDown && e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 1 && !decompiledTextArea.isEditable()){ + if (ctrlDown && e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 1 && !decompiledTextArea.isEditable()) { ctrlDown = false; decompiledTextArea.setCursor(Cursor.getDefaultCursor()); - gotoDeclaration(); - } + gotoDeclaration(); + } } @Override - public void mousePressed(MouseEvent e) { - + public void mousePressed(MouseEvent e) { + } @Override @@ -634,12 +626,12 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se @Override public void mouseMoved(MouseEvent e) { - if(ctrlDown && decompiledTextArea.isEditable()){ + if (ctrlDown && decompiledTextArea.isEditable()) { ctrlDown = false; decompiledTextArea.setCursor(Cursor.getDefaultCursor()); } } - + } public void reload() { @@ -713,11 +705,11 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se View.execInEventDispatchLater(new Runnable() { @Override - public void run() { + public void run() { searchPanel.showQuickFindDialog(decompiledTextArea); } }); - + } public String lastDecompiled = null; @@ -951,6 +943,5 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se break; } } - - + } diff --git a/src/com/jpexs/decompiler/flash/gui/abc/ABCPanelSearchResult.java b/src/com/jpexs/decompiler/flash/gui/abc/ABCPanelSearchResult.java index 8624cf623..931ed8b69 100644 --- a/src/com/jpexs/decompiler/flash/gui/abc/ABCPanelSearchResult.java +++ b/src/com/jpexs/decompiler/flash/gui/abc/ABCPanelSearchResult.java @@ -1,37 +1,36 @@ -/* - * Copyright (C) 2010-2014 JPEXS - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.jpexs.decompiler.flash.gui.abc; - -import com.jpexs.decompiler.flash.abc.ClassPath; -import com.jpexs.decompiler.flash.abc.ScriptPack; - -/** - * - * @author JPEXS - */ -public class ABCPanelSearchResult { - - public ScriptPack scriptPack; - public ClassPath classPath; - - @Override - public String toString() { - return classPath.toString(); - } - - -} +/* + * Copyright (C) 2010-2014 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.decompiler.flash.gui.abc; + +import com.jpexs.decompiler.flash.abc.ClassPath; +import com.jpexs.decompiler.flash.abc.ScriptPack; + +/** + * + * @author JPEXS + */ +public class ABCPanelSearchResult { + + public ScriptPack scriptPack; + public ClassPath classPath; + + @Override + public String toString() { + return classPath.toString(); + } + +} diff --git a/src/com/jpexs/decompiler/flash/gui/abc/ASMSourceEditorPane.java b/src/com/jpexs/decompiler/flash/gui/abc/ASMSourceEditorPane.java index 0b7399579..a38fa9060 100644 --- a/src/com/jpexs/decompiler/flash/gui/abc/ASMSourceEditorPane.java +++ b/src/com/jpexs/decompiler/flash/gui/abc/ASMSourceEditorPane.java @@ -1,348 +1,348 @@ -/* - * Copyright (C) 2010-2014 JPEXS - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.jpexs.decompiler.flash.gui.abc; - -import com.jpexs.decompiler.flash.abc.ABC; -import com.jpexs.decompiler.flash.abc.avm2.AVM2Code; -import com.jpexs.decompiler.flash.abc.avm2.ConstantPool; -import com.jpexs.decompiler.flash.abc.avm2.UnknownInstructionCode; -import com.jpexs.decompiler.flash.abc.avm2.graph.AVM2Graph; -import com.jpexs.decompiler.flash.abc.avm2.parser.ParseException; -import com.jpexs.decompiler.flash.abc.avm2.parser.pcode.ASM3Parser; -import com.jpexs.decompiler.flash.abc.avm2.parser.pcode.MissingSymbolHandler; -import com.jpexs.decompiler.flash.abc.types.MethodBody; -import com.jpexs.decompiler.flash.abc.types.traits.Trait; -import com.jpexs.decompiler.flash.configuration.Configuration; -import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode; -import com.jpexs.decompiler.flash.gui.GraphDialog; -import com.jpexs.decompiler.flash.gui.View; -import com.jpexs.decompiler.flash.helpers.HilightedText; -import com.jpexs.decompiler.flash.helpers.HilightedTextWriter; -import com.jpexs.decompiler.flash.helpers.hilight.Highlighting; -import com.jpexs.decompiler.flash.tags.Tag; -import com.jpexs.decompiler.graph.GraphTargetItem; -import com.jpexs.helpers.Helper; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.StringReader; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Stack; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.swing.event.CaretEvent; -import javax.swing.event.CaretListener; - -public class ASMSourceEditorPane extends LineMarkedEditorPane implements CaretListener { - - public ABC abc; - public int bodyIndex = -1; - private List disassembledHilights = new ArrayList<>(); - private List specialHilights = new ArrayList<>(); - private final DecompiledEditorPane decompiledEditor; - private boolean ignoreCarret = false; - private String name; - private HilightedText textWithHex; - private HilightedText textNoHex; - private HilightedText textHexOnly; - private ScriptExportMode exportMode = ScriptExportMode.PCODE; - private Trait trait; - - public ABCPanel getAbcPanel(){ - return decompiledEditor.getAbcPanel(); - } - - public ScriptExportMode getExportMode() { - return exportMode; - } - - private HilightedText getHilightedText(ScriptExportMode exportMode) { - HilightedTextWriter writer = new HilightedTextWriter(Configuration.getCodeFormatting(), true); - abc.bodies.get(bodyIndex).code.toASMSource(abc.constants, trait, abc.method_info.get(abc.bodies.get(bodyIndex).method_info), abc.bodies.get(bodyIndex), exportMode, writer); - return new HilightedText(writer); - } - - public void setHex(ScriptExportMode exportMode, boolean force) { - if (this.exportMode == exportMode & !force) { - return; - } - this.exportMode = exportMode; - long oldOffset = getSelectedOffset(); - if (exportMode == ScriptExportMode.PCODE) { - setContentType("text/flasm"); - if (textNoHex == null) { - textNoHex = getHilightedText(exportMode); - } - setText(textNoHex); - } else if (exportMode == ScriptExportMode.PCODE_HEX) { - setContentType("text/flasm"); - if (textWithHex == null) { - textWithHex = getHilightedText(exportMode); - } - setText(textWithHex); - } else { - setContentType("text/plain"); - if (textHexOnly == null) { - HilightedTextWriter writer = new HilightedTextWriter(Configuration.getCodeFormatting(), true); - Helper.byteArrayToHexWithHeader(writer, abc.bodies.get(bodyIndex).code.getBytes()); - textHexOnly = new HilightedText(writer); - } - setText(textHexOnly); - } - hilighOffset(oldOffset); - } - - public void setIgnoreCarret(boolean ignoreCarret) { - this.ignoreCarret = ignoreCarret; - } - - public ASMSourceEditorPane(DecompiledEditorPane decompiledEditor) { - this.decompiledEditor = decompiledEditor; - addCaretListener(this); - } - - public void hilighSpecial(String type, int index) { - Highlighting h2 = null; - for (Highlighting sh : specialHilights) { - if (type.equals(sh.getPropertyString("subtype"))) { - if (sh.getPropertyString("index").equals("" + index)) { - h2 = sh; - break; - } - } - } - if (h2 != null) { - ignoreCarret = true; - if (h2.startPos <= getDocument().getLength()) { - setCaretPosition(h2.startPos); - } - getCaret().setVisible(true); - ignoreCarret = false; - } - } - - public void hilighOffset(long offset) { - if (isEditable()) { - return; - } - Highlighting h2 = Highlighting.search(disassembledHilights, "offset", "" + offset); - if (h2 != null) { - ignoreCarret = true; - if (h2.startPos <= getDocument().getLength()) { - setCaretPosition(h2.startPos); - } - getCaret().setVisible(true); - ignoreCarret = false; - } - } - - @Override - public String getName() { - return super.getName(); - } - - public void setBodyIndex(int bodyIndex, ABC abc, String name, Trait trait) { - this.bodyIndex = bodyIndex; - this.abc = abc; - this.name = name; - this.trait = trait; - if (bodyIndex == -1) { - return; - } - textWithHex = null; - textNoHex = null; - setHex(exportMode, true); - } - - public void graph() { - try { - AVM2Graph gr = new AVM2Graph(abc.bodies.get(bodyIndex).code, abc, abc.bodies.get(bodyIndex), false, -1, -1, new HashMap(), new Stack(), new HashMap(), new ArrayList(), new HashMap(), abc.bodies.get(bodyIndex).code.visitCode(abc.bodies.get(bodyIndex))); - (new GraphDialog(getAbcPanel().getMainPanel().getMainFrame().getWindow(),gr, name)).setVisible(true); - } catch (InterruptedException ex) { - Logger.getLogger(ASMSourceEditorPane.class.getName()).log(Level.SEVERE, null, ex); - } - } - - public void exec() { - HashMap args = new HashMap<>(); - args.put(0, new Object()); //object "this" - args.put(1, new Long(466561)); //param1 - Object o = abc.bodies.get(bodyIndex).code.execute(args, abc.constants); - View.showMessageDialog(this, "Returned object:" + o.toString()); - } - - public boolean save(ConstantPool constants) { - try { - String text = getText(); - if (text.trim().startsWith("#hexdata")) { - byte[] data = Helper.getBytesFromHexaText(text); - MethodBody mb = abc.bodies.get(bodyIndex); - mb.codeBytes = data; - try { - mb.code = new AVM2Code(new ByteArrayInputStream(mb.codeBytes)); - } catch (UnknownInstructionCode re) { - mb.code = new AVM2Code(); - Logger.getLogger(ABC.class.getName()).log(Level.SEVERE, null, re); - } - mb.code.compact(); - } else { - AVM2Code acode = ASM3Parser.parse(new StringReader(text), constants, trait, new MissingSymbolHandler() { - //no longer ask for adding new constants - @Override - public boolean missingString(String value) { - return true; - } - - @Override - public boolean missingInt(long value) { - return true; - } - - @Override - public boolean missingUInt(long value) { - return true; - } - - @Override - public boolean missingDouble(double value) { - return true; - } - }, abc.bodies.get(bodyIndex), abc.method_info.get(abc.bodies.get(bodyIndex).method_info)); - acode.getBytes(abc.bodies.get(bodyIndex).codeBytes); - abc.bodies.get(bodyIndex).code = acode; - } - ((Tag) abc.parentTag).setModified(true); - } catch (IOException ex) { - } catch (InterruptedException ex) { - } catch (ParseException ex) { - View.showMessageDialog(this, (ex.text + " on line " + ex.line)); - selectLine((int) ex.line); - return false; - } - return true; - } - - @Override - public void setText(String t) { - disassembledHilights = new ArrayList<>(); - specialHilights = new ArrayList<>(); - super.setText(t); - setCaretPosition(0); - } - - public void setText(HilightedText hilightedText) { - disassembledHilights = hilightedText.instructionHilights; - specialHilights = hilightedText.specialHilights; - super.setText(hilightedText.text); - setCaretPosition(0); - } - - public void clear() { - setText(""); - bodyIndex = -1; - setCaretPosition(0); - } - - public void selectInstruction(int pos) { - String text = getText(); - int lineCnt = 1; - int lineStart = 0; - int lineEnd; - int instrCount = 0; - int dot = -2; - for (int i = 0; i < text.length(); i++) { - if (text.charAt(i) == '\n') { - - lineCnt++; - lineEnd = i; - String ins = text.substring(lineStart, lineEnd).trim(); - if (!((i > 0) && (text.charAt(i - 1) == ':'))) { - if (!ins.startsWith("exception ")) { - instrCount++; - } - } - if (instrCount == pos + 1) { - break; - } - lineStart = i + 1; - } - } - if (lineCnt == -1) { - //lineEnd = text.length() - 1; - } - //select(lineStart, lineEnd); - setCaretPosition(lineStart); - //requestFocus(); - } - - public void selectLine(int line) { - String text = getText(); - int lineCnt = 1; - int lineStart = 0; - int lineEnd = -1; - for (int i = 0; i < text.length(); i++) { - if (text.charAt(i) == '\n') { - lineCnt++; - if (lineCnt == line) { - lineStart = i; - } - if (lineCnt == line + 1) { - lineEnd = i; - } - } - } - if (lineCnt == -1) { - lineEnd = text.length() - 1; - } - select(lineStart, lineEnd); - requestFocus(); - } - - public Highlighting getSelectedSpecial() { - return Highlighting.search(specialHilights, getCaretPosition()); - } - - public long getSelectedOffset() { - int pos = getCaretPosition(); - Highlighting lastH = null; - for (Highlighting h : disassembledHilights) { - if (pos < h.startPos) { - break; - } - lastH = h; - } - return lastH == null ? 0 : lastH.getPropertyLong("offset"); - } - - @Override - public void caretUpdate(CaretEvent e) { - if (isEditable()) { - return; - } - if (ignoreCarret) { - return; - } - getCaret().setVisible(true); - - decompiledEditor.hilightOffset(getSelectedOffset()); - Highlighting spec = getSelectedSpecial(); - if (spec != null) { - decompiledEditor.hilightSpecial(spec.getPropertyString("subtype"), (int) (long) spec.getPropertyLong("index")); - } - } -} +/* + * Copyright (C) 2010-2014 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.decompiler.flash.gui.abc; + +import com.jpexs.decompiler.flash.abc.ABC; +import com.jpexs.decompiler.flash.abc.avm2.AVM2Code; +import com.jpexs.decompiler.flash.abc.avm2.ConstantPool; +import com.jpexs.decompiler.flash.abc.avm2.UnknownInstructionCode; +import com.jpexs.decompiler.flash.abc.avm2.graph.AVM2Graph; +import com.jpexs.decompiler.flash.abc.avm2.parser.ParseException; +import com.jpexs.decompiler.flash.abc.avm2.parser.pcode.ASM3Parser; +import com.jpexs.decompiler.flash.abc.avm2.parser.pcode.MissingSymbolHandler; +import com.jpexs.decompiler.flash.abc.types.MethodBody; +import com.jpexs.decompiler.flash.abc.types.traits.Trait; +import com.jpexs.decompiler.flash.configuration.Configuration; +import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode; +import com.jpexs.decompiler.flash.gui.GraphDialog; +import com.jpexs.decompiler.flash.gui.View; +import com.jpexs.decompiler.flash.helpers.HilightedText; +import com.jpexs.decompiler.flash.helpers.HilightedTextWriter; +import com.jpexs.decompiler.flash.helpers.hilight.Highlighting; +import com.jpexs.decompiler.flash.tags.Tag; +import com.jpexs.decompiler.graph.GraphTargetItem; +import com.jpexs.helpers.Helper; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.StringReader; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Stack; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.swing.event.CaretEvent; +import javax.swing.event.CaretListener; + +public class ASMSourceEditorPane extends LineMarkedEditorPane implements CaretListener { + + public ABC abc; + public int bodyIndex = -1; + private List disassembledHilights = new ArrayList<>(); + private List specialHilights = new ArrayList<>(); + private final DecompiledEditorPane decompiledEditor; + private boolean ignoreCarret = false; + private String name; + private HilightedText textWithHex; + private HilightedText textNoHex; + private HilightedText textHexOnly; + private ScriptExportMode exportMode = ScriptExportMode.PCODE; + private Trait trait; + + public ABCPanel getAbcPanel() { + return decompiledEditor.getAbcPanel(); + } + + public ScriptExportMode getExportMode() { + return exportMode; + } + + private HilightedText getHilightedText(ScriptExportMode exportMode) { + HilightedTextWriter writer = new HilightedTextWriter(Configuration.getCodeFormatting(), true); + abc.bodies.get(bodyIndex).code.toASMSource(abc.constants, trait, abc.method_info.get(abc.bodies.get(bodyIndex).method_info), abc.bodies.get(bodyIndex), exportMode, writer); + return new HilightedText(writer); + } + + public void setHex(ScriptExportMode exportMode, boolean force) { + if (this.exportMode == exportMode & !force) { + return; + } + this.exportMode = exportMode; + long oldOffset = getSelectedOffset(); + if (exportMode == ScriptExportMode.PCODE) { + setContentType("text/flasm"); + if (textNoHex == null) { + textNoHex = getHilightedText(exportMode); + } + setText(textNoHex); + } else if (exportMode == ScriptExportMode.PCODE_HEX) { + setContentType("text/flasm"); + if (textWithHex == null) { + textWithHex = getHilightedText(exportMode); + } + setText(textWithHex); + } else { + setContentType("text/plain"); + if (textHexOnly == null) { + HilightedTextWriter writer = new HilightedTextWriter(Configuration.getCodeFormatting(), true); + Helper.byteArrayToHexWithHeader(writer, abc.bodies.get(bodyIndex).code.getBytes()); + textHexOnly = new HilightedText(writer); + } + setText(textHexOnly); + } + hilighOffset(oldOffset); + } + + public void setIgnoreCarret(boolean ignoreCarret) { + this.ignoreCarret = ignoreCarret; + } + + public ASMSourceEditorPane(DecompiledEditorPane decompiledEditor) { + this.decompiledEditor = decompiledEditor; + addCaretListener(this); + } + + public void hilighSpecial(String type, int index) { + Highlighting h2 = null; + for (Highlighting sh : specialHilights) { + if (type.equals(sh.getPropertyString("subtype"))) { + if (sh.getPropertyString("index").equals("" + index)) { + h2 = sh; + break; + } + } + } + if (h2 != null) { + ignoreCarret = true; + if (h2.startPos <= getDocument().getLength()) { + setCaretPosition(h2.startPos); + } + getCaret().setVisible(true); + ignoreCarret = false; + } + } + + public void hilighOffset(long offset) { + if (isEditable()) { + return; + } + Highlighting h2 = Highlighting.search(disassembledHilights, "offset", "" + offset); + if (h2 != null) { + ignoreCarret = true; + if (h2.startPos <= getDocument().getLength()) { + setCaretPosition(h2.startPos); + } + getCaret().setVisible(true); + ignoreCarret = false; + } + } + + @Override + public String getName() { + return super.getName(); + } + + public void setBodyIndex(int bodyIndex, ABC abc, String name, Trait trait) { + this.bodyIndex = bodyIndex; + this.abc = abc; + this.name = name; + this.trait = trait; + if (bodyIndex == -1) { + return; + } + textWithHex = null; + textNoHex = null; + setHex(exportMode, true); + } + + public void graph() { + try { + AVM2Graph gr = new AVM2Graph(abc.bodies.get(bodyIndex).code, abc, abc.bodies.get(bodyIndex), false, -1, -1, new HashMap(), new Stack(), new HashMap(), new ArrayList(), new HashMap(), abc.bodies.get(bodyIndex).code.visitCode(abc.bodies.get(bodyIndex))); + (new GraphDialog(getAbcPanel().getMainPanel().getMainFrame().getWindow(), gr, name)).setVisible(true); + } catch (InterruptedException ex) { + Logger.getLogger(ASMSourceEditorPane.class.getName()).log(Level.SEVERE, null, ex); + } + } + + public void exec() { + HashMap args = new HashMap<>(); + args.put(0, new Object()); //object "this" + args.put(1, new Long(466561)); //param1 + Object o = abc.bodies.get(bodyIndex).code.execute(args, abc.constants); + View.showMessageDialog(this, "Returned object:" + o.toString()); + } + + public boolean save(ConstantPool constants) { + try { + String text = getText(); + if (text.trim().startsWith("#hexdata")) { + byte[] data = Helper.getBytesFromHexaText(text); + MethodBody mb = abc.bodies.get(bodyIndex); + mb.codeBytes = data; + try { + mb.code = new AVM2Code(new ByteArrayInputStream(mb.codeBytes)); + } catch (UnknownInstructionCode re) { + mb.code = new AVM2Code(); + Logger.getLogger(ABC.class.getName()).log(Level.SEVERE, null, re); + } + mb.code.compact(); + } else { + AVM2Code acode = ASM3Parser.parse(new StringReader(text), constants, trait, new MissingSymbolHandler() { + //no longer ask for adding new constants + @Override + public boolean missingString(String value) { + return true; + } + + @Override + public boolean missingInt(long value) { + return true; + } + + @Override + public boolean missingUInt(long value) { + return true; + } + + @Override + public boolean missingDouble(double value) { + return true; + } + }, abc.bodies.get(bodyIndex), abc.method_info.get(abc.bodies.get(bodyIndex).method_info)); + acode.getBytes(abc.bodies.get(bodyIndex).codeBytes); + abc.bodies.get(bodyIndex).code = acode; + } + ((Tag) abc.parentTag).setModified(true); + } catch (IOException ex) { + } catch (InterruptedException ex) { + } catch (ParseException ex) { + View.showMessageDialog(this, (ex.text + " on line " + ex.line)); + selectLine((int) ex.line); + return false; + } + return true; + } + + @Override + public void setText(String t) { + disassembledHilights = new ArrayList<>(); + specialHilights = new ArrayList<>(); + super.setText(t); + setCaretPosition(0); + } + + public void setText(HilightedText hilightedText) { + disassembledHilights = hilightedText.instructionHilights; + specialHilights = hilightedText.specialHilights; + super.setText(hilightedText.text); + setCaretPosition(0); + } + + public void clear() { + setText(""); + bodyIndex = -1; + setCaretPosition(0); + } + + public void selectInstruction(int pos) { + String text = getText(); + int lineCnt = 1; + int lineStart = 0; + int lineEnd; + int instrCount = 0; + int dot = -2; + for (int i = 0; i < text.length(); i++) { + if (text.charAt(i) == '\n') { + + lineCnt++; + lineEnd = i; + String ins = text.substring(lineStart, lineEnd).trim(); + if (!((i > 0) && (text.charAt(i - 1) == ':'))) { + if (!ins.startsWith("exception ")) { + instrCount++; + } + } + if (instrCount == pos + 1) { + break; + } + lineStart = i + 1; + } + } + if (lineCnt == -1) { + //lineEnd = text.length() - 1; + } + //select(lineStart, lineEnd); + setCaretPosition(lineStart); + //requestFocus(); + } + + public void selectLine(int line) { + String text = getText(); + int lineCnt = 1; + int lineStart = 0; + int lineEnd = -1; + for (int i = 0; i < text.length(); i++) { + if (text.charAt(i) == '\n') { + lineCnt++; + if (lineCnt == line) { + lineStart = i; + } + if (lineCnt == line + 1) { + lineEnd = i; + } + } + } + if (lineCnt == -1) { + lineEnd = text.length() - 1; + } + select(lineStart, lineEnd); + requestFocus(); + } + + public Highlighting getSelectedSpecial() { + return Highlighting.search(specialHilights, getCaretPosition()); + } + + public long getSelectedOffset() { + int pos = getCaretPosition(); + Highlighting lastH = null; + for (Highlighting h : disassembledHilights) { + if (pos < h.startPos) { + break; + } + lastH = h; + } + return lastH == null ? 0 : lastH.getPropertyLong("offset"); + } + + @Override + public void caretUpdate(CaretEvent e) { + if (isEditable()) { + return; + } + if (ignoreCarret) { + return; + } + getCaret().setVisible(true); + + decompiledEditor.hilightOffset(getSelectedOffset()); + Highlighting spec = getSelectedSpecial(); + if (spec != null) { + decompiledEditor.hilightSpecial(spec.getPropertyString("subtype"), (int) (long) spec.getPropertyLong("index")); + } + } +} diff --git a/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java b/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java index 6125b1674..831e804f6 100644 --- a/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java +++ b/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java @@ -61,29 +61,27 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL private boolean isStatic = false; private final Cache cache = Cache.getInstance(true); private Trait currentTrait = null; - + private final List scriptListeners = new ArrayList(); - - public void addScriptListener(Runnable l){ + + public void addScriptListener(Runnable l) { scriptListeners.add(l); } public ABCPanel getAbcPanel() { return abcPanel; } - - - - public void removeScriptListener(Runnable l){ + + public void removeScriptListener(Runnable l) { scriptListeners.remove(l); } - public void fireScript(){ - for(int i=0;i abcList; @@ -537,7 +535,7 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL } @Override - public void setText(String t) { + public void setText(String t) { super.setText(t); setCaretPosition(0); } diff --git a/src/com/jpexs/decompiler/flash/gui/abc/UsageFrame.java b/src/com/jpexs/decompiler/flash/gui/abc/UsageFrame.java index 60977b51f..862c924b3 100644 --- a/src/com/jpexs/decompiler/flash/gui/abc/UsageFrame.java +++ b/src/com/jpexs/decompiler/flash/gui/abc/UsageFrame.java @@ -58,18 +58,17 @@ public class UsageFrame extends AppDialog implements ActionListener, MouseListen public UsageFrame(List abcTags, ABC abc, int multinameIndex, ABCPanel abcPanel, boolean definitions) { super(abcPanel.getMainPanel().getMainFrame().getWindow()); this.abcPanel = abcPanel; - List usages = definitions?abc.findMultinameDefinition(abcTags,multinameIndex):abc.findMultinameUsage(abcTags,multinameIndex); + List usages = definitions ? abc.findMultinameDefinition(abcTags, multinameIndex) : abc.findMultinameUsage(abcTags, multinameIndex); Multiname m = abc.constants.constant_multiname.get(multinameIndex); - if(m.namespace_index>0 && abc.constants.constant_namespace.get(m.namespace_index).kind != Namespace.KIND_PRIVATE) - { - for(ABCContainerTag at:abcTags){ + if (m.namespace_index > 0 && abc.constants.constant_namespace.get(m.namespace_index).kind != Namespace.KIND_PRIVATE) { + for (ABCContainerTag at : abcTags) { ABC a = at.getABC(); - if(a == abc){ + if (a == abc) { continue; - } - int mid=a.constants.getMultinameId(m,false); - if(mid>0){ - usages.addAll(definitions?a.findMultinameDefinition(abcTags, mid):a.findMultinameUsage(abcTags, mid)); + } + int mid = a.constants.getMultinameId(m, false); + if (mid > 0) { + usages.addAll(definitions ? a.findMultinameDefinition(abcTags, mid) : a.findMultinameUsage(abcTags, mid)); } } } @@ -94,57 +93,56 @@ public class UsageFrame extends AppDialog implements ActionListener, MouseListen cont.add(new JScrollPane(usageList), BorderLayout.CENTER); cont.add(buttonsPanel, BorderLayout.SOUTH); setSize(400, 300); - setTitle((definitions?translate("dialog.title.declaration"):translate("dialog.title")) + abc.constants.getMultiname(multinameIndex).getNameWithNamespace(abc.constants)); + setTitle((definitions ? translate("dialog.title.declaration") : translate("dialog.title")) + abc.constants.getMultiname(multinameIndex).getNameWithNamespace(abc.constants)); View.centerScreen(this); View.setWindowIcon(this); } - public static void gotoUsage(final ABCPanel abcPanel,final MultinameUsage usage){ + public static void gotoUsage(final ABCPanel abcPanel, final MultinameUsage usage) { if (usage instanceof InsideClassMultinameUsage) { - final InsideClassMultinameUsage icu = (InsideClassMultinameUsage) usage; - - Runnable settrait = new Runnable() { + final InsideClassMultinameUsage icu = (InsideClassMultinameUsage) usage; - @Override - public void run() { - abcPanel.decompiledTextArea.removeScriptListener(this); - abcPanel.decompiledTextArea.setClassIndex(icu.classIndex); - if (usage instanceof TraitMultinameUsage) { - TraitMultinameUsage tmu = (TraitMultinameUsage) usage; - int traitIndex; - if (tmu.parentTraitIndex > -1) { - traitIndex = tmu.parentTraitIndex; - } else { - traitIndex = tmu.traitIndex; - } - if (!tmu.isStatic) { - traitIndex += abcPanel.abc.class_info.get(tmu.classIndex).static_traits.traits.size(); - } - if (tmu instanceof MethodMultinameUsage) { - MethodMultinameUsage mmu = (MethodMultinameUsage) usage; - if (mmu.isInitializer == true) { - traitIndex = abcPanel.abc.class_info.get(mmu.classIndex).static_traits.traits.size() + abcPanel.abc.instance_info.get(mmu.classIndex).instance_traits.traits.size() + (mmu.isStatic ? 1 : 0); - } - } - abcPanel.decompiledTextArea.gotoTrait(traitIndex); + Runnable settrait = new Runnable() { + + @Override + public void run() { + abcPanel.decompiledTextArea.removeScriptListener(this); + abcPanel.decompiledTextArea.setClassIndex(icu.classIndex); + if (usage instanceof TraitMultinameUsage) { + TraitMultinameUsage tmu = (TraitMultinameUsage) usage; + int traitIndex; + if (tmu.parentTraitIndex > -1) { + traitIndex = tmu.parentTraitIndex; + } else { + traitIndex = tmu.traitIndex; } + if (!tmu.isStatic) { + traitIndex += abcPanel.abc.class_info.get(tmu.classIndex).static_traits.traits.size(); + } + if (tmu instanceof MethodMultinameUsage) { + MethodMultinameUsage mmu = (MethodMultinameUsage) usage; + if (mmu.isInitializer == true) { + traitIndex = abcPanel.abc.class_info.get(mmu.classIndex).static_traits.traits.size() + abcPanel.abc.instance_info.get(mmu.classIndex).instance_traits.traits.size() + (mmu.isStatic ? 1 : 0); + } + } + abcPanel.decompiledTextArea.gotoTrait(traitIndex); } - }; - - - if(abcPanel.decompiledTextArea.getClassIndex() == icu.classIndex && abcPanel.abc == icu.abc){ - settrait.run(); - }else{ - abcPanel.decompiledTextArea.addScriptListener(settrait); - abcPanel.hilightScript(abcPanel.swf, abcPanel.abc.instance_info.get(icu.classIndex).getName(abcPanel.abc.constants).getNameWithNamespace(abcPanel.abc.constants)); - } + } + }; + + if (abcPanel.decompiledTextArea.getClassIndex() == icu.classIndex && abcPanel.abc == icu.abc) { + settrait.run(); + } else { + abcPanel.decompiledTextArea.addScriptListener(settrait); + abcPanel.hilightScript(abcPanel.swf, abcPanel.abc.instance_info.get(icu.classIndex).getName(abcPanel.abc.constants).getNameWithNamespace(abcPanel.abc.constants)); } + } } - + private void gotoUsage() { if (usageList.getSelectedIndex() != -1) { MultinameUsage usage = usageListModel.getUsage(usageList.getSelectedIndex()); - gotoUsage(abcPanel,usage); + gotoUsage(abcPanel, usage); } } diff --git a/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java b/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java index 930c7c753..d9088e9a1 100644 --- a/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java @@ -1,806 +1,806 @@ -/* - * Copyright (C) 2010-2014 JPEXS - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.jpexs.decompiler.flash.gui.action; - -import com.jpexs.decompiler.flash.AppStrings; -import com.jpexs.decompiler.flash.DisassemblyListener; -import com.jpexs.decompiler.flash.SWF; -import com.jpexs.decompiler.flash.action.Action; -import com.jpexs.decompiler.flash.action.ActionGraph; -import com.jpexs.decompiler.flash.action.parser.ParseException; -import com.jpexs.decompiler.flash.action.parser.pcode.ASMParser; -import com.jpexs.decompiler.flash.action.parser.script.ActionScriptParser; -import com.jpexs.decompiler.flash.action.swf4.ActionPush; -import com.jpexs.decompiler.flash.action.swf4.ConstantIndex; -import com.jpexs.decompiler.flash.configuration.Configuration; -import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode; -import com.jpexs.decompiler.flash.gui.GraphDialog; -import com.jpexs.decompiler.flash.gui.HeaderLabel; -import com.jpexs.decompiler.flash.gui.Main; -import com.jpexs.decompiler.flash.gui.MainPanel; -import com.jpexs.decompiler.flash.gui.SearchListener; -import com.jpexs.decompiler.flash.gui.SearchPanel; -import com.jpexs.decompiler.flash.gui.SearchResultsDialog; -import com.jpexs.decompiler.flash.gui.TagTreeModel; -import com.jpexs.decompiler.flash.gui.View; -import com.jpexs.decompiler.flash.gui.abc.LineMarkedEditorPane; -import com.jpexs.decompiler.flash.helpers.HilightedText; -import com.jpexs.decompiler.flash.helpers.HilightedTextWriter; -import com.jpexs.decompiler.flash.helpers.hilight.Highlighting; -import com.jpexs.decompiler.flash.tags.base.ASMSource; -import com.jpexs.decompiler.flash.treenodes.TreeNode; -import com.jpexs.decompiler.graph.CompilationException; -import com.jpexs.decompiler.graph.GraphTargetItem; -import com.jpexs.helpers.Cache; -import com.jpexs.helpers.CancellableWorker; -import com.jpexs.helpers.Helper; -import java.awt.BorderLayout; -import java.awt.FlowLayout; -import java.awt.Font; -import java.awt.Insets; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.concurrent.CancellationException; -import java.util.logging.Level; -import java.util.logging.Logger; -import java.util.regex.Pattern; -import javax.swing.BoxLayout; -import javax.swing.JButton; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JSplitPane; -import javax.swing.JToggleButton; -import javax.swing.SwingConstants; -import javax.swing.event.CaretEvent; -import javax.swing.event.CaretListener; -import javax.swing.tree.TreePath; -import jsyntaxpane.DefaultSyntaxKit; - -public class ActionPanel extends JPanel implements ActionListener, SearchListener { - - static final String ACTION_GRAPH = "GRAPH"; - static final String ACTION_HEX = "HEX"; - static final String ACTION_HEX_ONLY = "HEXONLY"; - static final String ACTION_SAVE_ACTION = "SAVEACTION"; - static final String ACTION_EDIT_ACTION = "EDITACTION"; - static final String ACTION_CANCEL_ACTION = "CANCELACTION"; - static final String ACTION_SAVE_DECOMPILED = "SAVEDECOMPILED"; - static final String ACTION_EDIT_DECOMPILED = "EDITDECOMPILED"; - static final String ACTION_CANCEL_DECOMPILED = "CANCELDECOMPILED"; - - private MainPanel mainPanel; - public LineMarkedEditorPane editor; - public LineMarkedEditorPane decompiledEditor; - public JSplitPane splitPane; - public JButton saveButton = new JButton(AppStrings.translate("button.save"), View.getIcon("save16")); - public JButton editButton = new JButton(AppStrings.translate("button.edit"), View.getIcon("edit16")); - public JButton cancelButton = new JButton(AppStrings.translate("button.cancel"), View.getIcon("cancel16")); - public JLabel experimentalLabel = new JLabel(AppStrings.translate("action.edit.experimental")); - public JButton editDecompiledButton = new JButton(AppStrings.translate("button.edit"), View.getIcon("edit16")); - public JButton saveDecompiledButton = new JButton(AppStrings.translate("button.save"), View.getIcon("save16")); - public JButton cancelDecompiledButton = new JButton(AppStrings.translate("button.cancel"), View.getIcon("cancel16")); - public JToggleButton hexButton; - public JToggleButton hexOnlyButton; - public JLabel asmLabel = new HeaderLabel(AppStrings.translate("panel.disassembled")); - public JLabel decLabel = new HeaderLabel(AppStrings.translate("panel.decompiled")); - public List decompiledHilights = new ArrayList<>(); - public List disassembledHilights = new ArrayList<>(); - private boolean ignoreCarret = false; - private boolean editMode = false; - private boolean editDecompiledMode = false; - private List lastCode; - private ASMSource src; - public JPanel topButtonsPan; - private HilightedText srcWithHex; - private HilightedText srcNoHex; - private HilightedText srcHexOnly; - private String lastDecompiled = ""; - private ASMSource lastASM; - public SearchPanel searchPanel; - private Cache cache = Cache.getInstance(true); - private CancellableWorker setSourceWorker; - - public void clearSource() { - lastCode = null; - lastASM = null; - lastDecompiled = null; - searchPanel.clear(); - src = null; - srcWithHex = null; - srcNoHex = null; - srcHexOnly = null; - } - - public void clearCache() { - cache.clear(); - } - - public String getStringUnderCursor() { - int pos = decompiledEditor.getCaretPosition(); - Highlighting h = Highlighting.search(decompiledHilights, pos); - if (h != null) { - List list = lastCode; - Action lastIns = null; - int inspos = 0; - Action selIns = null; - for (Action ins : list) { - if (h.getPropertyLong("offset") == ins.getOffset()) { - selIns = ins; - break; - } - if (ins.getOffset() > h.getPropertyLong("offset")) { - inspos = (int) (h.getPropertyLong("offset") - lastIns.getAddress()); - selIns = lastIns; - break; - } - lastIns = ins; - } - if (selIns != null) { - if (selIns instanceof ActionPush) { - ActionPush ap = (ActionPush) selIns; - Object var = ap.values.get(inspos - 1); - String identifier = null; - if (var instanceof String) { - identifier = (String) var; - } - if (var instanceof ConstantIndex) { - identifier = ap.constantPool.get(((ConstantIndex) var).index); - } - return identifier; - } - } - - } - return null; - } - - private CachedScript getCached(ASMSource pack) { - return (CachedScript) cache.get(pack); - } - - private boolean isCached(ASMSource src) { - return cache.contains(src); - } - - private void cacheScript(ASMSource src, List actions) throws InterruptedException { - if (!cache.contains(src)) { - if (actions == null) { - actions = src.getActions(); - } - HilightedTextWriter writer = new HilightedTextWriter(Configuration.getCodeFormatting(), true); - Action.actionsToSource(src, actions, src.toString()/*FIXME?*/, writer); - List hilights = writer.instructionHilights; - String srcNoHex = writer.toString(); - cache.put(src, new CachedScript(srcNoHex, hilights)); - } - } - - private void getASMs(String path, List nodes, Map result) { - for (TreeNode n : nodes) { - String subPath = path + "/" + n.toString(); - if (n.getItem() instanceof ASMSource) { - //cacheScript((ASMSource) n.tag); - String npath = subPath; - int ppos = 1; - while (result.containsKey(npath)) { - ppos++; - npath = subPath + "[" + ppos + "]"; - } - result.put(npath, (ASMSource) n.getItem()); - } - - getASMs(subPath, n.subNodes, result); - } - } - - public boolean search(final String txt, boolean ignoreCase, boolean regexp) { - if ((txt != null) && (!txt.isEmpty())) { - searchPanel.setOptions(ignoreCase, regexp); - List list = SWF.createASTagList(mainPanel.getCurrentSwf().tags, null); - Map asms = new HashMap<>(); - getASMs("", list, asms); - final List found = new ArrayList<>(); - Pattern pat = null; - if (regexp) { - pat = Pattern.compile(txt, ignoreCase ? Pattern.CASE_INSENSITIVE : 0); - } else { - pat = Pattern.compile(Pattern.quote(txt), ignoreCase ? Pattern.CASE_INSENSITIVE : 0); - } - int pos = 0; - for (Entry item : asms.entrySet()) { - pos++; - String workText = AppStrings.translate("work.searching"); - String decAdd = ""; - if (!isCached(item.getValue())) { - decAdd = ", " + AppStrings.translate("work.decompiling"); - } - Main.startWork(workText + " \"" + txt + "\"" + decAdd + " - (" + pos + "/" + asms.size() + ") " + item.getKey() + "... "); - try { - cacheScript(item.getValue(), null); - } catch (InterruptedException ex) { - break; - } - if (pat.matcher(getCached(item.getValue()).text).find()) { - found.add(new ActionSearchResult(item.getValue(),item.getKey())); - } - } - - Main.stopWork(); - searchPanel.setSearchText(txt); - View.execInEventDispatch(new Runnable() { - - @Override - public void run() { - SearchResultsDialog sr=new SearchResultsDialog<>(ActionPanel.this.mainPanel.getMainFrame().getWindow(),txt,ActionPanel.this); - sr.setResults(found); - sr.setVisible(true); - } - }); - return true; - //return searchPanel.setResults(found); - } - return false; - } - - private void setDecompiledText(final String text) { - View.execInEventDispatch(new Runnable() { - - @Override - public void run() { - ignoreCarret = true; - decompiledEditor.setText(text, "text/actionscript"); - ignoreCarret = false; - } - }); - } - - private void setEditorText(final String text, final String contentType) { - View.execInEventDispatch(new Runnable() { - - @Override - public void run() { - ignoreCarret = true; - editor.setText(text, contentType); - ignoreCarret = false; - } - }); - } - - private void setText(final HilightedText text, final String contentType) { - View.execInEventDispatch(new Runnable() { - - @Override - public void run() { - int pos = editor.getCaretPosition(); - Highlighting lastH = null; - for (Highlighting h : disassembledHilights) { - if (pos < h.startPos) { - break; - } - lastH = h; - } - String offset = lastH == null ? "0" : lastH.getPropertyString("offset"); - disassembledHilights = text.instructionHilights; - String stripped = text.text; - setEditorText(stripped, contentType); - Highlighting h = Highlighting.search(disassembledHilights, "offset", offset); - if (h != null) { - if (h.startPos <= editor.getDocument().getLength()) { - editor.setCaretPosition(h.startPos); - } - } - } - }); - } - - private HilightedText getHilightedText(ScriptExportMode exportMode) { - ASMSource asm = (ASMSource) src; - DisassemblyListener listener = getDisassemblyListener(); - asm.addDisassemblyListener(listener); - HilightedTextWriter writer = new HilightedTextWriter(Configuration.getCodeFormatting(), true); - try { - asm.getASMSource(exportMode, writer, lastCode); - } catch (InterruptedException ex) { - Logger.getLogger(ActionPanel.class.getName()).log(Level.SEVERE, null, ex); - } - asm.removeDisassemblyListener(listener); - return new HilightedText(writer); - } - - public void setHex(ScriptExportMode exportMode) { - if (exportMode != ScriptExportMode.HEX) { - if (exportMode == ScriptExportMode.PCODE) { - if (srcNoHex == null) { - srcNoHex = getHilightedText(exportMode); - } - setText(srcNoHex, "text/flasm"); - } else { - if (srcWithHex == null) { - srcWithHex = getHilightedText(exportMode); - } - setText(srcWithHex, "text/flasm"); - } - } else { - if (srcHexOnly == null) { - HilightedTextWriter writer = new HilightedTextWriter(Configuration.getCodeFormatting(), true); - Helper.byteArrayToHexWithHeader(writer, src.getActionBytes()); - srcHexOnly = new HilightedText(writer); - } - setText(srcHexOnly, "text/plain"); - } - } - - private DisassemblyListener getDisassemblyListener() { - DisassemblyListener listener = new DisassemblyListener() { - int percent = 0; - String phase = ""; - - @Override - public void progress(String phase, long pos, long total) { - if (total < 1) { - return; - } - int newpercent = (int) (pos * 100 / total); - if (((newpercent > percent) || (!this.phase.equals(phase))) && newpercent <= 100) { - percent = newpercent; - this.phase = phase; - setEditorText("; " + AppStrings.translate("work.disassembling") + " - " + phase + " " + percent + "%...", "text/flasm"); - } - } - }; - return listener; - } - - public void setSource(final ASMSource src, final boolean useCache) { - if (setSourceWorker != null) { - setSourceWorker.cancel(true); - setSourceWorker = null; - } - - this.src = src; - final ASMSource asm = (ASMSource) src; - - CancellableWorker worker = new CancellableWorker() { - - @Override - protected Void doInBackground() throws Exception { - setEditorText("; " + AppStrings.translate("work.disassembling") + "...", "text/flasm"); - if (Configuration.decompile.get()) { - setDecompiledText("//" + AppStrings.translate("work.waitingfordissasembly") + "..."); - } - DisassemblyListener listener = getDisassemblyListener(); - asm.addDisassemblyListener(listener); - List actions = asm.getActions(); - lastCode = actions; - asm.removeDisassemblyListener(listener); - srcWithHex = null; - srcNoHex = null; - srcHexOnly = null; - setHex(getExportMode()); - if (Configuration.decompile.get()) { - setDecompiledText("//" + AppStrings.translate("work.decompiling") + "..."); - if (!useCache) { - uncache(asm); - } - cacheScript(asm, actions); - CachedScript sc = getCached(asm); - decompiledHilights = sc.hilights; - lastDecompiled = sc.text; - lastASM = asm; - setDecompiledText(lastDecompiled); - } - setEditMode(false); - setDecompiledEditMode(false); - return null; - } - - @Override - protected void done() { - setSourceWorker = null; - Main.stopWork(); - - View.execInEventDispatch(new Runnable() { - - @Override - public void run() { - try { - get(); - } catch (CancellationException ex) { - setEditorText("; " + AppStrings.translate("work.canceled"), "text/flasm"); - } catch (Exception ex) { - setDecompiledText("//" + AppStrings.translate("decompilationError") + ": " + ex); - } - } - }); - } - }; - worker.execute(); - setSourceWorker = worker; - Main.startWork(AppStrings.translate("work.decompiling") + "...", worker); - } - - public void hilightOffset(long offset) { - } - - public ActionPanel(MainPanel mainPanel) { - DefaultSyntaxKit.initKit(); - this.mainPanel = mainPanel; - editor = new LineMarkedEditorPane(); - editor.setEditable(false); - decompiledEditor = new LineMarkedEditorPane(); - decompiledEditor.setEditable(false); - - searchPanel = new SearchPanel<>(new FlowLayout(), this); - - JButton graphButton = new JButton(View.getIcon("graph16")); - graphButton.setActionCommand(ACTION_GRAPH); - graphButton.addActionListener(this); - graphButton.setToolTipText(AppStrings.translate("button.viewgraph")); - graphButton.setMargin(new Insets(3, 3, 3, 3)); - - hexButton = new JToggleButton(View.getIcon("hexas16")); - hexButton.setActionCommand(ACTION_HEX); - hexButton.addActionListener(this); - hexButton.setToolTipText(AppStrings.translate("button.viewhex")); - hexButton.setMargin(new Insets(3, 3, 3, 3)); - - hexOnlyButton = new JToggleButton(View.getIcon("hex16")); - hexOnlyButton.setActionCommand(ACTION_HEX_ONLY); - hexOnlyButton.addActionListener(this); - hexOnlyButton.setToolTipText(AppStrings.translate("button.viewhex")); - hexOnlyButton.setMargin(new Insets(3, 3, 3, 3)); - - topButtonsPan = new JPanel(); - topButtonsPan.setLayout(new BoxLayout(topButtonsPan, BoxLayout.X_AXIS)); - topButtonsPan.add(graphButton); - topButtonsPan.add(hexButton); - topButtonsPan.add(hexOnlyButton); - JPanel panCode = new JPanel(new BorderLayout()); - panCode.add(new JScrollPane(editor), BorderLayout.CENTER); - panCode.add(topButtonsPan, BorderLayout.NORTH); - - JPanel panB = new JPanel(); - panB.setLayout(new BorderLayout()); - asmLabel.setHorizontalAlignment(SwingConstants.CENTER); - //asmLabel.setBorder(new BevelBorder(BevelBorder.RAISED)); - panB.add(asmLabel, BorderLayout.NORTH); - panB.add(panCode, BorderLayout.CENTER); - - JPanel buttonsPan = new JPanel(); - buttonsPan.setLayout(new FlowLayout()); - buttonsPan.add(editButton); - buttonsPan.add(saveButton); - buttonsPan.add(cancelButton); - - editButton.setMargin(new Insets(3, 3, 3, 10)); - saveButton.setMargin(new Insets(3, 3, 3, 10)); - cancelButton.setMargin(new Insets(3, 3, 3, 10)); - - JPanel decButtonsPan = new JPanel(new FlowLayout()); - decButtonsPan.add(editDecompiledButton); - decButtonsPan.add(experimentalLabel); - decButtonsPan.add(saveDecompiledButton); - decButtonsPan.add(cancelDecompiledButton); - - editDecompiledButton.setMargin(new Insets(3, 3, 3, 10)); - saveDecompiledButton.setMargin(new Insets(3, 3, 3, 10)); - cancelDecompiledButton.setMargin(new Insets(3, 3, 3, 10)); - - //buttonsPan.add(saveHexButton); - //buttonsPan.add(loadHexButton); - panB.add(buttonsPan, BorderLayout.SOUTH); - - saveButton.addActionListener(this); - saveButton.setActionCommand(ACTION_SAVE_ACTION); - editButton.addActionListener(this); - editButton.setActionCommand(ACTION_EDIT_ACTION); - cancelButton.addActionListener(this); - cancelButton.setActionCommand(ACTION_CANCEL_ACTION); - saveButton.setVisible(false); - cancelButton.setVisible(false); - - saveDecompiledButton.addActionListener(this); - saveDecompiledButton.setActionCommand(ACTION_SAVE_DECOMPILED); - editDecompiledButton.addActionListener(this); - editDecompiledButton.setActionCommand(ACTION_EDIT_DECOMPILED); - - cancelDecompiledButton.addActionListener(this); - cancelDecompiledButton.setActionCommand(ACTION_CANCEL_DECOMPILED); - saveDecompiledButton.setVisible(false); - cancelDecompiledButton.setVisible(false); - - JPanel decPanel = new JPanel(new BorderLayout()); - decPanel.add(new JScrollPane(decompiledEditor), BorderLayout.CENTER); - //decPanel.add(searchPanel, BorderLayout.NORTH); - - JPanel panA = new JPanel(); - panA.setLayout(new BorderLayout()); - panA.add(decPanel, BorderLayout.CENTER); - panA.add(decLabel, BorderLayout.NORTH); - panA.add(decButtonsPan, BorderLayout.SOUTH); - decLabel.setHorizontalAlignment(SwingConstants.CENTER); - //decLabel.setBorder(new BevelBorder(BevelBorder.RAISED)); - - setLayout(new BorderLayout()); - add(splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, panA, panB), BorderLayout.CENTER); - splitPane.setResizeWeight(0.5); - splitPane.addPropertyChangeListener(JSplitPane.DIVIDER_LOCATION_PROPERTY, new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent pce) { - Configuration.guiActionSplitPaneDividerLocation.set((int) pce.getNewValue()); - } - }); - editor.setFont(new Font("Monospaced", Font.PLAIN, editor.getFont().getSize())); - decompiledEditor.setFont(new Font("Monospaced", Font.PLAIN, decompiledEditor.getFont().getSize())); - - //tagTree.addTreeSelectionListener(this); - editor.addCaretListener(new CaretListener() { - @Override - public void caretUpdate(CaretEvent e) { - if (ignoreCarret) { - return; - } - if (editMode || editDecompiledMode) { - return; - } - editor.getCaret().setVisible(true); - int pos = editor.getCaretPosition(); - Highlighting lastH = null; - for (Highlighting h : disassembledHilights) { - if (pos < h.startPos) { - break; - } - lastH = h; - } - String ofs = lastH == null ? "0" : lastH.getPropertyString("offset"); - Highlighting h2 = Highlighting.search(decompiledHilights, "offset", ofs); - if (h2 != null) { - ignoreCarret = true; - if (h2.startPos <= decompiledEditor.getDocument().getLength()) { - decompiledEditor.setCaretPosition(h2.startPos); - } - decompiledEditor.getCaret().setVisible(true); - ignoreCarret = false; - - } - } - }); - decompiledEditor.addCaretListener(new CaretListener() { - @Override - public void caretUpdate(CaretEvent e) { - if (ignoreCarret) { - return; - } - if (editMode || editDecompiledMode) { - return; - } - decompiledEditor.getCaret().setVisible(true); - int pos = decompiledEditor.getCaretPosition(); - Highlighting h = Highlighting.search(decompiledHilights, pos); - if (h != null) { - Highlighting h2 = Highlighting.search(disassembledHilights, "offset", h.getPropertyString("offset")); - if (h2 != null) { - ignoreCarret = true; - if (h2.startPos > 0 && h2.startPos < editor.getText().length()) { - editor.setCaretPosition(h2.startPos); - } - editor.getCaret().setVisible(true); - ignoreCarret = false; - } - } - } - }); - } - - public void initSplits() { - int split = Configuration.guiActionSplitPaneDividerLocation.get(getWidth() / 2); - if (split == 0) { - split = getWidth() / 2; - } - splitPane.setDividerLocation(split); - } - - public void display() { - setVisible(true); - splitPane.setDividerLocation(0.5); - } - - public void setEditMode(boolean val) { - boolean rawEdit = hexOnlyButton.isSelected(); - - if (val) { - if (rawEdit) { - setText(srcHexOnly, "text/plain"); - } else { - setText(srcNoHex, "text/flasm"); - } - editor.setEditable(true); - saveButton.setVisible(true); - editButton.setVisible(false); - cancelButton.setVisible(true); - editor.getCaret().setVisible(true); - asmLabel.setIcon(View.getIcon("editing16")); - } else { - setHex(getExportMode()); - editor.setEditable(false); - saveButton.setVisible(false); - editButton.setVisible(true); - cancelButton.setVisible(false); - editor.getCaret().setVisible(true); - asmLabel.setIcon(null); - } - topButtonsPan.setVisible(!val); - editMode = val; - editor.requestFocusInWindow(); - } - - public void setDecompiledEditMode(boolean val) { - if (lastASM == null) { - return; - } - - int lastLine = decompiledEditor.getLine(); - int prefLines = lastASM.getPrefixLineCount(); - if (val) { - String newText = lastASM.removePrefixAndSuffix(lastDecompiled); - setDecompiledText(newText); - if (lastLine > -1) { - if (lastLine - prefLines >= 0) { - decompiledEditor.gotoLine(lastLine - prefLines + 1); - } - } - decompiledEditor.setEditable(true); - saveDecompiledButton.setVisible(true); - editDecompiledButton.setVisible(false); - experimentalLabel.setVisible(false); - cancelDecompiledButton.setVisible(true); - decompiledEditor.getCaret().setVisible(true); - decLabel.setIcon(View.getIcon("editing16")); - } else { - String newText = lastDecompiled; - setDecompiledText(newText); - if (lastLine > -1) { - decompiledEditor.gotoLine(lastLine + prefLines + 1); - } - decompiledEditor.setEditable(false); - saveDecompiledButton.setVisible(false); - editDecompiledButton.setVisible(true); - experimentalLabel.setVisible(true); - cancelDecompiledButton.setVisible(false); - decompiledEditor.getCaret().setVisible(true); - decLabel.setIcon(null); - } - editDecompiledMode = val; - decompiledEditor.requestFocusInWindow(); - } - - @Override - public void actionPerformed(ActionEvent e) { - switch (e.getActionCommand()) { - case ACTION_GRAPH: - if (lastCode != null) { - try { - GraphDialog gf = new GraphDialog(mainPanel.getMainFrame().getWindow(),new ActionGraph(lastCode, new HashMap(), new HashMap(), new HashMap(), SWF.DEFAULT_VERSION), ""); - gf.setVisible(true); - } catch (InterruptedException ex) { - Logger.getLogger(ActionPanel.class.getName()).log(Level.SEVERE, null, ex); - } - } - break; - case ACTION_EDIT_ACTION: - setEditMode(true); - break; - case ACTION_HEX: - case ACTION_HEX_ONLY: - if (e.getActionCommand() == ACTION_HEX) { - hexOnlyButton.setSelected(false); - } else { - hexButton.setSelected(false); - } - setHex(getExportMode()); - break; - case ACTION_CANCEL_ACTION: - setEditMode(false); - setHex(getExportMode()); - break; - case ACTION_SAVE_ACTION: - try { - String text = editor.getText(); - if (text.trim().startsWith("#hexdata")) { - src.setActionBytes(Helper.getBytesFromHexaText(text)); - } else { - src.setActions(ASMParser.parse(0, src.getPos(), true, text, src.getSwf().version, false)); - } - src.setModified(); - setSource(this.src, false); - View.showMessageDialog(this, AppStrings.translate("message.action.saved")); - saveButton.setVisible(false); - cancelButton.setVisible(false); - editButton.setVisible(true); - editor.setEditable(false); - editMode = false; - } catch (IOException ex) { - } catch (ParseException ex) { - View.showMessageDialog(this, AppStrings.translate("error.action.save").replace("%error%", ex.text).replace("%line%", "" + ex.line), AppStrings.translate("error"), JOptionPane.ERROR_MESSAGE); - editor.gotoLine((int) ex.line); - } - break; - case ACTION_EDIT_DECOMPILED: - if (View.showConfirmDialog(null, AppStrings.translate("message.confirm.experimental.function"), AppStrings.translate("message.warning"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, Configuration.warningExperimentalAS12Edit, JOptionPane.OK_OPTION) == JOptionPane.OK_OPTION) { - setDecompiledEditMode(true); - } - break; - case ACTION_CANCEL_DECOMPILED: - setDecompiledEditMode(false); - break; - case ACTION_SAVE_DECOMPILED: - try { - ActionScriptParser par = new ActionScriptParser(mainPanel.getCurrentSwf().version); - src.setActions(par.actionsFromString(decompiledEditor.getText())); - src.setModified(); - setSource(src, false); - - View.showMessageDialog(this, AppStrings.translate("message.action.saved")); - setDecompiledEditMode(false); - } catch (IOException ex) { - Logger.getLogger(ActionPanel.class.getName()).log(Level.SEVERE, "IOException during action compiling", ex); - } catch (ParseException ex) { - View.showMessageDialog(this, AppStrings.translate("error.action.save").replace("%error%", ex.text).replace("%line%", "" + ex.line), AppStrings.translate("error"), JOptionPane.ERROR_MESSAGE); - } catch (CompilationException ex) { - View.showMessageDialog(this, AppStrings.translate("error.action.save").replace("%error%", ex.text).replace("%line%", "" + ex.line), AppStrings.translate("error"), JOptionPane.ERROR_MESSAGE); - } - break; - } - } - - private ScriptExportMode getExportMode() { - ScriptExportMode exportMode = hexOnlyButton.isSelected() ? ScriptExportMode.HEX - : (hexButton.isSelected() ? ScriptExportMode.PCODE_HEX : ScriptExportMode.PCODE); - return exportMode; - } - - @Override - public void updateSearchPos(ActionSearchResult item) { - TagTreeModel ttm = (TagTreeModel) mainPanel.tagTree.getModel(); - TreePath tp = ttm.getTagPath(item.src); - mainPanel.tagTree.setSelectionPath(tp); - mainPanel.tagTree.scrollPathToVisible(tp); - decompiledEditor.setCaretPosition(0); - - View.execInEventDispatchLater(new Runnable() { - - @Override - public void run() { - searchPanel.showQuickFindDialog(decompiledEditor); - } - }); - } - - private void uncache(ASMSource pack) { - cache.remove(pack); - } -} +/* + * Copyright (C) 2010-2014 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.decompiler.flash.gui.action; + +import com.jpexs.decompiler.flash.AppStrings; +import com.jpexs.decompiler.flash.DisassemblyListener; +import com.jpexs.decompiler.flash.SWF; +import com.jpexs.decompiler.flash.action.Action; +import com.jpexs.decompiler.flash.action.ActionGraph; +import com.jpexs.decompiler.flash.action.parser.ParseException; +import com.jpexs.decompiler.flash.action.parser.pcode.ASMParser; +import com.jpexs.decompiler.flash.action.parser.script.ActionScriptParser; +import com.jpexs.decompiler.flash.action.swf4.ActionPush; +import com.jpexs.decompiler.flash.action.swf4.ConstantIndex; +import com.jpexs.decompiler.flash.configuration.Configuration; +import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode; +import com.jpexs.decompiler.flash.gui.GraphDialog; +import com.jpexs.decompiler.flash.gui.HeaderLabel; +import com.jpexs.decompiler.flash.gui.Main; +import com.jpexs.decompiler.flash.gui.MainPanel; +import com.jpexs.decompiler.flash.gui.SearchListener; +import com.jpexs.decompiler.flash.gui.SearchPanel; +import com.jpexs.decompiler.flash.gui.SearchResultsDialog; +import com.jpexs.decompiler.flash.gui.TagTreeModel; +import com.jpexs.decompiler.flash.gui.View; +import com.jpexs.decompiler.flash.gui.abc.LineMarkedEditorPane; +import com.jpexs.decompiler.flash.helpers.HilightedText; +import com.jpexs.decompiler.flash.helpers.HilightedTextWriter; +import com.jpexs.decompiler.flash.helpers.hilight.Highlighting; +import com.jpexs.decompiler.flash.tags.base.ASMSource; +import com.jpexs.decompiler.flash.treenodes.TreeNode; +import com.jpexs.decompiler.graph.CompilationException; +import com.jpexs.decompiler.graph.GraphTargetItem; +import com.jpexs.helpers.Cache; +import com.jpexs.helpers.CancellableWorker; +import com.jpexs.helpers.Helper; +import java.awt.BorderLayout; +import java.awt.FlowLayout; +import java.awt.Font; +import java.awt.Insets; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.concurrent.CancellationException; +import java.util.logging.Level; +import java.util.logging.Logger; +import java.util.regex.Pattern; +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JSplitPane; +import javax.swing.JToggleButton; +import javax.swing.SwingConstants; +import javax.swing.event.CaretEvent; +import javax.swing.event.CaretListener; +import javax.swing.tree.TreePath; +import jsyntaxpane.DefaultSyntaxKit; + +public class ActionPanel extends JPanel implements ActionListener, SearchListener { + + static final String ACTION_GRAPH = "GRAPH"; + static final String ACTION_HEX = "HEX"; + static final String ACTION_HEX_ONLY = "HEXONLY"; + static final String ACTION_SAVE_ACTION = "SAVEACTION"; + static final String ACTION_EDIT_ACTION = "EDITACTION"; + static final String ACTION_CANCEL_ACTION = "CANCELACTION"; + static final String ACTION_SAVE_DECOMPILED = "SAVEDECOMPILED"; + static final String ACTION_EDIT_DECOMPILED = "EDITDECOMPILED"; + static final String ACTION_CANCEL_DECOMPILED = "CANCELDECOMPILED"; + + private MainPanel mainPanel; + public LineMarkedEditorPane editor; + public LineMarkedEditorPane decompiledEditor; + public JSplitPane splitPane; + public JButton saveButton = new JButton(AppStrings.translate("button.save"), View.getIcon("save16")); + public JButton editButton = new JButton(AppStrings.translate("button.edit"), View.getIcon("edit16")); + public JButton cancelButton = new JButton(AppStrings.translate("button.cancel"), View.getIcon("cancel16")); + public JLabel experimentalLabel = new JLabel(AppStrings.translate("action.edit.experimental")); + public JButton editDecompiledButton = new JButton(AppStrings.translate("button.edit"), View.getIcon("edit16")); + public JButton saveDecompiledButton = new JButton(AppStrings.translate("button.save"), View.getIcon("save16")); + public JButton cancelDecompiledButton = new JButton(AppStrings.translate("button.cancel"), View.getIcon("cancel16")); + public JToggleButton hexButton; + public JToggleButton hexOnlyButton; + public JLabel asmLabel = new HeaderLabel(AppStrings.translate("panel.disassembled")); + public JLabel decLabel = new HeaderLabel(AppStrings.translate("panel.decompiled")); + public List decompiledHilights = new ArrayList<>(); + public List disassembledHilights = new ArrayList<>(); + private boolean ignoreCarret = false; + private boolean editMode = false; + private boolean editDecompiledMode = false; + private List lastCode; + private ASMSource src; + public JPanel topButtonsPan; + private HilightedText srcWithHex; + private HilightedText srcNoHex; + private HilightedText srcHexOnly; + private String lastDecompiled = ""; + private ASMSource lastASM; + public SearchPanel searchPanel; + private Cache cache = Cache.getInstance(true); + private CancellableWorker setSourceWorker; + + public void clearSource() { + lastCode = null; + lastASM = null; + lastDecompiled = null; + searchPanel.clear(); + src = null; + srcWithHex = null; + srcNoHex = null; + srcHexOnly = null; + } + + public void clearCache() { + cache.clear(); + } + + public String getStringUnderCursor() { + int pos = decompiledEditor.getCaretPosition(); + Highlighting h = Highlighting.search(decompiledHilights, pos); + if (h != null) { + List list = lastCode; + Action lastIns = null; + int inspos = 0; + Action selIns = null; + for (Action ins : list) { + if (h.getPropertyLong("offset") == ins.getOffset()) { + selIns = ins; + break; + } + if (ins.getOffset() > h.getPropertyLong("offset")) { + inspos = (int) (h.getPropertyLong("offset") - lastIns.getAddress()); + selIns = lastIns; + break; + } + lastIns = ins; + } + if (selIns != null) { + if (selIns instanceof ActionPush) { + ActionPush ap = (ActionPush) selIns; + Object var = ap.values.get(inspos - 1); + String identifier = null; + if (var instanceof String) { + identifier = (String) var; + } + if (var instanceof ConstantIndex) { + identifier = ap.constantPool.get(((ConstantIndex) var).index); + } + return identifier; + } + } + + } + return null; + } + + private CachedScript getCached(ASMSource pack) { + return (CachedScript) cache.get(pack); + } + + private boolean isCached(ASMSource src) { + return cache.contains(src); + } + + private void cacheScript(ASMSource src, List actions) throws InterruptedException { + if (!cache.contains(src)) { + if (actions == null) { + actions = src.getActions(); + } + HilightedTextWriter writer = new HilightedTextWriter(Configuration.getCodeFormatting(), true); + Action.actionsToSource(src, actions, src.toString()/*FIXME?*/, writer); + List hilights = writer.instructionHilights; + String srcNoHex = writer.toString(); + cache.put(src, new CachedScript(srcNoHex, hilights)); + } + } + + private void getASMs(String path, List nodes, Map result) { + for (TreeNode n : nodes) { + String subPath = path + "/" + n.toString(); + if (n.getItem() instanceof ASMSource) { + //cacheScript((ASMSource) n.tag); + String npath = subPath; + int ppos = 1; + while (result.containsKey(npath)) { + ppos++; + npath = subPath + "[" + ppos + "]"; + } + result.put(npath, (ASMSource) n.getItem()); + } + + getASMs(subPath, n.subNodes, result); + } + } + + public boolean search(final String txt, boolean ignoreCase, boolean regexp) { + if ((txt != null) && (!txt.isEmpty())) { + searchPanel.setOptions(ignoreCase, regexp); + List list = SWF.createASTagList(mainPanel.getCurrentSwf().tags, null); + Map asms = new HashMap<>(); + getASMs("", list, asms); + final List found = new ArrayList<>(); + Pattern pat = null; + if (regexp) { + pat = Pattern.compile(txt, ignoreCase ? Pattern.CASE_INSENSITIVE : 0); + } else { + pat = Pattern.compile(Pattern.quote(txt), ignoreCase ? Pattern.CASE_INSENSITIVE : 0); + } + int pos = 0; + for (Entry item : asms.entrySet()) { + pos++; + String workText = AppStrings.translate("work.searching"); + String decAdd = ""; + if (!isCached(item.getValue())) { + decAdd = ", " + AppStrings.translate("work.decompiling"); + } + Main.startWork(workText + " \"" + txt + "\"" + decAdd + " - (" + pos + "/" + asms.size() + ") " + item.getKey() + "... "); + try { + cacheScript(item.getValue(), null); + } catch (InterruptedException ex) { + break; + } + if (pat.matcher(getCached(item.getValue()).text).find()) { + found.add(new ActionSearchResult(item.getValue(), item.getKey())); + } + } + + Main.stopWork(); + searchPanel.setSearchText(txt); + View.execInEventDispatch(new Runnable() { + + @Override + public void run() { + SearchResultsDialog sr = new SearchResultsDialog<>(ActionPanel.this.mainPanel.getMainFrame().getWindow(), txt, ActionPanel.this); + sr.setResults(found); + sr.setVisible(true); + } + }); + return true; + //return searchPanel.setResults(found); + } + return false; + } + + private void setDecompiledText(final String text) { + View.execInEventDispatch(new Runnable() { + + @Override + public void run() { + ignoreCarret = true; + decompiledEditor.setText(text, "text/actionscript"); + ignoreCarret = false; + } + }); + } + + private void setEditorText(final String text, final String contentType) { + View.execInEventDispatch(new Runnable() { + + @Override + public void run() { + ignoreCarret = true; + editor.setText(text, contentType); + ignoreCarret = false; + } + }); + } + + private void setText(final HilightedText text, final String contentType) { + View.execInEventDispatch(new Runnable() { + + @Override + public void run() { + int pos = editor.getCaretPosition(); + Highlighting lastH = null; + for (Highlighting h : disassembledHilights) { + if (pos < h.startPos) { + break; + } + lastH = h; + } + String offset = lastH == null ? "0" : lastH.getPropertyString("offset"); + disassembledHilights = text.instructionHilights; + String stripped = text.text; + setEditorText(stripped, contentType); + Highlighting h = Highlighting.search(disassembledHilights, "offset", offset); + if (h != null) { + if (h.startPos <= editor.getDocument().getLength()) { + editor.setCaretPosition(h.startPos); + } + } + } + }); + } + + private HilightedText getHilightedText(ScriptExportMode exportMode) { + ASMSource asm = (ASMSource) src; + DisassemblyListener listener = getDisassemblyListener(); + asm.addDisassemblyListener(listener); + HilightedTextWriter writer = new HilightedTextWriter(Configuration.getCodeFormatting(), true); + try { + asm.getASMSource(exportMode, writer, lastCode); + } catch (InterruptedException ex) { + Logger.getLogger(ActionPanel.class.getName()).log(Level.SEVERE, null, ex); + } + asm.removeDisassemblyListener(listener); + return new HilightedText(writer); + } + + public void setHex(ScriptExportMode exportMode) { + if (exportMode != ScriptExportMode.HEX) { + if (exportMode == ScriptExportMode.PCODE) { + if (srcNoHex == null) { + srcNoHex = getHilightedText(exportMode); + } + setText(srcNoHex, "text/flasm"); + } else { + if (srcWithHex == null) { + srcWithHex = getHilightedText(exportMode); + } + setText(srcWithHex, "text/flasm"); + } + } else { + if (srcHexOnly == null) { + HilightedTextWriter writer = new HilightedTextWriter(Configuration.getCodeFormatting(), true); + Helper.byteArrayToHexWithHeader(writer, src.getActionBytes()); + srcHexOnly = new HilightedText(writer); + } + setText(srcHexOnly, "text/plain"); + } + } + + private DisassemblyListener getDisassemblyListener() { + DisassemblyListener listener = new DisassemblyListener() { + int percent = 0; + String phase = ""; + + @Override + public void progress(String phase, long pos, long total) { + if (total < 1) { + return; + } + int newpercent = (int) (pos * 100 / total); + if (((newpercent > percent) || (!this.phase.equals(phase))) && newpercent <= 100) { + percent = newpercent; + this.phase = phase; + setEditorText("; " + AppStrings.translate("work.disassembling") + " - " + phase + " " + percent + "%...", "text/flasm"); + } + } + }; + return listener; + } + + public void setSource(final ASMSource src, final boolean useCache) { + if (setSourceWorker != null) { + setSourceWorker.cancel(true); + setSourceWorker = null; + } + + this.src = src; + final ASMSource asm = (ASMSource) src; + + CancellableWorker worker = new CancellableWorker() { + + @Override + protected Void doInBackground() throws Exception { + setEditorText("; " + AppStrings.translate("work.disassembling") + "...", "text/flasm"); + if (Configuration.decompile.get()) { + setDecompiledText("//" + AppStrings.translate("work.waitingfordissasembly") + "..."); + } + DisassemblyListener listener = getDisassemblyListener(); + asm.addDisassemblyListener(listener); + List actions = asm.getActions(); + lastCode = actions; + asm.removeDisassemblyListener(listener); + srcWithHex = null; + srcNoHex = null; + srcHexOnly = null; + setHex(getExportMode()); + if (Configuration.decompile.get()) { + setDecompiledText("//" + AppStrings.translate("work.decompiling") + "..."); + if (!useCache) { + uncache(asm); + } + cacheScript(asm, actions); + CachedScript sc = getCached(asm); + decompiledHilights = sc.hilights; + lastDecompiled = sc.text; + lastASM = asm; + setDecompiledText(lastDecompiled); + } + setEditMode(false); + setDecompiledEditMode(false); + return null; + } + + @Override + protected void done() { + setSourceWorker = null; + Main.stopWork(); + + View.execInEventDispatch(new Runnable() { + + @Override + public void run() { + try { + get(); + } catch (CancellationException ex) { + setEditorText("; " + AppStrings.translate("work.canceled"), "text/flasm"); + } catch (Exception ex) { + setDecompiledText("//" + AppStrings.translate("decompilationError") + ": " + ex); + } + } + }); + } + }; + worker.execute(); + setSourceWorker = worker; + Main.startWork(AppStrings.translate("work.decompiling") + "...", worker); + } + + public void hilightOffset(long offset) { + } + + public ActionPanel(MainPanel mainPanel) { + DefaultSyntaxKit.initKit(); + this.mainPanel = mainPanel; + editor = new LineMarkedEditorPane(); + editor.setEditable(false); + decompiledEditor = new LineMarkedEditorPane(); + decompiledEditor.setEditable(false); + + searchPanel = new SearchPanel<>(new FlowLayout(), this); + + JButton graphButton = new JButton(View.getIcon("graph16")); + graphButton.setActionCommand(ACTION_GRAPH); + graphButton.addActionListener(this); + graphButton.setToolTipText(AppStrings.translate("button.viewgraph")); + graphButton.setMargin(new Insets(3, 3, 3, 3)); + + hexButton = new JToggleButton(View.getIcon("hexas16")); + hexButton.setActionCommand(ACTION_HEX); + hexButton.addActionListener(this); + hexButton.setToolTipText(AppStrings.translate("button.viewhex")); + hexButton.setMargin(new Insets(3, 3, 3, 3)); + + hexOnlyButton = new JToggleButton(View.getIcon("hex16")); + hexOnlyButton.setActionCommand(ACTION_HEX_ONLY); + hexOnlyButton.addActionListener(this); + hexOnlyButton.setToolTipText(AppStrings.translate("button.viewhex")); + hexOnlyButton.setMargin(new Insets(3, 3, 3, 3)); + + topButtonsPan = new JPanel(); + topButtonsPan.setLayout(new BoxLayout(topButtonsPan, BoxLayout.X_AXIS)); + topButtonsPan.add(graphButton); + topButtonsPan.add(hexButton); + topButtonsPan.add(hexOnlyButton); + JPanel panCode = new JPanel(new BorderLayout()); + panCode.add(new JScrollPane(editor), BorderLayout.CENTER); + panCode.add(topButtonsPan, BorderLayout.NORTH); + + JPanel panB = new JPanel(); + panB.setLayout(new BorderLayout()); + asmLabel.setHorizontalAlignment(SwingConstants.CENTER); + //asmLabel.setBorder(new BevelBorder(BevelBorder.RAISED)); + panB.add(asmLabel, BorderLayout.NORTH); + panB.add(panCode, BorderLayout.CENTER); + + JPanel buttonsPan = new JPanel(); + buttonsPan.setLayout(new FlowLayout()); + buttonsPan.add(editButton); + buttonsPan.add(saveButton); + buttonsPan.add(cancelButton); + + editButton.setMargin(new Insets(3, 3, 3, 10)); + saveButton.setMargin(new Insets(3, 3, 3, 10)); + cancelButton.setMargin(new Insets(3, 3, 3, 10)); + + JPanel decButtonsPan = new JPanel(new FlowLayout()); + decButtonsPan.add(editDecompiledButton); + decButtonsPan.add(experimentalLabel); + decButtonsPan.add(saveDecompiledButton); + decButtonsPan.add(cancelDecompiledButton); + + editDecompiledButton.setMargin(new Insets(3, 3, 3, 10)); + saveDecompiledButton.setMargin(new Insets(3, 3, 3, 10)); + cancelDecompiledButton.setMargin(new Insets(3, 3, 3, 10)); + + //buttonsPan.add(saveHexButton); + //buttonsPan.add(loadHexButton); + panB.add(buttonsPan, BorderLayout.SOUTH); + + saveButton.addActionListener(this); + saveButton.setActionCommand(ACTION_SAVE_ACTION); + editButton.addActionListener(this); + editButton.setActionCommand(ACTION_EDIT_ACTION); + cancelButton.addActionListener(this); + cancelButton.setActionCommand(ACTION_CANCEL_ACTION); + saveButton.setVisible(false); + cancelButton.setVisible(false); + + saveDecompiledButton.addActionListener(this); + saveDecompiledButton.setActionCommand(ACTION_SAVE_DECOMPILED); + editDecompiledButton.addActionListener(this); + editDecompiledButton.setActionCommand(ACTION_EDIT_DECOMPILED); + + cancelDecompiledButton.addActionListener(this); + cancelDecompiledButton.setActionCommand(ACTION_CANCEL_DECOMPILED); + saveDecompiledButton.setVisible(false); + cancelDecompiledButton.setVisible(false); + + JPanel decPanel = new JPanel(new BorderLayout()); + decPanel.add(new JScrollPane(decompiledEditor), BorderLayout.CENTER); + //decPanel.add(searchPanel, BorderLayout.NORTH); + + JPanel panA = new JPanel(); + panA.setLayout(new BorderLayout()); + panA.add(decPanel, BorderLayout.CENTER); + panA.add(decLabel, BorderLayout.NORTH); + panA.add(decButtonsPan, BorderLayout.SOUTH); + decLabel.setHorizontalAlignment(SwingConstants.CENTER); + //decLabel.setBorder(new BevelBorder(BevelBorder.RAISED)); + + setLayout(new BorderLayout()); + add(splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, panA, panB), BorderLayout.CENTER); + splitPane.setResizeWeight(0.5); + splitPane.addPropertyChangeListener(JSplitPane.DIVIDER_LOCATION_PROPERTY, new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent pce) { + Configuration.guiActionSplitPaneDividerLocation.set((int) pce.getNewValue()); + } + }); + editor.setFont(new Font("Monospaced", Font.PLAIN, editor.getFont().getSize())); + decompiledEditor.setFont(new Font("Monospaced", Font.PLAIN, decompiledEditor.getFont().getSize())); + + //tagTree.addTreeSelectionListener(this); + editor.addCaretListener(new CaretListener() { + @Override + public void caretUpdate(CaretEvent e) { + if (ignoreCarret) { + return; + } + if (editMode || editDecompiledMode) { + return; + } + editor.getCaret().setVisible(true); + int pos = editor.getCaretPosition(); + Highlighting lastH = null; + for (Highlighting h : disassembledHilights) { + if (pos < h.startPos) { + break; + } + lastH = h; + } + String ofs = lastH == null ? "0" : lastH.getPropertyString("offset"); + Highlighting h2 = Highlighting.search(decompiledHilights, "offset", ofs); + if (h2 != null) { + ignoreCarret = true; + if (h2.startPos <= decompiledEditor.getDocument().getLength()) { + decompiledEditor.setCaretPosition(h2.startPos); + } + decompiledEditor.getCaret().setVisible(true); + ignoreCarret = false; + + } + } + }); + decompiledEditor.addCaretListener(new CaretListener() { + @Override + public void caretUpdate(CaretEvent e) { + if (ignoreCarret) { + return; + } + if (editMode || editDecompiledMode) { + return; + } + decompiledEditor.getCaret().setVisible(true); + int pos = decompiledEditor.getCaretPosition(); + Highlighting h = Highlighting.search(decompiledHilights, pos); + if (h != null) { + Highlighting h2 = Highlighting.search(disassembledHilights, "offset", h.getPropertyString("offset")); + if (h2 != null) { + ignoreCarret = true; + if (h2.startPos > 0 && h2.startPos < editor.getText().length()) { + editor.setCaretPosition(h2.startPos); + } + editor.getCaret().setVisible(true); + ignoreCarret = false; + } + } + } + }); + } + + public void initSplits() { + int split = Configuration.guiActionSplitPaneDividerLocation.get(getWidth() / 2); + if (split == 0) { + split = getWidth() / 2; + } + splitPane.setDividerLocation(split); + } + + public void display() { + setVisible(true); + splitPane.setDividerLocation(0.5); + } + + public void setEditMode(boolean val) { + boolean rawEdit = hexOnlyButton.isSelected(); + + if (val) { + if (rawEdit) { + setText(srcHexOnly, "text/plain"); + } else { + setText(srcNoHex, "text/flasm"); + } + editor.setEditable(true); + saveButton.setVisible(true); + editButton.setVisible(false); + cancelButton.setVisible(true); + editor.getCaret().setVisible(true); + asmLabel.setIcon(View.getIcon("editing16")); + } else { + setHex(getExportMode()); + editor.setEditable(false); + saveButton.setVisible(false); + editButton.setVisible(true); + cancelButton.setVisible(false); + editor.getCaret().setVisible(true); + asmLabel.setIcon(null); + } + topButtonsPan.setVisible(!val); + editMode = val; + editor.requestFocusInWindow(); + } + + public void setDecompiledEditMode(boolean val) { + if (lastASM == null) { + return; + } + + int lastLine = decompiledEditor.getLine(); + int prefLines = lastASM.getPrefixLineCount(); + if (val) { + String newText = lastASM.removePrefixAndSuffix(lastDecompiled); + setDecompiledText(newText); + if (lastLine > -1) { + if (lastLine - prefLines >= 0) { + decompiledEditor.gotoLine(lastLine - prefLines + 1); + } + } + decompiledEditor.setEditable(true); + saveDecompiledButton.setVisible(true); + editDecompiledButton.setVisible(false); + experimentalLabel.setVisible(false); + cancelDecompiledButton.setVisible(true); + decompiledEditor.getCaret().setVisible(true); + decLabel.setIcon(View.getIcon("editing16")); + } else { + String newText = lastDecompiled; + setDecompiledText(newText); + if (lastLine > -1) { + decompiledEditor.gotoLine(lastLine + prefLines + 1); + } + decompiledEditor.setEditable(false); + saveDecompiledButton.setVisible(false); + editDecompiledButton.setVisible(true); + experimentalLabel.setVisible(true); + cancelDecompiledButton.setVisible(false); + decompiledEditor.getCaret().setVisible(true); + decLabel.setIcon(null); + } + editDecompiledMode = val; + decompiledEditor.requestFocusInWindow(); + } + + @Override + public void actionPerformed(ActionEvent e) { + switch (e.getActionCommand()) { + case ACTION_GRAPH: + if (lastCode != null) { + try { + GraphDialog gf = new GraphDialog(mainPanel.getMainFrame().getWindow(), new ActionGraph(lastCode, new HashMap(), new HashMap(), new HashMap(), SWF.DEFAULT_VERSION), ""); + gf.setVisible(true); + } catch (InterruptedException ex) { + Logger.getLogger(ActionPanel.class.getName()).log(Level.SEVERE, null, ex); + } + } + break; + case ACTION_EDIT_ACTION: + setEditMode(true); + break; + case ACTION_HEX: + case ACTION_HEX_ONLY: + if (e.getActionCommand() == ACTION_HEX) { + hexOnlyButton.setSelected(false); + } else { + hexButton.setSelected(false); + } + setHex(getExportMode()); + break; + case ACTION_CANCEL_ACTION: + setEditMode(false); + setHex(getExportMode()); + break; + case ACTION_SAVE_ACTION: + try { + String text = editor.getText(); + if (text.trim().startsWith("#hexdata")) { + src.setActionBytes(Helper.getBytesFromHexaText(text)); + } else { + src.setActions(ASMParser.parse(0, src.getPos(), true, text, src.getSwf().version, false)); + } + src.setModified(); + setSource(this.src, false); + View.showMessageDialog(this, AppStrings.translate("message.action.saved")); + saveButton.setVisible(false); + cancelButton.setVisible(false); + editButton.setVisible(true); + editor.setEditable(false); + editMode = false; + } catch (IOException ex) { + } catch (ParseException ex) { + View.showMessageDialog(this, AppStrings.translate("error.action.save").replace("%error%", ex.text).replace("%line%", "" + ex.line), AppStrings.translate("error"), JOptionPane.ERROR_MESSAGE); + editor.gotoLine((int) ex.line); + } + break; + case ACTION_EDIT_DECOMPILED: + if (View.showConfirmDialog(null, AppStrings.translate("message.confirm.experimental.function"), AppStrings.translate("message.warning"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, Configuration.warningExperimentalAS12Edit, JOptionPane.OK_OPTION) == JOptionPane.OK_OPTION) { + setDecompiledEditMode(true); + } + break; + case ACTION_CANCEL_DECOMPILED: + setDecompiledEditMode(false); + break; + case ACTION_SAVE_DECOMPILED: + try { + ActionScriptParser par = new ActionScriptParser(mainPanel.getCurrentSwf().version); + src.setActions(par.actionsFromString(decompiledEditor.getText())); + src.setModified(); + setSource(src, false); + + View.showMessageDialog(this, AppStrings.translate("message.action.saved")); + setDecompiledEditMode(false); + } catch (IOException ex) { + Logger.getLogger(ActionPanel.class.getName()).log(Level.SEVERE, "IOException during action compiling", ex); + } catch (ParseException ex) { + View.showMessageDialog(this, AppStrings.translate("error.action.save").replace("%error%", ex.text).replace("%line%", "" + ex.line), AppStrings.translate("error"), JOptionPane.ERROR_MESSAGE); + } catch (CompilationException ex) { + View.showMessageDialog(this, AppStrings.translate("error.action.save").replace("%error%", ex.text).replace("%line%", "" + ex.line), AppStrings.translate("error"), JOptionPane.ERROR_MESSAGE); + } + break; + } + } + + private ScriptExportMode getExportMode() { + ScriptExportMode exportMode = hexOnlyButton.isSelected() ? ScriptExportMode.HEX + : (hexButton.isSelected() ? ScriptExportMode.PCODE_HEX : ScriptExportMode.PCODE); + return exportMode; + } + + @Override + public void updateSearchPos(ActionSearchResult item) { + TagTreeModel ttm = (TagTreeModel) mainPanel.tagTree.getModel(); + TreePath tp = ttm.getTagPath(item.src); + mainPanel.tagTree.setSelectionPath(tp); + mainPanel.tagTree.scrollPathToVisible(tp); + decompiledEditor.setCaretPosition(0); + + View.execInEventDispatchLater(new Runnable() { + + @Override + public void run() { + searchPanel.showQuickFindDialog(decompiledEditor); + } + }); + } + + private void uncache(ASMSource pack) { + cache.remove(pack); + } +} diff --git a/src/com/jpexs/decompiler/flash/gui/action/ActionSearchResult.java b/src/com/jpexs/decompiler/flash/gui/action/ActionSearchResult.java index e2b846804..6d0f66453 100644 --- a/src/com/jpexs/decompiler/flash/gui/action/ActionSearchResult.java +++ b/src/com/jpexs/decompiler/flash/gui/action/ActionSearchResult.java @@ -1,41 +1,40 @@ -/* - * Copyright (C) 2014 JPEXS - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.jpexs.decompiler.flash.gui.action; - -import com.jpexs.decompiler.flash.tags.base.ASMSource; - -/** - * - * @author JPEXS - */ -public class ActionSearchResult { - public ASMSource src; - public String path; - - public ActionSearchResult(ASMSource src, String path) { - this.src = src; - this.path = path; - } - - @Override - public String toString() { - return path; - } - - -} +/* + * Copyright (C) 2014 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.decompiler.flash.gui.action; + +import com.jpexs.decompiler.flash.tags.base.ASMSource; + +/** + * + * @author JPEXS + */ +public class ActionSearchResult { + + public ASMSource src; + public String path; + + public ActionSearchResult(ASMSource src, String path) { + this.src = src; + this.path = path; + } + + @Override + public String toString() { + return path; + } + +} diff --git a/src/com/jpexs/decompiler/flash/tags/DefineBinaryDataTag.java b/src/com/jpexs/decompiler/flash/tags/DefineBinaryDataTag.java index 71624ef38..fc351a86b 100644 --- a/src/com/jpexs/decompiler/flash/tags/DefineBinaryDataTag.java +++ b/src/com/jpexs/decompiler/flash/tags/DefineBinaryDataTag.java @@ -62,7 +62,7 @@ public class DefineBinaryDataTag extends CharacterTag { super(sis.getSwf(), ID, "DefineBinaryData", pos, length); tag = sis.readUI16("tag"); reserved = sis.readUI32("reserved"); - binaryData = sis.readBytesEx(sis.available(),"binaryData"); + binaryData = sis.readBytesEx(sis.available(), "binaryData"); } @Override diff --git a/src/com/jpexs/decompiler/flash/tags/DefineEditTextTag.java b/src/com/jpexs/decompiler/flash/tags/DefineEditTextTag.java index f58f95801..c55ac0c46 100644 --- a/src/com/jpexs/decompiler/flash/tags/DefineEditTextTag.java +++ b/src/com/jpexs/decompiler/flash/tags/DefineEditTextTag.java @@ -765,7 +765,7 @@ public class DefineEditTextTag extends TextTag { } return false; } - + @Override public void toImage(int frame, int time, int ratio, DepthState stateUnderCursor, int mouseButton, SerializableImage image, Matrix transformation, ColorTransform colorTransform) { render(false, image, transformation, colorTransform); diff --git a/src/com/jpexs/decompiler/flash/tags/TagStub.java b/src/com/jpexs/decompiler/flash/tags/TagStub.java index a56051260..2ce313a03 100644 --- a/src/com/jpexs/decompiler/flash/tags/TagStub.java +++ b/src/com/jpexs/decompiler/flash/tags/TagStub.java @@ -27,7 +27,7 @@ import com.jpexs.decompiler.flash.SWFInputStream; public class TagStub extends Tag { private final SWFInputStream dataStream; - + /** * Constructor * diff --git a/src/com/jpexs/decompiler/flash/timeline/Timeline.java b/src/com/jpexs/decompiler/flash/timeline/Timeline.java index 609ec911f..46b953e84 100644 --- a/src/com/jpexs/decompiler/flash/timeline/Timeline.java +++ b/src/com/jpexs/decompiler/flash/timeline/Timeline.java @@ -194,13 +194,13 @@ public class Timeline { getNeededCharacters(i, usedCharacters); } } - + public void getNeededCharacters(List frames, Set usedCharacters) { for (int frame = 0; frame < frames.size(); frame++) { getNeededCharacters(frame, usedCharacters); } } - + public void getNeededCharacters(int frame, Set usedCharacters) { Frame frameObj = frames.get(frame); for (int depth : frameObj.layers.keySet()) { @@ -214,7 +214,7 @@ public class Timeline { } } } - + public boolean removeCharacter(int characterId) { boolean modified = false; for (int i = 0; i < tags.size(); i++) { diff --git a/src/com/jpexs/decompiler/flash/types/FILLSTYLE.java b/src/com/jpexs/decompiler/flash/types/FILLSTYLE.java index 8c5f41d51..fb00a4967 100644 --- a/src/com/jpexs/decompiler/flash/types/FILLSTYLE.java +++ b/src/com/jpexs/decompiler/flash/types/FILLSTYLE.java @@ -73,9 +73,9 @@ public class FILLSTYLE implements NeedsCharacters, Serializable { public boolean removeCharacter(int characterId) { if (bitmapId == characterId) { if ((fillStyleType == REPEATING_BITMAP) - || (fillStyleType == CLIPPED_BITMAP) - || (fillStyleType == NON_SMOOTHED_REPEATING_BITMAP) - || (fillStyleType == NON_SMOOTHED_CLIPPED_BITMAP)) { + || (fillStyleType == CLIPPED_BITMAP) + || (fillStyleType == NON_SMOOTHED_REPEATING_BITMAP) + || (fillStyleType == NON_SMOOTHED_CLIPPED_BITMAP)) { fillStyleType = SOLID; if (color == null) { color = inShape3 ? new RGBA(0, 0, 0, 0) : new RGB(0, 0, 0); diff --git a/src/com/jpexs/decompiler/flash/types/MORPHFILLSTYLE.java b/src/com/jpexs/decompiler/flash/types/MORPHFILLSTYLE.java index da33071a2..c52d045ec 100644 --- a/src/com/jpexs/decompiler/flash/types/MORPHFILLSTYLE.java +++ b/src/com/jpexs/decompiler/flash/types/MORPHFILLSTYLE.java @@ -78,9 +78,9 @@ public class MORPHFILLSTYLE implements NeedsCharacters, Serializable { public boolean removeCharacter(int characterId) { if (bitmapId == characterId) { if ((fillStyleType == REPEATING_BITMAP) - || (fillStyleType == CLIPPED_BITMAP) - || (fillStyleType == NON_SMOOTHED_REPEATING_BITMAP) - || (fillStyleType == NON_SMOOTHED_CLIPPED_BITMAP)) { + || (fillStyleType == CLIPPED_BITMAP) + || (fillStyleType == NON_SMOOTHED_REPEATING_BITMAP) + || (fillStyleType == NON_SMOOTHED_CLIPPED_BITMAP)) { fillStyleType = SOLID; } bitmapId = 0; diff --git a/src/com/jpexs/decompiler/flash/types/filters/Filtering.java b/src/com/jpexs/decompiler/flash/types/filters/Filtering.java index bf014e318..061614133 100644 --- a/src/com/jpexs/decompiler/flash/types/filters/Filtering.java +++ b/src/com/jpexs/decompiler/flash/types/filters/Filtering.java @@ -283,7 +283,7 @@ public class Filtering { hc.drawImage(hilightIm, 0, 0, null); hc.setComposite(AlphaComposite.DstOut); hc.drawImage(shadowIm, 0, 0, null); - + sc.drawImage(shadowIm, 0, 0, null); sc.setComposite(AlphaComposite.DstOut); sc.drawImage(hilightIm, 0, 0, null); diff --git a/src/com/jpexs/decompiler/flash/types/shaperecords/StyleChangeRecord.java b/src/com/jpexs/decompiler/flash/types/shaperecords/StyleChangeRecord.java index 21093e99a..9ce2b661d 100644 --- a/src/com/jpexs/decompiler/flash/types/shaperecords/StyleChangeRecord.java +++ b/src/com/jpexs/decompiler/flash/types/shaperecords/StyleChangeRecord.java @@ -88,7 +88,7 @@ public class StyleChangeRecord extends SHAPERECORD implements Cloneable { @Override public boolean removeCharacter(int characterId) { - if (fillStyles != null){ + if (fillStyles != null) { return fillStyles.removeCharacter(characterId); } return false; diff --git a/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java b/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java index d19f5ca68..8134f3fd2 100644 --- a/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java +++ b/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java @@ -1604,7 +1604,7 @@ public class XFLConverter { linkageExportForAS = true; mediaLinkStr += " linkageIdentifier=\"" + xmlString(characterVariables.get(symbol.getCharacterId())) + "\""; } - if(linkageExportForAS){ + if (linkageExportForAS) { mediaLinkStr += " linkageExportForAS=\"true\""; } mediaLinkStr += "/>\n"; diff --git a/src/com/jpexs/decompiler/graph/GraphTargetItem.java b/src/com/jpexs/decompiler/graph/GraphTargetItem.java index 3d95c3304..e82507d51 100644 --- a/src/com/jpexs/decompiler/graph/GraphTargetItem.java +++ b/src/com/jpexs/decompiler/graph/GraphTargetItem.java @@ -1,259 +1,259 @@ -/* - * Copyright (C) 2010-2014 JPEXS - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.jpexs.decompiler.graph; - -import com.jpexs.decompiler.flash.SourceGeneratorLocalData; -import com.jpexs.decompiler.flash.configuration.Configuration; -import com.jpexs.decompiler.flash.helpers.GraphTextWriter; -import com.jpexs.decompiler.flash.helpers.HilightedTextWriter; -import com.jpexs.decompiler.graph.model.BinaryOp; -import com.jpexs.decompiler.graph.model.LocalData; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -/** - * - * @author JPEXS - */ -public abstract class GraphTargetItem implements Serializable { - - public static final int PRECEDENCE_PRIMARY = 0; - public static final int PRECEDENCE_POSTFIX = 1; - public static final int PRECEDENCE_UNARY = 2; - public static final int PRECEDENCE_MULTIPLICATIVE = 3; - public static final int PRECEDENCE_ADDITIVE = 4; - public static final int PRECEDENCE_BITWISESHIFT = 5; - public static final int PRECEDENCE_RELATIONAL = 6; - public static final int PRECEDENCE_EQUALITY = 7; - public static final int PRECEDENCE_BITWISEAND = 8; - public static final int PRECEDENCE_BITWISEXOR = 9; - public static final int PRECEDENCE_BITWISEOR = 10; - public static final int PRECEDENCE_LOGICALAND = 11; - public static final int PRECEDENCE_LOGICALOR = 12; - public static final int PRECEDENCE_CONDITIONAL = 13; - public static final int PRECEDENCE_ASSIGMENT = 14; - public static final int PRECEDENCE_COMMA = 15; - public static final int NOPRECEDENCE = 16; - public GraphSourceItem src; - public int pos = -1; - protected int precedence; - public List moreSrc = new ArrayList<>(); - public GraphPart firstPart; - public GraphTargetItem value; - - public GraphPart getFirstPart() { - if (value == null) { - return firstPart; - } - GraphPart ret = value.getFirstPart(); - if (ret == null) { - return firstPart; - } - return ret; - } - - public GraphTargetItem() { - this(null, NOPRECEDENCE); - } - - public GraphTargetItem(GraphSourceItem src, int precedence) { - this.src = src; - this.precedence = precedence; - } - - public List getNeededSources() { - List ret = new ArrayList<>(); - ret.add(new GraphSourceItemPos(src, pos)); - ret.addAll(moreSrc); - if (value != null) { - ret.addAll(value.getNeededSources()); - } - return ret; - } - - public GraphTextWriter toStringSemicoloned(GraphTextWriter writer, LocalData localData) throws InterruptedException { - writer.startOffset(src, pos); - appendTo(writer, localData); - if (needsSemicolon()) { - writer.append(";"); - } - writer.endOffset(); - return writer; - } - - public boolean needsSemicolon() { - return true; - } - - @Override - public String toString() { - return this.getClass().getName(); - } - - public GraphTextWriter toString(GraphTextWriter writer, LocalData localData) throws InterruptedException { - writer.startOffset(src, pos); - appendTo(writer, localData); - writer.endOffset(); - return writer; - } - - public abstract GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException; - - public String toString(LocalData localData) throws InterruptedException { - HilightedTextWriter writer = new HilightedTextWriter(Configuration.getCodeFormatting(), false); - toString(writer, localData); - return writer.toString(); - } - - public int getPrecedence() { - return precedence; - } - - public boolean isCompileTime() { - Set dependencies = new HashSet<>(); - dependencies.add(this); - return isCompileTime(dependencies); - } - - public boolean isCompileTime(Set dependencies) { - return false; - } - - public boolean hasSideEffect() { - return false; - } - - public boolean isVariableComputed() { - return false; - } - - public Object getResult() { - return null; - } - - public String toStringNoQuotes(LocalData localData) { - return toString(); - } - - public GraphTextWriter toStringNoQuotes(GraphTextWriter writer, LocalData localData) throws InterruptedException { - writer.startOffset(src, pos); - appendToNoQuotes(writer, localData); - writer.endOffset(); - return writer; - } - - public GraphTextWriter appendToNoQuotes(GraphTextWriter writer, LocalData localData) throws InterruptedException { - return toString(writer, localData); - } - - public GraphTargetItem getNotCoerced() { - return this; - } - - public GraphTargetItem getThroughRegister() { - return this; - } - - public boolean needsNewLine() { - return false; - } - - public GraphTextWriter toStringNL(GraphTextWriter writer, LocalData localData) throws InterruptedException { - writer.startOffset(src, pos); - appendTo(writer, localData); - if (needsNewLine()) { - writer.newLine(); - } - writer.endOffset(); - return writer; - } - - public boolean isEmpty() { - return false; - } - - public GraphTargetItem getThroughNotCompilable() { - return this; - } - - public GraphTargetItem getThroughDuplicate() { - return this; - } - - public boolean valueEquals(GraphTargetItem target) { - return equals(target); - } - - public List toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { - return new ArrayList<>(); - } - - public List toSourceIgnoreReturnValue(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { - if(!hasReturnValue()){ - return toSource(localData, generator); - } - return generator.generateDiscardValue(localData, this); - } - - protected List toSourceBinary(BinaryOp op, GraphSourceItem action) { - List ret = new ArrayList<>(); - - return ret; - } - - public static List toSourceMerge(SourceGeneratorLocalData localData, SourceGenerator gen, Object... tar) throws CompilationException { - List ret = new ArrayList<>(); - for (Object o : tar) { - if (o == null) { - continue; - } - if (o instanceof GraphTargetItem) { - ret.addAll(((GraphTargetItem) o).toSource(localData, gen)); - } - if (o instanceof GraphSourceItem) { - ret.add((GraphSourceItem) o); - } - if (o instanceof List) { - List l = (List) o; - for (Object o2 : l) { - if (o2 instanceof GraphSourceItem) { - ret.add((GraphSourceItem) o2); - } - if (o2 instanceof GraphTargetItem) { - ret.addAll(((GraphTargetItem) o2).toSource(localData, gen)); - } - } - } - } - return ret; - } - - public abstract boolean hasReturnValue(); - - public List getAllSubItems() { - List ret = new ArrayList<>(); - if (value != null) { - ret.add(value); - } - return ret; - } - - public abstract GraphTargetItem returnType(); -} +/* + * Copyright (C) 2010-2014 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.decompiler.graph; + +import com.jpexs.decompiler.flash.SourceGeneratorLocalData; +import com.jpexs.decompiler.flash.configuration.Configuration; +import com.jpexs.decompiler.flash.helpers.GraphTextWriter; +import com.jpexs.decompiler.flash.helpers.HilightedTextWriter; +import com.jpexs.decompiler.graph.model.BinaryOp; +import com.jpexs.decompiler.graph.model.LocalData; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +/** + * + * @author JPEXS + */ +public abstract class GraphTargetItem implements Serializable { + + public static final int PRECEDENCE_PRIMARY = 0; + public static final int PRECEDENCE_POSTFIX = 1; + public static final int PRECEDENCE_UNARY = 2; + public static final int PRECEDENCE_MULTIPLICATIVE = 3; + public static final int PRECEDENCE_ADDITIVE = 4; + public static final int PRECEDENCE_BITWISESHIFT = 5; + public static final int PRECEDENCE_RELATIONAL = 6; + public static final int PRECEDENCE_EQUALITY = 7; + public static final int PRECEDENCE_BITWISEAND = 8; + public static final int PRECEDENCE_BITWISEXOR = 9; + public static final int PRECEDENCE_BITWISEOR = 10; + public static final int PRECEDENCE_LOGICALAND = 11; + public static final int PRECEDENCE_LOGICALOR = 12; + public static final int PRECEDENCE_CONDITIONAL = 13; + public static final int PRECEDENCE_ASSIGMENT = 14; + public static final int PRECEDENCE_COMMA = 15; + public static final int NOPRECEDENCE = 16; + public GraphSourceItem src; + public int pos = -1; + protected int precedence; + public List moreSrc = new ArrayList<>(); + public GraphPart firstPart; + public GraphTargetItem value; + + public GraphPart getFirstPart() { + if (value == null) { + return firstPart; + } + GraphPart ret = value.getFirstPart(); + if (ret == null) { + return firstPart; + } + return ret; + } + + public GraphTargetItem() { + this(null, NOPRECEDENCE); + } + + public GraphTargetItem(GraphSourceItem src, int precedence) { + this.src = src; + this.precedence = precedence; + } + + public List getNeededSources() { + List ret = new ArrayList<>(); + ret.add(new GraphSourceItemPos(src, pos)); + ret.addAll(moreSrc); + if (value != null) { + ret.addAll(value.getNeededSources()); + } + return ret; + } + + public GraphTextWriter toStringSemicoloned(GraphTextWriter writer, LocalData localData) throws InterruptedException { + writer.startOffset(src, pos); + appendTo(writer, localData); + if (needsSemicolon()) { + writer.append(";"); + } + writer.endOffset(); + return writer; + } + + public boolean needsSemicolon() { + return true; + } + + @Override + public String toString() { + return this.getClass().getName(); + } + + public GraphTextWriter toString(GraphTextWriter writer, LocalData localData) throws InterruptedException { + writer.startOffset(src, pos); + appendTo(writer, localData); + writer.endOffset(); + return writer; + } + + public abstract GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException; + + public String toString(LocalData localData) throws InterruptedException { + HilightedTextWriter writer = new HilightedTextWriter(Configuration.getCodeFormatting(), false); + toString(writer, localData); + return writer.toString(); + } + + public int getPrecedence() { + return precedence; + } + + public boolean isCompileTime() { + Set dependencies = new HashSet<>(); + dependencies.add(this); + return isCompileTime(dependencies); + } + + public boolean isCompileTime(Set dependencies) { + return false; + } + + public boolean hasSideEffect() { + return false; + } + + public boolean isVariableComputed() { + return false; + } + + public Object getResult() { + return null; + } + + public String toStringNoQuotes(LocalData localData) { + return toString(); + } + + public GraphTextWriter toStringNoQuotes(GraphTextWriter writer, LocalData localData) throws InterruptedException { + writer.startOffset(src, pos); + appendToNoQuotes(writer, localData); + writer.endOffset(); + return writer; + } + + public GraphTextWriter appendToNoQuotes(GraphTextWriter writer, LocalData localData) throws InterruptedException { + return toString(writer, localData); + } + + public GraphTargetItem getNotCoerced() { + return this; + } + + public GraphTargetItem getThroughRegister() { + return this; + } + + public boolean needsNewLine() { + return false; + } + + public GraphTextWriter toStringNL(GraphTextWriter writer, LocalData localData) throws InterruptedException { + writer.startOffset(src, pos); + appendTo(writer, localData); + if (needsNewLine()) { + writer.newLine(); + } + writer.endOffset(); + return writer; + } + + public boolean isEmpty() { + return false; + } + + public GraphTargetItem getThroughNotCompilable() { + return this; + } + + public GraphTargetItem getThroughDuplicate() { + return this; + } + + public boolean valueEquals(GraphTargetItem target) { + return equals(target); + } + + public List toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { + return new ArrayList<>(); + } + + public List toSourceIgnoreReturnValue(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { + if (!hasReturnValue()) { + return toSource(localData, generator); + } + return generator.generateDiscardValue(localData, this); + } + + protected List toSourceBinary(BinaryOp op, GraphSourceItem action) { + List ret = new ArrayList<>(); + + return ret; + } + + public static List toSourceMerge(SourceGeneratorLocalData localData, SourceGenerator gen, Object... tar) throws CompilationException { + List ret = new ArrayList<>(); + for (Object o : tar) { + if (o == null) { + continue; + } + if (o instanceof GraphTargetItem) { + ret.addAll(((GraphTargetItem) o).toSource(localData, gen)); + } + if (o instanceof GraphSourceItem) { + ret.add((GraphSourceItem) o); + } + if (o instanceof List) { + List l = (List) o; + for (Object o2 : l) { + if (o2 instanceof GraphSourceItem) { + ret.add((GraphSourceItem) o2); + } + if (o2 instanceof GraphTargetItem) { + ret.addAll(((GraphTargetItem) o2).toSource(localData, gen)); + } + } + } + } + return ret; + } + + public abstract boolean hasReturnValue(); + + public List getAllSubItems() { + List ret = new ArrayList<>(); + if (value != null) { + ret.add(value); + } + return ret; + } + + public abstract GraphTargetItem returnType(); +} diff --git a/src/com/jpexs/decompiler/graph/SourceGenerator.java b/src/com/jpexs/decompiler/graph/SourceGenerator.java index a4f0a4b6b..8ff393676 100644 --- a/src/com/jpexs/decompiler/graph/SourceGenerator.java +++ b/src/com/jpexs/decompiler/graph/SourceGenerator.java @@ -1,72 +1,72 @@ -/* - * Copyright (C) 2010-2014 JPEXS - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.jpexs.decompiler.graph; - -import com.jpexs.decompiler.flash.SourceGeneratorLocalData; -import com.jpexs.decompiler.graph.model.AndItem; -import com.jpexs.decompiler.graph.model.BreakItem; -import com.jpexs.decompiler.graph.model.CommaExpressionItem; -import com.jpexs.decompiler.graph.model.ContinueItem; -import com.jpexs.decompiler.graph.model.DoWhileItem; -import com.jpexs.decompiler.graph.model.DuplicateItem; -import com.jpexs.decompiler.graph.model.ForItem; -import com.jpexs.decompiler.graph.model.IfItem; -import com.jpexs.decompiler.graph.model.NotItem; -import com.jpexs.decompiler.graph.model.OrItem; -import com.jpexs.decompiler.graph.model.SwitchItem; -import com.jpexs.decompiler.graph.model.TernarOpItem; -import com.jpexs.decompiler.graph.model.WhileItem; -import java.util.List; - -/** - * - * @author JPEXS - */ -public interface SourceGenerator { - - public List generate(SourceGeneratorLocalData localData, AndItem item) throws CompilationException; - - public List generate(SourceGeneratorLocalData localData, OrItem item) throws CompilationException; - - public List generate(SourceGeneratorLocalData localData, IfItem item) throws CompilationException; - - public List generate(SourceGeneratorLocalData localData, TernarOpItem item) throws CompilationException; - - public List generate(SourceGeneratorLocalData localData, WhileItem item) throws CompilationException; - - public List generate(SourceGeneratorLocalData localData, DoWhileItem item) throws CompilationException; - - public List generate(SourceGeneratorLocalData localData, ForItem item) throws CompilationException; - - public List generate(SourceGeneratorLocalData localData, SwitchItem item) throws CompilationException; - - public List generate(SourceGeneratorLocalData localData, NotItem item) throws CompilationException; - - public List generate(SourceGeneratorLocalData localData, DuplicateItem item) throws CompilationException; - - public List generate(SourceGeneratorLocalData localData, BreakItem item) throws CompilationException; - - public List generate(SourceGeneratorLocalData localData, ContinueItem item) throws CompilationException; - - public List generate(SourceGeneratorLocalData localData, List commands) throws CompilationException; - - public List generate(SourceGeneratorLocalData localData, CommaExpressionItem item) throws CompilationException; - - public List generate(SourceGeneratorLocalData localData, TypeItem item) throws CompilationException; - - public List generateDiscardValue(SourceGeneratorLocalData localData, GraphTargetItem item) throws CompilationException; -} +/* + * Copyright (C) 2010-2014 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.decompiler.graph; + +import com.jpexs.decompiler.flash.SourceGeneratorLocalData; +import com.jpexs.decompiler.graph.model.AndItem; +import com.jpexs.decompiler.graph.model.BreakItem; +import com.jpexs.decompiler.graph.model.CommaExpressionItem; +import com.jpexs.decompiler.graph.model.ContinueItem; +import com.jpexs.decompiler.graph.model.DoWhileItem; +import com.jpexs.decompiler.graph.model.DuplicateItem; +import com.jpexs.decompiler.graph.model.ForItem; +import com.jpexs.decompiler.graph.model.IfItem; +import com.jpexs.decompiler.graph.model.NotItem; +import com.jpexs.decompiler.graph.model.OrItem; +import com.jpexs.decompiler.graph.model.SwitchItem; +import com.jpexs.decompiler.graph.model.TernarOpItem; +import com.jpexs.decompiler.graph.model.WhileItem; +import java.util.List; + +/** + * + * @author JPEXS + */ +public interface SourceGenerator { + + public List generate(SourceGeneratorLocalData localData, AndItem item) throws CompilationException; + + public List generate(SourceGeneratorLocalData localData, OrItem item) throws CompilationException; + + public List generate(SourceGeneratorLocalData localData, IfItem item) throws CompilationException; + + public List generate(SourceGeneratorLocalData localData, TernarOpItem item) throws CompilationException; + + public List generate(SourceGeneratorLocalData localData, WhileItem item) throws CompilationException; + + public List generate(SourceGeneratorLocalData localData, DoWhileItem item) throws CompilationException; + + public List generate(SourceGeneratorLocalData localData, ForItem item) throws CompilationException; + + public List generate(SourceGeneratorLocalData localData, SwitchItem item) throws CompilationException; + + public List generate(SourceGeneratorLocalData localData, NotItem item) throws CompilationException; + + public List generate(SourceGeneratorLocalData localData, DuplicateItem item) throws CompilationException; + + public List generate(SourceGeneratorLocalData localData, BreakItem item) throws CompilationException; + + public List generate(SourceGeneratorLocalData localData, ContinueItem item) throws CompilationException; + + public List generate(SourceGeneratorLocalData localData, List commands) throws CompilationException; + + public List generate(SourceGeneratorLocalData localData, CommaExpressionItem item) throws CompilationException; + + public List generate(SourceGeneratorLocalData localData, TypeItem item) throws CompilationException; + + public List generateDiscardValue(SourceGeneratorLocalData localData, GraphTargetItem item) throws CompilationException; +} diff --git a/src/com/jpexs/helpers/Helper.java b/src/com/jpexs/helpers/Helper.java index b97abc224..e5335c088 100644 --- a/src/com/jpexs/helpers/Helper.java +++ b/src/com/jpexs/helpers/Helper.java @@ -462,7 +462,7 @@ public class Helper { while ((cnt = is.read(buf)) > 0) { os.write(buf, 0, cnt); maxLength -= cnt; - + // last chunk is smaller if (maxLength < bufSize) { buf = new byte[(int) maxLength]; @@ -472,7 +472,7 @@ public class Helper { Logger.getLogger(Helper.class.getName()).log(Level.SEVERE, null, ex); } } - + public static void writeFile(String file, byte[] ... data) { try (FileOutputStream fos = new FileOutputStream(file)) { diff --git a/src/com/jpexs/helpers/NulStream.java b/src/com/jpexs/helpers/NulStream.java index c6d2091a7..482da60bb 100644 --- a/src/com/jpexs/helpers/NulStream.java +++ b/src/com/jpexs/helpers/NulStream.java @@ -27,5 +27,5 @@ public class NulStream extends OutputStream { @Override public void write(int i) { } - + } diff --git a/src/com/jpexs/helpers/resource/canvas.js b/src/com/jpexs/helpers/resource/canvas.js index dc00d1983..cbe3a3d13 100644 --- a/src/com/jpexs/helpers/resource/canvas.js +++ b/src/com/jpexs/helpers/resource/canvas.js @@ -840,8 +840,8 @@ var cxform = function(r_add, g_add, b_add, a_add, r_mult, g_mult, b_mult, a_mult v = max; return v; }; - this.apply = function(c) { - var d = c; + this.apply = function(c) { + var d = c; d[0] = this._cut(Math.round(d[0] * this.r_mult / 255 + this.r_add), 0, 255); d[1] = this._cut(Math.round(d[1] * this.g_mult / 255 + this.g_add), 0, 255); d[2] = this._cut(Math.round(d[2] * this.b_mult / 255 + this.b_add), 0, 255);