claus / as3swf

Low level Actionscript 3 library to parse, create, modify and publish SWF files.
MIT License
525 stars 127 forks source link

Scripts on Timeline #40

Closed helmutgranda closed 6 years ago

helmutgranda commented 9 years ago

Hi All,

I am trying to determine how to make changes to scripts on the timeline. For example my original SWF has the following:

var filetype = "parent";

Any derivative from this SWF I would like to change the variable filetype to "child".

After looking at the "loaderInfo.bytes" in its raw format I am not able to find the code that is added to the timeline. I see that external classes can be referenced but that would mean that I would have to update the external class as well at run time.

Thanks...

claus commented 9 years ago

If it's an AVM1 SWF (ActionScript 1 or 2), find all DoAction tags. In each DoAction tag, find the ActionConstantPool actions. Search the action's constant array for the string value you want to change.

If it's an AVM2 SWF (ActionScript 3), as3swf won't help you much because it doesn't parse AVM2 byte code. You'll have to use the as3commons bytecode library to do that (works similar there, change values in constant pool)

helmutgranda commented 9 years ago

I am using AVM2

If I understand this correctly the code would have to be compiled twice? one for the visual changes and once for the AS with two different libraries.

claus commented 9 years ago

There is no AS in a SWF, there's only byte code.

makc commented 9 years ago

also stuff like var filetype = "parent" is not normally preserved, so you can not search for "filetype". you could search for "parent", if that string is unique enough, but to replace it with the string of different length - you need to use as3commons.

helmutgranda commented 9 years ago

Thank you all for the comments, as a last resource I am looking at the possibility to be able to add AS to the timeline, given that the original content is being discarded.

Basically I have a very complex AS3 project that is composed of multiple external custom AS files and they are integral for the display of this file, the goal is that with a custom UI the user will be able to modify some of the default settings and save a new SWF with the new properties (for example filetype="child" - I am not really using filetype as a variable but was mainly to pass the point across).

Is that possible with just AS3SWF? I am also looking at HAXE but right now the problem is porting all the custom classes and custom code to HAXE.

robinrodricks commented 9 years ago

You can use as3commons bytecode lib to modify AS3 code, add code, anything you imagine. See

https://www.google.co.in/search?#q=modify%20as3%20bytecode

https://www.google.co.in/search?#q=modify+as3+bytecode+as3commons

A more similar example to what you need, modifying strings in AS3 code.

http://blogs.adobe.com/digitalmedia/2011/04/introducing-mixing-loom-runtime-actionscript-bytecode-modification/

The lib can parse & generate AS3 code via the DoABC Tag, that can be inserted into the SWF using as3swf.