#java #parsing #class #classfile

classfile-parser

A parser for Java Class files written in rust

9 releases

Uses old Rust 2015

0.3.5 Jul 12, 2021
0.3.4 Dec 30, 2018
0.3.2 Jun 30, 2018
0.3.0 Mar 31, 2018
0.2.1 Jun 30, 2017

#585 in Parser implementations

Download history 153/week @ 2022-11-28 125/week @ 2022-12-05 45/week @ 2022-12-12 24/week @ 2022-12-19 12/week @ 2022-12-26 9/week @ 2023-01-02 15/week @ 2023-01-09 9/week @ 2023-01-16 36/week @ 2023-01-23 65/week @ 2023-01-30 37/week @ 2023-02-06 38/week @ 2023-02-13 99/week @ 2023-02-20 39/week @ 2023-02-27 54/week @ 2023-03-06 65/week @ 2023-03-13

266 downloads per month

MIT license

53KB
1.5K SLoC

Java Classfile Parser

LICENSE Rust Crates.io Version

A parser for Java Classfiles, written in Rust using nom.

Installation

Classfile Parser is available from crates.io and can be included in your Cargo enabled project like this:

[dependencies]
classfile-parser = "~0.3"

Usage

extern crate classfile_parser;

use classfile_parser::class_parser;

fn main() {
    let classfile_bytes = include_bytes!("../path/to/JavaClass.class");
    
    match class_parser(classfile_bytes) {
        Ok((_, class_file)) => {
            println!(
                "version {},{} \
                 const_pool({}), \
                 this=const[{}], \
                 super=const[{}], \
                 interfaces({}), \
                 fields({}), \
                 methods({}), \
                 attributes({}), \
                 access({:?})",
                class_file.major_version,
                class_file.minor_version,
                class_file.const_pool_size,
                class_file.this_class,
                class_file.super_class,
                class_file.interfaces_count,
                class_file.fields_count,
                class_file.methods_count,
                class_file.attributes_count,
                class_file.access_flags
            );
        }
        Err(_) => panic!("Failed to parse"),
    };
}

Implementation Status

  • Header
    • Magic const
    • Version info
  • Constant pool
    • Constant pool size
    • Constant types
      • Utf8
      • Integer
      • Float
      • Long
      • Double
      • Class
      • String
      • Fieldref
      • Methodref
      • InterfaceMethodref
      • NameAndType
      • MethodHandle
      • MethodType
      • InvokeDynamic
  • Access flags
  • This class
  • Super class
  • Interfaces
  • Fields
  • Methods
  • Attributes
    • Basic attribute info block parsing
    • Known typed attributes parsing
      • Critical for JVM
        • ConstantValue
        • Code
        • StackMapTable
        • Exceptions
        • BootstrapMethods
      • Critical for Java SE
        • InnerClasses
        • EnclosingMethod
        • Synthetic
        • Signature
        • RuntimeVisibleAnnotations
        • RuntimeInvisibleAnnotations
        • RuntimeVisibleParameterAnnotations
        • RuntimeInvisibleParameterAnnotations
        • RuntimeVisibleTypeAnnotations
        • RuntimeInvisibleTypeAnnotations
        • AnnotationDefault
        • MethodParameters
      • Useful but not critical
        • SourceFile
        • SourceDebugExtension
        • LineNumberTable
        • LocalVariableTable
        • LocalVariableTypeTable
        • Deprecated

Dependencies

~795KB
~15K SLoC