0

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!!!

user2375809
  • 409
  • 1
  • 6
  • 12
  • Is it possible in actionscript to add methods at runtime? like in JavaScript, we can do eval(*) and create methods that didn't exist. – user2375809 Apr 28 '14 at 10:30

4 Answers4

1

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.

Andrey Popov
  • 7,362
  • 4
  • 38
  • 58
  • Thank you very much for your answer! The class starts with `public class HttpLoader extends Object`, does it mean this is not a dynamic class and no method can be defined at runtime? – user2375809 Apr 28 '14 at 12:19
  • As far as I know, it should be either dynamic, extended or added through prototype. I can't think of other way. The really best one here is to use break point and check what's the value of `this` and what is `CbSlotkey`. It will tell you everything :) If you don't know how to use it - I can explain it but in other question. – Andrey Popov Apr 28 '14 at 15:42
  • The code is deliberately obfuscated. I have been using Sothink SWF Decompiler to view the code. It worked very nicely for everything except the obfuscated part. I used another decompiler FFDec, which revealed the hidden part inside HttpLoader class. Thank you guys very very much for all the detailed answers. I now have a much better understanding about the syntax and grammars in ActionScript. – user2375809 Apr 29 '14 at 16:22
1

What does the keyword this mean in here?

This is a reference to a method’s containing object. When a script executes, the this keyword references the object that contains the script. Inside a method body, the this keyword references the class instance that contains the called method.

So I suppose in your case this is reference to HttpLoader if the code you posted is not in Bound Method

What would happen when a non-existent method is called?

There should be run-time exception. I think if class is defined as dynamic then it may not throw an error but I never used dynamic classes so I am not really sure.

In Java, this code won't even compile.

This is the case for AS3 too if . (dot) operator is used like in myObj.FooIsNotDefined(). But if [] is used then compiler will not perform the check like in myObj["FooIsNotDefined"]() but here should be run-time error.

Maybe HttpLoader is extending some other class which has methods you need? Or maybe decompiler messed things up?

Is it possible in actionscript to add methods at runtime?

Yes if class is dynamic or via Prototype

twoface
  • 131
  • 6
  • Thank you very very much for such a detailed explanation. I see `public class HttpLoader extends Object {...}`. It doesn't look like it is extending anything. What makes a class dynamic? Is there a keyword for dynamic classes? – user2375809 Apr 28 '14 at 12:10
  • 1
    It's not always true that if you use `.` (dot) it will throw runtime (as mentioned about the dynamic class thing). But I think it should be either dynamic, extended or added as prototype. Can't think of other way right now.. – Andrey Popov Apr 28 '14 at 15:41
1

Other answers have explained what will happen if a method is not existing in ActionScript3. (if method is referred to explicitely you'd get a compile error, if referred to by name you'd get a runtime error).

But maybe you should look for another explanation for your 'missing' methods.

In Actionscript3 it is possible to call functions with another this reference than the default using the Function class (using the call or apply functions). As this looks like deliberately obfuscated code (CB maybe means "Cheat Blocker"?) this could very well be the case.

A call to the function would be like this:

yourObject.yourMethod.call(yourOtherObjectThatIsNowThis, arg1, arg2, arg3);

By the way: the method calls that are the arguments of the String.fromCharCode function are definitely obfuscations - either meant for a decompiler or maybe for users of Cheat Engine or similar programs. So this makes it even more clear this is a deliberate obfuscation.

Simon Groenewolt
  • 10,607
  • 1
  • 36
  • 64
  • @AndreyPopov how do you know this is not the point here? I agree with you that the question does ask what happens with undefined functions, but I'd argue that this is probably what is happening in the posters code and the functions are in fact not undefined at all. I'll add an explanation in my answer. – Simon Groenewolt Apr 28 '14 at 16:11
  • I see your point now. But as I said somewhere before - it's important to know what `CbSlotkey` is. Yes, maybe `this` is something else, but I don't find this that important - dynamic properties can be injected by many ways. The question is about something else, and the answer is clear - dynamic functions can be called, and the only way to know where they come from, is by debugging. Your answer gives an option, but not a solution, yet I have to agree you are right and your option is a possible one :) – Andrey Popov Apr 28 '14 at 17:53
1

One more possibility:

If the code you attached is in a closure, this keyword can mean:

  • the global (root)
  • if called by Function.call(thisObj), then the thisObj parameter
Chaniks
  • 389
  • 1
  • 7