Skip to content

SWFRecomp/SWFRecomp

Repository files navigation

SWFRecomp

This is a stupid idea.

Let's do it anyway.

What is this?

SWFRecomp is a static recompiler (not an emulator) that converts Flash SWF files into C code. Inspired by N64Recomp by Wiseguy, a static recompiler (not emulator) for N64 games that translates N64 MIPS instructions into C code that can be compiled into a native port. You should probably check that out, because it's epic. So is he. :D

This project applies the same approach to preserve Flash content.

Live Demos: https://swfrecomp.github.io/SWFRecompDocs/

This fork adds:

  • Improved build system - Automated native and WASM builds with no manual file copying
  • Better project structure - Clean separation of source, generated, and build files
  • Enhanced documentation - Complete guides for the entire recompilation process
  • WebAssembly examples - Working demos that run in your browser

Documentation

This Repository

Core Documentation:

ActionScript 3 Support (Pure C):

Font and Text Support:

Deprecated Documentation (Moved to deprecated/):

Build System:

  • Each test directory has a Makefile and build_wasm.sh for automated builds
  • Runtime files are in tests/*/runtime/ directories

SWFModernRuntime

Upstream

Quick Start

Prerequisites

For native builds:

# Standard C++ compiler
sudo apt install build-essential cmake

For WASM builds:

# Install Emscripten
git clone https://github.com/emscripten-core/emsdk.git ~/tools/emsdk
cd ~/tools/emsdk
./emsdk install latest
./emsdk activate latest
source ./emsdk_env.sh

Build SWFRecomp

git clone https://github.com/SWFRecomp/SWFRecomp.git
cd SWFRecomp

# Build the recompiler
mkdir -p build && cd build
cmake ..
make
cd ..

Run an Example

cd tests/trace_swf_4

# Step 1: Recompile SWF to C
../../build/SWFRecomp config.toml

# Step 2: Build natively (for testing)
make
./build/native/TestSWFRecompiled
# Output: sup from SWF 4

# Step 3: Build for WASM (for web)
source ~/tools/emsdk/emsdk_env.sh
./build_wasm.sh

# Test in browser
cd build/wasm
python3 -m http.server 8000
# Open http://localhost:8000/index.html

Project Structure

SWFRecomp/
├── src/                    # Recompiler source code
│   ├── swf.cpp            # SWF parsing
│   ├── tag.cpp            # Tag processing
│   ├── action/            # ActionScript translation
│   └── recompilation.cpp  # C code generation
├── tests/                  # Test cases with complete build setup
│   ├── trace_swf_4/       # Console output test (working!)
│   │   ├── test.swf       # Source SWF file
│   │   ├── config.toml    # Recompiler config
│   │   ├── runtime/       # Runtime implementations
│   │   │   ├── native/    # For native builds
│   │   │   └── wasm/      # For WASM builds
│   │   ├── Makefile       # Automated native build
│   │   └── build_wasm.sh  # Automated WASM build
│   └── graphics/          # Graphics tests
├── docs/                   # GitHub Pages with live demos
└── wasm-hello-world/      # Basic WASM example

How It Works

┌─────────────┐
│  test.swf   │  Original Flash SWF file
└──────┬──────┘
       │
       ▼
┌─────────────┐
│  SWFRecomp  │  Static recompiler (this project)
└──────┬──────┘
       │
       │  Generates C files:
       │  ├── script_0.c      (ActionScript → C)
       │  ├── tagMain.c       (Frame logic)
       │  └── constants.c     (String literals)
       │
       ▼
┌─────────────┐
│   C Code    │  Portable C17 code
└──────┬──────┘
       │
       ├──────────────┬─────────────┐
       ▼              ▼             ▼
   ┌──────┐      ┌────────┐   ┌────────┐
   │ gcc  │      │ clang  │   │ emcc   │
   └──┬───┘      └───┬────┘   └───┬────┘
      │              │            │
      ▼              ▼            ▼
  ┌────────┐    ┌────────┐   ┌────────┐
  │ Native │    │ Native │   │  WASM  │
  │  x86   │    │  ARM   │   │Browser │
  └────────┘    └────────┘   └────────┘

Current Features

Feature Status Notes
SWF Parsing ✅ Working All compression formats
ActionScript 1.0 ✅ Partial SWF v4 actions working
Shape Rendering ✅ Partial DefineShape support
Native Builds ✅ Working gcc/clang compilation
WASM Builds ✅ Working Emscripten compilation
Automated Build ✅ Working No manual file copying

What Can This Do Right Now?

Currently, SWFRecomp successfully:

  • Decompresses all forms of SWF compression (none, zlib, LZMA)
  • Reads SWF file headers and metadata
  • Recompiles ActionScript actions from SWF 4 into equivalent C code
  • Handles many graphics operations defined in DefineShape tags
  • Generates portable C code that compiles to both native and WASM

Check out the live demo of the trace_swf_4 test!

Related Projects

  • SWFModernRuntime - Runtime library for executing recompiled Flash with graphics
  • N64Recomp - The inspiration for this project

Legal Note

Fortunately, Adobe released most of their control over Flash as part of the Open Screen Project, Adobe removed many restrictions from their SWF format, including restrictions on creating software that plays and renders SWF files:

To support this mission, and as part of Adobe’s ongoing commitment to enable Web innovation, Adobe will continue to open access to Adobe Flash technology, accelerating the deployment of content and rich Internet applications (RIAs). This work will include:

  • Removing restrictions on use of the SWF and FLV/F4V specifications
  • Publishing the device porting layer APIs for Adobe Flash Player
  • Publishing the Adobe Flash® Cast™ protocol and the AMF protocol for robust data services
  • Removing licensing fees - making next major releases of Adobe Flash Player and Adobe AIR for devices free

Special Thanks

All the people that wildly inspire me. 😋

My very dear friend Stave.

From RecompRando:

  • ThatHypedPerson
  • PixelShake92
  • Muervo_

From N64Recomp:

  • Wiseguy
  • Darío
  • dcvz
  • Reonu
  • thecozies
  • danielryb
  • kentonm

From Archipelago:

  • seto10987
  • Rogue
  • ArsonAssassin
  • CelestialKitsune
  • Vincent'sSin
  • LegendaryLinux
  • zakwiz
  • jjjj12212

From RotMG:

  • HuskyJew
  • Nequ
  • snowden
  • MoonMan
  • Auru

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •