fix(deobf): complete disable rename if all rename options unchecked (#1076)
This commit is contained in:
@@ -313,7 +313,8 @@ public class Deobfuscator {
|
||||
} else {
|
||||
if (!clsMap.containsKey(classInfo)) {
|
||||
String clsShortName = classInfo.getShortName();
|
||||
boolean badName = shouldRename(clsShortName) || reservedClsNames.contains(clsShortName);
|
||||
boolean badName = shouldRename(clsShortName)
|
||||
|| (args.isRenameValid() && reservedClsNames.contains(clsShortName));
|
||||
makeClsAlias(cls, badName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,17 +188,20 @@ public class RenameVisitor extends AbstractVisitor {
|
||||
mth.addAttr(new RenameReasonAttr(mth, notValid, notPrintable));
|
||||
}
|
||||
}
|
||||
Set<String> names = new HashSet<>(methods.size());
|
||||
for (MethodNode mth : methods) {
|
||||
AccessInfo accessFlags = mth.getAccessFlags();
|
||||
if (accessFlags.isBridge() || accessFlags.isSynthetic()
|
||||
|| mth.contains(AFlag.DONT_GENERATE) /* this flag not set yet */) {
|
||||
continue;
|
||||
}
|
||||
String signature = mth.getMethodInfo().makeSignature(true, false);
|
||||
if (!names.add(signature)) {
|
||||
deobfuscator.forceRenameMethod(mth);
|
||||
mth.addAttr(new RenameReasonAttr("collision with other method in class"));
|
||||
// Rename methods with same signature
|
||||
if (args.isRenameValid()) {
|
||||
Set<String> names = new HashSet<>(methods.size());
|
||||
for (MethodNode mth : methods) {
|
||||
AccessInfo accessFlags = mth.getAccessFlags();
|
||||
if (accessFlags.isBridge() || accessFlags.isSynthetic()
|
||||
|| mth.contains(AFlag.DONT_GENERATE) /* this flag not set yet */) {
|
||||
continue;
|
||||
}
|
||||
String signature = mth.getMethodInfo().makeSignature(true, false);
|
||||
if (!names.add(signature)) {
|
||||
deobfuscator.forceRenameMethod(mth);
|
||||
mth.addAttr(new RenameReasonAttr("collision with other method in class"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
package jadx.tests.integration.deobf.a;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jadx.tests.api.IntegrationTest;
|
||||
|
||||
import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat;
|
||||
|
||||
public class TestNegativeRenameCondition extends IntegrationTest {
|
||||
|
||||
public static class TestCls {
|
||||
|
||||
@SuppressWarnings("checkstyle:TypeName")
|
||||
public interface a {
|
||||
|
||||
@SuppressWarnings("checkstyle:MethodName")
|
||||
void a();
|
||||
}
|
||||
|
||||
public void test(a a) {
|
||||
a.a();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
noDebugInfo();
|
||||
enableDeobfuscation();
|
||||
// disable rename by length
|
||||
args.setDeobfuscationMinLength(0);
|
||||
args.setDeobfuscationMaxLength(999);
|
||||
// disable all renaming options
|
||||
args.setRenameFlags(Collections.emptySet());
|
||||
|
||||
assertThat(getClassNode(TestCls.class))
|
||||
.code()
|
||||
.doesNotContain("renamed from")
|
||||
.containsOne("package jadx.tests.integration.deobf.a;")
|
||||
.containsOne("public interface a {");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user