Search in sources :

Example 1 with IntInsnNode

use of org.objectweb.asm.tree.IntInsnNode in project enumerable by hraberg.

the class ExpressionInterpreter method newOperation.

public Value newOperation(final AbstractInsnNode insn) throws AnalyzerException {
    switch(insn.getOpcode()) {
        case ACONST_NULL:
            return new ExpressionValue(createClassOrInterfaceType(Object.class.getName()), new NullLiteralExpr());
        case ICONST_M1:
            return new ExpressionValue(PRIMITIVE_INT, new UnaryExpr(new IntegerLiteralExpr("1"), UnaryExpr.Operator.negative));
        case ICONST_0:
            return new ExpressionValue(PRIMITIVE_INT, new IntegerLiteralExpr("0"));
        case ICONST_1:
            return new ExpressionValue(PRIMITIVE_INT, new IntegerLiteralExpr("1"));
        case ICONST_2:
            return new ExpressionValue(PRIMITIVE_INT, new IntegerLiteralExpr("2"));
        case ICONST_3:
            return new ExpressionValue(PRIMITIVE_INT, new IntegerLiteralExpr("3"));
        case ICONST_4:
            return new ExpressionValue(PRIMITIVE_INT, new IntegerLiteralExpr("4"));
        case ICONST_5:
            return new ExpressionValue(PRIMITIVE_INT, new IntegerLiteralExpr("5"));
        case LCONST_0:
            return new ExpressionValue(PRIMITIVE_LONG, new LongLiteralExpr("0L"));
        case LCONST_1:
            return new ExpressionValue(PRIMITIVE_LONG, new LongLiteralExpr("1L"));
        case FCONST_0:
            return new ExpressionValue(PRIMITIVE_FLOAT, new DoubleLiteralExpr("0.0f"));
        case FCONST_1:
            return new ExpressionValue(PRIMITIVE_FLOAT, new DoubleLiteralExpr("1.0f"));
        case FCONST_2:
            return new ExpressionValue(PRIMITIVE_FLOAT, new DoubleLiteralExpr("2.0f"));
        case DCONST_0:
            return new ExpressionValue(PRIMITIVE_DOUBLE, new DoubleLiteralExpr("0.0"));
        case DCONST_1:
            return new ExpressionValue(PRIMITIVE_DOUBLE, new DoubleLiteralExpr("1.0"));
        case BIPUSH:
        case SIPUSH:
            int operand = ((IntInsnNode) insn).operand;
            if (operand < 0)
                return new ExpressionValue(PRIMITIVE_INT, new UnaryExpr(new IntegerLiteralExpr("" + Math.abs(operand)), UnaryExpr.Operator.negative));
            return new ExpressionValue(PRIMITIVE_INT, new IntegerLiteralExpr("" + operand));
        case LDC:
            Object cst = ((LdcInsnNode) insn).cst;
            if (cst instanceof Number) {
                ExpressionValue value = null;
                if (cst instanceof Integer) {
                    value = new ExpressionValue(PRIMITIVE_INT, new IntegerLiteralExpr(cst.toString()));
                } else if (cst instanceof Float) {
                    value = new ExpressionValue(PRIMITIVE_FLOAT, new DoubleLiteralExpr(cst.toString() + "f"));
                } else if (cst instanceof Long) {
                    value = new ExpressionValue(PRIMITIVE_LONG, new LongLiteralExpr(cst.toString() + "L"));
                } else if (cst instanceof Double) {
                    value = new ExpressionValue(PRIMITIVE_DOUBLE, new DoubleLiteralExpr(cst.toString()));
                }
                if (((Number) cst).intValue() < 0) {
                    StringLiteralExpr expr = (StringLiteralExpr) value.expression;
                    expr.setValue(expr.getValue().substring("-".length()));
                    value.expression = new UnaryExpr(expr, UnaryExpr.Operator.negative);
                }
                return value;
            } else if (cst instanceof Type) {
                ClassExpr classExpr = new ClassExpr(new ReferenceType(createClassOrInterfaceType(((Type) cst).getClassName())));
                return new ExpressionValue(createClassOrInterfaceType(Class.class.getName()), classExpr);
            } else {
                return new ExpressionValue(createClassOrInterfaceType(String.class.getName()), new StringLiteralExpr(cst.toString()));
            }
        case JSR:
            throw new UnsupportedOperationException(AbstractVisitor.OPCODES[insn.getOpcode()]);
        case GETSTATIC:
            FieldInsnNode fieldNode = (FieldInsnNode) insn;
            ExpressionValue getField = (ExpressionValue) newValue(getType(fieldNode.desc));
            getField.expression = new FieldAccessExpr(new NameExpr(removeJavaLang(getObjectType(fieldNode.owner).getClassName())), fieldNode.name);
            return getField;
        case NEW:
            return newValue(Type.getObjectType(((TypeInsnNode) insn).desc));
        default:
            throw new Error("Internal error.");
    }
}
Also used : IntInsnNode(org.objectweb.asm.tree.IntInsnNode) TypeInsnNode(org.objectweb.asm.tree.TypeInsnNode) ReferenceType(japa.parser.ast.type.ReferenceType) LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) FieldInsnNode(org.objectweb.asm.tree.FieldInsnNode) Type(org.objectweb.asm.Type) ClassOrInterfaceType(japa.parser.ast.type.ClassOrInterfaceType) ReferenceType(japa.parser.ast.type.ReferenceType) PrimitiveType(japa.parser.ast.type.PrimitiveType)

