# jClassReader **Repository Path**: ZEUSFIRST/j-class-reader ## Basic Information - **Project Name**: jClassReader - **Description**: 解析class文件工具 - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: develop - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2021-09-06 - **Last Updated**: 2022-07-20 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # jCalssReader ## 介绍 解析class文件工具 ## 软件架构 软件架构说明 ## 安装教程 1. 基础 2. 开始开发 3. 验证 ## 使用说明 ### 1. 基础 下载jdk的文件说明 [文档目录](https://docs.oracle.com/en/java/javase/index.html) [java语言规范和虚拟机规范](https://docs.oracle.com/javase/specs/index.html) [java8语言规范](https://docs.oracle.com/javase/specs/jls/se8/jls8.pdf) [jvm8规范](https://docs.oracle.com/javase/specs/jvms/se8/jvms8.pdf) ### 2. 开始开发 class文件规范 ``` ClassFile { u4 magic; // 魔术:CAFFEE u2 minor_version; // 小版本 u2 major_version; // 大版本 u2 constant_pool_count;// 常量池数量 cp_info constant_pool[constant_pool_count-1];// 常量池表 u2 access_flags; // 访问声明 u2 this_class; // 类名 u2 super_class; // 父类 u2 interfaces_count; // 接口数 u2 interfaces[interfaces_count]; // 接口列表 u2 fields_count; // 字段数 field_info fields[fields_count];// 字段数组 u2 methods_count; // 方法数 method_info methods[methods_count];// 方法数组 u2 attributes_count;// 数量数 attribute_info attributes[attributes_count];// 属性数组 } ``` #### 2.1 魔术 固定值:CAFFEE,长度4 byte #### 2.2 小版本号 2 byte #### 2.3 大版本号 2 byte #### 2.3 常量池数 2 个byte #### 2.4 常量池数组 从1 开始,size = 常量池计数。格式如下: ``` cp_info { u1 tag; u1 info[]; } ``` 其中tag支持不同类型,主要是class类型、method、String类。明细如下: | Constant Type| Value| | ---- | ---- | | ConstanT_Class| 7| | ConstanT_Fieldref| 9| | ConstanT_Methodref| 10| | ConstanT_InterfaceMethodref| 11| | ConstanT_String| 8| | ConstanT_Integer| 3| | ConstanT_Float| 4| | ConstanT_Long| 5| | ConstanT_Double| 6| | ConstanT_NameAndType| 12| | ConstanT_Utf8| 1| | ConstanT_MethodHandle| 15| | ConstanT_MethodType| 16| | ConstanT_InvokeDynamic| 18| #### 2.5 访问标识 #### 2.6 类描述 #### 2.7 父类描述 #### 2.8 接口数 #### 2.8 接口数组 #### 2.9 字段数 #### 2.10 字段数组 #### 2.11 方法计数 #### 2.12 方法数组 #### 2.13 字属性计数 #### 2.14. 属性数组 3. 验证 ## 参与贡献 1. Fork 本仓库 2. 新建 Feat_xxx 分支 3. 提交代码 4. 新建 Pull Request ## 特技 1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md 2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) 3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) 6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)