
Product
Introducing Scala and Kotlin Support in Socket
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
jvm-visitor
Advanced tools
This module extends [`kylestev/jvm.js`](https://github.com/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 Patte
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.
import { Jar } from 'jvm';
import { ClassVisitor } from 'jvm-visitor';
// instantiate a new ClassVisitor object
let visitor = new ClassVisitor;
// bind an event listener to the `visit-field` event whose callback is passed
// a `ClassInfo` object as well as a `FieldInfo` object.
visitor.on('visit-field', (cls, field) => {
console.log(' %s %s.%s', field.desc, cls.name, field.name);
});
// parse the jar contents
Jar.unpack('/path/to/your.jar')
// called when the Promise returned from `Jar#unpack(string)` succeeds
.then((jar) => {
// iterate all `ClassInfo` objects (`cls`) in the jar
for (let [name, cls] of jar) {
// pass the `ClassInfo` object to `ClassVisitor#accept(ClassInfo)`
// in order to visit `cls` and its members
visitor.accept(cls);
}
})
// catch any uncaught errors during this Promise chain and log them to the console
.catch(console.error.bind(console));
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);
// output will look similar to the following:
// >>> [visit-start] ClassName
// >>> [visit-field] FieldDesc ClassName.FieldName
// >>> [visit-field] ...
// >>> [visit-method] ClassName#MethodName+MethodDesc
// >>> [visit-method] ...
// >>> [visit-end] ClassName completed in 0.004365655s
// >>> [visit-start] ClassName1
// >>> ...
// >>> [visit-end] ClassName1 completed in 0.004233272s
}
})
.catch(console.error.bind(console));
FAQs
This module extends [`kylestev/jvm.js`](https://github.com/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 Patte
The npm package jvm-visitor receives a total of 7 weekly downloads. As such, jvm-visitor popularity was classified as not popular.
We found that jvm-visitor demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
Application Security
/Security News
Socket CEO Feross Aboukhadijeh and a16z partner Joel de la Garza discuss vibe coding, AI-driven software development, and how the rise of LLMs, despite their risks, still points toward a more secure and innovative future.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.