Example 2 with IntInsnNode

use of org.objectweb.asm.tree.IntInsnNode in project bytecode-viewer by Konloch.

the class NumberNode method setNumber.

public void setNumber(int number) {
    AbstractInsnNode ain = insn();
    if (ain instanceof IntInsnNode) {
        ((IntInsnNode) insn()).operand = number;
        ((IntInsnNode) ain).operand = number;
    } else if (ain instanceof LdcInsnNode) {
        ((LdcInsnNode) insn()).cst = number;
        ((LdcInsnNode) ain).cst = number;
    }
}
Also used : LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) IntInsnNode(org.objectweb.asm.tree.IntInsnNode) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode)

Example 3 with IntInsnNode

use of org.objectweb.asm.tree.IntInsnNode in project phosphor by gmu-swe.

the class InstMethodSinkInterpreter method _unaryOperation.

private BasicValue _unaryOperation(AbstractInsnNode insn, BasicValue value) throws AnalyzerException {
    switch(insn.getOpcode()) {
        case INEG:
        case IINC:
        case L2I:
        case F2I:
        case D2I:
        case I2B:
        case I2C:
        case I2S:
            SinkableArrayValue ret = new SinkableArrayValue(Type.INT_TYPE);
            ret.addDep((SinkableArrayValue) value);
            return ret;
        case FNEG:
        case I2F:
        case L2F:
        case D2F:
            ret = new SinkableArrayValue(Type.FLOAT_TYPE);
            ret.addDep((SinkableArrayValue) value);
            return ret;
        case LNEG:
        case I2L:
        case F2L:
        case D2L:
            ret = new SinkableArrayValue(Type.LONG_TYPE);
            ret.addDep((SinkableArrayValue) value);
            return ret;
        case DNEG:
        case I2D:
        case L2D:
        case F2D:
            ret = new SinkableArrayValue(Type.DOUBLE_TYPE);
            ret.addDep((SinkableArrayValue) value);
            return ret;
        case IFEQ:
        case IFNE:
        case IFLT:
        case IFGE:
        case IFGT:
        case IFLE:
        case TABLESWITCH:
        case LOOKUPSWITCH:
            return null;
        case IRETURN:
        case LRETURN:
        case FRETURN:
        case DRETURN:
        case ARETURN:
        case PUTSTATIC:
            return null;
        case GETFIELD:
            return newValue(Type.getType(((FieldInsnNode) insn).desc));
        case NEWARRAY:
            ret = null;
            switch(((IntInsnNode) insn).operand) {
                case T_BOOLEAN:
                    ret = (SinkableArrayValue) newValue(Type.getType("[Z"));
                    break;
                case T_CHAR:
                    ret = (SinkableArrayValue) newValue(Type.getType("[C"));
                    break;
                case T_BYTE:
                    ret = (SinkableArrayValue) newValue(Type.getType("[B"));
                    break;
                case T_SHORT:
                    ret = (SinkableArrayValue) newValue(Type.getType("[S"));
                    break;
                case T_INT:
                    ret = (SinkableArrayValue) newValue(Type.getType("[I"));
                    break;
                case T_FLOAT:
                    ret = (SinkableArrayValue) newValue(Type.getType("[F"));
                    break;
                case T_DOUBLE:
                    ret = (SinkableArrayValue) newValue(Type.getType("[D"));
                    break;
                case T_LONG:
                    ret = (SinkableArrayValue) newValue(Type.getType("[J"));
                    break;
                default:
                    throw new AnalyzerException(insn, "Invalid array type");
            }
            if (Configuration.ARRAY_LENGTH_TRACKING)
                ret.addDep((SinkableArrayValue) value);
            ret.isNewArray = true;
            return ret;
        case ANEWARRAY:
            String desc = ((TypeInsnNode) insn).desc;
            return newValue(Type.getType("[" + Type.getObjectType(desc)));
        case ARRAYLENGTH:
            ret = (SinkableArrayValue) newValue(Type.INT_TYPE);
            if (value instanceof SinkableArrayValue && value.getType() != null && TaintUtils.isPrimitiveArrayType(value.getType()))
                ret.addDep((SinkableArrayValue) value);
            return ret;
        case ATHROW:
            return null;
        case CHECKCAST:
            desc = ((TypeInsnNode) insn).desc;
            BasicValue _ret = newValue(Type.getObjectType(desc));
            if (value instanceof SinkableArrayValue) {
                if ((_ret instanceof SinkableArrayValue))
                    ((SinkableArrayValue) _ret).addDep((SinkableArrayValue) value);
            }
            return _ret;
        case INSTANCEOF:
            return newValue(Type.INT_TYPE);
        case MONITORENTER:
        case MONITOREXIT:
        case IFNULL:
        case IFNONNULL:
            return null;
        default:
            throw new Error("Internal error.");
    }
}
Also used : AnalyzerException(org.objectweb.asm.tree.analysis.AnalyzerException) FieldInsnNode(org.objectweb.asm.tree.FieldInsnNode) IntInsnNode(org.objectweb.asm.tree.IntInsnNode) TypeInsnNode(org.objectweb.asm.tree.TypeInsnNode) BasicValue(org.objectweb.asm.tree.analysis.BasicValue)

