Skip to content

Chamomile is a Java Virtual Machine class file assembler and disassembler.

License

Notifications You must be signed in to change notification settings

Wdestroier/chamomile

Repository files navigation

project logo


Chamomile is a Java Virtual Machine class file assembler and disassembler.


Installation

Maven

<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>com.github.wdestroier</groupId>
        <artifactId>chamomile</artifactId>
        <version>1.0.0</version>
    </dependency>
</dependencies>

Gradle

repositories {
  maven("https://jitpack.io")
}

dependencies {
  implementation("com.github.wdestroier:chamomile:1.0.0")
}

Demonstration

Assemble a list of instructions

var assembler = new SinglePassAssembler();

var bytecode = assembler.assemble(List.of(
		new Iconst1Instruction(),
		new I2lInstruction(),
		new AconstNullInstruction(),
		new PopInstruction(),
		new Fconst2Instruction(),
		new F2lInstruction(),
		new LaddInstruction(),
		new InvokestaticInstruction(InstructionFactory.instance.getOpcode(
	InvokestaticInstruction.class), 12)
		));

System.out.println(Arrays.toString(bytecode));

Output

[4, 133, 1, 87, 13, 140, 97, 184, 0, 12]

Disassemble an array of "unsigned bytes"

var disassembler = new LinearSweepDisassembler();

var bytecode = new short[] { 4, 133, 1, 87, 13, 140, 97, 184, 0, 12 };

var instructions = disassembler.disassemble(bytecode);

instructions.stream()
	.map(instruction -> InstructionFactory.instance.getMnemonic(instruction.getOpcode()))
	.forEach(System.out::println);

Output

iconst_1
i2l
aconst_null
pop
fconst_2
f2l
ladd
invokestatic

More examples can be found here

About

Chamomile is a Java Virtual Machine class file assembler and disassembler.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages