bytecode-manipulation

Is there an analogue of visitLdcInsn for loading objects (not constant)?

三世轮回 提交于 2020-01-06 02:50:30
问题 We wrote a simple PostScript interpreter in Java and want to optimize it by generating bytecode directly for specific parts of source code. For this we need to load the object from the context of the Java bytecode context. Specify such object in the signature of the generated bytecode method is not good, because they may be in a large amount in our case. In Java Asm we have method public void visitLdcInsn(Object cst) It visits a LDC instruction. Parameter cst - the constant to be loaded on

Embed the existing code of a method in a try-finally block (2)

自作多情 提交于 2020-01-02 07:11:21
问题 Some time ago, I asked in Embed the existing code of a method in a try-finally block how to wrap the body of a method in a try-finally block using ASM. The solution was to visit a label for the try block at the beginning of the method body in visitCode() and to complete the try-finally block when visiting an instruction with a return opcode in visitInsn() . I was aware that the solution won't be working if a method has no return instruction which applies if the method is always leaving with

How can I run DataNucleus Bytecode Enhancer from SBT?

非 Y 不嫁゛ 提交于 2020-01-02 07:10:38
问题 I've put together a proof of concept which aims to provide a skeleton SBT multimodule project which utilizes DataNucleus JDO Enhancer with mixed Java and Scala sources. The difficulty appears when I try to enhance persistence classes from SBT. Apparently, I'm not passing the correct classpath when calling Fork.java.fork(...) from SBT. See also this question: How can SBT generate metamodel classes from model classes using DataNucleus? Exception in thread "main" java.lang.NoClassDefFoundError:

java disassemble reassemble

China☆狼群 提交于 2020-01-02 05:57:30
问题 Say I want to take a java class file, disassemble it, tweak the java bytecode output, and then reassemble it again. I need to rename a symbol in the constant pool table. I also don't have access to the source code, and using a decompiler seems like overkill for this. I'm not trying to optimize anything - java does a fine job at that. Is there... a simple way to do this? I've found several tools for either disassembly or reassembly, but none for both; or no pairs of tools which seem to use the

java disassemble reassemble

送分小仙女□ 提交于 2020-01-02 05:57:14
问题 Say I want to take a java class file, disassemble it, tweak the java bytecode output, and then reassemble it again. I need to rename a symbol in the constant pool table. I also don't have access to the source code, and using a decompiler seems like overkill for this. I'm not trying to optimize anything - java does a fine job at that. Is there... a simple way to do this? I've found several tools for either disassembly or reassembly, but none for both; or no pairs of tools which seem to use the

Javassist: re-creating a class - delete first, or defrost() and modify?

∥☆過路亽.° 提交于 2020-01-01 03:24:07
问题 I use Javassist to create a class. And in a test suite, when a second test tries to create the same class, it fails at pool.makeClass( ... ) because the class is frozen (i.e. already created via toClass() . What's the way to overcome this? Ideally, the first test should delete the class somehow - perhaps unload from the classloader - but as I read in JLS, the unload operation is not reliable. So perhaps the workaround is to check in the class creating code whether it exists, and if it does,

Is it possible to change strings (content and size) in Lua bytecode so that it will still be correct?

故事扮演 提交于 2019-12-30 11:02:53
问题 Is it possible to change strings (content and size) in Lua bytecode so that it will still be correct? It's about translating strings in Lua bytecode. Of course, not every language has the same size for each word... 回答1: Yes, it is if you know what you're doing. Strings are prefixed by their size stored as an int. The size and endianness of that int is platform-dependent. But why do you have to edit bytecode? Have you lost the sources? 回答2: After some diving throught Lua source-code I found

Reassembling Python bytecode to the original code?

[亡魂溺海] 提交于 2019-12-30 09:00:12
问题 This might be a silly question, but, given the output of, say.. >>> from dis import dis >>> def myfunc(x): ... print x ** 2 ... >>> dis(myfunc) 2 0 LOAD_FAST 0 (x) 3 LOAD_CONST 1 (2) 6 BINARY_POWER 7 PRINT_ITEM 8 PRINT_NEWLINE 9 LOAD_CONST 0 (None) 12 RETURN_VALUE ..or a .pyc file - is it possible to reassembling this into a valid piece of Python source code? I.e where reassemble(dis(myfunc)) == "def reassembled_function(x):\n print x ** 2" Not for any particular practical reason, I'm just

Java Bytecode Manipulation Library Suggestions

百般思念 提交于 2019-12-30 01:57:08
问题 I'm looking for a well-maintained Java bytecode manipulation library with an intuitive API. There seem to be quite a lot of them out there. Any suggestions on which ones to try? 回答1: The best answer to your question will be governed by your specific needs and objectives; if you can expand upon what you're trying to accomplish, I can perhaps offer a more tailored response. In lieu of that, however, in my experience, ASM offers probably the best combination of maturity, flexibility, and ease-of

Alter value of a static field during class loading using a Java agent

南楼画角 提交于 2019-12-24 12:13:19
问题 We have a java process that calls some method of class X. Class X has timeout static field which decides how long thread should wait for in case of some error. Now, I want to change that value without changing my java process (I don't want deployment, and this change is experimental). How can I use java agent to change this timeout value to say 1 minute (1*60*1000) Class X { .... // timeout = 5 minutes private static long timeout = 5*60*1000; .... } In short, how to write java agent to change