Java Community | Help. Code. Learn.JC|HCL
Java Community | Help. Code. Learn.โ€ข8mo agoโ€ข
13 replies
cvs0

Java obfuscator issues

i am making an obfuscator for fun, trying to add dead code injection. its having issues with frame nodes.

Issue is, i cant use COMPUTE_FRAMES, it gives me lots of issues with superclass types.

private InsnList generateDeadCodeBlock(MethodNode methodNode) {
        InsnList instructions = new InsnList();

        LabelNode deadCodeStart = new LabelNode();
        LabelNode deadCodeEnd = new LabelNode();

        // Start of dead code block
        instructions.add(deadCodeStart);
        instructions.add(new InsnNode(Opcodes.ICONST_0));
        instructions.add(new JumpInsnNode(Opcodes.IFNE, deadCodeEnd));

        // Add dead code
        instructions.add(generateSimpleDeadCode(methodNode));

        // End of dead code block
        instructions.add(deadCodeEnd);
        instructions.add(new FrameNode(Opcodes.F_APPEND, 1, new Object[]{Opcodes.INTEGER}, 0, null));

        return instructions;
    }


    private InsnList generateSimpleDeadCode(MethodNode methodNode) {
        InsnList instructions = new InsnList();
        int localVar = findAvailableLocalVar(methodNode);

        instructions.add(new InsnNode(Opcodes.ICONST_0));
        instructions.add(new VarInsnNode(Opcodes.ISTORE, localVar));
        instructions.add(new FrameNode(Opcodes.F_SAME, 0, new Object[]{Opcodes.INTEGER}, 0, null));
        instructions.add(new VarInsnNode(Opcodes.ILOAD, localVar));
        instructions.add(new InsnNode(Opcodes.ICONST_1));
        instructions.add(new InsnNode(Opcodes.IADD));
        instructions.add(new VarInsnNode(Opcodes.ISTORE, localVar));

        return instructions;
    }
Was this page helpful?