AnvilASM 1.0.0

dotnet add package AnvilASM --version 1.0.0
                    
NuGet\Install-Package AnvilASM -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AnvilASM" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AnvilASM" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="AnvilASM" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add AnvilASM --version 1.0.0
                    
#r "nuget: AnvilASM, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package AnvilASM@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=AnvilASM&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=AnvilASM&version=1.0.0
                    
Install as a Cake Tool

AnvilASM

A high-level library for reading, modifying, and generating JVM bytecode.

AnvilASM is a modern successor to SharpASM, designed to make JVM bytecode manipulation intuitive and developer-friendly within the .NET ecosystem.

💡 Design Philosophy

Unlike traditional stream-based parsers (such as the Visitor pattern often found in Java libraries), AnvilASM is built around a High-Level Object Model. The library abstracts the complexities of the raw binary format into a structured, easily navigable hierarchy.

The workflow is straightforward:

  1. Parse: Converts raw JVM bytecode (.class files) into a rich high-level data structure.
  2. Modify: Access and edit class elements (constants, methods, fields, instructions) directly, using standard C# collections like Dictionaries and Arrays.
  3. Build: Reconstructs valid JVM bytecode from the modified structure, handling serialization details automatically.

🏗️ Architecture: High-Level vs. Low-Level

AnvilASM bridges the gap between developer usability and raw binary structure through a two-layer object model. The data flow is structured as follows:

graph LR
    HL[High-Level Object] <-->|Convert| LL[Low-Level Object]
    LL <-->|Serialize / Deserialize| Data[Data / Bytecode]

High-Level Object ←--> Low-Level Object (Serialization/Deserialization) ←--> Data

  • High-Level Objects: These are the user-facing objects you interact with (e.g., ClassNode, MethodNode). They abstract away complexities like Constant Pool indices, turning them into direct references and standard C# types.
  • Low-Level Objects: These objects serve as a direct mapping of the JVM ClassFile structure. They represent the raw u1, u2, u4 data types and strict structural layout required by the JVM specification.
  • Transformation:
    • Deserialization: Raw Data is read into Low-Level Objects, which are then resolved into High-Level Objects for editing.
    • Serialization: Your modified High-Level Objects are converted back into Low-Level Objects (rebuilding the Constant Pool), which are then serialized into the final binary Data.

⚠️ Important Note

This project is currently under active development and reconstruction.

If you attempt to run the generated bytecode on a JVM during this phase, you may need to disable the bytecode verifier (e.g., using -Xverify:none or -noverify) as the output may not yet fully comply with strict JVM verification constraints. It is not recommended for production use at this stage.

Java toolchain integration tests

The integration tests that invoke java, javac, and javap are disabled by default. Enable them explicitly when a JDK is available on PATH:

ANVIL_RUN_JAVA_INTEGRATION_TESTS=1 \
  dotnet test --filter "Category=JavaIntegration"

These tests verify JVM execution and strict bytecode verification, disassemble a class built from scratch by AnvilASM, and round-trip control-flow bytecode compiled by javac.

📄 License

This project is licensed under the Apache License 2.0.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 109 7/24/2026