提交 df115251 编写于 作者: S Skylot

core: print original value near replaced with field value in switch

上级 02f9c25f
...@@ -5,8 +5,6 @@ import jadx.core.dex.attributes.AType; ...@@ -5,8 +5,6 @@ import jadx.core.dex.attributes.AType;
import jadx.core.dex.attributes.nodes.DeclareVariablesAttr; import jadx.core.dex.attributes.nodes.DeclareVariablesAttr;
import jadx.core.dex.attributes.nodes.ForceReturnAttr; import jadx.core.dex.attributes.nodes.ForceReturnAttr;
import jadx.core.dex.attributes.nodes.LoopLabelAttr; import jadx.core.dex.attributes.nodes.LoopLabelAttr;
import jadx.core.dex.info.FieldInfo;
import jadx.core.dex.instructions.IndexInsnNode;
import jadx.core.dex.instructions.SwitchNode; import jadx.core.dex.instructions.SwitchNode;
import jadx.core.dex.instructions.args.InsnArg; import jadx.core.dex.instructions.args.InsnArg;
import jadx.core.dex.instructions.args.NamedArg; import jadx.core.dex.instructions.args.NamedArg;
...@@ -17,6 +15,7 @@ import jadx.core.dex.nodes.IBlock; ...@@ -17,6 +15,7 @@ import jadx.core.dex.nodes.IBlock;
import jadx.core.dex.nodes.IContainer; import jadx.core.dex.nodes.IContainer;
import jadx.core.dex.nodes.IRegion; import jadx.core.dex.nodes.IRegion;
import jadx.core.dex.nodes.InsnNode; import jadx.core.dex.nodes.InsnNode;
import jadx.core.dex.nodes.parser.FieldValueAttr;
import jadx.core.dex.regions.Region; import jadx.core.dex.regions.Region;
import jadx.core.dex.regions.SwitchRegion; import jadx.core.dex.regions.SwitchRegion;
import jadx.core.dex.regions.SynchronizedRegion; import jadx.core.dex.regions.SynchronizedRegion;
...@@ -249,11 +248,16 @@ public class RegionGen extends InsnGen { ...@@ -249,11 +248,16 @@ public class RegionGen extends InsnGen {
code.add(fn.getName()); code.add(fn.getName());
} else { } else {
staticField(code, fn.getFieldInfo()); staticField(code, fn.getFieldInfo());
// print original value, sometimes replace with incorrect field
FieldValueAttr valueAttr = fn.get(AType.FIELD_VALUE);
if (valueAttr != null && valueAttr.getValue() != null) {
code.add(" /*").add(valueAttr.getValue().toString()).add("*/");
}
} }
} else if (k instanceof IndexInsnNode) { } else if (k instanceof Integer) {
staticField(code, (FieldInfo) ((IndexInsnNode) k).getIndex());
} else {
code.add(TypeGen.literalToString((Integer) k, arg.getType())); code.add(TypeGen.literalToString((Integer) k, arg.getType()));
} else {
throw new JadxRuntimeException("Unexpected key in switch: " + (k != null ? k.getClass() : k));
} }
code.add(':'); code.add(':');
} }
......
...@@ -90,7 +90,7 @@ public class ModVisitor extends AbstractVisitor { ...@@ -90,7 +90,7 @@ public class ModVisitor extends AbstractVisitor {
for (int k = 0; k < sn.getCasesCount(); k++) { for (int k = 0; k < sn.getCasesCount(); k++) {
FieldNode f = parentClass.getConstField(sn.getKeys()[k]); FieldNode f = parentClass.getConstField(sn.getKeys()[k]);
if (f != null) { if (f != null) {
sn.getKeys()[k] = new IndexInsnNode(InsnType.SGET, f.getFieldInfo(), 0); sn.getKeys()[k] = f;
} }
} }
break; break;
......
...@@ -38,11 +38,11 @@ public class TestSwitchLabels extends IntegrationTest { ...@@ -38,11 +38,11 @@ public class TestSwitchLabels extends IntegrationTest {
public void test() { public void test() {
ClassNode cls = getClassNode(TestCls.class); ClassNode cls = getClassNode(TestCls.class);
String code = cls.getCode().toString(); String code = cls.getCode().toString();
assertThat(code, containsString("case CONST_ABC:")); assertThat(code, containsString("case CONST_ABC"));
assertThat(code, containsString("return CONST_CDE;")); assertThat(code, containsString("return CONST_CDE;"));
cls.addInnerClass(getClassNode(TestCls.Inner.class)); cls.addInnerClass(getClassNode(TestCls.Inner.class));
assertThat(code, containsString("case CONST_CDE_PRIVATE:")); assertThat(code, containsString("case CONST_CDE_PRIVATE"));
assertThat(code, containsString(".CONST_ABC;")); assertThat(code, containsString(".CONST_ABC;"));
} }
} }
...@@ -11,6 +11,7 @@ import static org.junit.Assert.assertThat; ...@@ -11,6 +11,7 @@ import static org.junit.Assert.assertThat;
public class TestSwitchWithFallThroughCase extends IntegrationTest { public class TestSwitchWithFallThroughCase extends IntegrationTest {
@SuppressWarnings("fallthrough")
public static class TestCls { public static class TestCls {
public String test(int a, boolean b, boolean c) { public String test(int a, boolean b, boolean c) {
String str = ""; String str = "";
......
...@@ -11,6 +11,7 @@ import static org.junit.Assert.assertThat; ...@@ -11,6 +11,7 @@ import static org.junit.Assert.assertThat;
public class TestSwitchWithFallThroughCase2 extends IntegrationTest { public class TestSwitchWithFallThroughCase2 extends IntegrationTest {
@SuppressWarnings("fallthrough")
public static class TestCls { public static class TestCls {
public String test(int a, boolean b, boolean c) { public String test(int a, boolean b, boolean c) {
String str = ""; String str = "";
...@@ -56,7 +57,6 @@ public class TestSwitchWithFallThroughCase2 extends IntegrationTest { ...@@ -56,7 +57,6 @@ public class TestSwitchWithFallThroughCase2 extends IntegrationTest {
@Test @Test
public void test() { public void test() {
setOutputCFG();
ClassNode cls = getClassNode(TestCls.class); ClassNode cls = getClassNode(TestCls.class);
String code = cls.getCode().toString(); String code = cls.getCode().toString();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册