Do not parse imports from names with namespace suffix

This commit is contained in:
Jindra Petřík
2025-08-01 19:29:45 +02:00
parent a76ce37d33
commit be5ead4087
9 changed files with 128 additions and 1 deletions

View File

@@ -174,6 +174,14 @@ public class Multiname {
public void setDisplayNamespace(boolean displayNamespace) {
this.displayNamespace = displayNamespace;
}
/**
* Checks whether this multiname displays its namespace as #suffix
* @return True when displays
*/
public boolean doesDisplayNamespace() {
return displayNamespace;
}
/**
* Checks if the multiname kind is valid.

View File

@@ -140,7 +140,7 @@ public class DependencyParser {
Namespace ns = m.getNamespace(abc.constants);
String name = m.getName(usedDeobfuscations, abc, abc.constants, fullyQualifiedNames, true, true);
NamespaceSet nss = m.getNamespaceSet(abc.constants);
if (ns != null) {
if (ns != null && !m.doesDisplayNamespace()) {
parseDependenciesFromNS(abcIndex, ignoredCustom, abc, dependencies, m.namespace_index, ignorePackage, name, dependencyType, uses);
}
if (nss != null) {

View File

@@ -26,6 +26,8 @@ public class ActionScriptTestBase {
pCode = pCode.replaceAll("\t", " ").trim();
pCode = pCode.replaceAll("( *[\r\n]+ *)+", "\n").trim();
pCode = pCode.replaceAll(" +", " ").trim();
//replace ns suffixes, so testCollidingPublicTraits will work even when ns indices change
pCode = pCode.replaceAll("#[0-9]+", "#_");
return pCode;
}
}

View File

@@ -90,6 +90,13 @@ public class ActionScript3AssembledDecompileTest extends ActionScript3DecompileT
false);
}
@Test
public void testCollidingPublicTraits() {
decompileMethod("assembled", "testCollidingPublicTraits", "trace(\"ns1 = \" + this.a#87);\r\n"
+ "trace(\"ns2 = \" + this.a#88);\r\n",
false);
}
@Test
public void testDeclareReg() {
decompileMethod("assembled", "testDeclareReg", "var other:XML;\r\n"

View File

@@ -41,5 +41,6 @@ program
#include "tests/TestAlwaysBreak2.script.asasm"
#include "tests/TestPushPlacement.script.asasm"
#include "tests/TestConstructDynamically.script.asasm"
#include "tests/TestCollidingPublicTraits.script.asasm"
; place to add next
end ; program

View File

@@ -0,0 +1,80 @@
class
refid "tests:TestCollidingPublicTraits"
instance QName(PackageNamespace("tests"), "TestCollidingPublicTraits")
extends QName(PackageNamespace(""), "Object")
flag SEALED
flag PROTECTEDNS
protectedns ProtectedNamespace("tests:TestCollidingPublicTraits")
iinit
refid "tests:TestCollidingPublicTraits/instance/init"
body
maxstack 1
localcount 1
initscopedepth 4
maxscopedepth 5
code
getlocal0
pushscope
getlocal0
constructsuper 0
returnvoid
end ; code
end ; body
end ; method
trait slot QName(PackageNamespace("test1"),"a")
slotid 0
type QName(PackageNamespace(""),"int")
value Integer(1)
end ; trait
trait slot QName(PackageNamespace("test2"),"a")
slotid 0
type QName(PackageNamespace(""),"int")
value Integer(2)
end ; trait
trait method QName(PackageNamespace(""), "run")
method
refid "tests:TestCollidingPublicTraits/instance/run"
returns QName(PackageNamespace(""), "void")
body
maxstack 2
localcount 4
initscopedepth 4
maxscopedepth 5
code
getlocal0
pushscope
findpropstrict QName(PackageNamespace(""),"trace")
pushstring "ns1 = "
getlocal0
getproperty QName(PackageNamespace("test1"),"a")
add
callpropvoid QName(PackageNamespace(""),"trace"), 1
findpropstrict QName(PackageNamespace(""),"trace")
pushstring "ns2 = "
getlocal0
getproperty QName(PackageNamespace("test2"),"a")
add
callpropvoid QName(PackageNamespace(""),"trace"), 1
returnvoid
end ; code
end ; body
end ; method
end ; trait
end ; instance
cinit
refid "tests:TestCollidingPublicTraits/class/init"
body
maxstack 1
localcount 1
initscopedepth 3
maxscopedepth 4
code
getlocal0
pushscope
returnvoid
end ; code
end ; body
end ; method
end ; class

View File

@@ -0,0 +1,29 @@
script
sinit
refid "tests:TestCollidingPublicTraits/init"
body
maxstack 2
localcount 1
initscopedepth 1
maxscopedepth 3
code
getlocal0
pushscope
findpropstrict Multiname("TestCollidingPublicTraits", [PackageNamespace("tests")])
getlex QName(PackageNamespace(""), "Object")
pushscope
getlex Multiname("Object", [PrivateNamespace(null, "tests:TestCollidingPublicTraits"), PackageNamespace(""), PackageNamespace("tests"), PackageInternalNs("tests"), Namespace("http://adobe.com/AS3/2006/builtin")])
newclass "tests:TestCollidingPublicTraits"
popscope
initproperty QName(PackageNamespace("tests"), "TestCollidingPublicTraits")
returnvoid
end ; code
end ; body
end ; method
trait class QName(PackageNamespace("tests"), "TestCollidingPublicTraits")
#include "TestCollidingPublicTraits.class.asasm"
end ; trait
end ; script