ASM : Return a value

Hi. How, with ASM MethodVisitor, can I set the value my method returns ?
8 Replies
JavaBot
JavaBot2y ago
This post has been reserved for your question.
Hey @tyranobast! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Tyranobast
TyranobastOP2y ago
For example : make a method that returns 3.
0x150
0x1502y ago
the instructions you're looking for are
ldc 3
ireturn
ldc 3
ireturn
Tyranobast
TyranobastOP2y ago
with what visit call ? mv.visitIntInsn(); ?
0x150
0x1502y ago
first: visitCode to start the code section then: visitLdcInsn(3) for ldc 3, followed by visitInsn(Opcodes.IRETURN) for ireturn dont forget to set the correct method return type in the descriptor, should be (whateverArgsYouWant)I forgot: visitEnd afterwards
Tyranobast
TyranobastOP2y ago
Ok thank you very much!
JavaBot
JavaBot2y ago
If you are finished with your post, please close it. If you are not, please ignore this message. Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
JavaBot
JavaBot2y ago
Post Closed
This post has been closed by <@428632258413330442>.
Want results from more Discord servers?
Add your server