Fixed: #2192 Long script lines are now wrapped (1000 chars limit by default) to avoid problems on Linux

This commit is contained in:
Jindra Petřík
2024-10-29 16:55:43 +01:00
parent a36e16fc73
commit db5aa019a6
19 changed files with 75 additions and 24 deletions
@@ -174,16 +174,16 @@ public abstract class AVM2Item extends GraphTargetItem {
if (((FullMultinameAVM2Item) propertyName).name != null) {
if (((FullMultinameAVM2Item) propertyName).namespace != null) {
//writer.append(".");
writer.hilightSpecial(".", HighlightSpecialType.PROPERTY_TYPE, 0, data);
writer.allowWrapHere().hilightSpecial(".", HighlightSpecialType.PROPERTY_TYPE, 0, data);
}
return propertyName.toString(writer, localData);
} else {
writer.hilightSpecial(".", HighlightSpecialType.PROPERTY_TYPE, 0, data);
writer.allowWrapHere().hilightSpecial(".", HighlightSpecialType.PROPERTY_TYPE, 0, data);
//writer.append(".");
return propertyName.toString(writer, localData);
}
} else {
writer.append("[");
writer.append("[").allowWrapHere();
propertyName.toString(writer, localData);
return writer.append("]");
}
@@ -236,7 +236,7 @@ public class CallAVM2Item extends AVM2Item {
writer.append("(");
for (int a = 0; a < arguments.size(); a++) {
if (a > 0) {
writer.append(",");
writer.allowWrapHere().append(",");
}
arguments.get(a).toString(writer, localData);
}
@@ -77,13 +77,13 @@ public class CallMethodAVM2Item extends AVM2Item {
} else {
receiver.toString(writer, localData);
}
writer.append(".");
writer.allowWrapHere().append(".");
writer.append(methodName);
writer.spaceBeforeCallParenthesies(arguments.size());
writer.append("(");
for (int a = 0; a < arguments.size(); a++) {
if (a > 0) {
writer.append(",");
writer.allowWrapHere().append(",");
}
arguments.get(a).toString(writer, localData);
}
@@ -101,8 +101,8 @@ public class CallPropertyAVM2Item extends AVM2Item {
writer.spaceBeforeCallParenthesies(arguments.size());
writer.append("(");
for (int a = 0; a < arguments.size(); a++) {
if (a > 0) {
writer.append(",");
if (a > 0) {
writer.allowWrapHere().append(",");
}
arguments.get(a).toString(writer, localData);
}
@@ -89,7 +89,7 @@ public class ConstructAVM2Item extends AVM2Item {
writer.append("(");
for (int a = 0; a < args.size(); a++) {
if (a > 0) {
writer.append(",");
writer.allowWrapHere().append(",");
}
args.get(a).toString(writer, localData);
}
@@ -91,7 +91,7 @@ public class ConstructPropAVM2Item extends AVM2Item {
writer.append("(");
for (int a = 0; a < args.size(); a++) {
if (a > 0) {
writer.append(",");
writer.allowWrapHere().append(",");
}
args.get(a).toString(writer, localData);
}
@@ -71,13 +71,13 @@ public class ConstructSuperAVM2Item extends AVM2Item {
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
if (!object.toString().equals("this")) {
object.toString(writer, localData);
writer.append(".");
writer.allowWrapHere().append(".");
}
writer.spaceBeforeCallParenthesies(args.size());
writer.append("super(");
for (int a = 0; a < args.size(); a++) {
if (a > 0) {
writer.append(",");
writer.allowWrapHere().append(",");
}
args.get(a).toString(writer, localData);
}
@@ -67,7 +67,7 @@ public class NewArrayAVM2Item extends AVM2Item {
writer.append("[");
for (int a = 0; a < values.size(); a++) {
if (a > 0) {
writer.append(",");
writer.allowWrapHere().append(",");
}
values.get(a).toString(writer, localData);
}
@@ -103,7 +103,7 @@ public class CallFunctionActionItem extends ActionItem {
writer.append("(");
for (int t = 0; t < arguments.size(); t++) {
if (t > 0) {
writer.append(",");
writer.allowWrapHere().append(",");
}
arguments.get(t).toStringNL(writer, localData);
}
@@ -120,7 +120,7 @@ public class CallMethodActionItem extends ActionItem {
} else {
scriptObject.toString(writer, localData);
}
writer.append(".");
writer.allowWrapHere().append(".");
writer.append(setterGetterVarName);
return writer;
} else if (special == SPECIAL_SETTER) {
@@ -131,7 +131,7 @@ public class CallMethodActionItem extends ActionItem {
} else {
scriptObject.toString(writer, localData);
}
writer.append(".");
writer.allowWrapHere().append(".");
writer.append(setterGetterVarName);
writer.append(" = ");
arguments.get(0).toStringNL(writer, localData);
@@ -160,7 +160,7 @@ public class CallMethodActionItem extends ActionItem {
}
if (!(((DirectValueActionItem) methodName).value instanceof RegisterNumber)
&& IdentifiersDeobfuscation.isValidName(false, methodName.toStringNoQuotes(localData))) {
writer.append(".");
writer.allowWrapHere().append(".");
methodName.toStringNoQuotes(writer, localData);
} else {
writer.append("[");
@@ -189,7 +189,7 @@ public class CallMethodActionItem extends ActionItem {
writer.append("(");
for (int t = 0; t < arguments.size(); t++) {
if (t > 0) {
writer.append(",");
writer.allowWrapHere().append(",");
}
arguments.get(t).toStringNL(writer, localData);
}
@@ -78,7 +78,7 @@ public class GetMemberActionItem extends ActionItem {
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
object.toString(writer, localData);
if ((memberName instanceof DirectValueActionItem) && printObfuscatedMemberName) {
writer.append(".");
writer.allowWrapHere().append(".");
StringBuilder sb = new StringBuilder();
StringBuilderTextWriter sbw = new StringBuilderTextWriter(new CodeFormatting(), sb);
stripQuotes(memberName, localData, sbw);
@@ -90,7 +90,7 @@ public class GetMemberActionItem extends ActionItem {
memberName.toString(writer, localData);
return writer.append("]");
}
writer.append(".");
writer.allowWrapHere().append(".");
return stripQuotes(memberName, localData, writer);
}
@@ -129,7 +129,7 @@ public class SetMemberActionItem extends ActionItem implements SetTypeActionItem
objectName.toString(writer, localData);
writer.append("]");
} else {
writer.append(".");
writer.allowWrapHere().append(".");
stripQuotes(objectName, localData, writer);
}
if (compoundOperator != null) {
@@ -1041,6 +1041,10 @@ public final class Configuration {
public static ConfigurationItem<String> lastSessionEasySwf = null;
@ConfigurationDefaultInt(1000)
@ConfigurationCategory("limit")
public static ConfigurationItem<Integer> maxScriptLineLength = null;
private enum OSId {
WINDOWS, OSX, UNIX
}
@@ -16,6 +16,7 @@
*/
package com.jpexs.decompiler.flash.helpers;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.helpers.hilight.HighlightData;
import com.jpexs.decompiler.flash.helpers.hilight.HighlightSpecialType;
import com.jpexs.decompiler.graph.GraphSourceItem;
@@ -41,7 +42,12 @@ public abstract class GraphTextWriter {
* Code formatting
*/
protected CodeFormatting formatting;
/**
* Line length
*/
protected int lineLength = 0;
/**
* Trait index - instance initializer
*/
@@ -315,6 +321,14 @@ public abstract class GraphTextWriter {
*/
public abstract GraphTextWriter append(String str, long offset, long fileOffset);
/**
* Enlarges line length
* @param len Length to add
*/
protected final void addLineLength(int len) {
lineLength += len;
}
/**
* Appends text without highlight.
* @param i Text
@@ -350,6 +364,7 @@ public abstract class GraphTextWriter {
* @return GraphTextWriter
*/
public GraphTextWriter newLine() {
lineLength = 0;
return this;
}
@@ -431,6 +446,13 @@ public abstract class GraphTextWriter {
return append(" ");
}
public GraphTextWriter allowWrapHere() {
if (Configuration.maxScriptLineLength.get() > 0 && lineLength > Configuration.maxScriptLineLength.get()) {
newLine();
}
return this;
}
/**
* Space before call parenthesies.
* @param argCount Argument count
@@ -224,7 +224,8 @@ public class HighlightedTextWriter extends GraphTextWriter {
}
@Override
public HighlightedTextWriter appendWithData(String str, HighlightData data) {
public HighlightedTextWriter appendWithData(String str, HighlightData data) {
addLineLength(str.length());
Highlighting h = null;
if (!offsets.empty()) {
GraphSourceItemPosition itemPos = offsets.peek();
@@ -258,11 +259,13 @@ public class HighlightedTextWriter extends GraphTextWriter {
@Override
public HighlightedTextWriter append(String str) {
addLineLength(str.length());
return appendWithData(str, null);
}
@Override
public HighlightedTextWriter append(String str, long offset, long fileOffset) {
addLineLength(str.length());
Highlighting h = null;
if (hilight) {
HighlightData data = new HighlightData();
@@ -280,12 +283,14 @@ public class HighlightedTextWriter extends GraphTextWriter {
@Override
public HighlightedTextWriter appendNoHilight(int i) {
addLineLength(Integer.toString(i).length());
appendNoHilight(Integer.toString(i));
return this;
}
@Override
public HighlightedTextWriter appendNoHilight(String str) {
addLineLength(str.length());
appendToSb(str);
return this;
}
@@ -307,6 +312,7 @@ public class HighlightedTextWriter extends GraphTextWriter {
appendToSb(formatting.newLineChars);
newLine = true;
newLineCount++;
lineLength = 0;
return this;
}
@@ -53,36 +53,42 @@ public class StreamTextWriter extends GraphTextWriter implements AutoCloseable {
@Override
public GraphTextWriter hilightSpecial(String text, HighlightSpecialType type, String specialValue, HighlightData data) {
addLineLength(text.length());
writeToOutputStream(text);
return this;
}
@Override
public GraphTextWriter appendWithData(String str, HighlightData data) {
addLineLength(str.length());
writeToOutputStream(str);
return this;
}
@Override
public StreamTextWriter append(String str) {
addLineLength(str.length());
writeToOutputStream(str);
return this;
}
@Override
public StreamTextWriter append(String str, long offset, long fileOffset) {
addLineLength(str.length());
writeToOutputStream(str);
return this;
}
@Override
public StreamTextWriter appendNoHilight(int i) {
addLineLength(Integer.toString(i).length());
writeToOutputStream(Integer.toString(i));
return this;
}
@Override
public StreamTextWriter appendNoHilight(String str) {
addLineLength(str.length());
writeToOutputStream(str);
return this;
}
@@ -103,6 +109,7 @@ public class StreamTextWriter extends GraphTextWriter implements AutoCloseable {
public StreamTextWriter newLine() {
writeToOutputStream(formatting.newLineChars);
newLine = true;
lineLength = 0;
return this;
}
@@ -46,36 +46,42 @@ public class StringBuilderTextWriter extends GraphTextWriter {
@Override
public GraphTextWriter hilightSpecial(String text, HighlightSpecialType type, String specialValue, HighlightData data) {
addLineLength(text.length());
writeToOutputStream(text);
return this;
}
@Override
public GraphTextWriter appendWithData(String str, HighlightData data) {
addLineLength(str.length());
writeToOutputStream(str);
return this;
}
@Override
public StringBuilderTextWriter append(String str) {
addLineLength(str.length());
writeToOutputStream(str);
return this;
}
@Override
public StringBuilderTextWriter append(String str, long offset, long fileOffset) {
addLineLength(str.length());
writeToOutputStream(str);
return this;
}
@Override
public StringBuilderTextWriter appendNoHilight(int i) {
addLineLength(Integer.toString(i).length());
writeToOutputStream(Integer.toString(i));
return this;
}
@Override
public StringBuilderTextWriter appendNoHilight(String str) {
addLineLength(str.length());
writeToOutputStream(str);
return this;
}
@@ -96,6 +102,7 @@ public class StringBuilderTextWriter extends GraphTextWriter {
public StringBuilderTextWriter newLine() {
writeToOutputStream(formatting.newLineChars);
newLine = true;
lineLength = 0;
return this;
}