Issue #302 AS3 goto local variable declaration

Ant upload release/nightly task
This commit is contained in:
Jindra Petřík
2014-10-31 16:42:08 +01:00
parent b97165de9d
commit bea3babacf
31 changed files with 2051 additions and 54 deletions

6
.gitignore vendored
View File

@@ -44,4 +44,8 @@ hs_err_pid*.log
/libsrc/ttf/build/
/libsrc/tablelayout/nbproject/private/
/libsrc/tablelayout/build/
/libsrc/tablelayout/dist/
/libsrc/tablelayout/dist/
/libsrc/uploader/nbproject/private/
/libsrc/uploader/build/
/libsrc/uploader/dist/
jpexs_website.properties

View File

@@ -59,5 +59,7 @@
<property name="RUNPARAMS" value=""/>
<property name="website.upload.url" value="https://www.free-decompiler.com/flash/release.html?action=release" />
<import file="${basedir}/build_common.xml"/>
</project>

View File

@@ -19,7 +19,7 @@
<include name="**/?*.js"/>
<include name="**/?*.swf"/>
</patternset>
<path id="emma.lib">
<pathelement location="${TESTLIBDIR}/emma.jar"/>
<pathelement location="${TESTLIBDIR}/emma_ant.jar"/>
@@ -116,6 +116,7 @@
</condition>
<target name="installer" depends="dist" if="is_windows">
<property name="exe.file" value="${RELEASESDIR}/${PREFIXFILENAME}_${VERSION}${VERSIONSUFFIX}_setup.exe"/>
<echo message="#define MyAppVersion &quot;${VERSION}${VERSIONSUFFIX}&quot;" file="${INSTALLERCONFIG}" />
<exec dir="${basedir}" executable="${INNOSETUPPATH}\iscc.exe">
<arg file="${INSTALLERPROJECT}" />
@@ -129,7 +130,8 @@
<target name="archive" depends="dist">
<mkdir dir="${RELEASESDIR}"/>
<zip destfile="${RELEASESDIR}/${PREFIXFILENAME}_${VERSION}${VERSIONSUFFIX}.zip" basedir="${DISTRIBUTIONDIR}" excludes="ffdec.sh">
<property name="zip.file" value="${RELEASESDIR}/${PREFIXFILENAME}_${VERSION}${VERSIONSUFFIX}.zip" />
<zip destfile="${zip.file}" basedir="${DISTRIBUTIONDIR}" excludes="ffdec.sh">
<zipfileset dir="${DISTRIBUTIONDIR}" includes="ffdec.sh" fullpath="ffdec.sh" filemode="755"/>
</zip>
</target>
@@ -252,6 +254,54 @@
<antcall target="all" />
</target>
<target name="nighlty-upload" depends="nightly,-upload">
</target>
<target name="all-upload" depends="all,-upload">
</target>
<target name="-upload-fail" unless="upload.config.exists">
<fail message="Cannot upload - Website properties file missing. Create file named jpexs_website.properties and put username=xxx, password=yyy lines in there" />
</target>
<target name="-upload-do" if="upload.config.exists">
<loadproperties srcfile="jpexs_website.properties" prefix="website"/>
<java jar="uploader.jar" fork="true" failonerror="true">
<arg value="${website.upload.url}" />
<arg value="-field" />
<arg value="set_username" />
<arg value="${website.username}" />
<arg value="-field" />
<arg value="set_password" />
<arg value="${website.password}" />
<arg value="-file" />
<arg value="fileExe" />
<arg value="${exe.file}" />
<arg value="-file" />
<arg value="fileZip" />
<arg value="${zip.file}" />
<arg value="-file" />
<arg value="fileLang" />
<arg value="${lang.file}" />
</java>
</target>
<target name="-upload-check-config">
<available file="jpexs_website.properties" property="upload.config.exists"/>
</target>
<target name="-upload" depends="-upload-check-config,-upload-do,-upload-fail">
</target>
<target name="dist" depends="build,exe">
<copy todir="${DISTRIBUTIONDIR}">
@@ -289,7 +339,8 @@
-------------------------------------------------------------------
Please follow instructions on http://www.free-decompiler.com/flash/translations.html
</echo>
<zip destfile="${RELEASESDIR}/${PREFIXFILENAME}_${VERSION}${VERSIONSUFFIX}_lang.zip" basedir="${LOCALESTARGETDIR}"/>
<property name="lang.file" value="${RELEASESDIR}/${PREFIXFILENAME}_${VERSION}${VERSIONSUFFIX}_lang.zip" />
<zip destfile="${lang.file}" basedir="${LOCALESTARGETDIR}"/>
</target>
<target name="-nightly-suffix" if="NIGHTLY">

View File

