Your SlideShare is downloading. ×

Planet of the AOPs

10,615

Published on

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

No Downloads
Views
Total Views
10,615
On Slideshare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
0
Comments
0
Likes
3
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

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

×