Search code examples
actionscript-3flashactionscriptdecompiling

what happens when calling a non-existent method in flash actionscript?


I am a Java developer. My recent project requires me to understand some decompiled ActionScript.

I think I understand most of the code since the syntax isn't much different from Java. However, it starts confusing me when I see

_loc_10 = {};
if (param1.lastIndexOf("?") != -1)
{
  _loc_8 = param1.split("?", 2);
  param1 = _loc_8[0];
  _loc_13 = _loc_8[1];
  _loc_10["mzsg"] = _loc_13;
}
if (param3 != null)
{
  for (_loc_16 in param3)
  {           
    _loc_10[_loc_16] = _loc_17[_loc_16];
  }
}
_loc_10[this.CbSlotkey()] = this.CbSlotvalue();
_loc_11 = JSON.stringify(_loc_10);
_loc_15 = "";
_loc_15 = String.fromCharCode(this.CbSlot(), this.CbSlot2(), this.CbSlot3(), this.CbSlot4(), this.CbSlot5()) + this.CbSlot6();
_loc_12 = new URLVariables();
 _loc_12.z = myzip(_loc_11);
_loc_12.b = MD5.hash(_loc_12.z + _loc_15);
param3 = _loc_12;

The upper half is all right, but I can't find CbSlotKey() or CbSlotvalue() defined anywhere in the entire code base. What would happen when a non-existent method is called? In Java, this code won't even compile. Does actionscript compiler not check methods' existences?

What does the keyword this mean in here? The class I am looking at is called HttpLoader. Is this pointing to HttpLoader or it could be pointing to something else? I find something calls like the one below in the same class, and the methods are clearly not defined in HttpLoader?

this.escape(ver_build)

Thank you very much in advance!!!


Solution

  • First - it's hard to understand decompiled code :)

    this points to the current Class that is being used - for example if you have member variable with the same name as the param passed to a function, this.param will point to the member variable.

    And yes, Classes can be dynamically modified if the class is marked as dynamic (check here: http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7f89.html). Every unit is an Object itself, so it's like adding properties to an object.

    So in your case, it is possible that this particular key (this.CbSlotkey()) is dynamically defined, exactly like other properties are being defined there (_loc_10[_loc_16] = _loc_17[_loc_16];)

    For example, this is a valid AS3:

    this['test' + 'Func'] = function() {
        trace ('test');
    }
    this.testFunc(); // traces test
    

    Unfortunately, this means that there's not a lot options to understand what's going on. The best choice is to use debugger and track all those variables and the result of the actions. You may first try to give some proper names to all those messy variables in the code.

    Edit: I forgot to mention, that if you call a dynamic non-existent method withing Flash, it will throw a runtime exception. If you try to call a method of non dynamic scope that does not exists, it will throw a compilation error.