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