Search in sources :

Example 41 with JumpInsnNode

use of org.objectweb.asm.tree.JumpInsnNode in project Random-Things by lumien231.

the class ClassTransformer method patchInventoryPlayer.

private byte[] patchInventoryPlayer(byte[] basicClass) {
    ClassNode classNode = new ClassNode();
    ClassReader classReader = new ClassReader(basicClass);
    classReader.accept(classNode, 0);
    logger.log(Level.DEBUG, "Found InventoryPlayer Class: " + classNode.name);
    MethodNode dropAllItems = null;
    for (MethodNode mn : classNode.methods) {
        if (mn.name.equals(MCPNames.method("func_70436_m"))) {
            dropAllItems = mn;
            break;
        }
    }
    if (dropAllItems != null) {
        logger.log(Level.DEBUG, " - Found dropAllItems (1/2)");
        for (int i = 0; i < dropAllItems.instructions.size(); i++) {
            AbstractInsnNode ain = dropAllItems.instructions.get(i);
            if (ain instanceof JumpInsnNode) {
                JumpInsnNode jin = (JumpInsnNode) ain;
                if (jin.getOpcode() == Opcodes.IFNE) {
                    AbstractInsnNode before = dropAllItems.instructions.get(i - 1);
                    if (before instanceof MethodInsnNode && ((MethodInsnNode) before).name.equals(MCPNames.method("func_190926_b"))) {
                        LabelNode l0 = jin.label;
                        InsnList toInsert = new InsnList();
                        toInsert.add(new VarInsnNode(ALOAD, 0));
                        toInsert.add(new VarInsnNode(ILOAD, 3));
                        toInsert.add(new VarInsnNode(ALOAD, 4));
                        toInsert.add(new MethodInsnNode(Opcodes.INVOKESTATIC, asmHandler, "shouldPlayerDrop", "(Lnet/minecraft/entity/player/InventoryPlayer;ILnet/minecraft/item/ItemStack;)Z", false));
                        toInsert.add(new JumpInsnNode(IFEQ, l0));
                        dropAllItems.instructions.insert(jin, toInsert);
                        i += 5;
                        logger.log(Level.DEBUG, " - Patched dropAllItems (2/2)");
                    }
                }
            }
        }
    }
    CustomClassWriter writer = new CustomClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
    classNode.accept(writer);
    return writer.toByteArray();
}
Also used : LabelNode(org.objectweb.asm.tree.LabelNode) ClassNode(org.objectweb.asm.tree.ClassNode) MethodNode(org.objectweb.asm.tree.MethodNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) ClassReader(org.objectweb.asm.ClassReader) JumpInsnNode(org.objectweb.asm.tree.JumpInsnNode) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) InsnList(org.objectweb.asm.tree.InsnList) VarInsnNode(org.objectweb.asm.tree.VarInsnNode)

Example 42 with JumpInsnNode

use of org.objectweb.asm.tree.JumpInsnNode in project maple-ir by LLVM-but-worse.

the class Subroutine method merge.

public boolean merge(final Subroutine subroutine) throws AnalyzerException {
    boolean changes = false;
    for (int i = 0; i < access.length; ++i) {
        if (subroutine.access[i] && !access[i]) {
            access[i] = true;
            changes = true;
        }
    }
    if (subroutine.start == start) {
        for (int i = 0; i < subroutine.callers.size(); ++i) {
            JumpInsnNode caller = subroutine.callers.get(i);
            if (!callers.contains(caller)) {
                callers.add(caller);
                changes = true;
            }
        }
    }
    return changes;
}
Also used : JumpInsnNode(org.objectweb.asm.tree.JumpInsnNode)

Example 43 with JumpInsnNode

use of org.objectweb.asm.tree.JumpInsnNode in project maple-ir by LLVM-but-worse.

the class JumpInsnNodeSerializer method deserialize.

@Override
public JumpInsnNode deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    JsonObject jsonObject = (JsonObject) json;
    int opcode = jsonObject.get("opcode").getAsInt();
    LabelNode labelNode = context.deserialize(jsonObject.get("local"), List.class);
    return new JumpInsnNode(opcode, labelNode);
}
Also used : LabelNode(org.objectweb.asm.tree.LabelNode) JsonObject(com.google.gson.JsonObject) JumpInsnNode(org.objectweb.asm.tree.JumpInsnNode)

