Skip to content

Library

Jindra Petřík edited this page Jan 3, 2021 · 6 revisions

FFDec has two main parts

  • FFDec GUI (licensed as GNU/GPLv3)
  • FFDec Library (licensed as GNU/LGPLv3)

This page has some information about the library so you can properly use it in your projects.

Library sources

You can find sources of ffdec_lib under libsrc/ffdec_lib/. There is also compiled JAR version of library in releases section (see Library only (Java SE) - Zipped).

Basic usage

package com.jpexs.decompiler.flash.test;

import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.SwfOpenException;
import com.jpexs.decompiler.flash.tags.Tag;
import com.jpexs.decompiler.flash.tags.base.CharacterIdTag;
import java.io.FileInputStream;
import java.io.IOException;

public class Test {
    public static void main(String[] args) {
       try ( FileInputStream fis = new FileInputStream("data/as3.swf")) { //open up a file

            //Pass the InputStream to SWF constructor.
            //Note: There are many variants of the constructor - Do not use single parameter version - is does not process whole SWF.
            SWF swf = new SWF(fis, true); 

            //Get some SWF parameters
            System.out.println("SWF version = " + swf.version);
            System.out.println("FrameCount = " + swf.frameCount);

            //Process all tags
            for (Tag t : swf.getTags()) {                
                if (t instanceof CharacterIdTag) {  //Print character id with the tag if it has any
                    System.out.println("Tag " + t.getTagName() + " (" + ((CharacterIdTag) t).getCharacterId() + ")");
                } else {
                    System.out.println("Tag " + t.getTagName());
                }
            }

            System.out.println("OK");
        } catch (SwfOpenException ex) {
            System.out.println("ERROR: Invalid SWF file");
        } catch (IOException ex) {
            System.out.println("ERROR: Error during SWF opening");
        } catch (InterruptedException ex) {
            System.out.println("ERROR: Parsing interrupted");
        }
    }
}

Usefull packages and classes

com.jpexs.decompiler.flash - SWF reading and writing

  • SWF - Basic class for SWF manipulation
  • SWFInputStream - Reading of SWF data
  • SWFOuputStream - Writing of SWF data

com.jpexs.decompiler.flash.abc - AS3 bytecode (ABC format)

  • ABC - AS3 bytecode structure
  • ABCInputStream - Reading AS3 bytecode structure
  • ABCOutputStream - Writing AS3 bytecode structure
  • ScriptPack - important - for purposes of easily displaying of flashCC/alchemy long scripts, ABC scripts can be splitted into so called script packs which is script index and list of trait indices. FFDec always displays a scriptpack, not a whole script.

com.jpexs.decompiler.flash.abc.avm2 - AS3 AVM2 code

  • AVM2Code - code handling

com.jpexs.decompiler.flash.abc.avm2.deobfuscation - Some AS3 AVM2 code deobfuscation classes

com.jpexs.decompiler.flash.abc.avm2.graph - Generates high-level code from instructions of AVM2 code

com.jpexs.decompiler.flash.abc.avm2.instructions.* - Instructions for AS3 AVM2 code

com.jpexs.decompiler.flash.abc.avm2.model.* - Model representing generated high-level code of AS3

com.jpexs.decompiler.flash.abc.avm2.parser.* - Compilers of AS3 and its p-code

com.jpexs.decompiler.flash.abc.types - ABC format related types

com.jpexs.decompiler.flash.abc.types.traits - ABC traits

com.jpexs.decompiler.flash.abc.usages - Get usages feature

com.jpexs.decompiler.flash.action - AS1/2 related

com.jpexs.decompiler.flash.action.swf* - AS1/2 Actions

com.jpexs.decompiler.flash.action.model - Model representing generated high-level code of AS1/2

com.jpexs.decompiler.flash.action.parser.* - Compilers of A1/2 and its p-code

com.jpexs.decompiler.flash.configuration - Configuration of the decompilation

com.jpexs.decompiler.flash.exporters - Exporters of resources/scripts to various formats

com.jpexs.decompiler.flash.iggy - Iggy format related

com.jpexs.decompiler.flash.importers - Importers of resources/scripts from various formats

com.jpexs.decompiler.flash.tags - Definitions of SWF tags

com.jpexs.decompiler.flash.timeline - Browsing SWF in a timeline

com.jpexs.decompiler.flash.types - Structures used in SWF file

com.jpexs.decompiler.flash.xfl - Export to FLA and XFL

com.jpexs.decompiler.flash.graph - Generates high-level code from instructions of AS1/2/3 code

com.jpexs.decompiler.flash.graph.model.* - Shared model representing generated high-level code

Clone this wiki locally