/Classreader

A Java class-file reader

Primary LanguageOdinMIT LicenseMIT

Classreader

A Java class-file reader

Under progress..

Usage

classreader SomeJavaFile.class

API

import "core:os"
import "../dependencies/classreader"

main :: proc() {
    data, ok := os.read_entire_file("Demo.class")
    assert(ok)
    defer delete(data)

    reader := classreader.reader_new(data)
    // Note that the returned class' lifetime is bound to
    // the bytes it got from the reader
    class, err := classreader.read_classfile(&reader)
    assert(err == .None)

    classreader.classfile_dump(class)
}

Sample output:

Version: minor=0, major=65 (Java SE 21)
Access flags: 0x0021 (ACC_PUBLIC, ACC_SUPER)
Constant pool:
   #1 = MethodRef          java/lang/Object.<init>
   #2 = Class              java/lang/Object
   #3 = NameAndType        <init>:()V
   #4 = Utf8               java/lang/Object
   #5 = Utf8               <init>
   #6 = Utf8               ()V
   #7 = FieldRef           Test.i
   #8 = Class              Test
   #9 = NameAndType        i:I
  #10 = Utf8               Test
  #11 = Utf8               i
  #12 = Utf8               I
  #13 = FieldRef           Test.s
  #14 = NameAndType        s:Ljava/lang/String;
  #15 = Utf8               s
  #16 = Utf8               Ljava/lang/String;
  #17 = Utf8               ConstantValue
  #18 = Integer            2
  #19 = Utf8               (Ljava/lang/String;)V
  #20 = Utf8               Code
  #21 = Utf8               LineNumberTable
  #22 = Utf8               (I)V
  #23 = Utf8               getI
  #24 = Utf8               ()I
  #25 = Utf8               getS
  #26 = Utf8               ()Ljava/lang/String;
  #27 = Utf8               SourceFile
  #28 = Utf8               Test.java
Attributes:
  SourceFile

Building the project