javaclass-rb by Peter ‘Code Cop’ Kofler
-
email peter dot kofler at code minus cop dot org
Description¶ ↑
javaclass-rb (Java Class File Parser for Ruby) is a parser and disassembler for Java class files, similar to the javap command. It provides access to the package, protected, and public fields and methods of the classes passed to it together with a list of all outgoing references.
Motivation¶ ↑
I am still doing Java most of the time. I used to be quite enthusiastic about it, but after 11 years I can see the advantages of being a polyglot. So I use Ruby for all kind of stuff, just for fun. When I needed some Java class analysis I wrote it in Ruby. As I am a puritan, I did not want to call javap from my script, so I started disassembling the class files, which might be the base for some serious static code analysis tools. (I started adding methods to that end and planned for some common metrics as well.)
Install¶ ↑
sudo gem install javaclass
Documentation¶ ↑
Module JavaClass
is the entry point for basic functions. All advanced functions are available in Object
through the JavaClass::Dsl::Mixin
. The main class or the parser is JavaClass::ClassFile::JavaClassHeader
which provides access to all information of a Java class file.
I tried hard to rdoc all classes and public methods, so just read it.
Usage¶ ↑
See the various examples in the examples folder of the gem.
-
Classes in modules/Jars, classpath
-
Dependencies to other classes
There is some experimental logic to recognize Java class name literals in Ruby which are mapped to JavaClass::JavaQualifiedName
. Packages have to be suffixed with “.*” to be recognized. See JavaClass::Dsl::JavaNameFactory
for its usage.
Dependencies¶ ↑
-
Ruby 1.8.7 (also tested 1.9.3, 2.0, 2.1 to 2.7)
-
rubyzip 0.9.1 (also tested 0.9.6.1, 0.9.9, 1.0.0, 1.1.7, 1.3.0, 2.3.0)
-
Originally Ruby 1.8.6 with rubyzip 0.9.1
References¶ ↑
-
The Java class file lifestyle, JavaWorld 1996.
-
The class File Format, The Java Virtual Machine Specification, Second Edition.
-
Similar Project by unageanu, GitHub 2010.
License¶ ↑
Typically the licenses listed for the project are that of the project itself, and not of dependencies.
-
The 2-Clause BSD License, it's enclosed in license.txt.