Planet of the AOPs<br />Michael Labriola  @mlabriola<br />James Ward @_JamesWard<br />
good modularity<br />Sorting<br />red shows relevant lines of code<br />nicely fits in one box<br />
good modularity<br />ICollectionView (XMLListCollection, ArrayCollection, VectorCollection)<br />red shows relevant lines ...
problem...<br />Display list updating in Flex<br />red shows lines of code that calls invalidateDisplayList<br />not in ju...
Aspect Oriented Programming?<br />AOP is a method to achieve better modularity<br />OOP is hierarchical<br />Some function...
How is AOP Implemented?<br />Compilers create bytecode from OOP sources<br />AOP is implemented through post compile, byte...
How is AOP Implemented - in Java?<br />AspectJ - Java bytecode post-processor<br />CGLib - Runtime Java bytecode modificat...
Modify your application code,<br />from your application code<br />http://github.com/MixingLoom<br />"Please Do Evil"<br /...
What you need to know first<br />ABC - ActionScriptBytecode is a binary representation of the code you write<br />AVM - Th...
Preloader-based Patching<br />
What is Mixing Loom?<br />Intercept SWF loading (main app, RSLs, and Modules) through:<br />Custom preloader<br />LoomAppl...
How to use it<br />Create a custom preloader that registers patchers<br />Patchers get access to frame 2 bytes, before fra...
Create a Patcher<br />public class SamplePatcher extends AbstractPatcher{<br />    override public function apply( invocat...
Create a Preloader<br />public class SamplePatcherPreloader extends AbstractPreloader{<br />    override protected functio...
Use the Preloader<br /><s:Applicationxmlns:fx="http://ns.adobe.com/mxml/2009"<br />xmlns:s="library://ns.adobe.com/flex/sp...
SampleXMLPatcher<br />Read an XML file<br />Modify classes on Frame 2 based on contents of XML file<br />PATCHER REFERENCE...
LoomApplication-based Patching<br />Preloader-based patching only gives access to frame 2 and modules<br />LoomApplication...
How to use it<br />Same as patcher-based method, just change the root application:<br /><ml:LoomApplication<br />xmlns:fx=...
Writing Patchers that Patch Stuff<br />SwfContext.swfTags : Vector.<SwfTag><br />SwfTag<br />name : String<br />tagBody : ...
Sample Patchers<br />Simple<br />Simple Async<br />Simple XML<br />String Modifier<br />Reveal Privates<br />
How do you reveal your privates?<br />Method visibility is stored in the ABC Constant Pool<br />Parse the Constant Pool<br...
Constant Pool references are stored in a compact unsigned 30-bit integer format<br />max 5 bytes for storage with max of 4...
Seriously?  WTF?  Why?<br />Alternative to Monkey Patching<br />Revealing Private / Protected<br />Fixing bugs in closed A...
Introducing AspectA<br />package cuts {<br />    aspect DisplayAspect{<br />    <br />       pointcutupdate( component:UIC...
Shout-Outs<br />Maxim Porges - Loom<br />Roland Zwaga - AS3 Commons Bytecode<br />Tom Lee - Frame 2 Debauchery<br />
NowGo forthAnd do evil<br />
Upcoming SlideShare
Loading in …5
×

Planet of the AOPs

11,734 views

Published on

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
11,734
On SlideShare
0
From Embeds
0
Number of Embeds
7,459
Actions
Shares
0
Downloads
0
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Planet of the AOPs

  1. 1. Planet of the AOPs<br />Michael Labriola @mlabriola<br />James Ward @_JamesWard<br />
  2. 2. good modularity<br />Sorting<br />red shows relevant lines of code<br />nicely fits in one box<br />
  3. 3. good modularity<br />ICollectionView (XMLListCollection, ArrayCollection, VectorCollection)<br />red shows relevant lines of code<br />nicely fits in two boxes (using inheritance)<br />
  4. 4. problem...<br />Display list updating in Flex<br />red shows lines of code that calls invalidateDisplayList<br />not in just one place<br />not even in a small number of places<br />everything MUST be a DisplayObject<br />
  5. 5. Aspect Oriented Programming?<br />AOP is a method to achieve better modularity<br />OOP is hierarchical<br />Some functionality is expressed better non-hierarchically<br />An Aspect is functionality applied across objects, no matter where they are in a hierarchy<br />
  6. 6. How is AOP Implemented?<br />Compilers create bytecode from OOP sources<br />AOP is implemented through post compile, bytecode modification<br />Bytecode modification can happen before runtime or at runtime<br />
  7. 7. How is AOP Implemented - in Java?<br />AspectJ - Java bytecode post-processor<br />CGLib - Runtime Java bytecode modification<br />AOP Alliance - Standard interfaces for applying AOP in Java <br />Examples:<br />Hibernate: Turns VOs into smart objects<br />Spring: Injects dependencies through XML or annotation based configuration<br />
  8. 8. Modify your application code,<br />from your application code<br />http://github.com/MixingLoom<br />"Please Do Evil"<br />Introducing Mixing Loom<br />
  9. 9. What you need to know first<br />ABC - ActionScriptBytecode is a binary representation of the code you write<br />AVM - The ActionScript Virtual Machine that "runs" ABC<br />SWF - A collection of ABC and other stuff<br />Frame - A divider in a SWF file that allows progressive loading of ABC blocks<br />ByteArray - A collection of bytes, which could be ABC<br />
  10. 10. Preloader-based Patching<br />
  11. 11. What is Mixing Loom?<br />Intercept SWF loading (main app, RSLs, and Modules) through:<br />Custom preloader<br />LoomApplication<br />Patchers modify a SWF, then allow the SWF to load<br />Patchers can be synchronous or asynchronous<br />Patchers run in sequence<br />Patchers can do ANYTHING they want<br />Only Frame 2 of the main app SWF can be modified<br />
  12. 12. How to use it<br />Create a custom preloader that registers patchers<br />Patchers get access to frame 2 bytes, before frame 2 is loaded into the player<br />Patchers modify the bytes<br />Once all registered patchers are done, the modified frame 2 is loaded<br />The application continues loading normally<br />
  13. 13. Create a Patcher<br />public class SamplePatcher extends AbstractPatcher{<br /> override public function apply( invocationType:InvocationType,<br />swfContext:SwfContext):void {<br /> // do something with the bytes from swfContext.swfTags<br /> // when done, let the PatchManager know<br />invokeCallBack();<br /> }<br />}<br />
  14. 14. Create a Preloader<br />public class SamplePatcherPreloader extends AbstractPreloader{<br /> override protected function setupPatchers( manager:IPatchManager ):void {<br />super.setupPatchers( manager );<br /> // register your patcher(s)<br />manager.registerPatcher( new SamplePatcher());<br /> }<br />}<br />
  15. 15. Use the Preloader<br /><s:Applicationxmlns:fx="http://ns.adobe.com/mxml/2009"<br />xmlns:s="library://ns.adobe.com/flex/spark"<br />preloader="preloader.SamplePatcherPreloader"><br /></s:Application><br />
  16. 16. SampleXMLPatcher<br />Read an XML file<br />Modify classes on Frame 2 based on contents of XML file<br />PATCHER REFERENCED CLASSES GO ON FRAME 1!!!<br />
  17. 17. LoomApplication-based Patching<br />Preloader-based patching only gives access to frame 2 and modules<br />LoomApplication also gives access to RSLs<br />
  18. 18. How to use it<br />Same as patcher-based method, just change the root application:<br /><ml:LoomApplication<br />xmlns:fx="http://ns.adobe.com/mxml/2009"<br />xmlns:ml="library://ns.mixingloom.org/flex/spark"<br />xmlns:s="library://ns.adobe.com/flex/spark"<br />preloader="preloader.SamplePatcherPreloader"><br />
  19. 19. Writing Patchers that Patch Stuff<br />SwfContext.swfTags : Vector.<SwfTag><br />SwfTag<br />name : String<br />tagBody : ByteArray<br />recordHeader : ByteArray<br />Simply modify a swfTag'stagBody & recordHeader<br />
  20. 20. Sample Patchers<br />Simple<br />Simple Async<br />Simple XML<br />String Modifier<br />Reveal Privates<br />
  21. 21. How do you reveal your privates?<br />Method visibility is stored in the ABC Constant Pool<br />Parse the Constant Pool<br />Find the method in the namespace pool<br />079a038067<br /> 0x07 = Type QName<br /> 0x9a 0x03 = Ref to NS: 410<br /> 0x80 0x67 = Ref to String: 13184<br />Replace the namespace in the constant pool<br />07018067<br />This can change the size of the constant pool<br />
  22. 22. Constant Pool references are stored in a compact unsigned 30-bit integer format<br />max 5 bytes for storage with max of 4 bits used for indicating if the next byte should be read<br /> 9a03 =? 410<br />Read the first byte = 0x9a<br /> 0x9a = 1001 1010<br />First bit is on, so toss it, but will read the next byte<br /> 0x9a & 0111 1111 = 0001 1010<br />Next byte is 0x03<br /> 0x03 = 0000 0011<br />First bit is off, so we stop reading bytes<br />U30 storage is in LITTLE_ENDIAN so 0x03 is really before 0x9a, so we shift it left 7 places<br /> 0x03 << 7 = 0001 1000 0000<br />Now "OR" the first byte (was 0x9a) with the second byte (0x03) and we get:<br /> 0001 1001 1010 = 410 in decimal!<br />
  23. 23. Seriously? WTF? Why?<br />Alternative to Monkey Patching<br />Revealing Private / Protected<br />Fixing bugs in closed APIs<br />DI / IoC<br />Weaving<br />AOP<br />XML-based application configuration<br />Annotation-based application configuration<br />Security<br />Bytecode optimization (Apparat)<br />
  24. 24. Introducing AspectA<br />package cuts {<br />    aspect DisplayAspect{<br />    <br />       pointcutupdate( component:UIComponent ):<br />           call( UIComponent.move(x:Number, y:Number) );<br /> call( UIComponent.setActualSize(w:Number, h:Number) );<br />       after( component:UIComponent ): {<br />          UIComponentGlobals.layoutManager.invalidateDisplayList(<br />component );<br />       }<br />    }<br />}<br />
  25. 25. Shout-Outs<br />Maxim Porges - Loom<br />Roland Zwaga - AS3 Commons Bytecode<br />Tom Lee - Frame 2 Debauchery<br />
  26. 26. NowGo forthAnd do evil<br />

×