highlighting refactored

This commit is contained in:
2014-11-16 14:49:31 +01:00
parent 0e128e2ef7
commit cb052143f5
48 changed files with 469 additions and 880 deletions
@@ -563,7 +563,7 @@ public class ABC {
loadNamespaceMap();
/*for(int i=0;i<script_count;i++){
MethodBody bod=bodies.get(bodyIdxFromMethodIdx.get(script_info.get(i).init_index));
GraphTextWriter t=new HilightedTextWriter(Configuration.getCodeFormatting(),false);
GraphTextWriter t=new HighlightedTextWriter(Configuration.getCodeFormatting(),false);
try {
bod.toString("script", ScriptExportMode.PCODE, this, null, constants, method_info, t, new ArrayList<String>());
} catch (InterruptedException ex) {
@@ -221,7 +221,8 @@ import com.jpexs.decompiler.flash.dumpview.DumpInfo;
import com.jpexs.decompiler.flash.ecma.EcmaScript;
import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.flash.helpers.HilightedTextWriter;
import com.jpexs.decompiler.flash.helpers.HighlightedTextWriter;
import com.jpexs.decompiler.flash.helpers.hilight.HighlightSpecialType;
import com.jpexs.decompiler.graph.Block;
import com.jpexs.decompiler.graph.Graph;
import com.jpexs.decompiler.graph.GraphPart;
@@ -927,10 +928,10 @@ public class AVM2Code implements Cloneable {
if (trait instanceof TraitFunction) {
TraitFunction tf = (TraitFunction) trait;
writer.appendNoHilight("trait ");
writer.hilightSpecial("function ", "traittype");
writer.hilightSpecial(constants.multinameToString(tf.name_index), "traitname");
writer.hilightSpecial("function ", HighlightSpecialType.TRAIT_TYPE);
writer.hilightSpecial(constants.multinameToString(tf.name_index), HighlightSpecialType.TRAIT_NAME);
writer.appendNoHilight(" slotid ");
writer.hilightSpecial("" + tf.slot_id, "slotid");
writer.hilightSpecial("" + tf.slot_id, HighlightSpecialType.SLOT_ID);
writer.newLine();
}
if (trait instanceof TraitMethodGetterSetter) {
@@ -938,70 +939,70 @@ public class AVM2Code implements Cloneable {
writer.appendNoHilight("trait ");
switch (tm.kindType) {
case Trait.TRAIT_METHOD:
writer.hilightSpecial("method ", "traittype");
writer.hilightSpecial("method ", HighlightSpecialType.TRAIT_TYPE);
break;
case Trait.TRAIT_GETTER:
writer.hilightSpecial("getter ", "traittype");
writer.hilightSpecial("getter ", HighlightSpecialType.TRAIT_TYPE);
break;
case Trait.TRAIT_SETTER:
writer.hilightSpecial("setter ", "traittype");
writer.hilightSpecial("setter ", HighlightSpecialType.TRAIT_TYPE);
break;
}
writer.hilightSpecial(constants.multinameToString(tm.name_index), "traitname");
writer.hilightSpecial(constants.multinameToString(tm.name_index), HighlightSpecialType.TRAIT_NAME);
writer.appendNoHilight(" dispid ");
writer.hilightSpecial("" + tm.disp_id, "dispid");
writer.hilightSpecial("" + tm.disp_id, HighlightSpecialType.DISP_ID);
writer.newLine();
}
}
if (info != null) {
writer.appendNoHilight("method").newLine();
writer.appendNoHilight("name ");
writer.hilightSpecial(info.name_index == 0 ? "null" : "\"" + Helper.escapeString(info.getName(constants)) + "\"", "methodname");
writer.hilightSpecial(info.name_index == 0 ? "null" : "\"" + Helper.escapeString(info.getName(constants)) + "\"", HighlightSpecialType.METHOD_NAME);
writer.newLine();
if (info.flagExplicit()) {
writer.appendNoHilight("flag ");
writer.hilightSpecial("EXPLICIT", "flag.EXPLICIT");
writer.hilightSpecial("EXPLICIT", HighlightSpecialType.FLAG_EXPLICIT);
writer.newLine();
}
if (info.flagHas_optional()) {
writer.appendNoHilight("flag ");
writer.hilightSpecial("HAS_OPTIONAL", "flag.HAS_OPTIONAL");
writer.hilightSpecial("HAS_OPTIONAL", HighlightSpecialType.FLAG_HAS_OPTIONAL);
writer.newLine();
writer.appendNoHilight("flag HAS_OPTIONAL").newLine();
}
if (info.flagHas_paramnames()) {
writer.appendNoHilight("flag ");
writer.hilightSpecial("HAS_PARAM_NAMES", "flag.HAS_PARAM_NAMES");
writer.hilightSpecial("HAS_PARAM_NAMES", HighlightSpecialType.FLAG_HAS_PARAM_NAMES);
writer.newLine();
}
if (info.flagIgnore_rest()) {
writer.appendNoHilight("flag ");
writer.hilightSpecial("EXPLICIT", "flag.IGNORE_REST");
writer.hilightSpecial("EXPLICIT", HighlightSpecialType.FLAG_IGNORE_REST);
writer.newLine();
}
if (info.flagNeed_activation()) {
writer.appendNoHilight("flag ");
writer.hilightSpecial("NEED_ACTIVATION", "flag.NEED_ACTIVATION");
writer.hilightSpecial("NEED_ACTIVATION", HighlightSpecialType.FLAG_NEED_ACTIVATION);
writer.newLine();
}
if (info.flagNeed_arguments()) {
writer.appendNoHilight("flag ");
writer.hilightSpecial("NEED_ARGUMENTS", "flag.NEED_ARGUMENTS");
writer.hilightSpecial("NEED_ARGUMENTS", HighlightSpecialType.FLAG_NEED_ARGUMENTS);
writer.newLine();
}
if (info.flagNeed_rest()) {
writer.appendNoHilight("flag ");
writer.hilightSpecial("NEED_REST", "flag.NEED_REST");
writer.hilightSpecial("NEED_REST", HighlightSpecialType.FLAG_NEED_REST);
writer.newLine();
}
if (info.flagSetsdxns()) {
writer.appendNoHilight("flag ");
writer.hilightSpecial("SET_DXNS", "flag.SET_DXNS");
writer.hilightSpecial("SET_DXNS", HighlightSpecialType.FLAG_SET_DXNS);
writer.newLine();
}
for (int p = 0; p < info.param_types.length; p++) {
writer.appendNoHilight("param ");
writer.hilightSpecial(constants.multinameToString(info.param_types[p]), "param", p);
writer.hilightSpecial(constants.multinameToString(info.param_types[p]), HighlightSpecialType.PARAM, p);
writer.newLine();
}
if (info.flagHas_paramnames()) {
@@ -1021,12 +1022,12 @@ public class AVM2Code implements Cloneable {
for (int i = 0; i < info.optional.length; i++) {
ValueKind vk = info.optional[i];
writer.appendNoHilight("optional ");
writer.hilightSpecial(vk.toString(constants), "optional", i);
writer.hilightSpecial(vk.toString(constants), HighlightSpecialType.OPTIONAL, i);
writer.newLine();
}
}
writer.appendNoHilight("returns ");
writer.hilightSpecial(constants.multinameToString(info.ret_type), "returns");
writer.hilightSpecial(constants.multinameToString(info.ret_type), HighlightSpecialType.RETURNS);
writer.newLine();
}
writer.newLine();
@@ -1068,10 +1069,10 @@ public class AVM2Code implements Cloneable {
offsets.add((long) body.exceptions[e].target);
writer.appendNoHilight(" type ");
writer.hilightSpecial(body.exceptions[e].type_index == 0 ? "null" : constants.getMultiname(body.exceptions[e].type_index).toString(constants, new ArrayList<String>()), "try.type", e);
writer.hilightSpecial(body.exceptions[e].type_index == 0 ? "null" : constants.getMultiname(body.exceptions[e].type_index).toString(constants, new ArrayList<String>()), HighlightSpecialType.TRY_TYPE, e);
writer.appendNoHilight(" name ");
writer.hilightSpecial(body.exceptions[e].name_index == 0 ? "null" : constants.getMultiname(body.exceptions[e].name_index).toString(constants, new ArrayList<String>()), "try.name", e);
writer.hilightSpecial(body.exceptions[e].name_index == 0 ? "null" : constants.getMultiname(body.exceptions[e].name_index).toString(constants, new ArrayList<String>()), HighlightSpecialType.TRY_NAME, e);
writer.newLine();
}
@@ -2448,7 +2449,7 @@ public class AVM2Code implements Cloneable {
invalidateCache();
try {
List<Integer> outputMap = new ArrayList<>();
HilightedTextWriter writer = new HilightedTextWriter(Configuration.getCodeFormatting(), false);
HighlightedTextWriter writer = new HighlightedTextWriter(Configuration.getCodeFormatting(), false);
toASMSource(constants, trait, info, body, outputMap, ScriptExportMode.PCODE, writer);
String src = writer.toString();
@@ -2490,7 +2491,7 @@ public class AVM2Code implements Cloneable {
public void removeIgnored(AVM2ConstantPool constants, Trait trait, MethodInfo info, MethodBody body) throws InterruptedException {
try {
List<Integer> outputMap = new ArrayList<>();
HilightedTextWriter writer = new HilightedTextWriter(Configuration.getCodeFormatting(), false);
HighlightedTextWriter writer = new HighlightedTextWriter(Configuration.getCodeFormatting(), false);
toASMSource(constants, trait, info, body, outputMap, ScriptExportMode.PCODE, writer);
String src = writer.toString();
AVM2Code acode = ASM3Parser.parse(new StringReader(src), constants, trait, body, info);
@@ -25,7 +25,7 @@ import com.jpexs.decompiler.flash.abc.avm2.model.UnparsedAVM2Item;
import com.jpexs.decompiler.flash.abc.types.MethodBody;
import com.jpexs.decompiler.flash.abc.types.MethodInfo;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.helpers.HilightedTextWriter;
import com.jpexs.decompiler.flash.helpers.HighlightedTextWriter;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.ScopeStack;
import com.jpexs.decompiler.graph.TranslateStack;
@@ -42,7 +42,7 @@ public class NewClassIns extends InstructionDefinition {
@Override
public void translate(boolean isStatic, int scriptIndex, int classIndex, HashMap<Integer, GraphTargetItem> localRegs, TranslateStack stack, ScopeStack scopeStack, AVM2ConstantPool constants, AVM2Instruction ins, List<MethodInfo> method_info, List<GraphTargetItem> output, MethodBody body, ABC abc, HashMap<Integer, String> localRegNames, List<String> fullyQualifiedNames, String path, HashMap<Integer, Integer> localRegsAssignmentIps, int ip, HashMap<Integer, List<Integer>> refs, AVM2Code code) throws InterruptedException {
int clsIndex = ins.operands[0];
HilightedTextWriter writer = new HilightedTextWriter(Configuration.getCodeFormatting(), false);
HighlightedTextWriter writer = new HighlightedTextWriter(Configuration.getCodeFormatting(), false);
stack.pop().toString(writer, LocalData.create(constants, localRegNames, fullyQualifiedNames));
String baseType = writer.toString();
stack.push(new UnparsedAVM2Item(ins, "new " + abc.constants.getMultiname(abc.instance_info.get(clsIndex).name_index).getName(constants, fullyQualifiedNames, false) + ".class extends " + baseType));
@@ -27,7 +27,7 @@ import com.jpexs.decompiler.flash.abc.avm2.model.SetSuperAVM2Item;
import com.jpexs.decompiler.flash.abc.types.MethodBody;
import com.jpexs.decompiler.flash.abc.types.MethodInfo;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.helpers.HilightedTextWriter;
import com.jpexs.decompiler.flash.helpers.HighlightedTextWriter;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.ScopeStack;
import com.jpexs.decompiler.graph.TranslateStack;
@@ -56,7 +56,7 @@ public class SetSuperIns extends InstructionDefinition implements SetTypeIns {
public String getObject(Stack<AVM2Item> stack, ABC abc, AVM2Instruction ins, List<AVM2Item> output, MethodBody body, HashMap<Integer, String> localRegNames, List<String> fullyQualifiedNames) throws InterruptedException {
int multinameIndex = ins.operands[0];
String multiname = resolveMultinameNoPop(1, stack, abc.constants, multinameIndex, ins, fullyQualifiedNames);
HilightedTextWriter writer = new HilightedTextWriter(Configuration.getCodeFormatting(), false);
HighlightedTextWriter writer = new HighlightedTextWriter(Configuration.getCodeFormatting(), false);
stack.get(1 + resolvedCount(abc.constants, multinameIndex)).toString(writer, LocalData.create(abc.constants, localRegNames, fullyQualifiedNames));
String obj = writer.toString();
return obj + ".super." + multiname;
@@ -36,7 +36,7 @@ public class GetLexAVM2Item extends AVM2Item {
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) {
String localName = propertyName.getName(localData.constantsAvm2, localData.fullyQualifiedNames, false);
srcData.put("localName", localName);
srcData.localName = localName;
return writer.append(propertyName.getName(localData.constantsAvm2, localData.fullyQualifiedNames, false));
}
@@ -39,7 +39,7 @@ public class GetSlotAVM2Item extends AVM2Item {
if (slotName == null) {
return writer.append("/*UnknownSlot*/");
}
srcData.put("localName", getNameAsStr(localData));
srcData.localName = getNameAsStr(localData);
return writer.append(slotName.getName(localData.constantsAvm2, localData.fullyQualifiedNames, false));
}
@@ -64,7 +64,7 @@ public class LocalRegAVM2Item extends AVM2Item {
return computedValue.toString(writer, localData);
}
String localName = localRegName(localData.localRegNames, regIndex);
srcData.put("localName", localName);
srcData.localName = localName;
return writer.append(localName);
}
@@ -48,7 +48,7 @@ public class SetLocalAVM2Item extends AVM2Item implements SetTypeAVM2Item, Assig
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
String localName = localRegName(localData.localRegNames, regIndex);
srcData.put("localName", localName);
srcData.localName = localName;
writer.append(localName + " = ");
return value.toString(writer, localData);
}
@@ -45,7 +45,7 @@ public class SetSlotAVM2Item extends AVM2Item implements SetTypeAVM2Item, Assign
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
srcData.put("localName", slotName.getName(localData.constantsAvm2, localData.fullyQualifiedNames, false));
srcData.localName = slotName.getName(localData.constantsAvm2, localData.fullyQualifiedNames, false);
getName(writer, localData);
writer.append(" = ");
return value.toString(writer, localData);
@@ -36,7 +36,7 @@ public class ThisAVM2Item extends AVM2Item {
public ThisAVM2Item(GraphSourceItem instruction, Multiname className) {
super(instruction, PRECEDENCE_PRIMARY);
this.className = className;
srcData.put("localName", "this");
srcData.localName = "this";
}
@Override
@@ -53,9 +53,9 @@ public class DeclarationAVM2Item extends AVM2Item {
if (assignment instanceof LocalRegAVM2Item) { //for..in
LocalRegAVM2Item lti = (LocalRegAVM2Item) assignment;
String localName = localRegName(localData.localRegNames, lti.regIndex);
srcData.put("localName", localName);
srcData.put("declaration", "true");
srcData.put("declaredType", "*");
srcData.localName = localName;
srcData.declaration = true;
srcData.declaredType = "*";
writer.append("var ");
writer.append(localName);
return writer;
@@ -63,9 +63,9 @@ public class DeclarationAVM2Item extends AVM2Item {
if (assignment instanceof GetSlotAVM2Item) { //for..in
GetSlotAVM2Item sti = (GetSlotAVM2Item) assignment;
srcData.put("localName", sti.getNameAsStr(localData));
srcData.put("declaration", "true");
srcData.put("declaredType", "*");
srcData.localName = sti.getNameAsStr(localData);
srcData.declaration = true;
srcData.declaredType = "*";
writer.append("var ");
sti.getName(writer, localData);
return writer;
@@ -74,8 +74,8 @@ public class DeclarationAVM2Item extends AVM2Item {
if (assignment instanceof SetLocalAVM2Item) {
SetLocalAVM2Item lti = (SetLocalAVM2Item) assignment;
String localName = localRegName(localData.localRegNames, lti.regIndex);
srcData.put("localName", localName);
srcData.put("declaration", "true");
srcData.localName = localName;
srcData.declaration = true;
GraphTargetItem coerType = TypeItem.UNBOUNDED;
if (lti.value instanceof CoerceAVM2Item) {
@@ -84,7 +84,7 @@ public class DeclarationAVM2Item extends AVM2Item {
if (lti.value instanceof ConvertAVM2Item) {
coerType = ((ConvertAVM2Item) lti.value).type;
}
srcData.put("declaredType", (coerType instanceof TypeItem) ? ((TypeItem) coerType).fullTypeName : "*");
srcData.declaredType = (coerType instanceof TypeItem) ? ((TypeItem) coerType).fullTypeName : "*";
writer.append("var ");
writer.append(localName);
writer.append(":");
@@ -94,9 +94,9 @@ public class DeclarationAVM2Item extends AVM2Item {
}
if (assignment instanceof SetSlotAVM2Item) {
SetSlotAVM2Item ssti = (SetSlotAVM2Item) assignment;
srcData.put("localName", ssti.getNameAsStr(localData));
srcData.put("declaration", "true");
srcData.put("declaredType", (type instanceof TypeItem) ? ((TypeItem) type).fullTypeName : "*");
srcData.localName = ssti.getNameAsStr(localData);
srcData.declaration = true;
srcData.declaredType = (type instanceof TypeItem) ? ((TypeItem) type).fullTypeName : "*";
writer.append("var ");
ssti.getName(writer, localData);
writer.append(":");
@@ -23,6 +23,8 @@ import com.jpexs.decompiler.flash.abc.avm2.parser.script.AssignableAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.parser.script.NameAVM2Item;
import com.jpexs.decompiler.flash.abc.types.ABCException;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.flash.helpers.hilight.HighlightData;
import com.jpexs.decompiler.flash.helpers.hilight.HighlightSpecialType;
import com.jpexs.decompiler.graph.Block;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
@@ -32,9 +34,7 @@ import com.jpexs.decompiler.graph.TypeItem;
import com.jpexs.decompiler.graph.model.ContinueItem;
import com.jpexs.decompiler.graph.model.LocalData;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class TryAVM2Item extends AVM2Item implements Block {
@@ -79,16 +79,16 @@ public class TryAVM2Item extends AVM2Item implements Block {
writer.newLine();
writer.append("catch(");
String localName = catchExceptions.get(e).getVarName(localData.constantsAvm2, localData.fullyQualifiedNames);
Map<String, String> data = new HashMap<>();
data.put("localName", localName);
data.put("declaration", "true");
HighlightData data = new HighlightData();
data.localName = localName;
data.declaration = true;
int eti = catchExceptions.get(e).type_index;
data.put("declaredType", eti <= 0 ? "*" : localData.constantsAvm2.constant_multiname.get(eti).getNameWithNamespace(localData.constantsAvm2, true));
writer.hilightSpecial(localName, "try.name", e, data);
data.declaredType = eti <= 0 ? "*" : localData.constantsAvm2.constant_multiname.get(eti).getNameWithNamespace(localData.constantsAvm2, true);
writer.hilightSpecial(localName, HighlightSpecialType.TRY_NAME, e, data);
writer.append(":");
writer.hilightSpecial(catchExceptions.get(e).getTypeName(localData.constantsAvm2, localData.fullyQualifiedNames), "try.type", e);
writer.hilightSpecial(catchExceptions.get(e).getTypeName(localData.constantsAvm2, localData.fullyQualifiedNames), HighlightSpecialType.TRY_TYPE, e);
writer.append(")");
writer.startBlock();
List<GraphTargetItem> commands = catchCommands.get(e);
@@ -20,6 +20,7 @@ import com.jpexs.decompiler.flash.abc.ABC;
import com.jpexs.decompiler.flash.abc.avm2.AVM2ConstantPool;
import com.jpexs.decompiler.flash.abc.types.traits.Traits;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.flash.helpers.hilight.HighlightSpecialType;
import com.jpexs.helpers.Helper;
import java.util.ArrayList;
import java.util.List;
@@ -76,12 +77,12 @@ public class InstanceInfo {
}
writer.appendNoHilight(modifiers + objType);
writer.hilightSpecial(abc.constants.getMultiname(name_index).getName(abc.constants, new ArrayList<String>()/* No full names here*/, false), "classname");
writer.hilightSpecial(abc.constants.getMultiname(name_index).getName(abc.constants, new ArrayList<String>()/* No full names here*/, false), HighlightSpecialType.CLASS_NAME);
if (super_index > 0) {
String typeName = abc.constants.getMultiname(super_index).getNameWithNamespace(abc.constants, true);
writer.appendNoHilight(" extends ");
writer.hilightSpecial(abc.constants.getMultiname(super_index).getName(abc.constants, fullyQualifiedNames, false), "typename", typeName);
writer.hilightSpecial(abc.constants.getMultiname(super_index).getName(abc.constants, fullyQualifiedNames, false), HighlightSpecialType.TYPE_NAME, typeName);
}
if (interfaces.length > 0) {
if (isInterface()) {
@@ -94,7 +95,7 @@ public class InstanceInfo {
writer.append(", ");
}
String typeName = abc.constants.getMultiname(interfaces[i]).getNameWithNamespace(abc.constants, true);
writer.hilightSpecial(abc.constants.getMultiname(interfaces[i]).getName(abc.constants, fullyQualifiedNames, false), "typename", typeName);
writer.hilightSpecial(abc.constants.getMultiname(interfaces[i]).getName(abc.constants, fullyQualifiedNames, false), HighlightSpecialType.TYPE_NAME, typeName);
}
}
@@ -23,6 +23,8 @@ import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction;
import com.jpexs.decompiler.flash.abc.avm2.instructions.construction.NewFunctionIns;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.flash.helpers.hilight.HighlightData;
import com.jpexs.decompiler.flash.helpers.hilight.HighlightSpecialType;
import com.jpexs.helpers.Helper;
import java.util.HashMap;
import java.util.List;
@@ -272,7 +274,6 @@ public class MethodInfo {
if (body != null && Configuration.getLocalNamesFromDebugInfo.get()) {
localRegNames = body.getCode().getLocalRegNamesFromDebug(abc);
}
Map<String, String> pdata;
for (int i = 0; i < param_types.length; i++) {
if (i > 0) {
@@ -283,30 +284,30 @@ public class MethodInfo {
ptype = constants.getMultiname(param_types[i]).getNameWithNamespace(constants, false);
}
pdata = new HashMap<>();
pdata.put("declaration", "true");
pdata.put("declaredType", ptype);
HighlightData pdata = new HighlightData();
pdata.declaration = true;
pdata.declaredType = ptype;
if (!localRegNames.isEmpty()) {
pdata.put("localName", localRegNames.get(i + 1)); //assuming it is a slot
writer.hilightSpecial(IdentifiersDeobfuscation.printIdentifier(true, localRegNames.get(i + 1)), "paramname", i, pdata);
pdata.localName = localRegNames.get(i + 1); //assuming it is a slot
writer.hilightSpecial(IdentifiersDeobfuscation.printIdentifier(true, localRegNames.get(i + 1)), HighlightSpecialType.PARAM_NAME, i, pdata);
} else if ((paramNames.length > i) && (paramNames[i] != 0) && Configuration.paramNamesEnable.get()) {
pdata.put("localName", constants.getString(paramNames[i]));
writer.hilightSpecial(IdentifiersDeobfuscation.printIdentifier(true, constants.getString(paramNames[i])), "paramname", i, pdata);
pdata.localName = constants.getString(paramNames[i]);
writer.hilightSpecial(IdentifiersDeobfuscation.printIdentifier(true, constants.getString(paramNames[i])), HighlightSpecialType.PARAM_NAME, i, pdata);
} else {
pdata.put("localName", "param" + (i + 1));
writer.hilightSpecial("param" + (i + 1), "paramname", i, pdata);
pdata.localName = "param" + (i + 1);
writer.hilightSpecial("param" + (i + 1), HighlightSpecialType.PARAM_NAME, i, pdata);
}
writer.appendNoHilight(":");
if (param_types[i] == 0) {
writer.hilightSpecial("*", "param", i);
writer.hilightSpecial("*", HighlightSpecialType.PARAM, i);
} else {
writer.hilightSpecial(constants.getMultiname(param_types[i]).getName(constants, fullyQualifiedNames, false), "param", i);
writer.hilightSpecial(constants.getMultiname(param_types[i]).getName(constants, fullyQualifiedNames, false), HighlightSpecialType.PARAM, i);
}
if (optional != null) {
if (i >= param_types.length - optional.length) {
int optionalIndex = i - (param_types.length - optional.length);
writer.appendNoHilight(" = ");
writer.hilightSpecial(optional[optionalIndex].toString(constants), "optional", optionalIndex);
writer.hilightSpecial(optional[optionalIndex].toString(constants), HighlightSpecialType.OPTIONAL, optionalIndex);
}
}
}
@@ -322,12 +323,13 @@ public class MethodInfo {
} else {
restName = "rest";
}
pdata = new HashMap<>();
pdata.put("declaration", "true");
pdata.put("declaredType", "*");
pdata.put("localName", restName);
HighlightData pdata = new HighlightData();
pdata.declaration = true;
pdata.declaredType = "*";
pdata.localName = restName;
writer.append(restAdd);
writer.hilightSpecial(restName, "flag.NEED_REST", 0, pdata);
writer.hilightSpecial(restName, HighlightSpecialType.FLAG_NEED_REST, 0, pdata);
}
return writer;
}
@@ -337,7 +339,7 @@ public class MethodInfo {
if (ret_type > 0) {
rname = IdentifiersDeobfuscation.printIdentifier(true, constants.getMultiname(ret_type).getName(constants, fullyQualifiedNames, true), "void");
}
return writer.hilightSpecial(rname, "returns");
return writer.hilightSpecial(rname, HighlightSpecialType.RETURNS);
}
public void setBody(MethodBody body) {
@@ -21,6 +21,7 @@ import com.jpexs.decompiler.flash.abc.types.MethodBody;
import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.flash.helpers.NulWriter;
import com.jpexs.decompiler.flash.helpers.hilight.HighlightSpecialType;
import com.jpexs.decompiler.flash.tags.ABCContainerTag;
import com.jpexs.decompiler.graph.ScopeStack;
import com.jpexs.helpers.Helper;
@@ -58,8 +59,8 @@ public class TraitFunction extends Trait implements TraitWithSlot {
modifier = "";
}
writer.appendNoHilight(modifier);
writer.hilightSpecial("function ", "traittype");
writer.hilightSpecial(abc.constants.getMultiname(name_index).getName(abc.constants, fullyQualifiedNames, false), "traitname");
writer.hilightSpecial("function ", HighlightSpecialType.TRAIT_TYPE);
writer.hilightSpecial(abc.constants.getMultiname(name_index).getName(abc.constants, fullyQualifiedNames, false), HighlightSpecialType.TRAIT_NAME);
writer.appendNoHilight("(");
abc.method_info.get(method_info).getParamStr(writer, abc.constants, body, abc, fullyQualifiedNames);
writer.appendNoHilight(") : ");
@@ -21,6 +21,7 @@ import com.jpexs.decompiler.flash.abc.types.MethodBody;
import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.flash.helpers.NulWriter;
import com.jpexs.decompiler.flash.helpers.hilight.HighlightSpecialType;
import com.jpexs.decompiler.flash.tags.ABCContainerTag;
import com.jpexs.decompiler.graph.ScopeStack;
import com.jpexs.helpers.Helper;
@@ -66,8 +67,8 @@ public class TraitMethodGetterSetter extends Trait {
}
writer.appendNoHilight(modifier);
writer.hilightSpecial("function " + addKind, "traittype");
writer.hilightSpecial(getName(abc).getName(abc.constants, fullyQualifiedNames, false), "traitname");
writer.hilightSpecial("function " + addKind, HighlightSpecialType.TRAIT_TYPE);
writer.hilightSpecial(getName(abc).getName(abc.constants, fullyQualifiedNames, false), HighlightSpecialType.TRAIT_NAME);
writer.appendNoHilight("(");
abc.method_info.get(method_info).getParamStr(writer, abc.constants, body, abc, fullyQualifiedNames);
writer.appendNoHilight(") : ");
@@ -25,6 +25,7 @@ import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.flash.helpers.NulWriter;
import com.jpexs.decompiler.flash.helpers.hilight.HighlightSpecialType;
import com.jpexs.decompiler.flash.tags.ABCContainerTag;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.model.LocalData;
@@ -86,9 +87,9 @@ public class TraitSlotConst extends Trait implements TraitWithSlot {
if (val != null && val.isNamespace()) {
slotconst = "namespace";
}
writer.hilightSpecial(slotconst + " ", "traittype");
writer.hilightSpecial(getName(abc).getName(abc.constants, fullyQualifiedNames, false), "traitname");
writer.hilightSpecial(typeStr, "traittypename");
writer.hilightSpecial(slotconst + " ", HighlightSpecialType.TRAIT_TYPE);
writer.hilightSpecial(getName(abc).getName(abc.constants, fullyQualifiedNames, false), HighlightSpecialType.TRAIT_NAME);
writer.hilightSpecial(typeStr, HighlightSpecialType.TRAIT_TYPE_NAME);
return writer;
}
@@ -117,7 +118,7 @@ public class TraitSlotConst extends Trait implements TraitWithSlot {
if (value_kind != 0) {
ValueKind val = new ValueKind(value_index, value_kind);
writer.hilightSpecial(val.toString(abc.constants), "traitvalue");
writer.hilightSpecial(val.toString(abc.constants), HighlightSpecialType.TRAIT_VALUE);
}
}
@@ -21,7 +21,7 @@ import com.jpexs.decompiler.flash.abc.types.traits.TraitSlotConst;
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.HighlightedTextWriter;
import com.jpexs.decompiler.flash.helpers.NulWriter;
import com.jpexs.decompiler.flash.tags.ABCContainerTag;
import java.util.ArrayList;
@@ -53,7 +53,7 @@ public abstract class ConstVarMultinameUsage extends TraitMultinameUsage {
//ignore
}
HilightedTextWriter writer = new HilightedTextWriter(Configuration.getCodeFormatting(), false);
HighlightedTextWriter writer = new HighlightedTextWriter(Configuration.getCodeFormatting(), false);
writer.appendNoHilight(super.toString() + " ");
if (parentTraitIndex > -1) {
if (isStatic) {
@@ -20,7 +20,7 @@ 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.HighlightedTextWriter;
import com.jpexs.decompiler.flash.helpers.NulWriter;
import com.jpexs.decompiler.flash.tags.ABCContainerTag;
import java.util.ArrayList;
@@ -57,7 +57,7 @@ public abstract class MethodMultinameUsage extends TraitMultinameUsage {
((TraitMethodGetterSetter) traits.traits.get(traitIndex)).convertHeader(null, "", abcTags, abc, isStatic, ScriptExportMode.AS, -1/*FIXME*/, classIndex, nulWriter, new ArrayList<String>(), false);
}
HilightedTextWriter writer = new HilightedTextWriter(Configuration.getCodeFormatting(), false);
HighlightedTextWriter writer = new HighlightedTextWriter(Configuration.getCodeFormatting(), false);
writer.appendNoHilight(super.toString());
writer.appendNoHilight(" ");
if (isInitializer) {
@@ -57,7 +57,7 @@ import com.jpexs.decompiler.flash.ecma.Null;
import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode;
import com.jpexs.decompiler.flash.helpers.CodeFormatting;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.flash.helpers.HilightedTextWriter;
import com.jpexs.decompiler.flash.helpers.HighlightedTextWriter;
import com.jpexs.decompiler.flash.helpers.NulWriter;
import com.jpexs.decompiler.flash.helpers.collections.MyEntry;
import com.jpexs.decompiler.flash.tags.base.ASMSource;
@@ -387,7 +387,7 @@ public class Action implements GraphSourceItem {
*
*/
public static String actionsToString(List<DisassemblyListener> listeners, long address, ActionList list, int version, ScriptExportMode exportMode) {
HilightedTextWriter writer = new HilightedTextWriter(new CodeFormatting(), false);
HighlightedTextWriter writer = new HighlightedTextWriter(new CodeFormatting(), false);
actionsToString(listeners, address, list, version, exportMode, writer);
return writer.toString();
}
@@ -682,7 +682,7 @@ public class Action implements GraphSourceItem {
* @throws java.lang.InterruptedException
*/
public static String actionsToSource(final ASMSource asm, final List<Action> actions, final String path) throws InterruptedException {
HilightedTextWriter writer = new HilightedTextWriter(new CodeFormatting(), false);
HighlightedTextWriter writer = new HighlightedTextWriter(new CodeFormatting(), false);
actionsToSource(asm, actions, path, writer);
return writer.toString();
}
@@ -33,7 +33,7 @@ import com.jpexs.decompiler.flash.ecma.Null;
import com.jpexs.decompiler.flash.ecma.Undefined;
import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.flash.helpers.HilightedTextWriter;
import com.jpexs.decompiler.flash.helpers.HighlightedTextWriter;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.TranslateStack;
@@ -302,7 +302,7 @@ public class ActionPush extends Action {
@Override
public String toString() {
HilightedTextWriter writer = new HilightedTextWriter(Configuration.getCodeFormatting(), false);
HighlightedTextWriter writer = new HighlightedTextWriter(Configuration.getCodeFormatting(), false);
toString(writer);
return writer.toString();
}
@@ -16,12 +16,13 @@
*/
package com.jpexs.decompiler.flash.helpers;
import com.jpexs.decompiler.flash.helpers.hilight.HighlightData;
import com.jpexs.decompiler.flash.helpers.hilight.HighlightSpecialType;
import com.jpexs.helpers.utf8.Utf8OutputStreamWriter;
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;
@@ -43,19 +44,7 @@ public class FileTextWriter extends GraphTextWriter implements AutoCloseable {
}
@Override
public FileTextWriter hilightSpecial(String text, String type) {
writeToFile(text);
return this;
}
@Override
public FileTextWriter hilightSpecial(String text, String type, String index) {
writeToFile(text);
return this;
}
@Override
public GraphTextWriter hilightSpecial(String text, String type, String index, Map<String, String> data) {
public GraphTextWriter hilightSpecial(String text, HighlightSpecialType type, String specialValue, HighlightData data) {
writeToFile(text);
return this;
}
@@ -67,7 +56,7 @@ public class FileTextWriter extends GraphTextWriter implements AutoCloseable {
}
@Override
public GraphTextWriter appendWithData(String str, Map<String, String> data) {
public GraphTextWriter appendWithData(String str, HighlightData data) {
writeToFile(str);
return this;
}
@@ -16,8 +16,8 @@
*/
package com.jpexs.decompiler.flash.helpers;
import com.jpexs.decompiler.flash.helpers.hilight.HighlightData;
import com.jpexs.decompiler.graph.GraphSourceItem;
import java.util.Map;
/**
* Provides methods for highlighting positions of instructions in the text.
@@ -28,6 +28,6 @@ public class GraphSourceItemPosition {
public GraphSourceItem graphSourceItem;
public int position;
public Map<String, String> data;
public HighlightData data;
}
@@ -16,9 +16,9 @@
*/
package com.jpexs.decompiler.flash.helpers;
import com.jpexs.decompiler.flash.helpers.hilight.HighlightData;
import com.jpexs.decompiler.flash.helpers.hilight.HighlightSpecialType;
import com.jpexs.decompiler.graph.GraphSourceItem;
import java.util.HashMap;
import java.util.Map;
/**
* Provides methods for highlighting positions of instructions in the text.
@@ -52,7 +52,7 @@ public abstract class GraphTextWriter {
* @param data
* @return GraphTextWriter
*/
public GraphTextWriter startOffset(GraphSourceItem src, int pos, Map<String, String> data) {
public GraphTextWriter startOffset(GraphSourceItem src, int pos, HighlightData data) {
return this;
}
@@ -102,23 +102,23 @@ public abstract class GraphTextWriter {
return this;
}
public GraphTextWriter hilightSpecial(String text, String type) {
return hilightSpecial(text, type, "0");
public final GraphTextWriter hilightSpecial(String text, HighlightSpecialType type) {
return hilightSpecial(text, type, "");
}
public GraphTextWriter hilightSpecial(String text, String type, int index) {
return hilightSpecial(text, type, "" + index);
public final GraphTextWriter hilightSpecial(String text, HighlightSpecialType type, int specialValue) {
return hilightSpecial(text, type, Integer.toString(specialValue), new HighlightData());
}
public GraphTextWriter hilightSpecial(String text, String type, String index) {
return hilightSpecial(text, type, "0", new HashMap<String, String>());
public final GraphTextWriter hilightSpecial(String text, HighlightSpecialType type, int specialValue, HighlightData data) {
return hilightSpecial(text, type, Integer.toString(specialValue), data);
}
public GraphTextWriter hilightSpecial(String text, String type, int index, Map<String, String> data) {
return hilightSpecial(text, type, "" + index, data);
public final GraphTextWriter hilightSpecial(String text, HighlightSpecialType type, String specialValue) {
return hilightSpecial(text, type, specialValue, new HighlightData());
}
public GraphTextWriter hilightSpecial(String text, String type, String index, Map<String, String> data) {
public GraphTextWriter hilightSpecial(String text, HighlightSpecialType type, String specialValue, HighlightData data) {
return this;
}
@@ -126,7 +126,7 @@ public abstract class GraphTextWriter {
return "";
}
public abstract GraphTextWriter appendWithData(String str, Map<String, String> data);
public abstract GraphTextWriter appendWithData(String str, HighlightData data);
public abstract GraphTextWriter append(String str);
@@ -1,27 +0,0 @@
/*
* Copyright (C) 2010-2014 JPEXS, All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. */
package com.jpexs.decompiler.flash.helpers;
/**
* Provides methods for highlighting positions of instructions in the text.
*
* @author JPEXS
*/
public enum HilightType {
TRAIT, CLASS, METHOD, OFFSET, SPECIAL
}
@@ -1,70 +0,0 @@
/*
* Copyright (C) 2010-2014 JPEXS, All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. */
package com.jpexs.decompiler.flash.helpers;
import com.jpexs.decompiler.flash.helpers.hilight.Highlighting;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
/**
* Provides methods for highlighting positions of instructions in the text.
*
* @author JPEXS
*/
public class HilightedText implements Serializable {
public String text;
public List<Highlighting> traitHilights;
public List<Highlighting> classHilights;
public List<Highlighting> methodHilights;
public List<Highlighting> instructionHilights;
public List<Highlighting> specialHilights;
public List<Highlighting> getTraitHighlights() {
return traitHilights;
}
public List<Highlighting> getMethodHighlights() {
return methodHilights;
}
public List<Highlighting> getClassHighlights() {
return classHilights;
}
public List<Highlighting> getSpecialHighligths() {
return specialHilights;
}
public HilightedText(HilightedTextWriter writer) {
this.text = writer.toString();
this.traitHilights = writer.traitHilights;
this.classHilights = writer.classHilights;
this.methodHilights = writer.methodHilights;
this.instructionHilights = writer.instructionHilights;
this.specialHilights = writer.specialHilights;
}
public HilightedText(String text) {
this.text = text;
this.traitHilights = new ArrayList<>();
this.classHilights = new ArrayList<>();
this.methodHilights = new ArrayList<>();
this.instructionHilights = new ArrayList<>();
this.specialHilights = new ArrayList<>();
}
}
@@ -1,319 +0,0 @@
/*
* Copyright (C) 2010-2014 JPEXS, All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
package com.jpexs.decompiler.flash.helpers;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.helpers.hilight.Highlighting;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.helpers.Helper;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Stack;
/**
* Provides methods for highlighting positions of instructions in the text.
*
* @author JPEXS
*/
public class HilightedTextWriter extends GraphTextWriter {
private final StringBuilder sb = new StringBuilder();
private final boolean hilight;
private boolean newLine = true;
private int indent = 0;
private final Stack<GraphSourceItemPosition> offsets = new Stack<>();
private boolean toStringCalled = false;
private int newLineCount = 0;
private final Stack<Highlighting> hilightStack = new Stack<>();
public List<Highlighting> traitHilights = new ArrayList<>();
public List<Highlighting> classHilights = new ArrayList<>();
public List<Highlighting> methodHilights = new ArrayList<>();
public List<Highlighting> instructionHilights = new ArrayList<>();
public List<Highlighting> specialHilights = new ArrayList<>();
public HilightedTextWriter(CodeFormatting formatting, boolean hilight) {
super(formatting);
this.hilight = hilight;
}
public HilightedTextWriter(CodeFormatting formatting, boolean hilight, int indent) {
super(formatting);
this.hilight = hilight;
this.indent = indent;
}
@Override
public boolean getIsHighlighted() {
return hilight;
}
/**
* Highlights specified text as instruction by adding special tags
*
* @param src
* @param pos Offset of instruction
* @param data
* @return HilightedTextWriter
*/
@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;
}
@Override
public HilightedTextWriter endOffset() {
offsets.pop();
return this;
}
/**
* Highlights specified text as method by adding special tags
*
* @param index MethodInfo index
* @return HilightedTextWriter
*/
@Override
public HilightedTextWriter startMethod(long index) {
Map<String, String> data = new HashMap<>();
data.put("index", Long.toString(index));
return start(data, HilightType.METHOD);
}
@Override
public HilightedTextWriter endMethod() {
return end(HilightType.METHOD);
}
/**
* Highlights specified text as class by adding special tags
*
* @param index Class index
* @return HilightedTextWriter
*/
@Override
public HilightedTextWriter startClass(long index) {
Map<String, String> data = new HashMap<>();
data.put("index", Long.toString(index));
return start(data, HilightType.CLASS);
}
@Override
public HilightedTextWriter endClass() {
return end(HilightType.CLASS);
}
/**
* Highlights specified text as trait by adding special tags
*
* @param index Trait index
* @return HilightedTextWriter
*/
@Override
public HilightedTextWriter startTrait(long index) {
Map<String, String> data = new HashMap<>();
data.put("index", Long.toString(index));
return start(data, HilightType.TRAIT);
}
@Override
public HilightedTextWriter endTrait() {
return end(HilightType.TRAIT);
}
@Override
public HilightedTextWriter hilightSpecial(String text, String type) {
return hilightSpecial(text, type, "0");
}
@Override
public HilightedTextWriter hilightSpecial(String text, String type, String index) {
return hilightSpecial(text, type, index, new HashMap<String, String>());
}
@Override
public HilightedTextWriter hilightSpecial(String text, String type, String index, Map<String, String> data) {
Map<String, String> ndata = new HashMap<>();
ndata.putAll(data);
ndata.put("subtype", type);
ndata.put("index", 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) {
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);
}
}
appendToSb(str);
if (h != null) {
h.len = sb.length() - newLineCount - h.startPos;
}
return this;
}
@Override
public HilightedTextWriter append(String str, long offset) {
Highlighting h = null;
if (hilight) {
Map<String, String> data = new HashMap<>();
data.put("offset", Long.toString(offset));
h = new Highlighting(sb.length() - newLineCount, data, HilightType.OFFSET, str);
instructionHilights.add(h);
}
appendToSb(str);
if (h != null) {
h.len = sb.length() - newLineCount - h.startPos;
}
return this;
}
@Override
public HilightedTextWriter appendNoHilight(int i) {
appendNoHilight(Integer.toString(i));
return this;
}
@Override
public HilightedTextWriter appendNoHilight(String str) {
appendToSb(str);
return this;
}
@Override
public HilightedTextWriter indent() {
indent++;
return this;
}
@Override
public HilightedTextWriter unindent() {
indent--;
return this;
}
@Override
public HilightedTextWriter newLine() {
appendToSb(formatting.newLineChars);
newLine = true;
newLineCount++;
return this;
}
@Override
public int getLength() {
return sb.length();
}
@Override
public int getIndent() {
return indent;
}
@Override
public String toString() {
if (toStringCalled) {
throw new Error("HilightedTextWriter.toString() was already called.");
}
if (Configuration.debugMode.get()) {
long stopTime = System.currentTimeMillis();
long time = stopTime - startTime;
if (time > 500) {
System.out.println("Rendering is too slow: " + Helper.formatTimeSec(time) + " length: " + sb.length());
}
}
toStringCalled = true;
return sb.toString();
}
private HilightedTextWriter start(Map<String, String> data, HilightType type) {
if (hilight) {
Highlighting h = new Highlighting(sb.length() - newLineCount, data, type, null);
hilightStack.add(h);
}
return this;
}
private HilightedTextWriter end(HilightType expectedType) {
if (hilight) {
Highlighting h = hilightStack.pop();
h.len = sb.length() - newLineCount - h.startPos;
if (!expectedType.equals(h.type)) {
throw new Error("Hilighting mismatch.");
}
switch (h.type) {
case CLASS:
classHilights.add(h);
break;
case METHOD:
methodHilights.add(h);
break;
case TRAIT:
traitHilights.add(h);
break;
case SPECIAL:
specialHilights.add(h);
break;
case OFFSET:
instructionHilights.add(h);
break;
}
}
return this;
}
private void appendToSb(String str) {
if (newLine) {
newLine = false;
appendIndent();
}
sb.append(str);
}
private void appendIndent() {
for (int i = 0; i < indent; i++) {
appendNoHilight(formatting.indentString);
}
}
}
@@ -16,7 +16,8 @@
*/
package com.jpexs.decompiler.flash.helpers;
import java.util.Map;
import com.jpexs.decompiler.flash.helpers.hilight.HighlightData;
import com.jpexs.decompiler.flash.helpers.hilight.HighlightSpecialType;
import java.util.Stack;
/**
@@ -93,19 +94,7 @@ public class NulWriter extends GraphTextWriter {
}
@Override
public NulWriter hilightSpecial(String text, String type) {
stringAdded = true;
return this;
}
@Override
public NulWriter hilightSpecial(String text, String type, String index) {
stringAdded = true;
return this;
}
@Override
public NulWriter hilightSpecial(String text, String type, String index, Map<String, String> data) {
public NulWriter hilightSpecial(String text, HighlightSpecialType type, String specialValue, HighlightData data) {
stringAdded = true;
return this;
}
@@ -117,7 +106,7 @@ public class NulWriter extends GraphTextWriter {
}
@Override
public GraphTextWriter appendWithData(String str, Map<String, String> data) {
public GraphTextWriter appendWithData(String str, HighlightData data) {
stringAdded = true;
return this;
}
@@ -17,12 +17,9 @@
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;
/**
* Provides methods for highlighting positions of instructions in the text.
@@ -31,8 +28,8 @@ import java.util.Map;
*/
public class Highlighting implements Serializable {
public HilightType type;
public String hilightedText;
public HighlightType type;
public String HighlightedText;
/**
* Starting position
*/
@@ -41,55 +38,13 @@ public class Highlighting implements Serializable {
* Length of highlighted text
*/
public int len;
private final Map<String, String> properties;
private final HighlightData properties;
public Long getPropertyLong(String key) {
String dataStr = getPropertyString(key);
if (dataStr == null) {
return null;
}
try {
return Long.parseLong(dataStr);
} catch (NumberFormatException nfe) {
return null;
}
public HighlightData getProperties() {
return properties;
}
public Map<String, String> getProperties() {
return new HashMap<>(properties);
}
public String getPropertyString(String key) {
return properties.get(key);
}
public static Highlighting search(List<Highlighting> list, long pos) {
return search(list, pos, null, null, -1, -1);
}
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) {
public static Highlighting search(List<Highlighting> list, HighlightData properties, long from, long to) {
Highlighting ret = null;
looph:
for (Highlighting h : list) {
@@ -103,56 +58,34 @@ public class Highlighting implements Serializable {
continue;
}
}
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;
}
}
}
HighlightData hProp = h.getProperties();
if (properties.declaration && !hProp.declaration) {
continue;
}
if (properties.declaredType != null && !properties.declaredType.equals(hProp.declaredType)) {
continue;
}
if (properties.localName != null && !properties.localName.equals(hProp.localName)) {
continue;
}
if (properties.specialValue != null && !properties.specialValue.equals(hProp.specialValue)) {
continue;
}
if (pos == -1 || (pos >= h.startPos && (pos < h.startPos + h.len))) {
if (ret == null || h.startPos > ret.startPos) { //get the closest one
ret = h;
}
}
if (pos == -1 && ret != null) {
return ret;
}
return h;
}
if (Configuration.debugMode.get()) {
if (ret != null) {
System.out.println("Highlight found: " + ret.hilightedText);
}
}
return ret;
return null;
}
public static List<Highlighting> searchAll(List<Highlighting> list, long pos, String property, String value, long from, long to) {
List<Highlighting> ret = new ArrayList<>();
public static Highlighting searchPos(List<Highlighting> list, long pos) {
return searchPos(list, pos, -1, -1);
}
public static Highlighting searchPos(List<Highlighting> list, long pos, long from, long to) {
Highlighting ret = null;
looph:
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;
@@ -164,13 +97,90 @@ public class Highlighting implements Serializable {
}
}
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 (ret == null || h.startPos > ret.startPos) { //get the closest one
ret = h;
}
}
if (pos == -1 && ret != null) {
return ret;
}
}
return ret;
}
public static Highlighting searchOffset(List<Highlighting> list, long offset) {
return searchOffset(list, offset, -1, -1);
}
public static Highlighting searchOffset(List<Highlighting> list, long offset, long from, long to) {
looph:
for (Highlighting h : list) {
if (from > -1) {
if (h.startPos < from) {
continue;
}
}
if (to > -1) {
if (h.startPos > to) {
continue;
}
}
if (h.getProperties().offset != offset) {
continue;
}
return h;
}
return null;
}
public static Highlighting searchIndex(List<Highlighting> list, long index) {
return searchIndex(list, index, -1, -1);
}
public static Highlighting searchIndex(List<Highlighting> list, long index, long from, long to) {
looph:
for (Highlighting h : list) {
if (from > -1) {
if (h.startPos < from) {
continue;
}
}
if (to > -1) {
if (h.startPos > to) {
continue;
}
}
if (h.getProperties().index != index) {
continue;
}
return h;
}
return null;
}
public static List<Highlighting> searchAllPos(List<Highlighting> list, long pos) {
List<Highlighting> ret = new ArrayList<>();
for (Highlighting h : list) {
if (pos == -1 || (pos >= h.startPos && (pos < h.startPos + h.len))) {
ret.add(h);
}
}
return ret;
}
public static List<Highlighting> searchAllIndexes(List<Highlighting> list, long index) {
List<Highlighting> ret = new ArrayList<>();
for (Highlighting h : list) {
long i = h.getProperties().index;
if (i == index) {
ret.add(h);
}
//if (pos == -1) {
// return ret;
//}
}
return ret;
@@ -193,11 +203,11 @@ public class Highlighting implements Serializable {
* @param type Highlighting type
* @param text
*/
public Highlighting(int startPos, Map<String, String> data, HilightType type, String text) {
public Highlighting(int startPos, HighlightData data, HighlightType type, String text) {
this.startPos = startPos;
this.type = type;
if (Configuration.debugMode.get()) {
this.hilightedText = text;
this.HighlightedText = text;
}
this.properties = data;
}
@@ -30,7 +30,7 @@ import com.jpexs.decompiler.flash.exporters.commonshape.Matrix;
import com.jpexs.decompiler.flash.exporters.modes.MovieExportMode;
import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode;
import com.jpexs.decompiler.flash.exporters.modes.SoundExportMode;
import com.jpexs.decompiler.flash.helpers.HilightedTextWriter;
import com.jpexs.decompiler.flash.helpers.HighlightedTextWriter;
import com.jpexs.decompiler.flash.tags.CSMTextSettingsTag;
import com.jpexs.decompiler.flash.tags.DefineButton2Tag;
import com.jpexs.decompiler.flash.tags.DefineButtonCxformTag;
@@ -1166,7 +1166,7 @@ public class XFLConverter {
}
private static String convertActionScript(ASMSource as) {
HilightedTextWriter writer = new HilightedTextWriter(Configuration.getCodeFormatting(), false);
HighlightedTextWriter writer = new HighlightedTextWriter(Configuration.getCodeFormatting(), false);
try {
Action.actionsToSource(as, as.getActions(), as.toString(), writer);
} catch (InterruptedException ex) {