roscopeco / jasm Goto Github PK
View Code? Open in Web Editor NEWA JVM assembler for the modern age
License: MIT License
A JVM assembler for the modern age
License: MIT License
Literal names are not currently emitted by the disassembler. Going forward, where the disassembler detects that a name needs escaping as a literal name (enclosing in backticks) it should do so.
The nature of this issue is that there are alot of open problems about dealing with technially jvm valid input but invalid input regarding to antlr or jasm
public class java/lang/Example {
public test()V {
getstatic 1.0 I
}
}
Results in: test.j : Cannot invoke "org.antlr.v4.runtime.tree.RuleNode.getChildCount()" because "node" is null
This should work because 1.0
is a valid path descriptor
Any class, extends, implements, method or field declaration fails when the access modifiers are used as names, but they should because they are valid jvm names
Example
public class public
extends private
implements final, static, private {
}
Is technically valid by the JVM but jasm errors with: test.j : Cannot invoke "org.antlr.v4.runtime.tree.TerminalNode.getText()" because the return value of "com.roscopeco.jasm.antlr.JasmParser$ClassnameContext.QNAME()" is null
It is impossible to name lables, variables, methods after any instruction and it will fail with: test.j : Cannot read field "inputLocals" because "dstFrame" is null
in the goto case.
Example:
public class java/lang/Example {
public test()V {
goto ldc
ldc:
return
}
}
It is also impossible for invokex descriptors to contain any keywords
Example:
public class java/lang/Example {
public test()V {
invokevirtual ldc/private.final(goto)V
}
}
Also string escape is not working on example:
public class java/lang/Example {
public test()V {
ldc "\"\\\\\\\""
}
}
Which should just result in the string '"\"' but instead errors with: test.j : Errors: test.j:[4:22]: extraneous input '""'
Hi,
I'm currently looking for an assembler to use for writing tests for a transpiler I am developing, and came across this project.
The transpiler searches for methods to transpile based on an annotation either present on the declaring type of a method, or on the method itself. The annotation has retention level CLASS; it is invisible at runtime, but still present in the class file.
Objectweb's ASM represents these annotations as entries in the "invisible annotation" list, and my transpiler checks for the annotation in that list.
Your project seems to treat every annotation in the source file as a runtime visible annotation tho, which results in all annotations being present in the "visible annotation" list, instead of the "invisible annotation" list.
Example:
Source:
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.CLASS)
@interface Annot {}
@Annot
public class Hi {}
Jasm:
@Annot
public class Hi extends java/lang/Object {
public <init>()V {
aload 0
invokespecial java/lang/Object.<init>()V
return
}
}
Compiling and loading the source version, there is one annotation in the "invisible annotation" list, that being Annot
. Doing the same thing for the jasm version results in the Annot
annotation being placed in the "visible annotation" list instead.
Code responsible: JasmAssemblingVisitor at line 83: visitor.visitAnnotation(..., true)
. true
means "runtime visible".
I understand this is just a minor nitpick, but I still wanted to make sure you know about this. Is runtime invisible annotation support planned?
Please create a tool to convert .class files into .jasm files. This will make reading .class files much easier than the output from javap.
public class com/example/HelloWorld {
public static main([java/lang/String)V {
getstatic java/lang/System.out
ldc "Hello, World"
invokevirtual java/io/PrintStream.println(java/lang/String)V
return
}
}
Error Message
Index 0 out of bounds for length 0
I suspect the error is on the getstatic java/lang/System.out
line, due to the missing import.
How do I write import java.lang.*;
in JASM?
catchType can be null to catch all exceptions (finally blocks) according to the asm docs
java.lang.NullPointerException: Parameter specified as non-null is null: method com.roscopeco.jasm.JasmDisassemblingVisitor$JasmDisassemblingMethodVisitor.visitTryCatchBlock, parameter type
at com.roscopeco.jasm.JasmDisassemblingVisitor$JasmDisassemblingMethodVisitor.visitTryCatchBlock(JasmDisassemblingVisitor.kt)
at org.objectweb.asm.ClassReader.readCode(ClassReader.java:1857)
at org.objectweb.asm.ClassReader.readMethod(ClassReader.java:1514)
at org.objectweb.asm.ClassReader.accept(ClassReader.java:744)
at org.objectweb.asm.ClassReader.accept(ClassReader.java:424)
at com.roscopeco.jasm.JasmDisassembler.disassemble(JasmDisassembler.kt:42)
Hello! I'm using jasm in a "toy compiler". It's an amazing project :-)
I assembled a lot of jasm files, without any problem. But, with the example bellow, I got a "[BUG]: [java.lang.NullPointerException".
I'm using jasm 0.7.0, installed from the binary distribution.
public class if_with_integers_with_and_or {
public static main([java/lang/String)V {
sipush 2
sipush 1
if_icmple L3
iconst_1
goto L4
L3:
iconst_0
L4:
ifeq L1
getstatic java/lang/System.out java/io/PrintStream
ldc "true"
invokevirtual java/io/PrintStream.print(java/lang/String)V
getstatic java/lang/System.out java/io/PrintStream
invokevirtual java/io/PrintStream.println()V
goto L2
L1:
getstatic java/lang/System.out java/io/PrintStream
ldc "false"
invokevirtual java/io/PrintStream.print(java/lang/String)V
getstatic java/lang/System.out java/io/PrintStream
invokevirtual java/io/PrintStream.println()V
L2:
return
}
}
Could someone help me?
Regards.
Currently it is not possible to use instruction mnemonics (e.g. invokespecial
, d2i
, fconst
etc) as member names.
These are perfectly valid JVM member names. The grammar should be extended to allow this.
Likely it'll need to allow the individual instruction tokens in the membername
rule, which is a bit verbose, but probably the cleanest way to do it with Antlr.
Currently, JASM supports only basic escaping in Strings (using ""
to allow strings to contain double-quotes).
Going forward, we should probably have better support for special characters in strings, using the standard backslash escapes.
$ ./gradlew check
> Task :compileKotlin
w: E:\msys64\home\topkek\t\a\jasm\src\main\kotlin\com\roscopeco\jasm\JasmDisassemblingVisitor.kt: (385, 27): This class shouldn't be used in Kotlin. Use kotlin.Int instead.
w: E:\msys64\home\topkek\t\a\jasm\src\main\kotlin\com\roscopeco\jasm\JasmDisassemblingVisitor.kt: (387, 27): This class shouldn't be used in Kotlin. Use kotlin.Long instead.
w: E:\msys64\home\topkek\t\a\jasm\src\main\kotlin\com\roscopeco\jasm\JasmDisassemblingVisitor.kt: (389, 27): This class shouldn't be used in Kotlin. Use kotlin.Float instead.
w: E:\msys64\home\topkek\t\a\jasm\src\main\kotlin\com\roscopeco\jasm\JasmDisassemblingVisitor.kt: (391, 27): This class shouldn't be used in Kotlin. Use kotlin.Double instead.
> Task :compileTestKotlin
w: E:\msys64\home\topkek\t\a\jasm\src\test\kotlin\com\roscopeco\jasm\asserts\AnnotatableItemAssert.kt: (23, 60): Unchecked cast: AnnotatableItemAssert<Self, Actual> to Self
w: E:\msys64\home\topkek\t\a\jasm\src\test\kotlin\com\roscopeco\jasm\asserts\AnnotatableItemAssert.kt: (31, 91): Unchecked cast: AnnotatableItemAssert<Self, Actual> to Self
w: E:\msys64\home\topkek\t\a\jasm\src\test\kotlin\com\roscopeco\jasm\asserts\AnnotationAssert.kt: (34, 70): Unchecked cast: Any? to Array<String>
> Task :compileTestJava FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileTestJava'.
> java.lang.NoSuchFieldError: Class com.sun.tools.javac.tree.JCTree$JCImport does not have member field 'com.sun.tools.javac.tree.JCTree qualid'
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 42s
9 actionable tasks: 9 executed
When trying to disassemble and re-assemble RasterPrinterJob.class
from Eclipse Temurin's JRE build of OpenJDK 17.0.5+8, I get the following error:
$ jasm -d java.desktop/sun/print/RasterPrinterJob.class
$ jasm java.desktop/sun/print/RasterPrinterJob.jasm -o out
ERROR: There were failed tasks:
RasterPrinterJob.jasm : Cannot read field "outgoingEdges" because "handlerRangeBlock" is null
I have uploaded RasterPrinterJob.class
and RasterPrinterJob.jasm
to https://gist.github.com/tyilo/ffeb20c26cc619a319abfb7ef3448990
The BAT file you included depends a ton on environment variables that are NOT existing as part of Windows, or even as part of any JDK installation. They are only set by certain IDEs like Eclipse. As such, the provided BAT file to run this assembler is useless for running in a command line. Nor are any of your instructions on the readme here helpful for helping me to get it running from a command line.
There doesn't currently seem to be any way to apply annotation to things is jasm files. Some frameworks and libraries depend on runtime annotations and would thus require class files intended for use with them to have it.
If this is a feature then examples of the syntax would be useful
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.