Commit e5b84d94 authored by Skylot's avatar Skylot

core: fix types for constant replace

parent 22e9ac22
......@@ -279,10 +279,16 @@ public class ClassNode extends LineAttrNode implements ILoadable {
if (field == null && searchGlobal) {
field = dex.getConstFields().get(obj);
}
if (field == null && obj instanceof Integer) {
if (obj instanceof Integer) {
String str = dex.root().getResourcesNames().get(obj);
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;
......
......@@ -9,12 +9,14 @@ import jadx.core.dex.instructions.InvokeType;
import jadx.core.dex.instructions.args.ArgType;
import jadx.core.dex.instructions.args.InsnArg;
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.SSAVar;
import jadx.core.dex.nodes.BlockNode;
import jadx.core.dex.nodes.FieldNode;
import jadx.core.dex.nodes.InsnNode;
import jadx.core.dex.nodes.MethodNode;
import jadx.core.dex.visitors.typeinference.PostTypeInference;
import jadx.core.utils.InstructionRemover;
import jadx.core.utils.exceptions.JadxException;
......@@ -124,7 +126,13 @@ public class ConstInlinerVisitor extends AbstractVisitor {
fixTypes(mth, useInsn, litArg);
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) {
litArg.wrapInstruction(new IndexInsnNode(InsnType.SGET, f.getFieldInfo(), 0));
}
......@@ -138,6 +146,7 @@ public class ConstInlinerVisitor extends AbstractVisitor {
* but contains some expensive operations needed only after constant inline
*/
private static void fixTypes(MethodNode mth, InsnNode insn, LiteralArg litArg) {
PostTypeInference.process(mth, insn);
switch (insn.getType()) {
case CONST:
insn.getArg(0).merge(insn.getResult());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment