All Projects → leonardosnt → java-class-tools

leonardosnt / java-class-tools

Licence: MIT license
Read and write java class files in Node.js or in the browser.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to java-class-tools

Asmresolver
A library for editing PE files with full .NET metadata support
Stars: ✭ 267 (+888.89%)
Mutual labels:  disassembler, writer, reader
Xml
XML without worries
Stars: ✭ 35 (+29.63%)
Mutual labels:  writer, reader
mp4-rust
🎥 MP4 reader and writer library in Rust! 🦀
Stars: ✭ 149 (+451.85%)
Mutual labels:  writer, reader
Cistern
Ruby API client framework
Stars: ✭ 81 (+200%)
Mutual labels:  writer, reader
maildir
A Go package for reading & writing messages in maildir format
Stars: ✭ 13 (-51.85%)
Mutual labels:  writer, reader
Choetl
ETL Framework for .NET / c# (Parser / Writer for CSV, Flat, Xml, JSON, Key-Value, Parquet, Yaml, Avro formatted files)
Stars: ✭ 372 (+1277.78%)
Mutual labels:  writer, reader
Xopen
open files for buffered reading and writing in #golang
Stars: ✭ 55 (+103.7%)
Mutual labels:  writer, reader
Spout
Read and write spreadsheet files (CSV, XLSX and ODS), in a fast and scalable way
Stars: ✭ 3,861 (+14200%)
Mutual labels:  writer, reader
Parquet4s
Read and write Parquet in Scala. Use Scala classes as schema. No need to start a cluster.
Stars: ✭ 125 (+362.96%)
Mutual labels:  writer, reader
Bitio
Optimized bit-level Reader and Writer for Go.
Stars: ✭ 145 (+437.04%)
Mutual labels:  writer, reader
Qtcsv
Library for reading and writing csv-files in Qt.
Stars: ✭ 156 (+477.78%)
Mutual labels:  writer, reader
iobit
Package iobit provides primitives for reading & writing bits
Stars: ✭ 16 (-40.74%)
Mutual labels:  writer, reader
Ini
Ini file reader/writer for C# / .NET written in pure .NET in a single source file
Stars: ✭ 43 (+59.26%)
Mutual labels:  writer, reader
Iostreams
IOStreams is an incredibly powerful streaming library that makes changes to file formats, compression, encryption, or storage mechanism transparent to the application.
Stars: ✭ 84 (+211.11%)
Mutual labels:  writer, reader
Acr122u Reader Writer
A simple tool to read/write Mifare RFID tags with an ACR122U device
Stars: ✭ 169 (+525.93%)
Mutual labels:  writer, reader
Classanalyzer
A Java Class File Disassembler
Stars: ✭ 148 (+448.15%)
Mutual labels:  class, disassembler
collaboration
Spring '20 IoT - systems and security class. This is the collaborative half of the class.
Stars: ✭ 14 (-48.15%)
Mutual labels:  class
Capstone.NET
.NET Core and .NET Framework binding for the Capstone Disassembly Framework
Stars: ✭ 108 (+300%)
Mutual labels:  disassembler
MangAdventure
A simple manga hosting CMS written in Django
Stars: ✭ 51 (+88.89%)
Mutual labels:  reader
gdt helper
Ghidra Data Type (GDT) Helper
Stars: ✭ 24 (-11.11%)
Mutual labels:  disassembler

java-class-tools

Build status

The structure of the ClassFile object returned by JavaClassFileReader#read and its inner objects matches the Java Virtual Machine Specification, therefore you can use this specification as a guide on how to understand and change a Class file.

Install

npm install java-class-tools

Examples:

Print method names (Node.js):

const { JavaClassFileReader } = require('java-class-tools');
const { TextDecoder } = require('util');

const reader = new JavaClassFileReader();
const classFile = reader.read('./Foo.class');
const textDecoder = new TextDecoder();

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];

  // It is also possible to use the string_decoder builtin module.
  const name = textDecoder.decode(new Uint8Array(nameInConstantPool.bytes));

  console.log(name);
});

Print method names (Node.js):

<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);
    const textDecoder = new TextDecoder();

    classFile.methods.forEach(method => {
      /**
       * 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 nameEntry = classFile.constant_pool[method.name_index];

      const name = textDecoder.decode(new Uint8Array(nameEntry.bytes));

      console.log(name);
    });
 }
</script>

License

Copyright (C) 2017-2020 leonardosnt <[email protected]>
Licensed under the MIT License. See LICENSE file in the project root for full license information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].