java-class-rs
A Java .class file parser written in Rust, based on the JVM Specification §4.
English | 中文
Features
- Full constant pool — all 17 entry types including MethodHandle, InvokeDynamic, Module, Package
- Access flags — class, field, and method level
- 20+ specialized attributes — Code, StackMapTable, Exceptions, BootstrapMethods, InnerClasses, Annotations (runtime/parameter/type), NestHost/Members, Record, PermittedSubclasses, and more
- Modified UTF-8 — CESU-8 decoding via the
cesu8crate - Serde support — optional
serdefeature for JSON/serialization - No unsafe — pure safe Rust
Quick Start
# Cargo.toml
[]
= "0.1"
use parse_classfile;
let data = read.unwrap;
let = parse_classfile.unwrap;
println!;
println!;
println!;
Examples
Iterate methods and fields
for method in &class_file.methods
Parse specialized attributes
Raw attributes are stored as AttributeInfo (name index + bytes). Use parse_specialized_attribute to decode them:
use ;
for attr in &class_file.methods.attributes
Serde support
[]
= { = "0.1", = ["serde"] }
let json = to_string_pretty.unwrap;
println!;
Constant pool helpers
use ;
for in class_file.constant_pool.iter.enumerate
Supported Attributes
| Category | Attributes |
|---|---|
| Bytecode | Code, StackMapTable, Exceptions |
| Linkage | BootstrapMethods, NestHost, NestMembers |
| Debug | SourceFile, LineNumberTable, LocalVariableTable, LocalVariableTypeTable |
| Annotations | RuntimeVisible/InvisibleAnnotations, RuntimeVisible/InvisibleParameterAnnotations, RuntimeVisible/InvisibleTypeAnnotations |
| Sealed | PermittedSubclasses |
| Records | Record |
| Other | ConstantValue, InnerClasses, Signature, Deprecated, Synthetic |
MSRV
Minimum Supported Rust Version: 1.71