-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: avoid local variables collision with full class names (#647)
- Loading branch information
Showing
8 changed files
with
141 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package jadx.core.utils; | ||
|
||
import java.util.Collections; | ||
import java.util.Set; | ||
|
||
public class CacheStorage { | ||
|
||
private Set<String> rootPkgs = Collections.emptySet(); | ||
|
||
public Set<String> getRootPkgs() { | ||
return rootPkgs; | ||
} | ||
|
||
public void setRootPkgs(Set<String> rootPkgs) { | ||
this.rootPkgs = rootPkgs; | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
jadx-core/src/test/java/jadx/tests/integration/names/TestLocalVarCollideWithPackage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package jadx.tests.integration.names; | ||
|
||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import jadx.core.dex.nodes.ClassNode; | ||
import jadx.tests.api.SmaliTest; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.containsString; | ||
import static org.hamcrest.Matchers.not; | ||
|
||
public class TestLocalVarCollideWithPackage extends SmaliTest { | ||
//@formatter:off | ||
/* | ||
----------------------------------------------------------- | ||
package first; | ||
import pkg.Second; | ||
public class A { | ||
public String test() { | ||
Second second = new Second(); | ||
second.A.call(); // collision | ||
return second.str; | ||
} | ||
} | ||
----------------------------------------------------------- | ||
package pkg; | ||
public class Second { | ||
public String str; | ||
} | ||
----------------------------------------------------------- | ||
package second; | ||
public class A { | ||
} | ||
----------------------------------------------------------- | ||
*/ | ||
//@formatter:on | ||
|
||
@Test | ||
public void test() { | ||
List<ClassNode> clsList = loadFromSmaliFiles(); | ||
ClassNode firstA = searchCls(clsList, "first.A"); | ||
String code = firstA.getCode().toString(); | ||
|
||
assertThat(code, containsString("second.A.call();")); | ||
assertThat(code, not(containsString("Second second = new Second();"))); | ||
} | ||
|
||
@Test | ||
public void testNoDebug() { | ||
noDebugInfo(); | ||
loadFromSmaliFiles(); | ||
} | ||
|
||
@Test | ||
public void testWithoutImports() { | ||
getArgs().setUseImports(false); | ||
loadFromSmaliFiles(); | ||
} | ||
|
||
@Test | ||
public void testWithDeobfuscation() { | ||
enableDeobfuscation(); | ||
loadFromSmaliFiles(); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
jadx-core/src/test/smali/names/TestLocalVarCollideWithPackage/1.smali
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
.class public Lfirst/A; | ||
.super Ljava/lang/Object; | ||
|
||
.method public test()Ljava/lang/String; | ||
.registers 2 | ||
|
||
new-instance v1, Lpkg/Second; | ||
|
||
invoke-direct {v1}, Lpkg/Second;-><init>()V | ||
|
||
.local v1, "second":Lpkg/Second; | ||
|
||
invoke-static {}, Lsecond/A;->call()Ljava/lang/String; | ||
|
||
iget-object v0, v1, Lpkg/Second;->str:Ljava/lang/String; | ||
|
||
return-object v0 | ||
.end method |
10 changes: 10 additions & 0 deletions
10
jadx-core/src/test/smali/names/TestLocalVarCollideWithPackage/2.smali
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.class public Lsecond/A; | ||
.super Ljava/lang/Object; | ||
|
||
.method static public call()Ljava/lang/String; | ||
.registers 1 | ||
|
||
const v0, 0 | ||
|
||
return-object v0 | ||
.end method |
4 changes: 4 additions & 0 deletions
4
jadx-core/src/test/smali/names/TestLocalVarCollideWithPackage/3.smali
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.class public Lpkg/Second; | ||
.super Ljava/lang/Object; | ||
|
||
.field public str:Ljava/lang/String; |