mirror of
https://github.com/skylot/jadx.git
synced 2024-11-23 12:50:02 +00:00
fix: ignore source name if current alias is better (#1795)
This commit is contained in:
parent
e933b41236
commit
1891f6fd7e
@ -8,6 +8,7 @@ import jadx.core.deobf.NameMapper;
|
||||
import jadx.core.dex.attributes.AFlag;
|
||||
import jadx.core.dex.nodes.ClassNode;
|
||||
import jadx.core.dex.nodes.RootNode;
|
||||
import jadx.core.utils.BetterName;
|
||||
import jadx.core.utils.StringUtils;
|
||||
|
||||
public class SourceFileRename {
|
||||
@ -45,6 +46,15 @@ public class SourceFileRename {
|
||||
if (otherCls != null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (cls.getClassInfo().hasAlias()) {
|
||||
// ignore source name if current alias is "better"
|
||||
String currentAlias = cls.getAlias();
|
||||
String betterName = BetterName.compareAndGet(name, currentAlias);
|
||||
if (betterName.equals(currentAlias)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
cls.remove(JadxAttrType.SOURCE_FILE);
|
||||
return name;
|
||||
}
|
||||
|
@ -25,9 +25,9 @@ public class BetterName {
|
||||
boolean firstBetter = firstRating >= secondRating;
|
||||
if (DEBUG) {
|
||||
if (firstBetter) {
|
||||
LOG.info("Better name: '{}' > '{}' ({} > {})", first, second, firstRating, secondRating);
|
||||
LOG.debug("Better name: '{}' > '{}' ({} > {})", first, second, firstRating, secondRating);
|
||||
} else {
|
||||
LOG.info("Better name: '{}' > '{}' ({} > {})", second, first, secondRating, firstRating);
|
||||
LOG.debug("Better name: '{}' > '{}' ({} > {})", second, first, secondRating, firstRating);
|
||||
}
|
||||
}
|
||||
return firstBetter ? first : second;
|
||||
|
@ -0,0 +1,40 @@
|
||||
package jadx.tests.integration.deobf;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jadx.tests.api.SmaliTest;
|
||||
|
||||
import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat;
|
||||
|
||||
public class TestBadSourceFile extends SmaliTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
// use source name disabled by default
|
||||
enableDeobfuscation();
|
||||
args.setDeobfuscationMinLength(100); // rename everything
|
||||
assertThat(searchCls(loadFromSmaliFiles(), "b"))
|
||||
.code()
|
||||
.containsOne("class C0000b {");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithUseSourceName() {
|
||||
args.setUseSourceNameAsClassAlias(true);
|
||||
// deobfuscation disabled
|
||||
assertThat(searchCls(loadFromSmaliFiles(), "b"))
|
||||
.code()
|
||||
.containsOne("class a {");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithUseSourceNameAndDeobf() {
|
||||
args.setUseSourceNameAsClassAlias(true);
|
||||
enableDeobfuscation();
|
||||
args.setDeobfuscationMinLength(100); // rename everything
|
||||
assertThat(searchCls(loadFromSmaliFiles(), "b"))
|
||||
.code()
|
||||
.containsOne("class C0000b {")
|
||||
.containsOne("/* compiled from: a.java */");
|
||||
}
|
||||
}
|
9
jadx-core/src/test/smali/deobf/TestBadSourceFile/b.smali
Normal file
9
jadx-core/src/test/smali/deobf/TestBadSourceFile/b.smali
Normal file
@ -0,0 +1,9 @@
|
||||
.class Lb;
|
||||
.super Ljava/lang/Object;
|
||||
.source "a.java"
|
||||
|
||||
.method constructor <init>()V
|
||||
.registers 1
|
||||
invoke-direct {p0}, Ljava/lang/Object;-><init>()V
|
||||
return-void
|
||||
.end method
|
Loading…
Reference in New Issue
Block a user