constant pool editing: escape strings

This commit is contained in:
2015-05-08 14:01:44 +02:00
parent e49296770f
commit c5a890fce7
24 changed files with 181 additions and 57 deletions
@@ -914,7 +914,7 @@ public class AVM2Code implements Cloneable {
if (info != null) {
writer.appendNoHilight("method").newLine();
writer.appendNoHilight("name ");
writer.hilightSpecial(info.name_index == 0 ? "null" : "\"" + Helper.escapeString(info.getName(constants)) + "\"", HighlightSpecialType.METHOD_NAME);
writer.hilightSpecial(info.name_index == 0 ? "null" : "\"" + Helper.escapeActionScriptString(info.getName(constants)) + "\"", HighlightSpecialType.METHOD_NAME);
writer.newLine();
if (info.flagExplicit()) {
writer.appendNoHilight("flag ");
@@ -211,7 +211,7 @@ public class AVM2Instruction implements Cloneable, GraphSourceItem {
s.append(" null");
} else {
s.append(" \"");
s.append(Helper.escapeString(constants.getString(operands[i])));
s.append(Helper.escapeActionScriptString(constants.getString(operands[i])));
s.append("\"");
}
break;
@@ -1,18 +1,19 @@
/*
* Copyright (C) 2010-2015 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.␍ */
* License along with this library.
*/
package com.jpexs.decompiler.flash.abc.avm2.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
@@ -41,7 +42,7 @@ public class StringAVM2Item extends AVM2Item {
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) {
return writer.append("\"" + Helper.escapeString(value) + "\"");
return writer.append("\"" + Helper.escapeActionScriptString(value) + "\"");
}
@Override
@@ -191,7 +191,7 @@ public class Multiname {
break;
}
}
return constants.getNamespace(index).getKindStr() + "(" + (name == null ? "null" : "\"" + Helper.escapeString(name) + "\"") + (sub > 0 ? ",\"" + sub + "\"" : "") + ")";
return constants.getNamespace(index).getKindStr() + "(" + (name == null ? "null" : "\"" + Helper.escapeActionScriptString(name) + "\"") + (sub > 0 ? ",\"" + sub + "\"" : "") + ")";
}
private static String namespaceSetToString(AVM2ConstantPool constants, int index) {
@@ -222,16 +222,16 @@ public class Multiname {
switch (kind) {
case QNAME:
case QNAMEA:
return getKindStr() + "(" + namespaceToString(constants, namespace_index) + "," + (name_index == 0 ? "null" : "\"" + Helper.escapeString(constants.getString(name_index)) + "\"") + ")";
return getKindStr() + "(" + namespaceToString(constants, namespace_index) + "," + (name_index == 0 ? "null" : "\"" + Helper.escapeActionScriptString(constants.getString(name_index)) + "\"") + ")";
case RTQNAME:
case RTQNAMEA:
return getKindStr() + "(" + (name_index == 0 ? "null" : "\"" + Helper.escapeString(constants.getString(name_index))) + "\"" + ")";
return getKindStr() + "(" + (name_index == 0 ? "null" : "\"" + Helper.escapeActionScriptString(constants.getString(name_index))) + "\"" + ")";
case RTQNAMEL:
case RTQNAMELA:
return getKindStr() + "()";
case MULTINAME:
case MULTINAMEA:
return getKindStr() + "(" + (name_index == 0 ? "null" : "\"" + Helper.escapeString(constants.getString(name_index)) + "\"") + "," + namespaceSetToString(constants, namespace_set_index) + ")";
return getKindStr() + "(" + (name_index == 0 ? "null" : "\"" + Helper.escapeActionScriptString(constants.getString(name_index)) + "\"") + "," + namespaceSetToString(constants, namespace_set_index) + ")";
case MULTINAMEL:
case MULTINAMELA:
return getKindStr() + "(" + namespaceSetToString(constants, namespace_set_index) + ")";
@@ -137,7 +137,7 @@ public class ValueKind {
ret = "" + constants.getDecimal(value_index);
break;
case CONSTANT_Utf8:
ret = "\"" + Helper.escapeString(constants.getString(value_index)) + "\"";
ret = "\"" + Helper.escapeActionScriptString(constants.getString(value_index)) + "\"";
break;
case CONSTANT_True:
ret = "true";
@@ -179,7 +179,7 @@ public class ValueKind {
ret = "Decimal(" + constants.getDecimal(value_index) + ")";
break;
case CONSTANT_Utf8:
ret = "Utf8(\"" + Helper.escapeString(constants.getString(value_index)) + "\")";
ret = "Utf8(\"" + Helper.escapeActionScriptString(constants.getString(value_index)) + "\")";
break;
case CONSTANT_True:
ret = "True";
@@ -603,7 +603,7 @@ public abstract class Action implements GraphSourceItem {
for (String c : cPool.constantPool) {
writer.appendNoHilight(constIdx);
writer.appendNoHilight("|");
writer.appendNoHilight(c);
writer.appendNoHilight(Helper.escapeString(c));
writer.newLine();
constIdx++;
}
@@ -166,10 +166,10 @@ public class DirectValueActionItem extends ActionItem {
}
}
if (value instanceof String) {
return writer.append("\"" + Helper.escapeString((String) value) + "\"");
return writer.append("\"" + Helper.escapeActionScriptString((String) value) + "\"");
}
if (value instanceof ConstantIndex) {
return writer.append("\"" + Helper.escapeString(this.constants.get(((ConstantIndex) value).index)) + "\"");
return writer.append("\"" + Helper.escapeActionScriptString(this.constants.get(((ConstantIndex) value).index)) + "\"");
}
if (value instanceof RegisterNumber) {
return writer.append(((RegisterNumber) value).translate());
@@ -37,7 +37,7 @@ public class GetURLActionItem extends ActionItem {
writer.append("getUrl");
writer.spaceBeforeCallParenthesies(2);
writer.append("(\"");
writer.append(Helper.escapeString(urlString) + "\", \"" + Helper.escapeString(targetString));
writer.append(Helper.escapeActionScriptString(urlString) + "\", \"" + Helper.escapeActionScriptString(targetString));
return writer.append("\")");
}
@@ -1,18 +1,19 @@
/*
* Copyright (C) 2010-2015 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.␍ */
* License along with this library.
*/
package com.jpexs.decompiler.flash.action.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
@@ -39,7 +40,7 @@ public class GotoLabelActionItem extends ActionItem {
writer.append("gotoAndStop");
writer.spaceBeforeCallParenthesies(1);
writer.append("(\"");
writer.append(Helper.escapeString(label));
writer.append(Helper.escapeActionScriptString(label));
return writer.append("\")");
}
@@ -1,18 +1,19 @@
/*
* Copyright (C) 2010-2015 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.␍ */
* License along with this library.
*/
package com.jpexs.decompiler.flash.action.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
@@ -36,7 +37,7 @@ public class SetTargetActionItem extends ActionItem {
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) {
writer.append("tellTarget(\"");
writer.append(Helper.escapeString(target));
writer.append(Helper.escapeActionScriptString(target));
return writer.append("\")");
}
@@ -78,7 +78,7 @@ public class ActionGetURL extends Action {
@Override
public String toString() {
return "GetUrl \"" + Helper.escapeString(urlString) + "\" \"" + Helper.escapeString(targetString) + "\"";
return "GetUrl \"" + Helper.escapeActionScriptString(urlString) + "\" \"" + Helper.escapeActionScriptString(targetString) + "\"";
}
@Override
@@ -1,18 +1,19 @@
/*
* Copyright (C) 2010-2015 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.␍ */
* License along with this library.
*/
package com.jpexs.decompiler.flash.action.swf3;
import com.jpexs.decompiler.flash.SWFInputStream;
@@ -47,7 +48,7 @@ public class ActionGoToLabel extends Action {
@Override
public String toString() {
return "GoToLabel \"" + Helper.escapeString(label) + "\"";
return "GoToLabel \"" + Helper.escapeActionScriptString(label) + "\"";
}
@Override
@@ -1,18 +1,19 @@
/*
* Copyright (C) 2010-2015 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.␍ */
* License along with this library.
*/
package com.jpexs.decompiler.flash.action.swf3;
import com.jpexs.decompiler.flash.SWFInputStream;
@@ -47,7 +48,7 @@ public class ActionSetTarget extends Action {
@Override
public String toString() {
return "SetTarget \"" + Helper.escapeString(targetName) + "\"";
return "SetTarget \"" + Helper.escapeActionScriptString(targetName) + "\"";
}
@Override
@@ -279,7 +279,7 @@ public class ActionPush extends Action {
((ConstantIndex) values.get(i)).constantPool = constantPool;
ret = ((ConstantIndex) values.get(i)).toString();
} else if (values.get(i) instanceof String) {
ret = "\"" + Helper.escapeString((String) values.get(i)) + "\"";
ret = "\"" + Helper.escapeActionScriptString((String) values.get(i)) + "\"";
} else if (values.get(i) instanceof RegisterNumber) {
ret = ((RegisterNumber) values.get(i)).toStringNoName();
} else {
@@ -55,7 +55,7 @@ public class ConstantIndex implements Serializable {
if (Configuration.resolveConstants.get()) {
if (constantPool != null) {
if (index < constantPool.size()) {
return "\"" + Helper.escapeString(constantPool.get(index)) + "\"";
return "\"" + Helper.escapeActionScriptString(constantPool.get(index)) + "\"";
}
}
}
@@ -1,18 +1,19 @@
/*
* Copyright (C) 2010-2015 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.␍ */
* License along with this library.
*/
package com.jpexs.decompiler.flash.action.swf5;
import com.jpexs.decompiler.flash.SWFInputStream;
@@ -82,7 +83,7 @@ public class ActionConstantPool extends Action {
StringBuilder ret = new StringBuilder();
ret.append("ConstantPool");
for (int i = 0; i < constantPool.size(); i++) {
ret.append(" \"").append(Helper.escapeString(constantPool.get(i))).append("\"");
ret.append(" \"").append(Helper.escapeActionScriptString(constantPool.get(i))).append("\"");
}
return ret.toString();
}
@@ -113,10 +113,10 @@ public class ActionDefineFunction extends Action implements GraphSourceItemConta
public String getASMSource(ActionList container, Set<Long> knownAddreses, ScriptExportMode exportMode) {
StringBuilder paramStr = new StringBuilder();
for (int i = 0; i < paramNames.size(); i++) {
paramStr.append("\"").append(Helper.escapeString(paramNames.get(i))).append("\" ");
paramStr.append("\"").append(Helper.escapeActionScriptString(paramNames.get(i))).append("\" ");
}
return "DefineFunction \"" + Helper.escapeString(functionName) + "\" " + paramNames.size() + " " + paramStr + " {" + (codeSize == 0 ? "\r\n}" : "");// + "\r\n" +Action.actionsToString(getAddress() + getHeaderLength(),getItems(container) , knownAddreses, constantPool, version, hex, getFileAddress() + hdrSize) + "}";
return "DefineFunction \"" + Helper.escapeActionScriptString(functionName) + "\" " + paramNames.size() + " " + paramStr + " {" + (codeSize == 0 ? "\r\n}" : "");// + "\r\n" +Action.actionsToString(getAddress() + getHeaderLength(),getItems(container) , knownAddreses, constantPool, version, hex, getFileAddress() + hdrSize) + "}";
}
@Override
@@ -202,10 +202,10 @@ public class ActionDefineFunction2 extends Action implements GraphSourceItemCont
public String getASMSource(ActionList container, Set<Long> knownAddreses, ScriptExportMode exportMode) {
StringBuilder paramStr = new StringBuilder();
for (int i = 0; i < paramNames.size(); i++) {
paramStr.append(paramRegisters.get(i)).append(" \"").append(Helper.escapeString(paramNames.get(i))).append("\" ");
paramStr.append(paramRegisters.get(i)).append(" \"").append(Helper.escapeActionScriptString(paramNames.get(i))).append("\" ");
}
return ("DefineFunction2 \"" + Helper.escapeString(functionName) + "\" " + paramRegisters.size() + " " + registerCount
return ("DefineFunction2 \"" + Helper.escapeActionScriptString(functionName) + "\" " + paramRegisters.size() + " " + registerCount
+ " " + preloadParentFlag
+ " " + preloadRootFlag
+ " " + suppressSuperFlag
@@ -168,7 +168,7 @@ public class ActionTry extends Action implements GraphSourceItemContainer {
if (catchInRegisterFlag) {
ret.append("register").append(catchRegister);
} else {
ret.append("\"").append(Helper.escapeString(catchName)).append("\"");
ret.append("\"").append(Helper.escapeActionScriptString(catchName)).append("\"");
}
ret.append(" ");
}
@@ -189,7 +189,7 @@ public class DefineText2Tag extends TextTag {
if (fnt == null) {
writer.append(AppResources.translate("fontNotFound").replace("%fontId%", Integer.toString(rec.fontId)));
} else {
writer.hilightSpecial(Helper.escapeString(rec.getText(fnt)).replace("[", "\\[").replace("]", "\\]"), HighlightSpecialType.TEXT);
writer.hilightSpecial(Helper.escapeActionScriptString(rec.getText(fnt)).replace("[", "\\[").replace("]", "\\]"), HighlightSpecialType.TEXT);
}
}
return new HighlightedText(writer);
@@ -189,7 +189,7 @@ public class DefineTextTag extends TextTag {
if (fnt == null) {
writer.append(AppResources.translate("fontNotFound").replace("%fontId%", Integer.toString(rec.fontId)));
} else {
writer.hilightSpecial(Helper.escapeString(rec.getText(fnt)).replace("[", "\\[").replace("]", "\\]"), HighlightSpecialType.TEXT);
writer.hilightSpecial(Helper.escapeActionScriptString(rec.getText(fnt)).replace("[", "\\[").replace("]", "\\]"), HighlightSpecialType.TEXT);
}
}
return new HighlightedText(writer);