JBcRs-basic

JBcRs is a Library, written in rust, to support reading and writing of java class files.

This library is not close from being finished, but certain features have already been implemented:


Getting Started:

First, add this library as a dependency to your Cargo.toml toml [dependencies] jbcrs_basic = "0.1.4"

We want to parse a class from a byte array and print its version, access flags and name. Of course you could use std::fs::File or a zip library, but showing this is not the purpose of this tutorial.

```rust extern crate jbcrs_basic;

use jbcrs_basic::*;

// You got the bytes from any possible source. let bytes: &[u8] = [0xCA, 0xFE, 0xBA, 0xBE];

// After parsing the class file, // you will get the constant pool // and the class itself. // You don't have to annotate the types here. let (constant_pool, class): (Pool, Class) = parse(bytes) .expect("could not parse class file");

// Print its major and minor version: println!("version: {}.{}", class.majorversion, class.minorversion);

// Access Flags can be printed human readable println!("access: {:?}", class.access_flags);

// Printing the name requires us to use the constant pool. println!("name: {}", constantpool.getclass_name(class.name).expect("could not get class name")); ```


Resources

Java Virtual Machine Specification (Java SE 9)