Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading external swf and executing a function with redtamarin #22

Closed
Swanty opened this issue Dec 11, 2015 · 6 comments

Comments

Projects
None yet
2 participants
@Swanty
Copy link

commented Dec 11, 2015

Is it possible to load swf from file and then call a function that's inside the swf with redtamarin?

I see that there is shell.FileSystem for loading the file into bytearray, but there is no flash.display.Loader to load from bytearray

There is also the shell.Domain.load() and shell.Domain.loadBytes(), but as I understand it only supports .abc files?

@zwetan

This comment has been minimized.

Copy link
Member

commented Dec 11, 2015

So "as is" no it's not possible

for now the default allow us only to load .abc files

but in a future update we will add a library/tool (name to be decided)
that will be able to dynamically load a SWF file and maybe SWC files
or at least dump the ABC from a SWF etc.

a SWF file format can be quite complicated, it can contains code in "doABC" tags,
but also assets like audio, image, video, font, etc.

I had already a go with a tool "swfinfo" to parse SWF files
see SWFParser

there are more advanced libraries like as3swf

and also abcdump/abcdis that you can find in the src/utils

and there are also a couple of thing missing in the native redtamarin libraries
for example: if you could load a SWF, then extract the ABC from the SWF and
load them in memory, it could break because you're missing some Flash or AIR native implementations, and that can be quite hard to debug.

For now, it is safer to compile your own ABC and load only ABC files

first, it will force you to use ASC to compile the AS3 source code
see Compiling Programs
and be able to see upfront if there are compatibilities issues with redtamarin
and second, once you generate an ABC you can simply load it dynamically

Yes all that can become quickly very complicated, hence why a tool like redbean exists

I will document different use case, but let's be clear loading a SWF
produced for Flash or AIR is unlikely to be available soon

@zwetan zwetan added the question label Dec 11, 2015

@Swanty

This comment has been minimized.

Copy link
Author

commented Dec 11, 2015

Ah, that's unfortunate.
RedTamarin seems like the perfect project that I needed as in executing as3 from CLI

Specifically what I'm trying to do is execute a CrossBridge/FlasCC function that is inside an swf, since it's really hard to decompile/reverse engineer CrossBridge compiled actionscript back to its C/C++ equivalent, especially if the original code was obfuscated.

I tried using rabcdasm abcexport tool to get .abc from .swf, but upon loading it with Domain.load() function I get "VerifyError: Error #1014" which is what you said, that it will break since I'm missing some native implementations.

Either way, thank you!

@zwetan

This comment has been minimized.

Copy link
Member

commented Dec 11, 2015

on this special case
"trying to do is execute a CrossBridge/FlasCC function that is inside an swf"
I can guarantee it will never work as redtamarin take a very different approach

if in CrossBridge project you were to use the mkdir() C function
this resolve to a syscall at compilation time which is then linked back
to a native call from the Flash/AIR API

in Redtamarin you can use the mkdir() C function
because it is a native library which call the "real" mkdir native C function

the two are not compatible at all
for now, adding CrossBridge support inside Redtamarin is not planed

so even if loading a SWF was possible,
loading a SWF produced by CrossBridge code would certainly break

@zwetan

This comment has been minimized.

Copy link
Member

commented Feb 4, 2017

From Redtamarin 0.4.2 you will be able to dynamically load a SWF file

A Person class

package test.as3examples
{

    // A basic class for testing
    public class Person
    {

        public var name:String;
        public var age:uint;

        public function Person( name:String = "", age:uint = 0 )
        {
            this.name = name;
            this.age = age;
        }

        public function toString():String
        {
            return "{Person \"" + name + "\" age: " + age + "}";
        }

    }

}

you compile it to Person.swf
eg. $ java -jar asc.jar -AS3 -optimize -d -import redtamarin.abc -swf Person,100,100 Person.as

now at runtime you can load it with either
Runtime.load( filename:String ):Boolean
or Runtime.loadAnyBytes( b:ByteArray, filename:String ):int

example

import shell.*;

var loaded:Boolean = Runtime.load( "Person.swf" );
trace( "Person class dynamically loaded: " + loaded );

// now that the definition is in-memory
// you can directly use any package, class, interface, etc.
// as if it was part of your code
import test.as3examples.Person;

// there is a limitation, you can not type the var with Person
// eg. 'var johndoe:Person' will fail as Person need to be a constant
var johndoe:* = new Person( "John Doe", 21 );
trace( "johndoe = " + johndoe );
trace( "is Person class: " + (johndoe is Person) );

Only SWF containing AS3 definitions in doABC tags are supported

what will not work or be supported

  • SWF compiled with playerglobal.swc or airglobal.swc
    that use native implementations not available in Redtamarin
  • SWF compiled with CrossBridge/FlasCC
    that depends on C/C++ libraries

Runtime.load() can dynamically load either *.as, *.abc or *.swf files
but it is not "magic", those files need to define AS3 code that can actually run inside Redtamarin

@zwetan zwetan added this to the 0.4.2 milestone Feb 4, 2017

@zwetan zwetan added the enhancement label Feb 4, 2017

@zwetan zwetan closed this Feb 4, 2017

@zwetan zwetan reopened this Nov 8, 2017

@zwetan

This comment has been minimized.

Copy link
Member

commented Nov 8, 2017

so to this

Specifically what I'm trying to do is execute a CrossBridge/FlasCC function that is inside an swf, since it's really hard to decompile/reverse engineer CrossBridge compiled actionscript back to its C/C++ equivalent, especially if the original code was obfuscated.

I orignally answered

on this special case
"trying to do is execute a CrossBridge/FlasCC function that is inside an swf"
I can guarantee it will never work as redtamarin take a very different approach

if in CrossBridge project you were to use the mkdir() C function
this resolve to a syscall at compilation time which is then linked back
to a native call from the Flash/AIR API

in Redtamarin you can use the mkdir() C function
because it is a native library which call the "real" mkdir native C function

the two are not compatible at all
for now, adding CrossBridge support inside Redtamarin is not planed

so even if loading a SWF was possible,
loading a SWF produced by CrossBridge code would certainly break

And I was wrong :)

For something unrelated, I went a lot more in deep into the crossbridge sources, and even if crossbridge and redtamarin have a completely different approach, there are not necessarily incompatible.

It not gonna happen overnight, but supporting crossbridge is definitively possible
but there will be some limitations

  • probably do a crossbridge compile with a path
    (eg. already generated crossbridge libraries would probably have to be recompiled)
  • no UI or other GUI rendering
  • no support for Flash API not implemented in Redtamarin yet
  • maybe not a full support of pthreads

That said, it should be possible to use crossbridge to compile C/C++ sources to .abc and/or .swf and/or .swc and use that library in a redtamarin project.

So, as part of the different "glue" libraries, crossbridge support is back on the map as "planed".

Don't hold your breath though, it could take a while (~1 year) for this to work with redtamarin.

@zwetan

This comment has been minimized.

Copy link
Member

commented May 21, 2018

see #129 adding CrossBridge support

@zwetan zwetan closed this May 21, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.