Skip to content

fabricio-p/javaclass

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

javaclass

A Java ClassFile parser and generator written in Nim using the binarylang library.

How to use

import javaclass
# From string
#  Directly
let data = readFile("JavaClass.class")
block:
  let
    parsedClass = data.toClassFile()
    generatedClass = parsedClass.fromClassFile()
  doAssert data == generatedClass
#  Using a BitStream
block:
  let
    stream = newStringBitStream(data)
    parsedClass = classFile.get(stream)
    collectorStream = newStringBitStream("")
    generatedClass = block:
      classFile.put(collectorStream, parsedClass)
      collectorStream.readStr(data.len * 8) # *8 because smth with bitstreams idk
  doAssert data == generatedClass
# From file
block:
  let
    stream = newFileBitStream("JavaClass.class")
    parsedClass = classFile.get(stream)
    collectorStream = newStringBitStream("")
    generatedClass = block:
      classFile.put(collectorStream, parsedClass)
      collectorStream.readStr(data.len * 8) # *8 because smth with bitstreams idk
  doAssert data == generatedClass

NOTE

This was a learning project and I don't expect anyone to need or want to use this, thus the documentation is short and dry, just some examples of how to call the parser/generator functions. If you need/want to use this library, please open an issue so that I can know and write a more complete documentation.