jvm-visitor
This module extends kylestev/jvm.js
by
exposing classes used for traversing the contents of a ClassInfo
object from
jvm.js (a JavaScript representation of the JVM class file format) by utilizing
the Visitor Pattern.
Examples
Field Logging Visitor
import { Jar } from 'jvm';
import { ClassVisitor } from 'jvm-visitor';
let visitor = new ClassVisitor;
visitor.on('visit-field', (cls, field) => {
console.log(' %s %s.%s', field.desc, cls.name, field.name);
});
Jar.unpack('/path/to/your.jar')
.then((jar) => {
for (let [name, cls] of jar) {
visitor.accept(cls);
}
})
.catch(console.error.bind(console));
VerboseClassVisitor
jvm-visitor
ships with a verbose version of the default ClassVisitor
which
has the same interface for interacting with it and behaves the same way with
one caveat: it binds event listeners for each type of even that ClassVisitor
emits and prints out basic information about the class file when visited.
This can aid debugging efforts without hampering development time as you can
simply swap new ClassVisitor
references with new VerboseClassVisitor
in
your code -- even if you're binding your own event listeners on top of those
used by VerboseClassVisitor
.
import { Jar } from 'jvm';
import { VerboseClassVisitor } from 'jvm-visitor';
let visitor = new VerboseClassVisitor;
Jar.unpack('/path/to/your.jar')
.then((jar) => {
for (let [name, cls] of jar) {
visitor.accept(cls);
}
})
.catch(console.error.bind(console));