mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-06-24 07:17:47 +00:00
Changed: AS1/2: Export names are deobfuscated only when start with __Packages.,
if not, then classical escaping is performed (with quotes)
This commit is contained in:
@@ -245,17 +245,15 @@ public class DoInitActionTag extends Tag implements CharacterIdTag, ASMSource {
|
||||
|
||||
@Override
|
||||
public Map<String, String> getNameProperties() {
|
||||
String expName = swf == null ? "" : swf.getExportName(spriteId);
|
||||
String exportName = swf == null ? "" : swf.getExportName(spriteId);
|
||||
|
||||
Map<String, String> ret = super.getNameProperties();
|
||||
ret.put("sid", "" + spriteId);
|
||||
|
||||
if (expName == null || expName.isEmpty()) {
|
||||
if (exportName == null || exportName.isEmpty()) {
|
||||
return ret;
|
||||
}
|
||||
//String[] pathParts = expName.contains(".") ? expName.split("\\.") : new String[]{expName};
|
||||
//ret.put("exp", pathParts[pathParts.length - 1]);
|
||||
ret.put("exp", expName);
|
||||
ret.put("exp", Helper.escapeExportname(exportName, true));
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ import com.jpexs.decompiler.flash.types.annotations.SWFVersion;
|
||||
import com.jpexs.decompiler.flash.types.annotations.Table;
|
||||
import com.jpexs.decompiler.graph.DottedChain;
|
||||
import com.jpexs.helpers.ByteArrayRange;
|
||||
import com.jpexs.helpers.Helper;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -58,7 +59,7 @@ public class ExportAssetsTag extends SymbolClassTypeTag {
|
||||
|
||||
@SWFArray(value = "name", countField = "count")
|
||||
@Table(value = "assets", itemName = "asset")
|
||||
@DottedIdentifier
|
||||
@DottedIdentifier(exportName = true)
|
||||
public List<String> names;
|
||||
|
||||
/**
|
||||
@@ -164,7 +165,8 @@ public class ExportAssetsTag extends SymbolClassTypeTag {
|
||||
Map<String, String> ret = super.getNameProperties();
|
||||
if (names.size() == 1) {
|
||||
ret.put("chid", "" + tags.get(0));
|
||||
ret.put("ex", "" + DottedChain.parseNoSuffix(names.get(0)).toPrintableString(false));
|
||||
String exportName = names.get(0);
|
||||
ret.put("exp", Helper.escapeExportname(exportName, true));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -162,7 +162,12 @@ public class ImportAssets2Tag extends Tag implements ImportTag {
|
||||
Map<String, String> ret = super.getNameProperties();
|
||||
if (names.size() == 1) {
|
||||
ret.put("chid", "" + tags.get(0));
|
||||
ret.put("im", "" + DottedChain.parseNoSuffix(names.get(0)).toPrintableString(false));
|
||||
String importName = names.get(0);
|
||||
if (importName.startsWith("__Packages.")) {
|
||||
ret.put("imp", DottedChain.parseNoSuffix(importName).toPrintableString(false));
|
||||
} else {
|
||||
ret.put("imp", "\"" + Helper.escapePCodeString(importName) + "\"");
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import com.jpexs.decompiler.flash.types.annotations.SWFVersion;
|
||||
import com.jpexs.decompiler.flash.types.annotations.Table;
|
||||
import com.jpexs.decompiler.graph.DottedChain;
|
||||
import com.jpexs.helpers.ByteArrayRange;
|
||||
import com.jpexs.helpers.Helper;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -138,7 +139,13 @@ public class ImportAssetsTag extends Tag implements ImportTag {
|
||||
Map<String, String> ret = super.getNameProperties();
|
||||
if (names.size() == 1) {
|
||||
ret.put("chid", "" + tags.get(0));
|
||||
ret.put("im", "" + DottedChain.parseNoSuffix(names.get(0)).toPrintableString(false));
|
||||
|
||||
String importName = names.get(0);
|
||||
if (importName.startsWith("__Packages.")) {
|
||||
ret.put("imp", DottedChain.parseNoSuffix(importName).toPrintableString(false));
|
||||
} else {
|
||||
ret.put("imp", "\"" + Helper.escapePCodeString(importName) + "\"");
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ public class PlaceObject2Tag extends PlaceObjectTypeTag implements ASMSourceCont
|
||||
* If PlaceFlagHasName, Name of character
|
||||
*/
|
||||
@Conditional("placeFlagHasName")
|
||||
@DottedIdentifier
|
||||
@DottedIdentifier
|
||||
public String name;
|
||||
|
||||
/**
|
||||
|
||||
@@ -99,7 +99,7 @@ public abstract class CharacterTag extends Tag implements CharacterIdTag {
|
||||
ret.put("chid", "" + chid);
|
||||
}
|
||||
if (exportName != null) {
|
||||
ret.put("exp", DottedChain.parseNoSuffix(exportName).toPrintableString(false));
|
||||
ret.put("exp", Helper.escapeExportname(exportName, true));
|
||||
}
|
||||
if (!classNames.isEmpty()) {
|
||||
List<String> escapedList = new ArrayList<>();
|
||||
|
||||
@@ -25,7 +25,9 @@ import com.jpexs.decompiler.flash.types.ColorTransform;
|
||||
import com.jpexs.decompiler.flash.types.MATRIX;
|
||||
import com.jpexs.decompiler.flash.types.RGBA;
|
||||
import com.jpexs.decompiler.flash.types.filters.FILTER;
|
||||
import com.jpexs.decompiler.graph.DottedChain;
|
||||
import com.jpexs.helpers.ByteArrayRange;
|
||||
import com.jpexs.helpers.Helper;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -336,7 +338,7 @@ public abstract class PlaceObjectTypeTag extends Tag implements CharacterIdTag,
|
||||
ret.put("chid", "" + charId);
|
||||
}
|
||||
if (exportName != null) {
|
||||
ret.put("exp", exportName);
|
||||
ret.put("exp", Helper.escapeExportname(exportName, true));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,9 @@ package com.jpexs.decompiler.flash.tags.base;
|
||||
|
||||
import com.jpexs.decompiler.flash.SWF;
|
||||
import com.jpexs.decompiler.flash.tags.Tag;
|
||||
import com.jpexs.decompiler.graph.DottedChain;
|
||||
import com.jpexs.helpers.ByteArrayRange;
|
||||
import com.jpexs.helpers.Helper;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -48,7 +50,7 @@ public abstract class RemoveTag extends Tag implements DepthTag {
|
||||
ret.put("chid", "" + getCharacterId());
|
||||
}
|
||||
if (exportName != null) {
|
||||
ret.put("exp", exportName);
|
||||
ret.put("exp", Helper.escapeExportname(exportName, true));
|
||||
}
|
||||
ret.put("dpt", "" + getDepth());
|
||||
|
||||
|
||||
@@ -30,4 +30,5 @@ import java.lang.annotation.Target;
|
||||
@Target(ElementType.FIELD)
|
||||
public @interface DottedIdentifier {
|
||||
boolean as3() default false;
|
||||
boolean exportName() default false;
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.jpexs.decompiler.flash.ApplicationInfo;
|
||||
import com.jpexs.decompiler.flash.configuration.Configuration;
|
||||
import com.jpexs.decompiler.flash.helpers.Freed;
|
||||
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
|
||||
import com.jpexs.decompiler.graph.DottedChain;
|
||||
import com.jpexs.decompiler.graph.TranslateStack;
|
||||
import com.jpexs.decompiler.graph.model.LocalData;
|
||||
import com.jpexs.helpers.utf8.Utf8Helper;
|
||||
@@ -237,6 +238,31 @@ public class Helper {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Escapes export name
|
||||
* @param s Input string
|
||||
* @param quote Add quotes when not starts __Packages.
|
||||
* @return Escaped string
|
||||
*/
|
||||
public static String escapeExportname(String s, boolean quote) {
|
||||
if (s.startsWith("__Packages.")) {
|
||||
return DottedChain.parseNoSuffix(s).toPrintableString(false);
|
||||
}
|
||||
return (quote ? "\"" : "") + escapePCodeString(s) + (quote ? "\"" : "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Unescape export name
|
||||
* @param s Input string
|
||||
* @return Unescaped string
|
||||
*/
|
||||
public static String unescapeExportname(String s) {
|
||||
if (s.startsWith("__Packages.")) {
|
||||
return DottedChain.parsePrintable(s).toRawString();
|
||||
}
|
||||
return unescapePCodeString(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Escapes string by adding backslashes
|
||||
*
|
||||
@@ -285,6 +311,58 @@ public class Helper {
|
||||
return ret.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Unescapes PCode String
|
||||
* @param s Input string
|
||||
* @return Unescaped string
|
||||
*/
|
||||
public static String unescapePCodeString(String s) {
|
||||
StringBuilder ret = new StringBuilder(s.length());
|
||||
for (int i = 0; i < s.length(); i++) {
|
||||
char c = s.charAt(i);
|
||||
if (c == '\\') {
|
||||
if (i + 1 < s.length() - 1) {
|
||||
i++;
|
||||
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 == '"') {
|
||||
ret.append("\"");
|
||||
} else if (c == '\'') {
|
||||
ret.append("'");
|
||||
} else if (c == 'x' && i + 2 < s.length() - 1) {
|
||||
ret.append((char) Integer.parseInt(s.substring(i + 1, i + 3), 16));
|
||||
i += 2;
|
||||
} else if (c == '{') {
|
||||
int endPos = s.indexOf("}", i);
|
||||
if (endPos != -1) {
|
||||
int numRepeat = Integer.parseInt(s.substring(i + 1, endPos));
|
||||
i = endPos + 1;
|
||||
c = s.charAt(i);
|
||||
for (int j = 0; j < numRepeat; j++) {
|
||||
ret.append(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ret.append(c);
|
||||
}
|
||||
}
|
||||
|
||||
return ret.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Escapes string by adding backslashes - limits to english characters -
|
||||
* other are unicode escaped.
|
||||
|
||||
Reference in New Issue
Block a user