📜 ⬆️ ⬇️

Undocumented features of ActionScript 1.0 / 2.0. Part 1.

Often, to solve an important task, one has to iterate over the properties of an object. Suppose you want to display property values ​​in the Output panel for debug information. Another example is the decoding of unknown properties of an object returned, say, when accessing a database on a server. Naturally, we would like to sort out the hidden (undocumented) properties of ActionScript and see if there is anything interesting in them.

From the point of view of the Flash interpreter, the core ActionScript for..in loop means the following: “Take the specified object and for each of its properties (including the methods stored in the properties) execute the body of the loop”. However, many built-in methods and properties of ActionScript are by default excluded from the iteration in the for..in loop. It is assumed that the programmer is interested in objects and properties created by him in the program, and not those that are the basis of the ActionScript operation, therefore, the built-in properties are excluded from the search for ..in. The undocumented ASSetPropFlags () function makes it possible to make visible even those properties and methods that usually remain invisible for iteration.

As you might guess from its name, the ASSetPropFlags () function allows you to set protection flags for properties from ActionScript. Flags tell Flash Player if appropriate methods and properties should be included in the for.in brute force. The ASSetPropFlags () function also allows you to prohibit the writing (or iteration) of the properties and methods of user objects, to prevent their accidental modification. This is especially true for global properties of the redistributable components to prevent conflicts with third-party components used in the same SWF file.
')
Let's take a look at how the ASSetPropFlags () function works.
ASSetPropFlags () call syntax:
ASSetPropFlags (object, properties, maskThree, maskFalse)
Where:
object - an object or scope;
properties - properties / methods of the object for which you are going to change
protection flags. The special argument null means "all properties";
MaskTrie - integer bitmask that defines configuration flags. Significant are the last three bits of an integer, representing (from right to left) the flags of "rewrite protection", "protection against deletion" and "hide". For example, the binary value of 11O (06 in hexadecimal notation, 6 in decimal) protects the properties specified by the second parameter from writing and deletion, but ceases to hide them when iterating;
mask False is another integer bitmask that works similarly as a mask, but resets the specified flags. Mask False is applied before the mask is applied.

On the FlashCodersWild page ( http://chattyfig.figleaf.com/flashcoders-wiki/?AssetPropFlags ) there is a diagram describing the various bit masks used by the ASSetPropFlags () function.
The properties / methods we want to make visible belong to the _global scope, which contains all the built-in ActionScript classes. Thus, after executing the following command, all ActionScript classes become fully searchable:
ASSetPropFlags (_global. Null. 6. 1);
The following snippet lists all the classes found in the open scope:

// Set the protection flags to _global to be 110 (dv.) To make them available for iteration
ASSetPropFlags (_global. Null. 6. 1);

// Create a list of objects in _global
for (thisObject in _global) {
trace (thisObject);
}

To find out if there are anything interesting in these classes, we will iterate through all of their properties. If the search finds the prototype property in which the methods and properties of the class are stored (in ActionScript 1.0 and 2.0), we will iterate through its contents:

// Set the protection flags to _global to be 110 (dv.) To make them available for iteration
ASSetPropFlags (_global, null, 6, 1);
// Create a list of objects in _global
for (thisObject in _global) {
ASSetPropFlags (_global [thisObject], null, 6, 1);

trace ("\ n" + thisObject);
for (props in _global [thisObject]) {
trace ("" + props);
// Display the contents of the prototype,
if (props == "prototype") {
ASSetPropFlags (_global [thisObject] .prototype, null, 6, 1);
for (protoChain in _global [thisObject] .prototype) {
trace ("" + protoChain);
}
}
}
}

If you attach this code to frame 1 and test a movie in Flash MX 2004, it
will display a long list of documented classes with methods and properties.

Source: https://habr.com/ru/post/30887/


All Articles