tsvbits

How did we make Flash Viewer at ActiveReports

August 11, 2019 • ☕️ 3 min read

TL;DR GrapeCity open-sources dotnet to flash bytecode cross-compiler

It was not easy path. First we implemented a cross compiler from dotnet to AVM bytecode.

And this post is about this cross compiling tool. It is called PageFX. I can use PFX for reference too.

History

This project started in the early days of WPF. It was intended to allow building multi-platform internet applications using C# and the Adobe Flash Player VM. The project was pivoted for internal use at Data Dynamics after the release of Microsoft Silverlight.

I joined this project in June of 2007. My first experience with this technology was an attempt to build a real-world applications on the initial prototypes, which were unsuccessful. We decided to rewrite the compiler based on the following:

  • .NET CLI ECMA-335 spec - this doc describes format of .NET executable files
  • AVM overview doc - this doc describes format of byte code parsed and executed by ActionScript Virtual Machine
  • AVM source code - initial version was hosted at Mozilla
  • also I’ve showed CIL, SWF, ABC readers I’ve done so far as artifact of my learning CIL and ABC executable file formats

I made few major iterations to make the compiler. First iteration was not successful though a lot of test cases worked. I’ve tried to build .NET decompiler first and then translate it to AVM bytecode. I don’t remember why I’ve decided to deny approach with decompiler, but idea with binary translation won and I’ve quickly implemented first prototype.

Then it took about 6 months to get working a lot of Mono tests for bytecode generated by C# 2.0 CLR 1.0 format (basically no generics).

With the availability of more resources the following were added:

  • Almost full support of CLR 2.0 byte code format including generics
  • Interop with libraries built by ActionScript compiler (ASC)
  • Debugger for Visual Studio 2008

The project was successfully used to build our multi-platform report viewer as part of the ActiveReports Server platform and ActiveReports product lines.

Going open source

This project might be interesting for education purposes for Microsoft Research students or any other universities.

I’ve made an experimental branch with additional changes that were not used in production:

  • PFX compiler to be cross-platform/runnable on Mono VM and compatible with Mono C# compiler
  • Reuse of Mono MDB reader, i.e. managed reader of debug symbols. Previously we use COM library runnable only on Windows
  • Multi-targeting on Flash Player 9.0 and higher, i.e. Flash APIs are declared in separate assemblies auto-generated as part of build process
  • Multi-targeting on Flex SDK 3.3 and higher. Interop assemblies for Flex SDK are also auto-generated
  • Faster lazy parsing of assemblies into immutable data structures with less memory consumption

In addition master branch includes these interesting experiments:

  • JavaScript code generation (many tests were passing)
  • CIL interpreter written in pure C# on top of PFX infrastructure
  • Port of Starling game engine

You might also find interesting this old project available on github. It has declarative CIL reader written in JavaScript. This could be a starting point for full CIL interpreter in JavaScript.

If someone interested to get more details about PageFX project please email me. I can write a series of blog posts on the topic.

Funny facts

  • Initial prototype of Flash Viewer was hacked by olegzee in July 2008 in few weeks during his vacation
  • PFX compiler was used almost ten years after discontinue of development. Without any fixes it compiled flash report viewer on build machines until drop of its support. I know it had bugs, but it was enough for this report viewer

P.S. All dates might be a little bit wrong. Sorry for that