提交 e5b84d94 编写于 作者: S Skylot

core: fix types for constant replace

上级 22e9ac22
...@@ -279,10 +279,16 @@ public class ClassNode extends LineAttrNode implements ILoadable { ...@@ -279,10 +279,16 @@ public class ClassNode extends LineAttrNode implements ILoadable {
if (field == null && searchGlobal) { if (field == null && searchGlobal) {
field = dex.getConstFields().get(obj); field = dex.getConstFields().get(obj);
} }
if (field == null && obj instanceof Integer) { if (obj instanceof Integer) {
String str = dex.root().getResourcesNames().get(obj); String str = dex.root().getResourcesNames().get(obj);
if (str != null) { if (str != null) {
return new ResRefField(dex, str.replace('/', '.')); ResRefField resField = new ResRefField(dex, str.replace('/', '.'));
if (field == null) {
return resField;
}
if (!field.getName().equals(resField.getName())) {
field = resField;
}
} }
} }
return field; return field;
......
...@@ -9,12 +9,14 @@ import jadx.core.dex.instructions.InvokeType; ...@@ -9,12 +9,14 @@ import jadx.core.dex.instructions.InvokeType;
import jadx.core.dex.instructions.args.ArgType; import jadx.core.dex.instructions.args.ArgType;
import jadx.core.dex.instructions.args.InsnArg; import jadx.core.dex.instructions.args.InsnArg;
import jadx.core.dex.instructions.args.LiteralArg; import jadx.core.dex.instructions.args.LiteralArg;
import jadx.core.dex.instructions.args.PrimitiveType;
import jadx.core.dex.instructions.args.RegisterArg; import jadx.core.dex.instructions.args.RegisterArg;
import jadx.core.dex.instructions.args.SSAVar; import jadx.core.dex.instructions.args.SSAVar;
import jadx.core.dex.nodes.BlockNode; import jadx.core.dex.nodes.BlockNode;
import jadx.core.dex.nodes.FieldNode; import jadx.core.dex.nodes.FieldNode;
import jadx.core.dex.nodes.InsnNode; import jadx.core.dex.nodes.InsnNode;
import jadx.core.dex.nodes.MethodNode; import jadx.core.dex.nodes.MethodNode;
import jadx.core.dex.visitors.typeinference.PostTypeInference;
import jadx.core.utils.InstructionRemover; import jadx.core.utils.InstructionRemover;
import jadx.core.utils.exceptions.JadxException; import jadx.core.utils.exceptions.JadxException;
...@@ -124,7 +126,13 @@ public class ConstInlinerVisitor extends AbstractVisitor { ...@@ -124,7 +126,13 @@ public class ConstInlinerVisitor extends AbstractVisitor {
fixTypes(mth, useInsn, litArg); fixTypes(mth, useInsn, litArg);
replaceCount++; replaceCount++;
FieldNode f = mth.getParentClass().getConstFieldByLiteralArg(litArg); FieldNode f = null;
ArgType litArgType = litArg.getType();
if (litArgType.isTypeKnown()) {
f = mth.getParentClass().getConstFieldByLiteralArg(litArg);
} else if (litArgType.contains(PrimitiveType.INT)) {
f = mth.getParentClass().getConstField((int) literal, false);
}
if (f != null) { if (f != null) {
litArg.wrapInstruction(new IndexInsnNode(InsnType.SGET, f.getFieldInfo(), 0)); litArg.wrapInstruction(new IndexInsnNode(InsnType.SGET, f.getFieldInfo(), 0));
} }
...@@ -138,6 +146,7 @@ public class ConstInlinerVisitor extends AbstractVisitor { ...@@ -138,6 +146,7 @@ public class ConstInlinerVisitor extends AbstractVisitor {
* but contains some expensive operations needed only after constant inline * but contains some expensive operations needed only after constant inline
*/ */
private static void fixTypes(MethodNode mth, InsnNode insn, LiteralArg litArg) { private static void fixTypes(MethodNode mth, InsnNode insn, LiteralArg litArg) {
PostTypeInference.process(mth, insn);
switch (insn.getType()) { switch (insn.getType()) {
case CONST: case CONST:
insn.getArg(0).merge(insn.getResult()); insn.getArg(0).merge(insn.getResult());
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册