SWF Decompiler for Macromedia Flash 4, 5 , MX and MX 2004 SWF files      
  What is ASV?   Download Demo   Documentation   ASV Tools   Reviews   News   FAQ   Order Online   History   Links   About Manitu Group

About the 'Show Register Optimizations as Temp Variables' option
'Show Register Optimizations as Temp Variables' is a new, experimental option, introduced with ASV 3.13.
 
ASV cannot show higher level actionscript code, if the code in a SWF is optimized by hand. Because there will be no actionscript representation for the p-code. In these cases, ASV will correctly show the p-code.
 
ASV 3.x supports SWF files generated by Flash 3, 4, 5 and MX. Also SWF files generated by some 3rd party applications and bypassing popular obfuscators (as requested by our customers) are, though unofficially, supported.
 
Some History
Just 3 days ago, on May 16, 2003, one of our customers submitted a SWF file that ASV cannot show the higher level compilable actionscript code for; the p-code was correctly shown. The SWF was not his but found online on a well known site. The code contained full register usage to cache variables, an optimization Flash MX won't generate!. On the other hand the optimizations seemed not done by hand, though possible.
 
What do these look like?
First of all, every function starts by pushing the unused registers 1, 2 and 3 (unused by Flash MX):
    push r:1, r:2, r:3
and restores them before returning:
    ...
    setRegister r:3
    pop
    setRegister r:2
    pop
    setRegister r:1
    pop
    ...
Also function results can be returned in registers:
    ...
    setRegister r:0
    ...
    push r:0
    return
After making sure that the function does not modify the register values (as above), it uses the registers to cache local variables. This is indeed a very good optimization, making access to objects many 'dots' deep faster. Also local variables just used for temporary purposes (like in a For...in loop) are stored in registers. These optimizations will make the code run faster and even smaller. Here's the full p-code:
	function 'useBaseStyle' (oldStyle)
	push r:1, r:2, r:3, 'oldStyle'
	getVariable
	setRegister r:1
	pop
	push 0.00, 'TextFormat'
	new
	setRegister r:2
	pop
	push r:1
	enumerateValue
@13	setRegister r:0
	push NULL
	equals
	branchIfTrue @24
	push r:0
	setRegister r:3
	pop
	push r:2, r:3, r:1, r:3
	getMember
	setMember
	branch @13
@24	push r:2
	branch @26
@26	setRegister r:0
	pop
	setRegister r:3
	pop
	setRegister r:2
	pop
	setRegister r:1
	pop
	push r:0
	return
We noticed some unnecessary jumps to the next address (see branch @26 line above), which hinted that the optimizations were not done by hand but by a compiler.
 
A Temporary Solution
If these optimizations are made by a compiler, adding support for these to ASV is not fully possible without having access to the compiler, with just one sample SWF file. Also the changes required to the decompiler engine will not be trivial. In any case, we cannot promise to update ASV 3.x to support this unknown compiler.
 
We worked hard and came up with a temporary solution. When the new 'Show Register Optimizations as Temp Variables' option in ASV 3.13 is selected in the Preferences Dialog, ASV shows the registers as temporary variables. The resulting code will be compilable with Flash and even may be faster than the 'original code' compiled with Flash MX! Still, this feature is experimental.
 
Original Code (our guess):
    function useBaseStyle (oldStyle) {
        var a = new TextFormat();
        for (var b in oldStyle) {
            a[b] = oldStyle[b];
        }
        return(a);
    }
The way ASV shows the optimized code:
    function useBaseStyle (oldStyle) {
        _ASVREG1 = oldStyle;
        _ASVREG2 = new TextFormat ();
        for (_ASVREG3 in _ASVREG1) {
            _ASVREG2[_ASVREG3] = _ASVREG1[_ASVREG3];
        }
        //
        return (_ASVREG2);
    }
ASV inserts the temporary variables _ASVREG1, _ASVREG2 and ASVREG3. (You can change the _ASVREG part by changing the _ASVREG=_ASVREG line in ASV.INI file.) You can remove the temporary variables if necessary (by hand). The register usage will be pretty obvious in the code as in the above sample. The empty comment line above is for the unnecessary jump.
 
The decompiled actionscript will not be the 'original code', because there is no 'code' you can write in Flash MX to generate the optimized p-code.
 
Notes
  • When the preference 'Show Register Optimizations as Temp Variables' is selected 'Show Action Address (Debug)' and 'Enable Temp Variable Insertion' preferences will be disabled.
  • You'll see some (maybe lots of) errors/warnings in the Error Log Dialog in either case.
  • This option is not selected by default, when you see the error messages 'Possible Errors in Actionscript Data', 'Registers modified in IF block', try selecting this option.

 
revision 0.1 May 19, 2003
Copyright © 2000-2003 Manitu Group, Istanbul, Turkey. All rights reserved. All trademarks acknowledged.
Privacy Policy