java-bytecode-asm

How to verify Java Bytecode before injecting into the JVM?

孤人 提交于 2021-02-19 07:27:47
问题 I'm trying to verify "on the fly" generated bytecode! I already had several attempts, one attempt was to compile my classes in runtime with the eclipse compiler another was to compile from memory as mentioned here: Compile From Memory First results looked okay but I'm still not a 100% sure if the verification process is truly valid according to the JAVA 6 guidelines and security measurements as well to normal OOP Models. Any better way on how to verify bytecode? 回答1: If you load the generated

What does the visitLocalVariable() method of the MethodVisitor class in the ASM bytecode engineering library do?

心已入冬 提交于 2021-02-09 05:38:23
问题 I am using ASM (for the first time) in an application to create Java class files. This is for the backend of a compiler I am writing. I read the relevant parts of the ASM documentation and have a question about stack map frames. ASM says it can automatically compute those frames if the class writer is initialized with the appropriate flags. My question is, does that mean I will not ever have to call the visitLocalVariable() method on the method visitors myself? I am not sure what that method

How to transform bytecodes to initialize primitive constants in static block with ASM?

冷暖自知 提交于 2021-02-08 09:57:10
问题 I need to transform Java bytecode with ASM to initialize public static final fields inside a static {...} block in the class. For example: Input: public static final int CONSTANT = 10; Output: public static final int CONSTANT; static { CONSTANT = 10; } I need this transformation because the compiler replaces primitive constants by their actual value in the bytecode, so their usage becomes untraceable. This transformation allows tracing the usage of constants. 回答1: For such a transformation,

How to transform bytecodes to initialize primitive constants in static block with ASM?

让人想犯罪 __ 提交于 2021-02-08 09:56:55
问题 I need to transform Java bytecode with ASM to initialize public static final fields inside a static {...} block in the class. For example: Input: public static final int CONSTANT = 10; Output: public static final int CONSTANT; static { CONSTANT = 10; } I need this transformation because the compiler replaces primitive constants by their actual value in the bytecode, so their usage becomes untraceable. This transformation allows tracing the usage of constants. 回答1: For such a transformation,

How to transform bytecodes to initialize primitive constants in static block with ASM?

谁说我不能喝 提交于 2021-02-08 09:56:51
问题 I need to transform Java bytecode with ASM to initialize public static final fields inside a static {...} block in the class. For example: Input: public static final int CONSTANT = 10; Output: public static final int CONSTANT; static { CONSTANT = 10; } I need this transformation because the compiler replaces primitive constants by their actual value in the bytecode, so their usage becomes untraceable. This transformation allows tracing the usage of constants. 回答1: For such a transformation,

ASM look at maxStack before instructions?

为君一笑 提交于 2021-02-07 21:33:43
问题 I'm trying to use the ASM library to translate byte code into a different format, which can be done with a MethodVisitor, as with this simple test code: return new MethodVisitor(ASM7) { @Override public void visitInsn(int opcode) { System.out.println(String.format("%02x", opcode)); } @Override public void visitMaxs(int maxStack, int maxLocals) { System.out.println(maxStack); } }; One issue is that I only get to see maxStack after the actual instructions – I've tested it, and that is the order

ASM look at maxStack before instructions?

旧街凉风 提交于 2021-02-07 21:32:08
问题 I'm trying to use the ASM library to translate byte code into a different format, which can be done with a MethodVisitor, as with this simple test code: return new MethodVisitor(ASM7) { @Override public void visitInsn(int opcode) { System.out.println(String.format("%02x", opcode)); } @Override public void visitMaxs(int maxStack, int maxLocals) { System.out.println(maxStack); } }; One issue is that I only get to see maxStack after the actual instructions – I've tested it, and that is the order

The type org.objectweb.asm.ClassVisitor cannot be resolved. It is indirectly referenced from required .class files

删除回忆录丶 提交于 2021-01-29 07:18:39
问题 I am using ASM 7.0 in a short Java 11 project, which convert a class file to a text using the following code: final var charset = StandardCharsets.UTF_8; final ByteArrayOutputStream bos = new ByteArrayOutputStream(); try (var pw = new PrintWriter(bos, false, charset)) { final org.objectweb.asm.ClassVisitor traceClassVisitor = new TraceClassVisitor(null, new org.objectweb.asm.util.Textifier(), new PrintWriter(bos)); new ClassReader(stream.getStream()).accept(traceClassVisitor, ClassReader.SKIP

ASM jar - Why my java project has a dependency on this?

倖福魔咒の 提交于 2021-01-20 18:12:53
问题 I have a Java project and internally it is dependent on asm jar . Strangely, I don't even know why my project somehow is dependent on this library ( might be brought in by maven as a transitive dependency )? Can anyone help me know why some one needs asm jar ? Thanks in advance ! EDIT: Can you also mention for what purposes/use-cases one might need asm jar? 回答1: ASM is a bytecode manipulation framework (see this page for a nice introduction) and is used by many things performing... bytecode

ASM jar - Why my java project has a dependency on this?

巧了我就是萌 提交于 2021-01-20 18:12:41
问题 I have a Java project and internally it is dependent on asm jar . Strangely, I don't even know why my project somehow is dependent on this library ( might be brought in by maven as a transitive dependency )? Can anyone help me know why some one needs asm jar ? Thanks in advance ! EDIT: Can you also mention for what purposes/use-cases one might need asm jar? 回答1: ASM is a bytecode manipulation framework (see this page for a nice introduction) and is used by many things performing... bytecode