-
Loom Becomes as3commons-bytecode
As you know if you follow my blog, I was working for a while on a bytecode parsing/weaving library for AS3 called Loom. I worked on this library during the six months coming up to my wedding, and then after we got back from our honeymoon I decided I just couldn’t be bothered to dig through binary with a hex editor any more.
I offered the project up to the people on the Loom forums, but there were no takers… until now! Roland Zwaga has been emailing me on and off for a few weeks asking questions about the library, which he’s been digging in to in order to add functionality to as3-commons and Spring Actionscript. They needed a way to extract the private and protected class data (amongst other things) during reflection, and the only way to do that in AS3 at the moment is to parse the bytecode. Rather than starting from scratch, Roland used Loom as a basis for understanding the AVM2 spec, and built from there.
After asking me if I minded (which of course I didn’t), Roland’s decided to publish the guts of Loom with his additional work as as3commons-bytecode. He sent out a message to the as3-commons dev list today as follows.
Good day gentlemen,
as3commons has a new addition: as3commons-bytecode. This library used to be known as Loom-as3 (http://code.google.com/p/loom-as3/), sadly before Loom was completed its creator, Maxim Porges, didn’t have the personal time anymoe to invest in its completion. Which is a huge shame since Loom is one of the most complete Actionscript implementations of the AVM spec.
A while ago I was sifting through the Loom sources to try and get a better understanding of all of this bytecode business and came to the conclusion that Loom would be an excellent addition to as3commons and would, as a first, be a great basis to implement bytecode based reflection on.
I just committed version 0.5 which will give you just that, the ByteCodeType class is the main entry point and c an be used like this:
1
ByteCodeType.fromLoader(FlexGlobals.topLevelApplication.loaderInfo);
or if you want to parse the loaded RSLS as well:
1 2 3
for (var info:* in systemManager.preloadedRSLs) { ByteCodeType.fromLoader(info); }
After that the ByteCodeType instance can be retrieved through these methods:
1 2 3
ByteCodeType.forInstance(); ByteCodeType.forClass(); ByteCodeType.forName();
or, if you’d like to inspect all of them, loop through the cached instacnes like this:
1 2 3 4 5 6
var typeCache:TypeCache = ByteCodeType.getTypeProvider().getTypeCache(); for each (var key:String in keys) { var type:ByteCodeType = typeCache.get(key) as ByteCodeType; /* ... do something... */ }
The resulting reflection classes are all inherited from the ones found in as3commons-reflect but augmented with the extra information we can extract from the bytecode. This includes private and protected members, optional parameter values, parameter names (allthough those values are not always reliable), initialized member values, and more.
Anyways, I think there’s PLENTY of room for improvement and other functionality for this library but for now I would really appreciate it if you guys could check it out, give it a test drive and give your opinion, criticism, etc,.
100 million kudos and the same amount of respect in tons go to Maxim Porges who did all of the heavy lifting in this library, I only finished some little details added the reflection bits.
have fun with the code!
cheers,
Roland
Although I didn’t have any interest in finishing Loom, I didn’t want all of the work I put in to it to be completely in vain. One of the things I really like about the open source community is that you can take somebody else’s work and put it to use for whatever you have in mind for it. In this way, people can learn so much from each other and push the envelope forward in to new areas the original authors never thought of. Loom certainly wouldn’t have been possible if I hadn’t been able to look deep in to the source of the Mozilla Tamarin and hurlant eval projects.
In closing, I’m really glad to see my work on Loom contributing value to the community now as part of ascommons-bytecode, and I look forward to seeing where things go under Roland’s leadership.
Category: Uncategorized | Tags:
5 Responses to “Loom Becomes as3commons-bytecode”
Related Posts
Recent Posts
- Greater Orlando Hackerspace (1)
- My Arduinome Build in Pictures
- How to Build An Arduinome (Part 3): Diodes and LEDs
- How to Build an Arduinome (Part 2): Components
- The Arduinome is Finished! (3)
- Loom Becomes as3commons-bytecode (5)
- Arduinome Coming Soon!
- Setting up WebDAV on OS X (1)
- Possible Fix for iPad Wifi Problems
- Bluetooth Headphones and iPad (4)