From efd8bd13da060f2a31d690944da8ff4e3ff7d5b3 Mon Sep 17 00:00:00 2001 From: Skylot Date: Sat, 4 Apr 2015 21:40:08 +0300 Subject: [PATCH] core: rename classes in default package --- .../jadx/core/dex/visitors/RenameVisitor.java | 5 ++++ .../java/jadx/tests/api/IntegrationTest.java | 23 ++++++++++--------- .../gui/settings/JadxSettingsAdapter.java | 2 +- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/jadx-core/src/main/java/jadx/core/dex/visitors/RenameVisitor.java b/jadx-core/src/main/java/jadx/core/dex/visitors/RenameVisitor.java index feaf8affb..043e1ee71 100644 --- a/jadx-core/src/main/java/jadx/core/dex/visitors/RenameVisitor.java +++ b/jadx-core/src/main/java/jadx/core/dex/visitors/RenameVisitor.java @@ -79,6 +79,11 @@ public class RenameVisitor extends AbstractVisitor { if (newShortName != null) { classInfo.rename(cls.dex(), classInfo.makeFullClsName(newShortName, true)); } + if (classInfo.getAlias().getPackage().isEmpty()) { + String fullName = classInfo.makeFullClsName(classInfo.getAlias().getShortName(), true); + String newFullName = Consts.DEFAULT_PACKAGE_NAME + "." + fullName; + classInfo.rename(cls.dex(), newFullName); + } } private void checkFields(ClassNode cls) { diff --git a/jadx-core/src/test/java/jadx/tests/api/IntegrationTest.java b/jadx-core/src/test/java/jadx/tests/api/IntegrationTest.java index 20e344bd3..b480c1420 100644 --- a/jadx-core/src/test/java/jadx/tests/api/IntegrationTest.java +++ b/jadx-core/src/test/java/jadx/tests/api/IntegrationTest.java @@ -29,17 +29,17 @@ import java.lang.reflect.Modifier; import java.net.URISyntaxException; import java.net.URL; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.jar.JarOutputStream; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.notNullValue; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; @@ -86,8 +86,8 @@ public abstract class IntegrationTest extends TestUtils { root.getResourcesNames().putAll(resMap); ClassNode cls = root.searchClassByName(clsName); - assertNotNull("Class not found: " + clsName, cls); - assertEquals(cls.getFullName(), clsName); + assertThat("Class not found: " + clsName, cls, notNullValue()); + assertThat(clsName, is(cls.getClassInfo().getFullName())); if (unloadCls) { decompile(d, cls); @@ -214,7 +214,7 @@ public abstract class IntegrationTest extends TestUtils { Throwable cause = ie.getCause(); if (cause instanceof AssertionError) { System.err.println(msg); - throw ((AssertionError) cause); + throw (AssertionError) cause; } else { cause.printStackTrace(); fail(msg + cause.getMessage()); @@ -283,7 +283,7 @@ public abstract class IntegrationTest extends TestUtils { list = compileClass(cls); } } - assertNotEquals("File list is empty", 0, list.size()); + assertThat("File list is empty", list, not(empty())); File temp = createTempFile(".jar"); JarOutputStream jo = new JarOutputStream(new FileOutputStream(temp)); @@ -354,11 +354,12 @@ public abstract class IntegrationTest extends TestUtils { if (!file.exists()) { file = new File(TEST_DIRECTORY2, fileName); } - assertTrue("Test source file not found: " + fileName, file.exists()); + assertThat("Test source file not found: " + fileName, file.exists(), is(true)); + List compileFileList = Collections.singletonList(file); File outTmp = createTempDir("jadx-tmp-classes"); outTmp.deleteOnExit(); - List files = StaticCompiler.compile(Arrays.asList(file), outTmp, withDebugInfo); + List files = StaticCompiler.compile(compileFileList, outTmp, withDebugInfo); // remove classes which are parents for test class Iterator iterator = files.iterator(); while (iterator.hasNext()) { diff --git a/jadx-gui/src/main/java/jadx/gui/settings/JadxSettingsAdapter.java b/jadx-gui/src/main/java/jadx/gui/settings/JadxSettingsAdapter.java index f048c57ee..712eb7906 100644 --- a/jadx-gui/src/main/java/jadx/gui/settings/JadxSettingsAdapter.java +++ b/jadx-gui/src/main/java/jadx/gui/settings/JadxSettingsAdapter.java @@ -46,7 +46,7 @@ public class JadxSettingsAdapter { if (settings == null) { return new JadxSettings(); } - LOG.info("Loaded settings: {}", makeString(settings)); + LOG.debug("Loaded settings: {}", makeString(settings)); return settings; } catch (Exception e) { LOG.error("Error load settings", e);