提交 ca448fc4 编写于 作者: S Skylot

core: fix variable definitions for 'try' blocks

上级 7a51c0d0
......@@ -5,7 +5,7 @@ import jadx.core.dex.nodes.IRegion;
public abstract class AbstractRegion extends AttrNode implements IRegion {
private final IRegion parent;
private IRegion parent;
public AbstractRegion(IRegion parent) {
this.parent = parent;
......@@ -16,4 +16,7 @@ public abstract class AbstractRegion extends AttrNode implements IRegion {
return parent;
}
public void setParent(IRegion parent) {
this.parent = parent;
}
}
......@@ -5,6 +5,7 @@ import jadx.core.dex.nodes.BlockNode;
import jadx.core.dex.nodes.IContainer;
import jadx.core.dex.nodes.IRegion;
import jadx.core.dex.nodes.MethodNode;
import jadx.core.dex.regions.AbstractRegion;
import jadx.core.dex.regions.Region;
import jadx.core.dex.trycatch.CatchAttr;
import jadx.core.dex.trycatch.ExceptionHandler;
......@@ -144,6 +145,14 @@ public class ProcessTryCatchRegions extends AbstractRegionVisitor {
region.getSubBlocks().removeAll(newRegion.getSubBlocks());
newRegion.getAttributes().add(tb.getCatchAttr());
// fix parents
for (IContainer cont : newRegion.getSubBlocks()) {
if (cont instanceof AbstractRegion) {
AbstractRegion aReg = (AbstractRegion) cont;
aReg.setParent(newRegion);
}
}
}
}
......
......@@ -60,7 +60,7 @@ public class ProcessVariables extends AbstractVisitor {
@Override
public String toString() {
return arg + " " + assigns + " " + usage;
return arg + ", a:" + assigns + ", u:" + usage;
}
}
......
......@@ -6,10 +6,16 @@ import jadx.core.dex.visitors.DepthTraverser;
import jadx.core.dex.visitors.IDexTreeVisitor;
import jadx.core.utils.exceptions.DecodeException;
import java.util.Iterator;
import java.util.List;
import org.junit.Test;
import org.slf4j.Logger;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertThat;
public class TestVariablesDefinitions extends InternalJadxTest {
public static class TestCls {
......@@ -20,23 +26,24 @@ public class TestVariablesDefinitions extends InternalJadxTest {
public void run() {
try {
cls.load();
for (IDexTreeVisitor visitor : passes) {
DepthTraverser.visit(visitor, cls);
Iterator<IDexTreeVisitor> iterator = passes.iterator();
while (iterator.hasNext()) {
DepthTraverser.visit(iterator.next(), cls);
}
} catch (DecodeException e) {
LOG.error("Decode exception: " + cls, e);
} finally {
cls.unload();
}
}
}
//@Test
@Test
public void test() {
ClassNode cls = getClassNode(TestCls.class);
String code = cls.getCode().toString();
System.out.println(code);
// 'iterator' variable must be declared inside 'try' block
assertThat(code, containsString(makeIndent(3) + "Iterator<IDexTreeVisitor> iterator = "));
assertThat(code, not(containsString("iterator;")));
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册