Example 4 with IntInsnNode

use of org.objectweb.asm.tree.IntInsnNode in project runelite by runelite.

the class InstructionDeserializer method deserialize.

@Override
public AbstractInsnNode deserialize(JsonElement var1, Type var2, JsonDeserializationContext var3) {
    JsonObject var4 = (JsonObject) var1;
    int var5 = var4.get("opcode").getAsInt();
    if (var5 != 21 && var5 != 25 && var5 != 58 && var5 != 54 && var5 != 22 && var5 != 55) {
        String var7;
        String var8;
        String var10;
        if (var5 != 184 && var5 != 182 && var5 != 183) {
            if (var5 == 18) {
                try {
                    return new LdcInsnNode(Integer.valueOf(var4.get("cst").getAsInt()));
                } catch (Exception var9) {
                    return new LdcInsnNode(var4.get("cst").getAsString());
                }
            } else if (var5 != 187 && var5 != 189) {
                if (var5 != 16 && var5 != 17) {
                    if (var5 != 179 && var5 != 178 && var5 != 180 && var5 != 181) {
                        return new InsnNode(var5);
                    } else {
                        var10 = var4.get("owner").getAsString();
                        var7 = var4.get("name").getAsString();
                        var8 = var4.get("desc").getAsString();
                        return new FieldInsnNode(var5, var10, var7, var8);
                    }
                } else {
                    return new IntInsnNode(var5, var4.get("operand").getAsInt());
                }
            } else {
                return new TypeInsnNode(var5, var4.get("desc").getAsString());
            }
        } else {
            var10 = var4.get("owner").getAsString();
            var7 = var4.get("name").getAsString();
            var8 = var4.get("desc").getAsString();
            return new MethodInsnNode(var5, var10, var7, var8);
        }
    } else {
        int var6 = var4.get("var").getAsInt();
        return new VarInsnNode(var5, var6);
    }
}
Also used : FieldInsnNode(org.objectweb.asm.tree.FieldInsnNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) IntInsnNode(org.objectweb.asm.tree.IntInsnNode) LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) TypeInsnNode(org.objectweb.asm.tree.TypeInsnNode) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) VarInsnNode(org.objectweb.asm.tree.VarInsnNode) InsnNode(org.objectweb.asm.tree.InsnNode) LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) JsonObject(com.google.gson.JsonObject) FieldInsnNode(org.objectweb.asm.tree.FieldInsnNode) IntInsnNode(org.objectweb.asm.tree.IntInsnNode) TypeInsnNode(org.objectweb.asm.tree.TypeInsnNode) VarInsnNode(org.objectweb.asm.tree.VarInsnNode)

