fix: rerun signature parser on class reload (#981)
This commit is contained in:
@@ -59,9 +59,7 @@ public final class JavaClass implements JavaNode {
|
||||
|
||||
public synchronized void refresh() {
|
||||
listsLoaded = false;
|
||||
cls.unload();
|
||||
cls.deepUnload();
|
||||
cls.reRunDecompile();
|
||||
cls.reloadCode();
|
||||
}
|
||||
|
||||
public synchronized String getSmali() {
|
||||
|
||||
@@ -225,13 +225,10 @@ public class ClassNode extends NotificationAttrNode implements ILoadable, ICodeN
|
||||
return decompile(true);
|
||||
}
|
||||
|
||||
public synchronized ICodeInfo reRunDecompile() {
|
||||
return decompile(false);
|
||||
}
|
||||
|
||||
public synchronized ICodeInfo reloadCode() {
|
||||
unload();
|
||||
deepUnload();
|
||||
root.runPreDecompileStageForClass(this);
|
||||
return decompile(false);
|
||||
}
|
||||
|
||||
|
||||
@@ -44,6 +44,7 @@ public class RootNode {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(RootNode.class);
|
||||
|
||||
private final JadxArgs args;
|
||||
private final List<IDexTreeVisitor> preDecompilePasses;
|
||||
private final List<IDexTreeVisitor> passes;
|
||||
|
||||
private final ErrorsCounter errorsCounter = new ErrorsCounter();
|
||||
@@ -68,6 +69,7 @@ public class RootNode {
|
||||
|
||||
public RootNode(JadxArgs args) {
|
||||
this.args = args;
|
||||
this.preDecompilePasses = Jadx.getPreDecompilePassesList();
|
||||
this.passes = Jadx.getPassesList(args);
|
||||
this.stringUtils = new StringUtils(args);
|
||||
this.constValues = new ConstStorage(args);
|
||||
@@ -191,7 +193,7 @@ public class RootNode {
|
||||
}
|
||||
|
||||
public void runPreDecompileStage() {
|
||||
for (IDexTreeVisitor pass : Jadx.getPreDecompilePassesList()) {
|
||||
for (IDexTreeVisitor pass : preDecompilePasses) {
|
||||
try {
|
||||
pass.init(this);
|
||||
} catch (Exception e) {
|
||||
@@ -203,6 +205,12 @@ public class RootNode {
|
||||
}
|
||||
}
|
||||
|
||||
public void runPreDecompileStageForClass(ClassNode cls) {
|
||||
for (IDexTreeVisitor pass : preDecompilePasses) {
|
||||
DepthTraversal.visit(pass, cls);
|
||||
}
|
||||
}
|
||||
|
||||
public List<ClassNode> getClasses() {
|
||||
return classes;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import jadx.core.dex.nodes.parser.SignatureParser;
|
||||
import jadx.core.dex.nodes.utils.TypeUtils;
|
||||
import jadx.core.dex.visitors.typeinference.TypeCompareEnum;
|
||||
import jadx.core.utils.Utils;
|
||||
import jadx.core.utils.exceptions.JadxException;
|
||||
|
||||
import static java.util.Collections.unmodifiableList;
|
||||
|
||||
@@ -24,12 +25,10 @@ public class SignatureProcessor extends AbstractVisitor {
|
||||
@Override
|
||||
public void init(RootNode root) {
|
||||
this.root = root;
|
||||
for (ClassNode cls : this.root.getClasses()) {
|
||||
processCls(cls);
|
||||
}
|
||||
}
|
||||
|
||||
private void processCls(ClassNode cls) {
|
||||
@Override
|
||||
public boolean visit(ClassNode cls) throws JadxException {
|
||||
parseClassSignature(cls);
|
||||
for (FieldNode field : cls.getFields()) {
|
||||
parseFieldSignature(field);
|
||||
@@ -37,6 +36,7 @@ public class SignatureProcessor extends AbstractVisitor {
|
||||
for (MethodNode mth : cls.getMethods()) {
|
||||
parseMethodSignature(mth);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void parseClassSignature(ClassNode cls) {
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package jadx.tests.integration.rename;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jadx.core.dex.nodes.ClassNode;
|
||||
import jadx.tests.api.IntegrationTest;
|
||||
|
||||
import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat;
|
||||
|
||||
public class TestFieldWithGenericRename extends IntegrationTest {
|
||||
|
||||
public static class TestCls {
|
||||
List<String> list;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
ClassNode cls = getClassNode(TestCls.class);
|
||||
assertThat(cls.getCode()).containsOnlyOnce("List<String> list;");
|
||||
|
||||
cls.searchFieldByName("list").getFieldInfo().setAlias("listFieldRenamed");
|
||||
|
||||
assertThat(cls.reloadCode()).print().containsOnlyOnce("List<String> listFieldRenamed;");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user