@@ -39,6 +39,8 @@ public class GetSlotAVM2Item extends AVM2Item {
if (slotName == null) {
return writer.append("/*UnknownSlot*/");
}
srcData.put("slotName", slotName.getName(localData.constantsAvm2, localData.fullyQualifiedNames, false));
return writer.append(slotName.getName(localData.constantsAvm2, localData.fullyQualifiedNames, false));
}

View File

@@ -56,6 +56,7 @@ public class LocalRegAVM2Item extends AVM2Item {
}
}
this.computedValue = computedValue;
srcData.put("regIndex", ""+regIndex);
}
@Override

View File

@@ -60,8 +60,9 @@ public class NewFunctionAVM2Item extends AVM2Item {
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
MethodBody body = abc.findBody(methodIndex);
writer.append("function" + (!functionName.isEmpty() ? " " + functionName : ""));
writer.startMethod(methodIndex);
writer.append("function");
writer.startMethod(methodIndex);
writer.append((!functionName.isEmpty() ? " " + functionName : ""));
writer.appendNoHilight("(");
methodInfo.get(methodIndex).getParamStr(writer, constants, body, abc, fullyQualifiedNames);
writer.appendNoHilight("):");
@@ -70,8 +71,7 @@ public class NewFunctionAVM2Item extends AVM2Item {
writer.appendNoHilight(abc.findBodyIndex(methodIndex));
writer.newLine();
}
methodInfo.get(methodIndex).getReturnTypeStr(writer, constants, fullyQualifiedNames);
writer.endMethod();
methodInfo.get(methodIndex).getReturnTypeStr(writer, constants, fullyQualifiedNames);
writer.startBlock();
if (body != null) {
if (writer instanceof NulWriter) {
@@ -81,6 +81,7 @@ public class NewFunctionAVM2Item extends AVM2Item {
}
}
writer.endBlock();
writer.endMethod();
return writer;
}

View File

@@ -43,6 +43,7 @@ public class SetLocalAVM2Item extends AVM2Item implements SetTypeAVM2Item, Assig
super(instruction, PRECEDENCE_ASSIGMENT);
this.regIndex = regIndex;
this.value = value;
srcData.put("regIndex", ""+regIndex);
}
@Override

View File

