Actionscript/LocalConnection

From Gnash Project Wiki

Jump to: navigation, search

LocalConnection

This is basically a Flash version of the a standard RPC (Remote Procedure Call), only it's limited to applications running on the same host. This is used to have multiple flash movies exchange data without converting it to XML first. This class uses shared memory to transfer AMF objects. There can be multiple clients for a connection, and it's possible to see if a receiver application is running and registered.

On a standard GNU/Linux machine, all shared memory segments live in /dev/shm, so it's relatively easy to find them for disassembly. The other player appears to use the older SYSV style shared memory segments, which makes them much harder to analyze.

The connection segment is always 64528 bytes in size, and the SYSV key appears to be different for each installation'. You can find the key for your machine easily by grepping the output from the ipcs for all shared memory segments of this size. Once you have that, you can use the set LCShmKey option in your ~/.gnashrc file so dumpshm and Gnash can access that segment. If you don't care about compatibility with the other player, then you can set this to any unique number you want, or use ftok() to create one.

The dumpshm utility in Gnash now supports two new options for dumping the segment to the screen, or writing the raw file to disk for later decoding.

The maximum size of an AMF object allowed in a connection is 40k bytes. The listener table starts after this, at byte location 40976. The listener table is a simple array of const char * strings. For an application to register itself on a connection, it merely adds itself to the list. When an application goes away, it removes itself from the list. Although they aren't available by ActionSctipt, the LocalConnection implementation in Gnash allows one to list, add, and remove Listeners from the table. These are currently used only internally.

  • method LocalConnection::connect()
  • method LocalConnection::domain()
  • method LocalConnection::send()
  • method LocalConnection::close()

LocalConnection::connect

This establishes a connection point so other movies can remotely execute methods in this movie. The shared memory segment is created in a form that can be attached to by clients. This must be called first by the receiver application, which creates the empty memory segment. Once created, it can later be sent to by the clients using the send command.

LocalConnection::domain

This correctly returns the network domain for this connection. The default is to return "localhost". The returned value is properly adjusted based on the version of the swf movie. For v6 or earlier, the domain was returned without the nodename, ie... www.foobar.com became foobar.com. For v7 this changed, and the full hostname is returned.

LocalConnection::send

This passes data between applications, and stores any type of AMF data. When storing objects, methods may be called on them by the clients in an RPC like manner.

LocalConnection::close

This is implemented, and it closes the current open connection, and removes the shared memory segment.

There is more information on this at http://osflash.org/localconnection.

Gnashrc Options

The following options are supported by Gnash when dealing with LocalConnections.

  • set set LCShmKey 0xdd3adabd
Specify the shared memory key used to access shared memory segments.

Debugging Tips

Once you have you shared memory key as described above, it's easy to use standard unix utilities to manipulate the shared memory segment on your machine. To list SYSV style shared memory segments, use ipcs, and to remove them, use ipcrm. So if you are paranoid, you can delete the memory segment, and it'll be recreated clean the next time you run the swf player.

ipcs -m | grep 64528
ipcrm -m [ID]