Example 5 with IntInsnNode

use of org.objectweb.asm.tree.IntInsnNode in project DynamicSurroundings by OreCruncher.

the class PatchSoundManagerPlayTime method transmorgrify.

@Override
public boolean transmorgrify(final ClassNode cn) {
    final String[] names = { "playSound", "func_148611_c" };
    final String sig = "(Lnet/minecraft/client/audio/ISound;)V";
    final MethodNode m = findMethod(cn, sig, names);
    if (m != null) {
        logMethod(Transformer.log(), m, "Found!");
        for (int i = 0; i < m.instructions.size(); i++) {
            final AbstractInsnNode node = m.instructions.get(i);
            if (node instanceof IntInsnNode) {
                final IntInsnNode intNode = (IntInsnNode) node;
                if (intNode.operand == 20) {
                    m.instructions.set(node, new IntInsnNode(Opcodes.BIPUSH, 0));
                    return true;
                }
            }
        }
    } else {
        Transformer.log().error("Unable to locate method {}{}", names[0], sig);
    }
    Transformer.log().info("Unable to patch [{}]!", getClassName());
    return false;
}
Also used : MethodNode(org.objectweb.asm.tree.MethodNode) IntInsnNode(org.objectweb.asm.tree.IntInsnNode) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode)

Aggregations

IntInsnNode (org.objectweb.asm.tree.IntInsnNode)15 FieldInsnNode (org.objectweb.asm.tree.FieldInsnNode)7 LdcInsnNode (org.objectweb.asm.tree.LdcInsnNode)7 MethodInsnNode (org.objectweb.asm.tree.MethodInsnNode)7 TypeInsnNode (org.objectweb.asm.tree.TypeInsnNode)7 AbstractInsnNode (org.objectweb.asm.tree.AbstractInsnNode)6 InsnNode (org.objectweb.asm.tree.InsnNode)5 VarInsnNode (org.objectweb.asm.tree.VarInsnNode)4 IincInsnNode (org.objectweb.asm.tree.IincInsnNode)3 JumpInsnNode (org.objectweb.asm.tree.JumpInsnNode)3 MultiANewArrayInsnNode (org.objectweb.asm.tree.MultiANewArrayInsnNode)3 JsonObject (com.google.gson.JsonObject)2 PrimitiveType (japa.parser.ast.type.PrimitiveType)2 ReferenceType (japa.parser.ast.type.ReferenceType)2 ArrayList (java.util.ArrayList)2 Label (org.objectweb.asm.Label)2 FrameNode (org.objectweb.asm.tree.FrameNode)2 LabelNode (org.objectweb.asm.tree.LabelNode)2 TryCatchBlockNode (org.objectweb.asm.tree.TryCatchBlockNode)2 AnalyzerException (org.objectweb.asm.tree.analysis.AnalyzerException)2