[][src]Struct jvm_class_file_parser::ClassFile

pub struct ClassFile {
    pub minor_version: u16,
    pub major_version: u16,
    pub constant_pool: Vec<Box<ConstantPoolEntry>>,
    pub access_flags: HashSet<ClassAccess>,
    pub this_class: u16,
    pub super_class: u16,
    pub interfaces: Vec<u16>,
    pub fields: Vec<Field>,
    pub methods: Vec<Method>,
    pub attributes: Vec<Attribute>,
}

A representation of a JVM class file.

For details on the format and structure of a JVM class file, see the corresponding section of the Java Virtual Machine Specification.

https://docs.oracle.com/javase/specs/jvms/se11/html/jvms-4.html

Fields

minor_version: u16major_version: u16constant_pool: Vec<Box<ConstantPoolEntry>>access_flags: HashSet<ClassAccess>this_class: u16super_class: u16interfaces: Vec<u16>fields: Vec<Field>methods: Vec<Method>attributes: Vec<Attribute>

Methods

impl ClassFile[src]

pub fn from_file<R: Read>(file: &mut R) -> Result<ClassFile>[src]

Parses the given class file. Fails if the given file is not a valid class file.

let mut file = File::open("classes/Dummy.class").unwrap();
let class_file = ClassFile::from_file(&mut file).unwrap();

pub fn to_file<W: Write>(&self, file: &mut W) -> Result<()>[src]

pub fn get_class_name(&self) -> &str[src]

Returns the name of the class file.

let mut file = File::open("classes/Dummy.class").unwrap();
let class_file = ClassFile::from_file(&mut file).unwrap();

assert_eq!("Dummy", class_file.get_class_name());

pub fn get_source_file_name(&self) -> Option<&str>[src]

Returns the name of the source file that the class file was compiled from.

If the class file does not have a SourceFile attribute, then a None option is returned.

let mut file = File::open("classes/Dummy.class").unwrap();
let class_file = ClassFile::from_file(&mut file).unwrap();

assert_eq!(Some("Dummy.java"), class_file.get_source_file_name());

pub fn get_constant_utf8(&self, index: usize) -> &str[src]

Returns a string representation of the specified Utf8 constant.

let mut file = File::open("classes/Dummy.class").unwrap();
let class_file = ClassFile::from_file(&mut file).unwrap();

assert_eq!("<init>", class_file.get_constant_utf8(4));

pub fn get_constant_class_str(&self, index: usize) -> &str[src]

Returns a string representation of the specified class constant.

let mut file = File::open("classes/Dummy.class").unwrap();
let class_file = ClassFile::from_file(&mut file).unwrap();

assert_eq!("java/lang/Object", class_file.get_constant_class_str(3));

pub fn get_constant_name_and_type_str(&self, index: usize) -> String[src]

Returns a string representation of the specified name and type constant.

let mut file = File::open("classes/Dummy.class").unwrap();
let class_file = ClassFile::from_file(&mut file).unwrap();

assert_eq!(
    "\"<init>\":()V",
    class_file.get_constant_name_and_type_str(10)
);

pub fn get_constant(&self, index: usize) -> &Box<ConstantPoolEntry>[src]

Returns the specified constant from the constant pool.

This method exists in order to encapsulate the fact that the constant pool indexes start at 1 rather than 0.

let mut file = File::open("classes/Dummy.class").unwrap();
let class_file = ClassFile::from_file(&mut file).unwrap();

assert_eq!(
    ConstantClass {
        name_index: 11,
    },
    *class_file.get_constant(2).deref()
);

Trait Implementations

impl Eq for ClassFile[src]

impl PartialEq<ClassFile> for ClassFile[src]

impl Debug for ClassFile[src]

Auto Trait Implementations

impl Send for ClassFile

impl Sync for ClassFile

Blanket Implementations

impl<T> From for T[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.