These days AS3 devs are all moving to AIR, so I am not sure how many of them still feel like they need to protect SWF bytecode. Neverless, my three years old “proof of concept” SWF obfuscator post remains one of the most visited posts of this blog. Guess what – it’s update time! Behold brand new free SWF obfuscator version 2 :) So, what’s new?
Faster processing
Much faster! New version still goes same old “replace the string everywhere in SWF” way, but it uses special charcode tree to replace all identifiers in single pass. I might write another post on subject, if there is enough interest.
Automatic identifiers collection
You no longer have to manually type identifiers that you want to replace. The obfuscator runs your SWF through as3commons parser and collects all identifiers; then you can remove identifiers that you don’t want to replace. Note that neither as3commons parser nor my wrapper code are perfect, so it will fail for some SWFs. You can send me those, if you want, but I may not be able to fix that after all.
Bulk filtering
You don’t want to rename stuff like beginBitmapFill, so I parsed playerglobal.swc v11.6 and made a checkbox to ignore all those identifiers. Did the same for apache flex then, but not sure if that’s useful – so that checkbox is off by default.
That’s about it. One last warning: there will be invalid SWFs, and there will be bugs. I can’t really fix them all, but if you send me your stuff I might try. Or not.
Wow this is great !
Bookmarked :D
Can you give swf for run it localy?
The url currently redirects to swf so just save it, and also “wr.swf” example game that it loads by default from the same folder. Any way, it does not send stuff you open to any servers nor log it in any way, check with network monitor if you want.
Hello i tried to obfuscate AIR SWF file and the program break, can you help me please.
Indeed, I probably need to filter airglobal stuff, not playerglobal… but why would you obfuscate AIR app? AIR replaces your scripts with native code, which is, therefore, immune to AS3 decompilers.
But when you install an .air app, create in windows an exe file and the swf that is unprotected and with a decompiler program i could view all the code.
Really? I thought it works more like iOS target. Oh well, okay then. I will try to update it this weekend.
Changed playerglobal exceptions list to airglobal, should work now.
Nice small tool, adds well to Closure/YUI/similar for projects with multi-target output.
Few points,
1. For SWFs that add their children to Stage directly (e.g. HaxeNME ones, which get that from preloader automatically), “everything is horrible” in terms of them leaking out of preview area, not being removed upon loading new SWF, overlapping UI elements, and otherwise behaving inappropriately. To be honest, I’m not sure how to fix this from AS3 side, but thought that I’d inform of this anyway.
2. It could be a useful option to add an extra identifier obfuscation option being renaming identifiers to random stuff, but with number of occurrences kept in mind. So that the most used identifiers would be renamed to 1 or 2 symbol long strings, less often used ones to 3 symbols (once ASCII range runs out for 1/2 char-long identifiers), then 4… such does well for both obfuscation (since it’s not a lot of help knowing that something is used often, if it’s named with random symbols) and compacting (since identifiers become shorter this way… though it’s probably not that much impact for AS3).
1 swfs that assume the stage is immediately available will fail too. that’s why preview has that checkbox.
2 that would require more intelligent approach. currently it is bruteforce search-and-replace across the swf.
Hello m8, I truly appreciate your work!
Unfortunately there are 2 problems I got
– when I click ‘Obfuskate’ on the demo swf as it is it goes blank
– if I download the obfuskator.swl it’s not working locally as the previous one does
Thanks a lot man, you rule! :)
Hmm, I do see 1st issue too. I updated exclude list with AIR stuff once, it might be it. Too bad :( Will have to look into it next weekend.
Thank you! Still the other one works for me :)
Obfuscator down?
Whole site is down ) Need to buy new hosting.
Eh, could you share obfuscator’s swf somewhere else?
Maybe tonight.
Regarding hosting – take a look at DigitalOcean.
makc3d, is it possible to download obfuscator?
Sorry, I have forgot about it. My hosting went down the drain, so I will probably be putting it on github some day.
It would be just fine! Thank you.
Done :) Link in the post is updated.
Thanks!
Thank you!
quick question, i used this on an swf, but i see for example this line unobfuscated:
private var _active:Boolean = false;
Why is it? it is because of the underscore? Or because it’s private?
There is the setting that limits minimal length of IDs eligible for obfuscation (8 by default, _active is 7). This is done because replacement algorithm is really dumb and replaces the string everywhere – allowing it to replace shorter strings increases the probability of broken SWF.
and what about this cases (copy pasting random unobfuscated code)
private var _flagBitmap:Bitmap = null;
private var _flagBitmapData:BitmapData = null;
private var _flagBounds:Rectangle = null;
private var _mainNode:Sprite = null;
private var _offset:Number = 0;
private var _small:BitmapData = null;
private var _scaleMatrix:Matrix = null;
Im using JPEXS Free Frlash decompiler…
Original swf im using: https://www.dropbox.com/s/tma4luangs411qd/example5.swf
Obfuscated:
https://www.dropbox.com/s/9t3uz98kfcuylcm/obfuscated.swf
Apparently its SWF parser misses most of stuff in your SWF :S Just by loading it into the obfuscator, you can see IDs list is very short.
What did you use to compile this SWF? I will try to see what’s wrong with the parser.
im using to compile Flash Develop 4.4.3 with Flex Framework that comes with it, which i think is Flex 4.
I didn’t wrote that code, it was from an example code in some site, i was just trying to test your obfuscator to see if it works… compiling then obfuscating and then trying to decompile…
Also is there any sourcecode available? I would like to include variables with less than 5 characters in length that match a particular criteria, like a RegExp… or if you dont want to provide the code, but you have some free time, could you add a field where you type a Regexp?? and remove the character limit? (at the user’s own risk obviously)
Yes, it’s on github.
Oh the irony, to have to decompile an swf made to obfuscate… LOL
well i was especting sourcecode, like AS3 and stuff, but i got all i needed from the decompilation so it’s all good…
Most probably you’re looking at the wrong branch.
ok, now i feel stupid U_U yeah i was looking at the wrong branch…
This code took me almost 2 hours to swallow, but i finally did! And damn! that’s very clever! I learned a new thing, thanks! :D
I believe it is called “trie“. Any way, for your purpose it is wrong part of code to look at. You need to dig into SWFUtil thing that collects IDs.
yes i know, but i like to understand how everything works before trying to edit something. Even if i know what to edit, i feel like i “must” know how everything works.
One problem i’m facing, is that i cant seems to find a way to replace a name for another SHORTER one without doing copy pasting of bytearrays and making things crazy slow…
Do you know a fast alternative to replace for example “Aeroplane” for “cat” ?
Since it’s a byteArray that would leave gaps… i did some test copying everything before the word to a new bytearray, then pasting the new name, and then the rest of the bytearay after the old word… but that was crazy slow, like 1 second per word speed slow…
any tips?
Obviously I know no easy way to do that. Hard way involves understanding DoABC tag structure and modifying it accordingly.
Mother of God… THANK YOU SOOOO MUCH FOR THIS!!
What about public vars and private/protected vars? I’ve seen that it have not been renamed
It’s a matter of adding them into the list. At the time I did not feel motivated to learn SWF format, so I just pulled everything I could find in debugger that looked like a text, into keywords list. Of course I could miss some cases. But the source is up there somewhere, feel free to submit a patch :)
Does it work with for written in as2 flash version 8?
Probably not. But the previous version, where you could add strings by hand, will work.