Download the Crossbridge compiler suite

Notice that the operating system is Windows and this compiler was originally developed by Adobe, called Flascc, and then Adobe made it open source, called Crossbridge and then Adobe dropped the maintenance of it, and it’s now maintained by the community, It’s called Crossbridge and I’m using the last version of Adobe, Crossbridge 1.0.1 GitHub download address, download that zip package and you’ll find the GitHub address of Crossbridge maintained by the community for reference only

Install other dependencies

For the next steps I refer to Adobe Flascc’s help documentation

  • Install 64-bit Java, not 32-bit, either Java7 or Java8
  • Download the Flex SDK 4.6 or above, this link is 4.6 (Flex SDK should be included in FlashBuilder, if there is no need to download it)
  • Download the Debug version of Flash Player (only if you need to debug the program with GDB)

Start the Cygwin environment for Crossbridge

Click on the run.bat folder in the crossbridge ZIP package to launch it. By default, it is in the sample directory. You can go to one of the samples to compile and run

shellcd 01_HelloWorld
make FLASCC=/cygdrive/c/flascc/sdk FLEX=/cygdrive/c/flex_sdk

Compiled to SWC

We can refer to 05_SWC in the sample directory and we need to write a wrapper, refer to the API in AS3/AS3.h that I wrote

#include <cstdlib>
#include <string>
#include "AS3/AS3.h"
#include "AES.h"

void encrypt() __attribute__((used,
    annotate("as3sig:public function encrypt(text:String):String"),
    annotate("as3package:com.qunhe.instdeco.diy.flashutil.aes")));

void encrypt()
{
    char *cstr = NULL;
    AS3_MallocString(cstr, text);
    int len = strlen(cstr);
    std::string str(cstr, cstr+len);
    free(cstr);

    std::string enc = AES::encrypt(str);

    AS3_DeclareVar(result, String);
    AS3_CopyCStringToVar(result, enc.c_str(), enc.length());
    AS3_ReturnAS3Var(result);
}

void decrypt() __attribute__((used,
    annotate("as3sig:public function decrypt(text:String):String"),
    annotate("as3package:com.qunhe.instdeco.diy.flashutil.aes")));

void decrypt()
{
    char *cstr = NULL;
    AS3_MallocString(cstr, text);
    int len = strlen(cstr);
    std::string str(cstr, cstr+len);
    free(cstr);

    std::string dec = AES::decrypt(str);

    AS3_DeclareVar(result, String);
    AS3_CopyCStringToVar(result, dec.c_str(), dec.length());
    AS3_ReturnAS3Var(result);
}