
Product
A New Design for GitHub PR Comments
We redesigned our GitHub PR comments to deliver clear, actionable security insights without adding noise to your workflow.
java-class-tools
Advanced tools
All object's structures are based on the Java Virtual Machine Specification
npm install java-class-tools
Print all method names (node.js)
const { JavaClassFileReader } = require('java-class-tools');
const reader = new JavaClassFileReader();
const classFile = reader.read('path/to/file.class');
classFile.methods.forEach(md => {
/**
* Method name in constant-pool.
*
* Points to a CONSTANT_Utf8_info structure: https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.4.7
*/
const nameInConstantPool = classFile.constant_pool[md.name_index];
// To string (hacky)
const name = String.fromCharCode.apply(null, nameInConstantPool.bytes);
console.log(name);
});
Usage Example (browser): print all method names
<script src="https://cdn.jsdelivr.net/npm/java-class-tools@latest/dist/java-class-tools.min.js"></script>
<script>
fetch('https://gist.githubusercontent.com/leonardosnt/69207dd9bcae55c93ff8fe6546c92eef/raw/fa008a94f9bc208cfa593cf568f0c504e3b30413/Class.class')
.then(r => r.arrayBuffer())
.then(printAllMethods);
function printAllMethods(classData) {
const reader = new JavaClassTools.JavaClassFileReader();
const classFile = reader.read(classData);
classFile.methods.forEach(md => {
/**
* Method name in constant-pool.
*
* Points to a CONSTANT_Utf8_info structure: https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.4.7
*/
const nameInConstantPool = classFile.constant_pool[md.name_index];
// To string (hacky)
const name = String.fromCharCode.apply(null, nameInConstantPool.bytes);
console.log(name);
});
}
</script>
Copyright (C) 2017 leonardosnt <leonrdsnt@gmail.com>
Licensed under the MIT License. See LICENSE file in the project root for full license information.
FAQs
Read and write java class files in node or browser.
The npm package java-class-tools receives a total of 545 weekly downloads. As such, java-class-tools popularity was classified as not popular.
We found that java-class-tools 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
We redesigned our GitHub PR comments to deliver clear, actionable security insights without adding noise to your workflow.
Product
Our redesigned Repositories page adds alert severity, filtering, and tabs for faster triage and clearer insights across all your projects.
Security News
Slopsquatting is a new supply chain threat where AI-assisted code generators recommend hallucinated packages that attackers register and weaponize.