-
1. Re: ByteMan Questions
adinn Jan 22, 2016 4:05 AM (in response to mutaz.alghafary)Hi Mutaz,
Thank you for using Byteman. I am very pleased to hear that you like it.
1- Is there any tool that supports auto-complete of btm files , I am thinking of writing an eclipse plugin to do that , what do you think ?
A prototype eclipse plugin was developed by Rebecca Simmonds, a MSc student at Newcastle University, as her dissertation project. However, this work was never finished. I also know of a prototype plugin for IntelliJ's Idea development enviroment. However, I think work on thta has been stalled for some time.
If you want to tackle this task I'd be happy to provide advice where I can.
2- What are some books/articles about bytecode injection / manipulation , I mean from where to get the knowledge needed to build a tool like ByteMan ?
The Byteman documentation page provides various resources detailing what Byteman does. Unfortunately, that material does not provide much explanation of how it does it.
The core API Byteman depends on, JVMTI, is provided by the Java JVM and JDK (the latter includes classes in the runtime jar rt.jar and also the SDK-only jar tools.jar). There is very little direct information to document how to go about building JVMTI agents. That's a shame because there are some nasty corner cases and gotchas in the way that it works that only arise from using the API. If you look into the Byteman sources I have documented a lot of these cases but unfortunately there is a fair amount of code so they are not straightforward to find. The API is documented here
- JDK 6 Java Virtual Machine Tool Interface (JVMTI)-relatedAPIs & Developer Guides
- java.lang.instrument (Java Platform SE 6)
I use ObjectWeb's ASM 5 library to do the low-level transformation of bytecode. I chose it rather than the other popular alternative, Javassist, because it gives better space and time performance for certain critical uses I need in Byteman. You might find Javassist easier to use if you are new to bytecode transformation.
Most of the other tricky things in the internals of Byteman are relatively standard stuff to those who have a background in parsing, interpretation and compilation. If you are not familiar with that field you can read up on that in both academic literature and popular books like Aho, Sethi and Ullman (the famous Dragon book) as well as in many online guides and tutorials. The specific tools I use are the parser/tokeniser generators JavaCUP/JFlex, both of which you will find (rather basically) documented online. You'll probably need to know about their precursors yacc and lex (or the open source equivalents bison and flex) to really understand that documentation. I came up with a few algorithms in the core of the bytecode translation that I might claim to be entirely my own invention. However, it is more likely that I merely re-invented a rather wonky version of someone else's earlier design for a smooth and perfectly circular wheel.
About 6 months ago I did present a couple of 1 hour video tutorials explaining the esssentials of the Byteman design to some of the staff at Red Hat. I have not yet cleaned these up ready for presentation to a wider public.When I get time to do that I will add a note to this thread indicating where they are a swell as linking them from the Byteman documentation page.
Unfortunately, in the absence of further information your only resort (and eventually your best resort) is the Byteman code itself. I do tend to comment really tricky stuff, and usually the trickier it is the more I add comment. I hope you enjoy studying it and feel free to ask on this forum if you are baffled by some specific detail.
regards,
Andrew Dinn