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;
}
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;
}
9 Replies
JavaBot
JavaBot6mo ago
This post has been reserved for your question.
Hey @cvs0! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
cvs0
cvs0OP6mo ago
java.lang.IllegalStateException at org.objectweb.asm.MethodWriter.visitFrame(MethodWriter.java:793) at org.objectweb.asm.MethodVisitor.visitFrame(MethodVisitor.java:312) at org.objectweb.asm.commons.MethodRemapper.visitFrame(MethodRemapper.java:117) at org.objectweb.asm.tree.FrameNode.accept(FrameNode.java:147) at org.objectweb.asm.tree.InsnList.accept(InsnList.java:144) at org.objectweb.asm.tree.MethodNode.accept(MethodNode.java:749) at org.objectweb.asm.tree.MethodNode.accept(MethodNode.java:647) at org.objectweb.asm.tree.ClassNode.accept(ClassNode.java:468)
JavaBot
JavaBot6mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Earth
Earth6mo ago
You can fix this by subclassing ClassWriter and overriding one of its methods iirc the method which finds the common superclass of two classes
JavaBot
JavaBot6mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
JavaBot
JavaBot6mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
cvs0
cvs0OP6mo ago
Im trying to avoid that, as it brings up issues for me Cant i manually add frame nodes?
JavaBot
JavaBot6mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.

Did you find this page helpful?