An open API service indexing awesome lists of open source software.

https://github.com/wdestroier/chamomile

Chamomile is a Java Virtual Machine class file assembler and disassembler.
https://github.com/wdestroier/chamomile

Last synced: 5 months ago
JSON representation

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

Awesome Lists containing this project

README

        


project logo



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



Installation

Maven

```xml


jitpack.io
https://jitpack.io


com.github.wdestroier
chamomile
1.0.0

```

Gradle

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

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



Demonstration

Assemble a list of instructions

```java
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

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



Disassemble an array of "unsigned bytes"

```java
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

```txt
iconst_1
i2l
aconst_null
pop
fconst_2
f2l
ladd
invokestatic
```


More examples can be found [here](/examples)