1.3.2 • Published 4 years ago

java-class-tools v1.3.2

Weekly downloads
6
License
MIT
Repository
github
Last release
4 years ago

java-class-tools

Build status

All object's structures are based on the Java Virtual Machine Specification

Install

npm install java-class-tools

Examples:

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>

License

Copyright (C) 2017 leonardosnt <leonrdsnt@gmail.com>
Licensed under the MIT License. See LICENSE file in the project root for full license information.

1.3.2

4 years ago

1.3.1

6 years ago

1.3.0

6 years ago

1.1.5

7 years ago

1.1.4

7 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.6

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago