Commit 380ee75d authored by Skylot's avatar Skylot

core: fix constants replace for constructors and other instructions

parent 99d98140
......@@ -297,19 +297,21 @@ public class ClassNode extends LineAttrNode implements ILoadable {
case BOOLEAN:
return getConstField(literal == 1, false);
case CHAR:
return getConstField((char) literal, Math.abs(literal) > 1);
return getConstField((char) literal, Math.abs(literal) > 10);
case BYTE:
return getConstField((byte) literal, Math.abs(literal) > 1);
return getConstField((byte) literal, Math.abs(literal) > 10);
case SHORT:
return getConstField((short) literal, Math.abs(literal) > 1);
return getConstField((short) literal, Math.abs(literal) > 100);
case INT:
return getConstField((int) literal, Math.abs(literal) > 1);
return getConstField((int) literal, Math.abs(literal) > 100);
case LONG:
return getConstField(literal, Math.abs(literal) > 1);
return getConstField(literal, Math.abs(literal) > 1000);
case FLOAT:
return getConstField(Float.intBitsToFloat((int) literal), true);
float f = Float.intBitsToFloat((int) literal);
return getConstField(f, f != 0.0);
case DOUBLE:
return getConstField(Double.longBitsToDouble(literal), true);
double d = Double.longBitsToDouble(literal);
return getConstField(d, d != 0);
}
return null;
}
......
......@@ -12,6 +12,7 @@ import jadx.core.dex.instructions.args.LiteralArg;
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.utils.InstructionRemover;
......@@ -103,7 +104,7 @@ public class ConstInlinerVisitor extends AbstractVisitor {
// continue;
// }
InsnNode useInsn = arg.getParentInsn();
if (useInsn.getType() == InsnType.PHI) {
if (useInsn == null || useInsn.getType() == InsnType.PHI) {
continue;
}
LiteralArg litArg;
......@@ -122,6 +123,11 @@ public class ConstInlinerVisitor extends AbstractVisitor {
if (useInsn.replaceArg(arg, litArg)) {
fixTypes(mth, useInsn, litArg);
replaceCount++;
FieldNode f = mth.getParentClass().getConstFieldByLiteralArg(litArg);
if (f != null) {
litArg.wrapInstruction(new IndexInsnNode(InsnType.SGET, f.getFieldInfo(), 0));
}
}
}
return replaceCount == use.size();
......
......@@ -165,16 +165,6 @@ public class ModVisitor extends AbstractVisitor {
replaceInsn(block, insnNumber, replace);
}
}
} else if (inv.getArgsCount() > 0) {
for (int j = 0; j < inv.getArgsCount(); j++) {
InsnArg arg = inv.getArg(j);
if (arg.isLiteral()) {
FieldNode f = parentClass.getConstFieldByLiteralArg((LiteralArg) arg);
if (f != null) {
arg.wrapInstruction(new IndexInsnNode(InsnType.SGET, f.getFieldInfo(), 0));
}
}
}
}
}
......
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