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

https://github.com/minad/chasm

Java Bytecode Assembler and Disassembler which uses S-expressions
https://github.com/minad/chasm

asm assembler bytecode disassembler java java-bytecode s-expressions

Last synced: 9 months ago
JSON representation

Java Bytecode Assembler and Disassembler which uses S-expressions

Awesome Lists containing this project

README

          

= Chasm - Java assembler and disassembler using S-expressions

Chasm can disassemble `{asterisk}.class` files and `{asterisk}.jar` files and output assembly in s-expression form.
Furthermore the main use case is to read s-expression assembly files and output `{asterisk}.class` or `{asterisk}.jar` files.
The s-expression syntax is both easy to parse and easy to generate.
Chasm uses the de-facto standard library ow2 ASM for bytecode generation. Since Chasm is only a minimal syntax on top of
ASM it is easy to keep it up to date with the current bytecode standard.

[source,scheme]
----
(class 53 (final public super) chasm/Main null java/lang/Object ()
(source "Main.java" null)
(inner-class chasm/Server$Command chasm/Server Command (abstract interface public static))
(inner-class java/lang/invoke/MethodHandles$Lookup java/lang/invoke/MethodHandles Lookup (final public static))
(method (public static) main "([Ljava/lang/String;)V" null (java/io/IOException)
(code
(label L0)
(line 13 L0)
(invokedynamic run "()Lchasm/Server$Command;"
(H invokestatic java/lang/invoke/LambdaMetafactory metafactory
"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;" false)
((T "(Ljava/nio/file/Path;[Ljava/lang/String;Ljava/io/PrintStream;)V")
(H invokestatic chasm/Main run
"(Ljava/nio/file/Path;[Ljava/lang/String;Ljava/io/PrintStream;)V" false)
(T "(Ljava/nio/file/Path;[Ljava/lang/String;Ljava/io/PrintStream;)V")))
(aload 0)
(invokestatic chasm/Server main "(Lchasm/Server$Command;[Ljava/lang/String;)V")
(label L1)
(line 14 L1)
(return)
(label L2)
(local args "[Ljava/lang/String;" null L0 L2 0)
(maxs 2 1)))
...
----

See link:example.chasm[] for the full example.

== Quick start

1. Build with `gradle` or use the precompiled binary in `dist` (reproducible build).
2. Disassemble class/jar file to chasm with `chasm example.{class|jar} example.chasm`
2. Assemble chasm to class/jar file with `chasm example.chasm example.{class|jar}`

== Binary version

The 'dist' directory contains a precompiled version which includes
a copy of ASM.

== License

MIT (c) 2018 Daniel Mendler

ASM: a very small and fast Java bytecode manipulation framework
Copyright (c) 2000-2011 INRIA, France Telecom
All rights reserved.

== Related projects

* http://asm.ow2.io/[ObjectWeb ASM]
* https://wiki.openjdk.java.net/display/CodeTools/asmtools[jdk asmtools]
* https://github.com/achmelev/lilac[Lilac]
** Does perfect roundtrip like chasm
** Overall more complex and more complex syntax
** Not based on ObjectWeb ASM
* https://github.com/Storyyeller/Krakatau[Krakatau]
** Written in Python
** Includes a decompiler
* https://github.com/davidar/jasmin[Jasmin]
* https://github.com/Whiley/Jasm[Whiley Jasm]
* http://www.judoscript.org/articles/jamaica.html[Jamaica]
* https://commons.apache.org/proper/commons-bcel/[BCEL]