core: print original value near replaced with field value in switch
This commit is contained in:
@@ -5,8 +5,6 @@ import jadx.core.dex.attributes.AType;
|
||||
import jadx.core.dex.attributes.nodes.DeclareVariablesAttr;
|
||||
import jadx.core.dex.attributes.nodes.ForceReturnAttr;
|
||||
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.args.InsnArg;
|
||||
import jadx.core.dex.instructions.args.NamedArg;
|
||||
@@ -17,6 +15,7 @@ import jadx.core.dex.nodes.IBlock;
|
||||
import jadx.core.dex.nodes.IContainer;
|
||||
import jadx.core.dex.nodes.IRegion;
|
||||
import jadx.core.dex.nodes.InsnNode;
|
||||
import jadx.core.dex.nodes.parser.FieldValueAttr;
|
||||
import jadx.core.dex.regions.Region;
|
||||
import jadx.core.dex.regions.SwitchRegion;
|
||||
import jadx.core.dex.regions.SynchronizedRegion;
|
||||
@@ -249,11 +248,16 @@ public class RegionGen extends InsnGen {
|
||||
code.add(fn.getName());
|
||||
} else {
|
||||
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) {
|
||||
staticField(code, (FieldInfo) ((IndexInsnNode) k).getIndex());
|
||||
} else {
|
||||
} else if (k instanceof Integer) {
|
||||
code.add(TypeGen.literalToString((Integer) k, arg.getType()));
|
||||
} else {
|
||||
throw new JadxRuntimeException("Unexpected key in switch: " + (k != null ? k.getClass() : k));
|
||||
}
|
||||
code.add(':');
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ public class ModVisitor extends AbstractVisitor {
|
||||
for (int k = 0; k < sn.getCasesCount(); k++) {
|
||||
FieldNode f = parentClass.getConstField(sn.getKeys()[k]);
|
||||
if (f != null) {
|
||||
sn.getKeys()[k] = new IndexInsnNode(InsnType.SGET, f.getFieldInfo(), 0);
|
||||
sn.getKeys()[k] = f;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -38,11 +38,11 @@ public class TestSwitchLabels extends IntegrationTest {
|
||||
public void test() {
|
||||
ClassNode cls = getClassNode(TestCls.class);
|
||||
String code = cls.getCode().toString();
|
||||
assertThat(code, containsString("case CONST_ABC:"));
|
||||
assertThat(code, containsString("case CONST_ABC"));
|
||||
assertThat(code, containsString("return CONST_CDE;"));
|
||||
|
||||
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;"));
|
||||
}
|
||||
}
|
||||
|
||||
+1
@@ -11,6 +11,7 @@ import static org.junit.Assert.assertThat;
|
||||
|
||||
public class TestSwitchWithFallThroughCase extends IntegrationTest {
|
||||
|
||||
@SuppressWarnings("fallthrough")
|
||||
public static class TestCls {
|
||||
public String test(int a, boolean b, boolean c) {
|
||||
String str = "";
|
||||
|
||||
+1
-1
@@ -11,6 +11,7 @@ import static org.junit.Assert.assertThat;
|
||||
|
||||
public class TestSwitchWithFallThroughCase2 extends IntegrationTest {
|
||||
|
||||
@SuppressWarnings("fallthrough")
|
||||
public static class TestCls {
|
||||
public String test(int a, boolean b, boolean c) {
|
||||
String str = "";
|
||||
@@ -56,7 +57,6 @@ public class TestSwitchWithFallThroughCase2 extends IntegrationTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
setOutputCFG();
|
||||
ClassNode cls = getClassNode(TestCls.class);
|
||||
String code = cls.getCode().toString();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user