From 14c012ad2f298c8bfff9c436239fbb5acd096601 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Sun, 12 Feb 2023 22:25:54 +0100 Subject: [PATCH] Fixed #1972 AS3 Renaming invalid identifiers - '#' character --- CHANGELOG.md | 2 ++ .../flash/IdentifiersDeobfuscation.java | 8 ++++---- .../flash/abc/avm2/AVM2Deobfuscation.java | 18 ++++++++++-------- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3afd3b594..f73a9ade9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file. - [#1970] FLA export - do not strip empty frames at the end of timeline - [#1970] AS2 Renaming invalid identifiers for direct strings (no constant indices) - [#1970] AS2 Renaming invalid identifiers IndexOutOfBounds on invalid constant index (obfuscated code, etc.) +- [#1972] AS3 Renaming invalid identifiers - '#' character ## [18.3.5] - 2023-02-12 ### Added @@ -2953,6 +2954,7 @@ All notable changes to this project will be documented in this file. [alpha 8]: https://github.com/jindrapetrik/jpexs-decompiler/compare/alpha7...alpha8 [alpha 7]: https://github.com/jindrapetrik/jpexs-decompiler/releases/tag/alpha7 [#1970]: https://www.free-decompiler.com/flash/issues/1970 +[#1972]: https://www.free-decompiler.com/flash/issues/1972 [#1959]: https://www.free-decompiler.com/flash/issues/1959 [#1960]: https://www.free-decompiler.com/flash/issues/1960 [#1964]: https://www.free-decompiler.com/flash/issues/1964 diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/IdentifiersDeobfuscation.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/IdentifiersDeobfuscation.java index c5d6a20f3..015f8f09e 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/IdentifiersDeobfuscation.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/IdentifiersDeobfuscation.java @@ -222,7 +222,7 @@ public class IdentifiersDeobfuscation { } public String deobfuscateNameWithPackage(boolean as3, String n, HashMap namesMap, RenameType renameType, Map selected) { - DottedChain nChain = DottedChain.parseWithSuffix(n); + DottedChain nChain = DottedChain.parseNoSuffix(n); DottedChain pkg = nChain.getWithoutLast(); String name = nChain.getLast(); @@ -340,7 +340,7 @@ public class IdentifiersDeobfuscation { usageType = "name"; } - DottedChain sChain = DottedChain.parseWithSuffix(s); + DottedChain sChain = DottedChain.parseNoSuffix(s); if (selected != null) { if (selected.containsKey(sChain)) { return selected.get(sChain).toRawString(); @@ -366,14 +366,14 @@ public class IdentifiersDeobfuscation { ret = fooString(firstUppercase, rndSize); if (allVariableNamesStr.contains(ret) || isReservedWord(ret, as3) - || namesMap.containsValue(DottedChain.parseWithSuffix(ret))) { + || namesMap.containsValue(DottedChain.parseNoSuffix(ret))) { found = true; rndSize++; } } } while (found); - namesMap.put(DottedChain.parseWithSuffix(s), DottedChain.parseWithSuffix(ret)); + namesMap.put(DottedChain.parseNoSuffix(s), DottedChain.parseNoSuffix(ret)); return ret; } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Deobfuscation.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Deobfuscation.java index ee3171c74..266bb534f 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Deobfuscation.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Deobfuscation.java @@ -93,7 +93,7 @@ public class AVM2Deobfuscation { return null; } - private String fooString(HashMap deobfuscated, String orig, boolean firstUppercase, String usageType, RenameType renameType) { + private String fooString(HashMap deobfuscated, String orig, boolean firstUppercase, String usageType, RenameType renameType, boolean autoAdd) { if (usageType == null) { usageType = "name"; } @@ -111,12 +111,14 @@ public class AVM2Deobfuscation { } if (swf.as3StringConstantExists(ret) || IdentifiersDeobfuscation.isReservedWord2(ret) - || deobfuscated.containsValue(DottedChain.parseWithSuffix(ret))) { + || deobfuscated.containsValue(DottedChain.parseNoSuffix(ret))) { found = true; rndSize++; } } while (found); - deobfuscated.put(DottedChain.parseWithSuffix(orig), DottedChain.parseWithSuffix(ret)); + if (autoAdd) { + deobfuscated.put(DottedChain.parseNoSuffix(orig), DottedChain.parseNoSuffix(ret)); + } return ret; } @@ -141,7 +143,7 @@ public class AVM2Deobfuscation { for (int p = 0; p < sChain.size(); p++) { String part = sChain.get(p); if (!isValidNSPart(part)) { - ret.add(fooString(namesMap, part, false, "package", renameType)); + ret.add(fooString(namesMap, part, false, "package", renameType, true)); } else { ret.add(part); } @@ -186,21 +188,21 @@ public class AVM2Deobfuscation { if (!isValid) { DottedChain newname; - DottedChain sChain = DottedChain.parseWithSuffix(s); + DottedChain sChain = DottedChain.parseNoSuffix(s); if (namesMap.containsKey(sChain)) { newname = namesMap.get(sChain); return constants.getStringId(newname, true); } - String str = fooString(namesMap, constants.getString(strIndex), firstUppercase, stringUsageTypes.get(strIndex), renameType); - newname = DottedChain.parseWithSuffix(str); + String str = fooString(namesMap, constants.getString(strIndex), firstUppercase, stringUsageTypes.get(strIndex), renameType, false); + newname = DottedChain.parseNoSuffix(str); if (stringUsages.contains(strIndex) || namespaceUsages.contains(strIndex)) { // this name is already referenced as String strIndex = constants.addString(s); // add new index } constants.setString(strIndex, newname.toRawString()); if (!namesMap.containsKey(sChain)) { - namesMap.put(sChain, DottedChain.parseWithSuffix(constants.getString(strIndex))); + namesMap.put(sChain, DottedChain.parseNoSuffix(constants.getString(strIndex))); } } return strIndex;