我正在使用ASM来修改java字节码,但是我有一个我无法解决的错误。
当我编译原始方法时,我在createDecryptMethod中重新创建了原始方法,但是我得到了一个if_icmplt错误,但是一切看起来都一样。
错误:
Exception Details:
Location:
tk/netindev/Main.randomString(Ljava/lang/String;)Ljava/lang/String; @55: if_icmplt
Reason:
Expected stackmap frame at this location.
Bytecode:
0x0000000: 1279 4c03 3dbb 007b 592b b800 81b7 0082
0x0000010: 2a1c b600 8610 3064 1288 1c12 88b6 008c
0x0000020: 0464 70b6 0086 8292 b600 90b6 0094 4c84
0x0000030: 0201 1c2a b600 8ca1 ffce 2bb0
ASM方法:
private MethodNode createDecryptMethod() {
MethodNode methodNode = new MethodNode(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC,
Miscellaneous.getRandomString(), "(Ljava/lang/String;)Ljava/lang/String;", null, null);
methodNode.visitCode();
methodNode.visitLdcInsn("");
methodNode.visitVarInsn(Opcodes.ASTORE, 2);
methodNode.visitInsn(Opcodes.ICONST_0);
methodNode.visitVarInsn(Opcodes.ISTORE, 3);
Label ifLabel = new Label();
methodNode.visitLabel(ifLabel);
methodNode.visitTypeInsn(Opcodes.NEW, "java/lang/StringBuilder");
methodNode.visitInsn(Opcodes.DUP);
methodNode.visitVarInsn(Opcodes.ALOAD, 2);
methodNode.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/String", "valueOf",
"(Ljava/lang/Object;)Ljava/lang/String;", false);
methodNode.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/StringBuilder", "<init>", "(Ljava/lang/String;)V",
false);
methodNode.visitVarInsn(Opcodes.ALOAD, 1);
methodNode.visitVarInsn(Opcodes.ILOAD, 3);
methodNode.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "charAt", "(I)C", false);
methodNode.visitIntInsn(Opcodes.BIPUSH, 48);
methodNode.visitInsn(Opcodes.ISUB);
methodNode.visitLdcInsn(this.randomKey);
methodNode.visitVarInsn(Opcodes.ILOAD, 3);
methodNode.visitLdcInsn(this.randomKey);
methodNode.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "length", "()I", false);
methodNode.visitInsn(Opcodes.ICONST_1);
methodNode.visitInsn(Opcodes.ISUB);
methodNode.visitInsn(Opcodes.IREM);
methodNode.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "charAt", "(I)C", false);
methodNode.visitInsn(Opcodes.IXOR);
methodNode.visitInsn(Opcodes.I2C);
methodNode.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "append",
"(C)Ljava/lang/StringBuilder;", false);
methodNode.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "toString",
"()Ljava/lang/String;", false);
methodNode.visitVarInsn(Opcodes.ASTORE, 2);
methodNode.visitIincInsn(2, 1);
methodNode.visitVarInsn(Opcodes.ILOAD, 3);
methodNode.visitVarInsn(Opcodes.ALOAD, 1);
methodNode.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "length", "()I", false);
methodNode.visitJumpInsn(Opcodes.IF_ICMPLT, ifLabel); // XXX
methodNode.visitVarInsn(Opcodes.ALOAD, 2);
methodNode.visitInsn(Opcodes.ARETURN);
methodNode.visitEnd();
return methodNode;
}
原始方法:
private String decrypt(String input) {
String output = "";
int i = 0;
do {
output += (char) ((input.charAt(i) - 48) ^ (int) "a".charAt(i % ("a".length() - 1)));
} while (i++ < input.length());
return output;
}
抱歉我的英语不好:(