Example 44 with JumpInsnNode

use of org.objectweb.asm.tree.JumpInsnNode in project jphp by jphp-compiler.

the class TryCatchCompiler method write.

@Override
public void write(TryStmtToken token) {
    if (token.getBody() == null || token.getBody().getInstructions().isEmpty()) {
        if (token.getFinally() != null)
            expr.write(BodyStmtToken.class, token.getFinally());
        return;
    }
    expr.writeDefineVariables(token.getLocal());
    LabelNode tryStart = expr.writeLabel(node, token.getMeta().getStartLine());
    LabelNode tryEnd = new LabelNode();
    LabelNode catchStart = new LabelNode();
    LabelNode catchEnd = new LabelNode();
    LabelNode returnLabel = new LabelNode();
    method.node.tryCatchBlocks.add(0, new TryCatchBlockNode(tryStart, tryEnd, catchStart, Type.getInternalName(BaseBaseException.class)));
    if (token.getFinally() != null) {
        method.getTryStack().push(new MethodStmtCompiler.TryCatchItem(token, returnLabel));
    }
    expr.write(BodyStmtToken.class, token.getBody());
    if (token.getFinally() != null) {
        method.getTryStack().pop();
    }
    add(tryEnd);
    add(new JumpInsnNode(GOTO, catchEnd));
    add(catchStart);
    LocalVariable exception = method.addLocalVariable("~catch~" + method.nextStatementIndex(BaseException.class), catchStart, BaseBaseException.class);
    exception.setEndLabel(catchEnd);
    expr.makeVarStore(exception);
    LabelNode nextCatch = null;
    int i = 0, size = token.getCatches().size();
    LocalVariable local = null;
    LabelNode catchFail = new LabelNode();
    for (CatchStmtToken _catch : token.getCatches()) {
        if (nextCatch != null) {
            add(nextCatch);
        }
        if (i == size - 1) {
            nextCatch = catchFail;
        } else {
            nextCatch = new LabelNode();
        }
        local = method.getLocalVariable(_catch.getVariable().getName());
        List<FulledNameToken> catchExceptions = _catch.getExceptions();
        LabelNode bodyLabel = new LabelNode();
        LabelNode nextCatchLocal = new LabelNode();
        int j = 0;
        for (FulledNameToken catchException : catchExceptions) {
            if (j > 0) {
                add(nextCatchLocal);
                nextCatchLocal = new LabelNode();
            }
            expr.writePushEnv();
            expr.writeVarLoad(exception);
            expr.writePushConstString(catchException.toName());
            expr.writePushConstString(catchException.toName().toLowerCase());
            expr.writeSysDynamicCall(Environment.class, "__throwCatch", Memory.class, BaseBaseException.class, String.class, String.class);
            expr.writeVarAssign(local, _catch.getVariable(), true, false);
            expr.writePopBoolean();
            add(new JumpInsnNode(IFEQ, j == catchExceptions.size() - 1 ? nextCatch : nextCatchLocal));
            expr.stackPop();
            if (catchExceptions.size() > 1) {
                add(new JumpInsnNode(GOTO, bodyLabel));
            }
            j++;
        }
        if (catchExceptions.size() > 1) {
            add(bodyLabel);
        }
        expr.write(BodyStmtToken.class, _catch.getBody());
        add(new JumpInsnNode(GOTO, catchEnd));
        i++;
    }
    add(catchFail);
    if (token.getFinally() != null) {
        expr.write(BodyStmtToken.class, token.getFinally());
    }
    /*if (method.getTryStack().empty()) {
            expr.writePushEnv();
            expr.writeVarLoad(exception);
            expr.writeSysDynamicCall(Environment.class, "__throwFailedCatch", void.class, BaseException.class);
        } else {*/
    expr.makeVarLoad(exception);
    add(new InsnNode(ATHROW));
    // }
    add(catchEnd);
    if (token.getFinally() != null) {
        LabelNode skip = new LabelNode();
        add(new JumpInsnNode(GOTO, skip));
        // finally for return
        add(returnLabel);
        expr.write(BodyStmtToken.class, token.getFinally());
        if (method.getTryStack().empty()) {
            // all finally blocks are done
            LocalVariable retVar = method.getOrAddLocalVariable("~result~", null, Memory.class);
            expr.writeVarLoad(retVar);
            add(new InsnNode(ARETURN));
            expr.stackPop();
        } else {
            // goto next finally block
            add(new JumpInsnNode(GOTO, method.getTryStack().peek().getReturnLabel()));
        }
        add(skip);
        // other finally
        expr.write(BodyStmtToken.class, token.getFinally());
    }
    expr.writeUndefineVariables(token.getLocal());
    method.prevStatementIndex(BaseBaseException.class);
}
Also used : LabelNode(org.objectweb.asm.tree.LabelNode) TryCatchBlockNode(org.objectweb.asm.tree.TryCatchBlockNode) MethodStmtCompiler(org.develnext.jphp.core.compiler.jvm.statement.MethodStmtCompiler) JumpInsnNode(org.objectweb.asm.tree.JumpInsnNode) InsnNode(org.objectweb.asm.tree.InsnNode) LocalVariable(org.develnext.jphp.core.compiler.jvm.misc.LocalVariable) JumpInsnNode(org.objectweb.asm.tree.JumpInsnNode) CatchStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.CatchStmtToken) BodyStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.BodyStmtToken) FulledNameToken(org.develnext.jphp.core.tokenizer.token.expr.value.FulledNameToken)

