How arakne/arakneswf works
Project type & purpose
• This is a PHP library (plus CLI tool) for parsing and extracting resources from SWF (Flash) files.
• It provides:
• A SwfFile façade to open/validate SWF streams
• A Parser module (raw tag reader -> structured tag/record objects)
• An AVM interpreter for ActionScript 2 variables
• Drawer back-ends: an SVG canvas implementation and a raster‐converter (via Imagick/InkScape/Rsvg)
• A small Console layer (bin/swf-extract) that invokes the core library
File‐structure → architectural layers
• bin/ (CLI entrypoint)
• src/Console → Symfony-style Command + options → orchestration layer
• src/SwfFile.php → façade that wires Parser, Extractor, AVM Processor
• src/Parser → low-level reader (SwfReader) + domain structures (Tag/Record classes)
• src/Avm → AVM interpreter (Processor + State + API)
• src/Extractor/Drawer/Svg → vector rendering
• src/Extractor/Drawer/Converter → raster conversion engine
• src/Error, src/Util → shared utilities & error flags
• tests/ → per-module unit/integration tests
Key interactions
• CLI → SwfFile façade → optionally variables()/execute() on AVM Processor or calls SwfExtractor
• SwfFile invokes Parser to produce Tag objects
• Parser → structured tags/records → returned to SwfFile/Extractor
• SwfExtractor builds in-memory models: ShapeDefinition, SpriteDefinition, Timeline
• DrawerInterface implementations render those models → SVGCanvas or Converter
• Converter uses external renderer back-ends (Imagick, Inkscape, Rsvg) for PNG/JPEG/GIF/WebP
• All layers respect Errors flags to handle corrupted data
• CLI Layer (bin/swf-extract + ExtractCommand)
• Facade Layer (SwfFile)
• Parser Layer
• AVM Interpreter
• Extractor Layer
• Drawer Layer
– SVG Canvas
– Raster Converter (Imagick / Inkscape / Rsvg back-ends)
• External Dependencies (gd, xml, json, Imagick, rsvg-convert, inkscape)
• Output & Storage (filesystem for SVG/PNG/JPEG)
• CLI → SwfFile façade (method calls)
• SwfFile → Parser (parse tags)
• SwfFile → AVM Processor (execute)
• Extractor → DrawerInterface → specific SVGCanvas or Converter
• Converter → external renderer executables/extensions
• Drawer → outputs SVG, PNG, JPEG files on disk
c. Architectural patterns & principles
• Facade (SwfFile) simplifies complex subsystem
• Strategy / Provider (DrawerInterface + multiple implementations)
• Layered separation: parsing, processing, rendering
• Dependency Injection: pass Processor, State, Drawer to methods
• Error-flag bitmask for configurable error handling
d. Technologies & libraries
• Pure PHP (≥8.4)
• Composer autoload (PSR-4)
• PHP extensions: gd, xml, json, Imagick
• External commands: librsvg2-bin (rsvg-convert), inkscape