All Projects β†’ Washi1337 β†’ JavaResolver

Washi1337 / JavaResolver

Licence: MIT license
Java class file inspection library for .NET.

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to JavaResolver

Kotlin Result
A multiplatform Result monad for modelling success or failure operations.
Stars: ✭ 369 (+846.15%)
Mutual labels:  jvm, class
Jvm
πŸ€— JVM εΊ•ε±‚εŽŸη†ζœ€ε…¨ηŸ₯θ―†ζ€»η»“
Stars: ✭ 7,756 (+19787.18%)
Mutual labels:  jvm, class
Dumpclass
Dump classes from running JVM process.
Stars: ✭ 156 (+300%)
Mutual labels:  jvm, class
ProType
A new kind of object oriented front-end JS framework.
Stars: ✭ 80 (+105.13%)
Mutual labels:  class
tools jvm autodeps
Automatic Dependency Management Tools for JVM Languages
Stars: ✭ 48 (+23.08%)
Mutual labels:  jvm
Hephaistos
NBT & Anvil save format library
Stars: ✭ 22 (-43.59%)
Mutual labels:  jvm
nes
Helping researchers in routine procedures for data collection
Stars: ✭ 16 (-58.97%)
Mutual labels:  metadata
wasm.cljc
Spec compliant WebAssembly compiler, decompiler, and generator
Stars: ✭ 178 (+356.41%)
Mutual labels:  jvm
discogstagger
Console based audio-file metadata tagger that uses the Discogs.com API v2 (JSON based). Relies on the Mutagen and discogs-client libraries. Currently supports FLAC and MP3 file types.
Stars: ✭ 65 (+66.67%)
Mutual labels:  metadata
Manga-Tagger
The only tool you'll need to rename and write metadata to your digital manga library
Stars: ✭ 110 (+182.05%)
Mutual labels:  metadata
Lastik
Kotlin Multiplatform + Jetpack Compose pet project, based on www.last.fm/api (in development)
Stars: ✭ 37 (-5.13%)
Mutual labels:  jvm
VideoMetadataProvider
Video metadata provider library (collect metadata from ExoPlayer, FFMpeg, Native Android)
Stars: ✭ 20 (-48.72%)
Mutual labels:  metadata
MetaCat
Minimally Supervised Categorization of Text with Metadata (SIGIR'20)
Stars: ✭ 52 (+33.33%)
Mutual labels:  metadata
LGP
A robust Linear Genetic Programming implementation on the JVM using Kotlin.
Stars: ✭ 14 (-64.1%)
Mutual labels:  jvm
appstream-generator
A fast AppStream metadata generator
Stars: ✭ 34 (-12.82%)
Mutual labels:  metadata
audio-metadata
A library for reading and, in the future, writing audio metadata. https://audio-metadata.readthedocs.io/
Stars: ✭ 41 (+5.13%)
Mutual labels:  metadata
rust-id3
A rust library for reading and writing ID3 metadata
Stars: ✭ 161 (+312.82%)
Mutual labels:  metadata
epubtool
A tool to manipulate ePub files.
Stars: ✭ 17 (-56.41%)
Mutual labels:  metadata
k8s-labeler
βš“οΈ Apply labels to Kubernetes pods on startup
Stars: ✭ 17 (-56.41%)
Mutual labels:  metadata
sherlock-distributed-lock
Distributed locking library for JVM
Stars: ✭ 17 (-56.41%)
Mutual labels:  jvm

JavaResolver

JavaResolver is a Java class file inspection library allowing .NET programmers to read, modify and write Java class files. The library allows for low level access of the .class file format (e.g. direct access to the constants pool and raw member and attribute structures), as well as a higher level representation that provides a more hierarchical view on the metadata.

JavaResolver is released under the MIT license.

Features

  • Create, read and edit any .class file using the JavaClassFile class.
  • Inspect and edit the constant pool.
  • Add, inspect, edit and remove members such as methods, fields and attributes.
  • Disassemble and assemble bytecode of methods (or arbitrary byte arrays).

Quick starters guide

Creating and reading class files

The JavaClassFile represents the basic raw structure of a class file. You can open one using for example:

var classFile = JavaClassFile.FromFile(@"C:\path\to\your\file.class");

Creating new class files can be done through the constructors

var classFile = new JavaClassFile();

The JavaClassFile is a low level representations of the class file. If you want a more higher level representation for easier access, you have to open a new JavaClassImage from the JavaClassFile:

(Note: the following snippet is subject to change)

var classImage = new JavaClassImage(classFile);

Creating new class images can also be done directly, by simply calling the other constructor:

var classImage = new JavaClassImage(new ClassDefinition("MyClass"))
{
    SuperClass = new ClassReference("java/lang/Object"),
};

Fields and methods

Fields and methods can be obtained through the representative properties of JavaClassImage:

foreach (var field in classImage.Fields)
    Console.WriteLine(field.Name);

foreach (var method in classImage.Methods)
    Console.WriteLine(method.Name);

Fields and methods are represented using the FieldDefinition and MethodDefinition classes, and can be created using their constructors.

var field = new FieldDefinition("myIntField", new FieldDescriptor(BaseType.Int));
var method = new MethodDefinition("myMethod", new MethodDescriptor(BaseType.Void));

A more low level approach, where we iterate over raw method, field and attribute structures can be done through the representative properties of the JavaClassFile class:

foreach (var methodInfo in classFile.Methods) 
{
    string methodName = classFile.ConstantPool.ResolveString(methodInfo.NameIndex);
    Console.WriteLine(methodName);
    // ...
}

Inspecting method bodies

In high level mode, simply access the Body property of a MethodDefinition. It contains mutable collections for instructions, local variables, exception handlers and more:

var method = classImage.Methods.First(m => m.Name == "main");
foreach (var instruction in method.Body.Instructions)
    Console.WriteLine(instruction);

You can also opt for a more low level approach. Java stores the method body as an attribute in the raw method info structure with the name "Code". You can find it yourself using:

var method = classFile.Methods.First(m => ...);

// Look up attribute:
var codeAttribute = method.Attributes.First(a => classFile.ConstantPool.ResolveString(a.NameIndex) == CodeAttribute.AttributeName);

// Deserialize contents:
var contents = CodeAttribute.FromReader(new MemoryBigEndianReader(codeAttribute.Contents));

// Disassemble bytecode:
var disassembler = new ByteCodeDisassembler(new MemoryBigEndianReader(contents.Code));
foreach (var instruction in disassembler.ReadInstructions())
    Console.WriteLine(instruction);

To write instructions, use the ByteCodeAssembler instead to get a byte[] of the new code.

Inspecting the raw constants pool:

Iterating over each constant defined in the pool can be done using:

var constantPool = classFile.ConstantPool

foreach (var constant in constantPool.Constants) 
{
    // ...
}

Resolving constant indices can be done through

var resolvedConstant = constantPool.ResolveConstant(index);

Since constants are often UTF8 string constants, there is a shortcut for it to make life a little bit easier:

string myString = constantPool.ResolveString(index);
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].