mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-06-01 19:04:38 +00:00
Added
- #2070 - SWF to XML format has new meta fields describing XML export major/minor version (major = uncompatible change) ### Fixed - #2070 - Handling newlines and tabs in string values inside SWF to XML export ### Changed - #2070 - String values inside SWF to XML export are backslash escaped to properly handle newlines and tabs. Older versions of FFDec can read this new format wrong and corrupt SWFs. Major version of SWF to XML export changed to 2.
This commit is contained in:
@@ -1244,6 +1244,104 @@ public class Helper {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public static String escapeXmlExportString(String s) {
|
||||
StringBuilder ret = new StringBuilder(s.length());
|
||||
for (int i = 0; i < s.length(); i++) {
|
||||
char c = s.charAt(i);
|
||||
if (c == '\n') {
|
||||
ret.append("\\n");
|
||||
} else if (c == '\r') {
|
||||
ret.append("\\r");
|
||||
} else if (c == '\t') {
|
||||
ret.append("\\t");
|
||||
} else if (c == '\b') {
|
||||
ret.append("\\b");
|
||||
} else if (c == '\f') {
|
||||
ret.append("\\f");
|
||||
} else if (c == '\\') {
|
||||
ret.append("\\\\");
|
||||
} else if (c < 32) {
|
||||
ret.append("\\u00").append(byteToHex((byte) c));
|
||||
} else if (!isCharacterValidInXml(c)){
|
||||
ret.append("\\u").append(String.format("%04x", (int) c));
|
||||
} else {
|
||||
ret.append(c);
|
||||
}
|
||||
}
|
||||
|
||||
return ret.toString();
|
||||
}
|
||||
|
||||
public static String unescapeXmlExportString(String st) {
|
||||
|
||||
StringBuilder sb = new StringBuilder(st.length());
|
||||
|
||||
for (int i = 0; i < st.length(); i++) {
|
||||
char ch = st.charAt(i);
|
||||
if (ch == '\\') {
|
||||
char nextChar = (i == st.length() - 1) ? '\\' : st
|
||||
.charAt(i + 1);
|
||||
// Octal escape?
|
||||
if (nextChar >= '0' && nextChar <= '7') {
|
||||
String code = "" + nextChar;
|
||||
i++;
|
||||
if ((i < st.length() - 1) && st.charAt(i + 1) >= '0'
|
||||
&& st.charAt(i + 1) <= '7') {
|
||||
code += st.charAt(i + 1);
|
||||
i++;
|
||||
if ((i < st.length() - 1) && st.charAt(i + 1) >= '0'
|
||||
&& st.charAt(i + 1) <= '7') {
|
||||
code += st.charAt(i + 1);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
sb.append((char) Integer.parseInt(code, 8));
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (nextChar) {
|
||||
case '\\':
|
||||
ch = '\\';
|
||||
break;
|
||||
case 'b':
|
||||
ch = '\b';
|
||||
break;
|
||||
case 'f':
|
||||
ch = '\f';
|
||||
break;
|
||||
case 'n':
|
||||
ch = '\n';
|
||||
break;
|
||||
case 'r':
|
||||
ch = '\r';
|
||||
break;
|
||||
case 't':
|
||||
ch = '\t';
|
||||
break;
|
||||
// Hex Unicode: u????
|
||||
case 'u':
|
||||
if (i >= st.length() - 5) {
|
||||
ch = 'u';
|
||||
break;
|
||||
}
|
||||
int code = Integer.parseInt(
|
||||
"" + st.charAt(i + 2) + st.charAt(i + 3)
|
||||
+ st.charAt(i + 4) + st.charAt(i + 5), 16);
|
||||
sb.append(Character.toChars(code));
|
||||
i += 5;
|
||||
continue;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
sb.append(ch);
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String removeInvalidXMLCharacters(String text) {
|
||||
StringBuilder sb = new StringBuilder(text.length());
|
||||
|
||||
Reference in New Issue
Block a user