Example 45 with JumpInsnNode

use of org.objectweb.asm.tree.JumpInsnNode in project jphp by jphp-compiler.

the class StaticDefinitionCompiler method write.

@Override
public void write(StaticStmtToken token) {
    LocalVariable local = method.getLocalVariable(token.getVariable().getName());
    assert local != null;
    LabelNode end = new LabelNode();
    boolean isClosure = method.clazz.isClosure();
    if (isClosure)
        expr.writeVarLoad(LocalVariable.THIS);
    else
        expr.writePushEnv();
    // writePushConstString(name);
    writePushNameForStaticVariable(local);
    expr.writeSysDynamicCall(isClosure ? null : Environment.class, "getStatic", Memory.class, String.class);
    expr.writePushDup();
    add(new JumpInsnNode(IFNONNULL, end));
    expr.stackPop();
    expr.writePopAll(1);
    if (isClosure)
        expr.writeVarLoad(LocalVariable.THIS);
    else
        expr.writePushEnv();
    writePushNameForStaticVariable(local);
    if (token.getInitValue() != null) {
        expr.writeExpression(token.getInitValue(), true, false, true);
    } else {
        expr.writePushNull();
    }
    expr.writePopBoxing(true);
    expr.writeSysDynamicCall(isClosure ? null : Environment.class, "getOrCreateStatic", Memory.class, String.class, Memory.class);
    add(end);
    expr.writeVarStore(local, false, false);
}
Also used : LabelNode(org.objectweb.asm.tree.LabelNode) LocalVariable(org.develnext.jphp.core.compiler.jvm.misc.LocalVariable) Environment(php.runtime.env.Environment) JumpInsnNode(org.objectweb.asm.tree.JumpInsnNode)

Aggregations

JumpInsnNode (org.objectweb.asm.tree.JumpInsnNode)49 LabelNode (org.objectweb.asm.tree.LabelNode)36 MethodInsnNode (org.objectweb.asm.tree.MethodInsnNode)28 AbstractInsnNode (org.objectweb.asm.tree.AbstractInsnNode)26 InsnNode (org.objectweb.asm.tree.InsnNode)25 VarInsnNode (org.objectweb.asm.tree.VarInsnNode)24 InsnList (org.objectweb.asm.tree.InsnList)22 FieldInsnNode (org.objectweb.asm.tree.FieldInsnNode)19 LdcInsnNode (org.objectweb.asm.tree.LdcInsnNode)18 MethodNode (org.objectweb.asm.tree.MethodNode)18 TypeInsnNode (org.objectweb.asm.tree.TypeInsnNode)15 ClassNode (org.objectweb.asm.tree.ClassNode)14 ClassReader (org.objectweb.asm.ClassReader)12 Label (org.objectweb.asm.Label)11 Type (org.objectweb.asm.Type)9 LocalVariable (org.develnext.jphp.core.compiler.jvm.misc.LocalVariable)6 LineNumberNode (org.objectweb.asm.tree.LineNumberNode)4 LinkedList (java.util.LinkedList)3 Mutation (org.evosuite.coverage.mutation.Mutation)3 FieldNode (org.objectweb.asm.tree.FieldNode)3