@@ -35,7 +35,7 @@ public class SetSlotAVM2Item extends AVM2Item implements SetTypeAVM2Item, Assign
super(instruction, PRECEDENCE_ASSIGMENT);
this.slotName = slotName;
this.value = value;
this.scope = scope;
this.scope = scope;
}
@Override
@@ -45,11 +45,16 @@ public class SetSlotAVM2Item extends AVM2Item implements SetTypeAVM2Item, Assign
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
srcData.put("slotName", slotName.getName(localData.constantsAvm2, localData.fullyQualifiedNames, false));
getName(writer, localData);
writer.append(" = ");
return value.toString(writer, localData);
}
public String getNameAsStr(LocalData localData){
return slotName.getName(localData.constantsAvm2, localData.fullyQualifiedNames, false);
}
public GraphTextWriter getName(GraphTextWriter writer, LocalData localData) {
/*ret = scope.toString(constants, localRegNames) + ".";
if (!(scope instanceof NewActivationAVM2Item)) {

View File

@@ -12,7 +12,8 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.abc.avm2.model.clauses;
import com.jpexs.decompiler.flash.abc.avm2.model.AVM2Item;
@@ -46,8 +47,10 @@ public class DeclarationAVM2Item extends AVM2Item {
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
if (assignment instanceof SetLocalAVM2Item) {
SetLocalAVM2Item lti = (SetLocalAVM2Item) assignment;
srcData.put("regIndex",""+lti.regIndex);
srcData.put("declaration", "true");
GraphTargetItem coerType = TypeItem.UNBOUNDED;
if (lti.value instanceof CoerceAVM2Item) {
coerType = ((CoerceAVM2Item) lti.value).typeObj;
@@ -64,6 +67,8 @@ public class DeclarationAVM2Item extends AVM2Item {
}
if (assignment instanceof SetSlotAVM2Item) {
SetSlotAVM2Item ssti = (SetSlotAVM2Item) assignment;
srcData.put("slotName",""+ssti.getNameAsStr(localData));
srcData.put("declaration", "true");
writer.append("var ");
ssti.getName(writer, localData);
writer.append(":");

View File

@@ -204,23 +204,23 @@ public class MethodBody implements Cloneable {
getCode().toASMSource(constants, trait, method_info.get(this.method_info), this, exportMode, writer);
} else {
if (!Configuration.decompile.get()) {
writer.startMethod(this.method_info);
//writer.startMethod(this.method_info);
writer.appendNoHilight("//" + AppResources.translate("decompilation.skipped")).newLine();
writer.endMethod();
//writer.endMethod();
return writer;
}
int timeout = Configuration.decompilationTimeoutSingleMethod.get();
if (convertException == null) {
HashMap<Integer, String> localRegNames = getLocalRegNames(abc);
writer.startMethod(this.method_info);
//writer.startMethod(this.method_info);
if (Configuration.showMethodBodyId.get()) {
writer.appendNoHilight("// method body id: ");
writer.appendNoHilight(abc.findBodyIndex(this.method_info));
writer.newLine();
}
Graph.graphToString(convertedItems, writer, LocalData.create(constants, localRegNames, fullyQualifiedNames));
writer.endMethod();
//writer.endMethod();
} else if (convertException instanceof TimeoutException) {
Logger.getLogger(MethodBody.class.getName()).log(Level.SEVERE, "Decompilation error", convertException);
Helper.appendTimeoutComment(writer, timeout);

View File

@@ -26,6 +26,7 @@ import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.helpers.Helper;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class MethodInfo {
@@ -271,16 +272,22 @@ public class MethodInfo {
if (body != null) {
localRegNames = body.getCode().getLocalRegNamesFromDebug(abc);
}
Map<String,String> pdata;
for (int i = 0; i < param_types.length; i++) {
if (i > 0) {
writer.appendNoHilight(", ");
}
pdata=new HashMap<>();
pdata.put("declaration", "true");
pdata.put("regIndex", ""+(i+1));
if (!localRegNames.isEmpty()) {
writer.appendNoHilight(Deobfuscation.printIdentifier(localRegNames.get(i + 1)));
pdata.put("slotName", localRegNames.get(i + 1)); //assuming it is a slot
writer.hilightSpecial(Deobfuscation.printIdentifier(localRegNames.get(i + 1)),"paramname",i,pdata);
} else if ((paramNames.length > i) && (paramNames[i] != 0) && Configuration.paramNamesEnable.get()) {
writer.appendNoHilight(Deobfuscation.printIdentifier(constants.getString(paramNames[i])));
writer.hilightSpecial(Deobfuscation.printIdentifier(constants.getString(paramNames[i])),"paramname",i,pdata);
} else {
writer.appendNoHilight("param" + (i + 1));
writer.hilightSpecial("param" + (i + 1),"paramname",i,pdata);
}
writer.appendNoHilight(":");
if (param_types[i] == 0) {
@@ -307,7 +314,10 @@ public class MethodInfo {
} else {
restAdd += "rest";
}
writer.hilightSpecial(restAdd, "flag.NEED_REST");
pdata=new HashMap<>();
pdata.put("declaration", "true");
pdata.put("regIndex", ""+(param_types.length + 1));
writer.hilightSpecial(restAdd, "flag.NEED_REST",0,pdata);
}
return writer;
}

View File

@@ -458,9 +458,11 @@ public class TraitClass extends Trait implements TraitWithSlot {
if (!classInitializerIsEmpty) {
writer.newLine();
writer.startTrait(abc.class_info.get(class_info).static_traits.traits.size() + abc.instance_info.get(class_info).instance_traits.traits.size() + 1);
writer.startMethod(abc.class_info.get(class_info).cinit_index);
writer.appendNoHilight("{").newLine();
abc.bodies.get(bodyIndex).toString(path +/*packageName +*/ "/" + abc.instance_info.get(class_info).getName(abc.constants).getName(abc.constants, fullyQualifiedNames, false) + ".staticinitializer", exportMode, abc, this, abc.constants, abc.method_info, writer, fullyQualifiedNames);
writer.appendNoHilight("}").newLine();
writer.endMethod();
writer.endTrait();
}
} else {
@@ -486,6 +488,7 @@ public class TraitClass extends Trait implements TraitWithSlot {
writer.newLine();
writer.startTrait(abc.class_info.get(class_info).static_traits.traits.size() + abc.instance_info.get(class_info).instance_traits.traits.size());
writer.startMethod(abc.instance_info.get(class_info).iinit_index);
writer.appendNoHilight(modifier);
writer.appendNoHilight("function ");
writer.appendNoHilight(abc.constants.getMultiname(abc.instance_info.get(class_info).name_index).getName(abc.constants, new ArrayList<String>()/*do not want full names here*/, false));
@@ -501,6 +504,7 @@ public class TraitClass extends Trait implements TraitWithSlot {
abc.bodies.get(bodyIndex).toString(path +/*packageName +*/ "/" + abc.instance_info.get(class_info).getName(abc.constants).getName(abc.constants, fullyQualifiedNames, false) + ".initializer", exportMode, abc, this, abc.constants, abc.method_info, writer, fullyQualifiedNames);
}
writer.endBlock().newLine();
writer.endMethod();
writer.endTrait();
}

View File

@@ -73,6 +73,7 @@ public class TraitFunction extends Trait implements TraitWithSlot {
@Override
public GraphTextWriter toString(Trait parent, String path, List<ABCContainerTag> abcTags, ABC abc, boolean isStatic, ScriptExportMode exportMode, int scriptIndex, int classIndex, GraphTextWriter writer, List<String> fullyQualifiedNames, boolean parallel) throws InterruptedException {
writer.startMethod(method_info);
toStringHeader(parent, path, abcTags, abc, isStatic, exportMode, scriptIndex, classIndex, writer, fullyQualifiedNames, parallel);
if (abc.instance_info.get(classIndex).isInterface()) {
writer.appendNoHilight(";");
@@ -86,11 +87,13 @@ public class TraitFunction extends Trait implements TraitWithSlot {
writer.appendNoHilight("}");
}
writer.newLine();
writer.endMethod();
return writer;
}
@Override
public void convert(Trait parent, String path, List<ABCContainerTag> abcTags, ABC abc, boolean isStatic, ScriptExportMode exportMode, int scriptIndex, int classIndex, NulWriter writer, List<String> fullyQualifiedNames, boolean parallel) throws InterruptedException {
writer.startMethod(method_info);
convertHeader(parent, path, abcTags, abc, isStatic, exportMode, scriptIndex, classIndex, writer, fullyQualifiedNames, parallel);
if (!abc.instance_info.get(classIndex).isInterface()) {
int bodyIndex = abc.findBodyIndex(method_info);
@@ -98,6 +101,7 @@ public class TraitFunction extends Trait implements TraitWithSlot {
abc.bodies.get(bodyIndex).convert(path + "." + abc.constants.getMultiname(name_index).getName(abc.constants, fullyQualifiedNames, false), exportMode, isStatic, scriptIndex, classIndex, abc, this, abc.constants, abc.method_info, new ScopeStack(), false, writer, fullyQualifiedNames, null, true);
}
}
writer.endMethod();
}
@Override

View File

@@ -77,6 +77,7 @@ public class TraitMethodGetterSetter extends Trait {
@Override
public void convert(Trait parent, String path, List<ABCContainerTag> abcTags, ABC abc, boolean isStatic, ScriptExportMode exportMode, int scriptIndex, int classIndex, NulWriter writer, List<String> fullyQualifiedNames, boolean parallel) throws InterruptedException {
writer.startMethod(method_info);
path = path + "." + getName(abc).getName(abc.constants, fullyQualifiedNames, false);
convertHeader(parent, path, abcTags, abc, isStatic, exportMode, scriptIndex, classIndex, writer, fullyQualifiedNames, parallel);
int bodyIndex = abc.findBodyIndex(method_info);
@@ -85,10 +86,12 @@ public class TraitMethodGetterSetter extends Trait {
abc.bodies.get(bodyIndex).convert(path, exportMode, isStatic, scriptIndex, classIndex, abc, this, abc.constants, abc.method_info, new ScopeStack(), false, writer, fullyQualifiedNames, null, true);
}
}
writer.endMethod();
}
@Override
public GraphTextWriter toString(Trait parent, String path, List<ABCContainerTag> abcTags, ABC abc, boolean isStatic, ScriptExportMode exportMode, int scriptIndex, int classIndex, GraphTextWriter writer, List<String> fullyQualifiedNames, boolean parallel) throws InterruptedException {
writer.startMethod(method_info);
path = path + "." + getName(abc).getName(abc.constants, fullyQualifiedNames, false);
toStringHeader(parent, path, abcTags, abc, isStatic, exportMode, scriptIndex, classIndex, writer, fullyQualifiedNames, parallel);
int bodyIndex = abc.findBodyIndex(method_info);
@@ -102,6 +105,7 @@ public class TraitMethodGetterSetter extends Trait {
writer.endBlock();
}
writer.newLine();
writer.endMethod();
return writer;
}

View File

@@ -12,7 +12,8 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.helpers;
import com.jpexs.helpers.utf8.Utf8OutputStreamWriter;
@@ -20,6 +21,7 @@ import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.Writer;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -58,6 +60,14 @@ public class FileTextWriter extends GraphTextWriter implements AutoCloseable {
return this;
}
@Override
public GraphTextWriter appendWithData(String str, Map<String, String> data) {
writeToFile(str);
return this;
}
@Override
public FileTextWriter append(String str, long offset) {
writeToFile(str);

View File

@@ -12,10 +12,12 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.helpers;
import com.jpexs.decompiler.graph.GraphSourceItem;
import java.util.Map;
/**
* Provides methods for highlighting positions of instructions in the text.
@@ -26,5 +28,6 @@ public class GraphSourceItemPosition {
public GraphSourceItem graphSourceItem;
public int position;
public Map<String,String> data;
}

View File

@@ -12,10 +12,13 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.helpers;
import com.jpexs.decompiler.graph.GraphSourceItem;
import java.util.HashMap;
import java.util.Map;
/**
* Provides methods for highlighting positions of instructions in the text.
@@ -46,9 +49,10 @@ public abstract class GraphTextWriter {
*
* @param src
* @param pos Offset of instruction
* @param data
* @return GraphTextWriter
*/
*/
public GraphTextWriter startOffset(GraphSourceItem src, int pos, Map<String,String> data) {
return this;
}
@@ -99,10 +103,14 @@ public abstract class GraphTextWriter {
}
public GraphTextWriter hilightSpecial(String text, String type) {
public GraphTextWriter hilightSpecial(String text, String type) {
return hilightSpecial(text, type, 0);
}
public GraphTextWriter hilightSpecial(String text, String type, int index) {
return hilightSpecial(text, type, 0, new HashMap<String, String>());
}
public GraphTextWriter hilightSpecial(String text, String type, int index, Map<String,String> data) {
return this;
}
@@ -110,6 +118,8 @@ public abstract class GraphTextWriter {
return "";
}
public abstract GraphTextWriter appendWithData(String str, Map<String,String> data);
public abstract GraphTextWriter append(String str);
public abstract GraphTextWriter append(String str, long offset);

View File

@@ -12,7 +12,8 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.helpers;
import com.jpexs.decompiler.flash.configuration.Configuration;
@@ -68,13 +69,15 @@ public class HilightedTextWriter extends GraphTextWriter {
*
* @param src
* @param pos Offset of instruction
* @param data
* @return HilightedTextWriter
*/
@Override
@Override
public HilightedTextWriter startOffset(GraphSourceItem src, int pos, Map<String,String> data) {
GraphSourceItemPosition itemPos = new GraphSourceItemPosition();
itemPos.graphSourceItem = src;
itemPos.position = pos;
itemPos.data = data;
offsets.add(itemPos);
return this;
}
@@ -146,25 +149,42 @@ public class HilightedTextWriter extends GraphTextWriter {
@Override
public HilightedTextWriter hilightSpecial(String text, String type, int index) {
public HilightedTextWriter hilightSpecial(String text, String type, int index) {
Map<String, String> data = new HashMap<>();
data.put("subtype", type);
data.put("index", Long.toString(index));
return hilightSpecial(text, type, index, new HashMap<String, String>());
}
@Override
public HilightedTextWriter hilightSpecial(String text, String type, int index, Map<String, String> data) {
Map<String, String> ndata = new HashMap<>();
ndata.putAll(data);
ndata.put("subtype", type);
ndata.put("index", Long.toString(index));
start(ndata, HilightType.SPECIAL);
appendNoHilight(text);
return end(HilightType.SPECIAL);
}
@Override
public HilightedTextWriter append(String str) {
return appendWithData(str, new HashMap<String, String>());
}
@Override
public HilightedTextWriter appendWithData(String str, Map<String,String> data) {
Highlighting h = null;
if (!offsets.empty()) {
GraphSourceItemPosition itemPos = offsets.peek();
GraphSourceItem src = itemPos.graphSourceItem;
int pos = itemPos.position;
if (src != null && hilight) {
if (src != null && hilight) {
Map<String, String> data = new HashMap<>();
data.put("offset", Long.toString(src.getOffset() + pos + 1));
Map<String,String> ndata=new HashMap<>();
ndata.putAll(itemPos.data);
ndata.putAll(data);
ndata.put("offset", Long.toString(src.getOffset() + pos + 1));
h = new Highlighting(sb.length() - newLineCount, ndata, HilightType.OFFSET, str);
instructionHilights.add(h);
}
}

View File

@@ -12,9 +12,11 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.helpers;
import java.util.Map;
import java.util.Stack;
/**
@@ -102,12 +104,28 @@ public class NulWriter extends GraphTextWriter {
return this;
}
@Override
public NulWriter hilightSpecial(String text, String type, int index, Map<String, String> data) {
stringAdded = true;
return this;
}
@Override
public NulWriter append(String str) {
stringAdded = true;
return this;
}
@Override
public GraphTextWriter appendWithData(String str, Map<String, String> data) {
stringAdded = true;
return this;
}
@Override
public NulWriter append(String str, long offset) {
stringAdded = true;

View File

@@ -12,12 +12,15 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.helpers.hilight;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.helpers.HilightType;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -52,6 +55,12 @@ public class Highlighting implements Serializable {
}
}
public Map<String, String> getProperties() {
return new HashMap<>(properties);
}
public String getPropertyString(String key) {
return properties.get(key);
}
@@ -63,23 +72,39 @@ public class Highlighting implements Serializable {
public static Highlighting search(List<Highlighting> list, String property, String value) {
return search(list, -1, property, value, -1, -1);
}
public static Highlighting search(List<Highlighting> list, Map<String,String> properties) {
return search(list, -1, properties, -1, -1);
}
public static Highlighting search(List<Highlighting> list, String property, String value, int from, int to) {
return search(list, -1, property, value, from, to);
}
}
public static Highlighting search(List<Highlighting> list, Map<String,String> properties, int from, int to) {
return search(list, -1, properties, from, to);
}
public static Highlighting search(List<Highlighting> list, long pos, String property, String value, long from, long to) {
Map<String,String> map= new HashMap<>();
map.put(property, value);
return search(list, pos, map, from, to);
}
public static Highlighting search(List<Highlighting> list, long pos, Map<String,String> properties, long from, long to) {
Highlighting ret = null;
Highlighting ret = null;
for (Highlighting h : list) {
if (property != null) {
String v = h.getPropertyString(property);
if (v == null) {
if (value != null) {
continue;
}
} else {
if (!v.equals(value)) {
looph:for (Highlighting h : list) {
for(String property:properties.keySet()){
if (property != null) {
String v = h.getPropertyString(property);
String value = properties.get(property);
if (v == null) {
if (value != null) {
continue looph;
}
} else {
if (!v.equals(value)) {
continue looph;
}
}
}
}
@@ -112,6 +137,44 @@ public class Highlighting implements Serializable {
return ret;
}
public static List<Highlighting> searchAll(List<Highlighting> list, long pos, String property, String value, long from, long to) {
List<Highlighting> ret = new ArrayList<>();
for (Highlighting h : list) {
if (property != null) {
String v = h.getPropertyString(property);
if (v == null) {
if (value != null) {
continue;
}
} else {
if (!v.equals(value)) {
continue;
}
}
}
if (from > -1) {
if (h.startPos < from) {
continue;
}
}
if (to > -1) {
if (h.startPos > to) {
continue;
}
}
if (pos == -1 ||(pos >= h.startPos && (pos < h.startPos + h.len))) {
//if (ret == null || h.startPos > ret.startPos) { //get the closest one
ret.add(h);
//}
}
//if (pos == -1) {
// return ret;
//}
}
return ret;
}
/**
* Returns a string representation of the object
*

View File

@@ -12,7 +12,8 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.graph;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
@@ -23,8 +24,10 @@ 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.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
@@ -56,6 +59,7 @@ public abstract class GraphTargetItem implements Serializable {
public List<GraphSourceItemPos> moreSrc = new ArrayList<>();
public GraphPart firstPart;
public GraphTargetItem value;
protected Map<String,String> srcData = new HashMap<String, String>();
public GraphPart getFirstPart() {
if (value == null) {
@@ -88,7 +92,7 @@ public abstract class GraphTargetItem implements Serializable {
}
public GraphTextWriter toStringSemicoloned(GraphTextWriter writer, LocalData localData) throws InterruptedException {
public GraphTextWriter toStringSemicoloned(GraphTextWriter writer, LocalData localData) throws InterruptedException {
writer.startOffset(src, pos, srcData);
appendTo(writer, localData);
if (needsSemicolon()) {
writer.append(";");
@@ -107,7 +111,7 @@ public abstract class GraphTargetItem implements Serializable {
}
public GraphTextWriter toString(GraphTextWriter writer, LocalData localData) throws InterruptedException {
public GraphTextWriter toString(GraphTextWriter writer, LocalData localData) throws InterruptedException {
writer.startOffset(src, pos, srcData);
appendTo(writer, localData);
writer.endOffset();
return writer;
@@ -152,7 +156,7 @@ public abstract class GraphTargetItem implements Serializable {
}
public GraphTextWriter toStringNoQuotes(GraphTextWriter writer, LocalData localData) throws InterruptedException {
public GraphTextWriter toStringNoQuotes(GraphTextWriter writer, LocalData localData) throws InterruptedException {
writer.startOffset(src, pos, srcData);
appendToNoQuotes(writer, localData);
writer.endOffset();
return writer;
@@ -175,7 +179,7 @@ public abstract class GraphTargetItem implements Serializable {
}
public GraphTextWriter toStringNL(GraphTextWriter writer, LocalData localData) throws InterruptedException {
public GraphTextWriter toStringNL(GraphTextWriter writer, LocalData localData) throws InterruptedException {
writer.startOffset(src, pos, srcData);
appendTo(writer, localData);
if (needsNewLine()) {
writer.newLine();

12
libsrc/uploader/build.xml Normal file
View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="uploader" default="default" basedir=".">
<description>Builds, tests, and runs the project uploader.</description>
<import file="nbproject/build-impl.xml"/>
<target name="-post-jar">
<delete file="../../README.TXT"/>
</target>
</project>

View File

@@ -0,0 +1,3 @@
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,8 @@
build.xml.data.CRC32=50abf8ab
build.xml.script.CRC32=319eb7df
build.xml.stylesheet.CRC32=8064a381@1.74.2.48
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=50abf8ab
nbproject/build-impl.xml.script.CRC32=0856044a
nbproject/build-impl.xml.stylesheet.CRC32=876e7a8f@1.74.2.48

View File

@@ -0,0 +1,75 @@
annotation.processing.enabled=true
annotation.processing.enabled.in.editor=false
annotation.processing.processors.list=
annotation.processing.run.all.processors=true
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
application.title=uploader
application.vendor=JPEXS
build.classes.dir=${build.dir}/classes
build.classes.excludes=**/*.java,**/*.form
# This directory is removed when the project is cleaned:
build.dir=build
build.generated.dir=${build.dir}/generated
build.generated.sources.dir=${build.dir}/generated-sources
# Only compile against the classpath explicitly listed here:
build.sysclasspath=ignore
build.test.classes.dir=${build.dir}/test/classes
build.test.results.dir=${build.dir}/test/results
# Uncomment to specify the preferred debugger connection transport:
#debug.transport=dt_socket
debug.classpath=\
${run.classpath}
debug.test.classpath=\
${run.test.classpath}
# Files in build.classes.dir which should be excluded from distribution jar
dist.archive.excludes=
# This directory is removed when the project is cleaned:
dist.dir=dist
dist.jar=../../uploader.jar
dist.javadoc.dir=${dist.dir}/javadoc
endorsed.classpath=
excludes=
includes=**
jar.compress=false
javac.classpath=
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
javac.processorpath=\
${javac.classpath}
javac.source=1.7
javac.target=1.7
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}
javac.test.processorpath=\
${javac.test.classpath}
javadoc.additionalparam=
javadoc.author=false
javadoc.encoding=${source.encoding}
javadoc.noindex=false
javadoc.nonavbar=false
javadoc.notree=false
javadoc.private=false
javadoc.splitindex=true
javadoc.use=true
javadoc.version=false
javadoc.windowtitle=
main.class=com.jpexs.uploader.Uploader
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false
platform.active=default_platform
run.classpath=\
${javac.classpath}:\
${build.classes.dir}
# Space-separated list of JVM arguments used when running the project.
# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value.
# To set system properties for unit tests define test-sys-prop.name=value:
run.jvmargs=
run.test.classpath=\
${javac.test.classpath}:\
${build.test.classes.dir}
source.encoding=UTF-8
src.dir=src
test.src.dir=test

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.java.j2seproject</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
<name>uploader</name>
<source-roots>
<root id="src.dir"/>
</source-roots>
<test-roots>
<root id="test.src.dir"/>
</test-roots>
</data>
</configuration>
</project>

View File

@@ -0,0 +1,201 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.jpexs.uploader;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author JPEXS
*/
public class Uploader {
private static class MultipartUtility {
private final String boundary;
private static final String LINE_FEED = "\r\n";
private HttpURLConnection httpConn;
private String charset;
private OutputStream outputStream;
private PrintWriter writer;
/**
* This constructor initializes a new HTTP POST request with content
* type is set to multipart/form-data
*
* @param requestURL
* @param charset
* @throws IOException
*/
public MultipartUtility(String requestURL, String charset)
throws IOException {
this.charset = charset;
// creates a unique boundary based on time stamp
boundary = "===" + System.currentTimeMillis() + "===";
URL url = new URL(requestURL);
httpConn = (HttpURLConnection) url.openConnection();
httpConn.setUseCaches(false);
httpConn.setDoOutput(true); // indicates POST method
httpConn.setDoInput(true);
httpConn.setRequestProperty("Content-Type",
"multipart/form-data; boundary=" + boundary);
httpConn.setRequestProperty("User-Agent", "JPEXS Uploader");
outputStream = httpConn.getOutputStream();
writer = new PrintWriter(new OutputStreamWriter(outputStream, charset),
true);
}
/**
* Adds a form field to the request
*
* @param name field name
* @param value field value
*/
public void addFormField(String name, String value) {
writer.append("--" + boundary).append(LINE_FEED);
writer.append("Content-Disposition: form-data; name=\"" + name + "\"")
.append(LINE_FEED);
writer.append("Content-Type: text/plain; charset=" + charset).append(
LINE_FEED);
writer.append(LINE_FEED);
writer.append(value).append(LINE_FEED);
writer.flush();
}
/**
* Adds a upload file section to the request
*
* @param fieldName name attribute in <input type="file" name="..." />
* @param uploadFile a File to be uploaded
* @throws IOException
*/
public void addFilePart(String fieldName, File uploadFile)
throws IOException {
String fileName = uploadFile.getName();
writer.append("--" + boundary).append(LINE_FEED);
writer.append(
"Content-Disposition: form-data; name=\"" + fieldName
+ "\"; filename=\"" + fileName + "\"")
.append(LINE_FEED);
writer.append(
"Content-Type: "
+ URLConnection.guessContentTypeFromName(fileName))
.append(LINE_FEED);
writer.append("Content-Transfer-Encoding: binary").append(LINE_FEED);
writer.append(LINE_FEED);
writer.flush();
FileInputStream inputStream = new FileInputStream(uploadFile);
byte[] buffer = new byte[4096];
int bytesRead = -1;
while ((bytesRead = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
}
outputStream.flush();
inputStream.close();
writer.append(LINE_FEED);
writer.flush();
}
/**
* Adds a header field to the request.
*
* @param name - name of the header field
* @param value - value of the header field
*/
public void addHeaderField(String name, String value) {
writer.append(name + ": " + value).append(LINE_FEED);
writer.flush();
}
/**
* Completes the request and receives response from the server.
*
* @return a list of Strings as response in case the server returned
* status OK, otherwise an exception is thrown.
* @throws IOException
*/
public List<String> finish() throws IOException {
List<String> response = new ArrayList<>();
writer.append(LINE_FEED).flush();
writer.append("--" + boundary + "--").append(LINE_FEED);
writer.close();
// checks server's status code first
int status = httpConn.getResponseCode();
if (status == HttpURLConnection.HTTP_OK) {
BufferedReader reader = new BufferedReader(new InputStreamReader(
httpConn.getInputStream()));
String line = null;
while ((line = reader.readLine()) != null) {
response.add(line);
}
reader.close();
httpConn.disconnect();
} else {
throw new IOException("Server returned non-OK status: " + status);
}
return response;
}
}
public static void main(String[] args) {
if(args.length<1){
System.err.println("1");
System.exit(1);
}
String charset = "UTF-8";
String requestURL = args[0];
try {
MultipartUtility multipart = new MultipartUtility(requestURL, charset);
multipart.addHeaderField("User-Agent", "JPEXS Uploader");
for(int i=1;i<args.length;i++){
if(args[i].equals("-field")){
multipart.addFormField(args[i+1], args[i+2]);
i+=2;
}
if(args[i].equals("-file")){
multipart.addFilePart(args[i+1], new File(args[i+2]));
i+=2;
}
}
List<String> response = multipart.finish();
for (String line : response) {
System.out.println(line);
}
System.exit(0);
} catch (IOException ex) {
ex.printStackTrace();
System.exit(1);
}
}
}

View File

@@ -369,7 +369,7 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se
@Override
public boolean isLink(Token token) {
return isDeclaration(token.start);
return hasDeclaration(token.start);
}
@Override
@@ -538,7 +538,7 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se
tabbedPane.addTab(AppStrings.translate("constants"), panConstants);
}
private boolean isDeclaration(int pos) {
private boolean hasDeclaration(int pos) {
int multinameIndex = decompiledTextArea.getMultinameAtPos(pos);
if (multinameIndex > -1) {
List<MultinameUsage> usages = abc.findMultinameDefinition(swf.abcList, multinameIndex);
@@ -562,6 +562,8 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se
if (!usages.isEmpty()) {
return true;
}
}else{
return decompiledTextArea.getLocalDeclarationOfPos(pos)!=-1;
}
return false;
}
@@ -593,6 +595,11 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se
} else if (!usages.isEmpty()) { //one
UsageFrame.gotoUsage(ABCPanel.this, usages.get(0));
}
}else{
int dpos=decompiledTextArea.getLocalDeclarationOfPos(pos);
if(dpos>-1){
decompiledTextArea.setCaretPosition(dpos);
}
}
}

View File

@@ -36,7 +36,9 @@ import com.jpexs.decompiler.flash.tags.ABCContainerTag;
import com.jpexs.helpers.Cache;
import java.awt.Point;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.SwingUtilities;
@@ -113,7 +115,7 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL
}
List<Highlighting> allh = new ArrayList<>();
for (Highlighting h : traitHighlights) {
for (Highlighting h : traitHighlights) {
if (h.getPropertyString("index").equals("" + lastTraitIndex)) {
for (Highlighting sh : specialHighlights) {
if (sh.startPos >= h.startPos && (sh.startPos + sh.len < h.startPos + h.len)) {
@@ -229,6 +231,45 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL
return getMultinameAtPos(getCaretPosition());
}
public int getLocalDeclarationOfPos(int pos) {
Highlighting sh=Highlighting.search(specialHighlights,pos);
Highlighting h=Highlighting.search(highlights,pos);
Highlighting tm = Highlighting.search(methodHighlights, pos);
if (tm == null) {
return -1;
}
List<Highlighting> tms= Highlighting.searchAll(methodHighlights, -1, "index", tm.getPropertyString("index"), -1, -1);
if(h==null){
return -1;
}
//is it already declaration?
if("true".equals(h.getPropertyString("declaration")) || (sh!=null && "true".equals(sh.getPropertyString("declaration")))){
return -1; //no jump
}
Map<String,String> search=h.getProperties();
search.remove("index");
search.remove("subtype");
search.remove("offset");
if(search.isEmpty()){
return -1;
}
search.put("declaration", "true");
for(Highlighting tm1:tms)
{
Highlighting rh= Highlighting.search(highlights, search, tm1.startPos, tm1.startPos+tm1.len);
if(rh==null){
rh=Highlighting.search(specialHighlights, search, tm1.startPos, tm1.startPos+tm1.len);
}
if(rh!=null){
return rh.startPos;
}
}
return -1;
}
public int getMultinameAtPos(int pos) {
Highlighting tm = Highlighting.search(methodHighlights, pos);
if (tm == null) {

BIN
uploader.jar Normal file

Binary file not shown.