ASM-使用ASM Bytecode Outline插件查看字节码

使用ASM Bytecode Outline插件查看字节码

前言

在使用 ASM 插入字节码代码时、如果不熟悉字节码相关语法和规则 可能对于插入 字节码代码 就束手无策了、幸好 ASM官方开发了一款IDE插件,可以将 Java代码 转换成 ASM 字节码类型代码,这样再使用 ASM 插入字节码时就比较方便了,下面就看一下如何使用了。

ASM Bytecode Outline 插件地址:https://plugins.jetbrains.com/plugin/5918-asm-bytecode-outline

Intellij IDEA使用

下面看一下如何在 IDEA 安装插件:

1.安装插件

在 preferences > Plugins 中 输入 asm bytecode outline 如下:

在这里插入图片描述
点击 install 安装、安装完毕后 重启 IDEA 之后在 Plugins - Installed 中 和 右侧出现工具栏说明安装已经成功!

在这里插入图片描述

2. 如何使用

安装完成插件之后 可以先编写一份 简单的Java源代码如下:

package com.java.design.source.class_byte;

public class ByteMain {

    private int a = 1;

    public int add() {
        int b = 2;
        int c = a + b;

        return c;
    }
}

之后 在当前类文件上 右击 在出现的菜单上选择: Show Bytecode outline

显示字节码
之后会出现 一个面板、在当前面板下会显示当前Java 代码对应的字节码文件如下:

在这里插入图片描述
当前面板下有三项内容:

  • Bytecode 表示对应的class字节码文件
  • ASMified 表示利用ASM框架生成字节码对应的代码
  • Groovified 对应的是class字节码指令

ASMified 文件如下:

在这里插入图片描述
Groovified 文件如下:

在这里插入图片描述
从上述文件可以看到 完全可以利用 ASM 框架生成 class 文件而且和 Java源文件编译的class 文件完全一致。

Android Studio 使用

在Android studio 上的安装和使用和 在 IDEA 的方式是一致的,所以就不在赘述了,直接参考上面的文章就行了。

存在的问题

目前Android studio 的插件在我使用的过程中发现 此插件不支持 分析 kotlin 代码,会在使用的过程中 会报如下错误:

Error:Kotlin: Unsupported plugin option: org.jetbrains.kotlin.android:enabled=true

在这里插入图片描述

所以我暂时也没有找到解决方案,如果有人知道请在下方留言告诉我一下,谢谢!

参考

https://plugins.jetbrains.com/plugin/5918-asm-bytecode-outline

As an AI language model, I can provide an overview of the ASM bytecode outline. ASM is a popular bytecode engineering library that allows developers to modify Java bytecode at runtime. The bytecode outline includes the following components: 1. Class Structure - This component contains the class name, access flags, superclass, interfaces, fields, and methods of a Java class. 2. Constant Pool - This component is a table of constants used by the bytecode instructions. It includes items such as strings, numbers, and class references. 3. Fields - This component defines the fields of a class, including their access flags, name, type, and value. 4. Methods - This component defines the methods of a class, including their access flags, name, return type, parameters, and bytecode instructions. 5. Instructions - This component defines the bytecode instructions that make up the methods of a class. Each instruction has an opcode and may have operands. 6. Exception Tables - This component defines the exception handling mechanism of a class. It includes information about the types of exceptions that can be thrown by a method and the code that should be executed to handle them. 7. Attributes - This component provides additional information about a class, its fields, or its methods. It includes items such as source file information, debug information, and annotations. Overall, the ASM bytecode outline provides a detailed description of a Java class and its bytecode instructions, allowing developers to modify and optimize their code at runtime.
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值