-
Notifications
You must be signed in to change notification settings - Fork 15
Home
The first step before being able to do any tinkering with the SWF file is initializing a new ShockwaveFlash object. There are a few other constructors you can use for initialization, but we'll go with a simple local file path for now.
string path = @"C:\Client.swf"
var flash = new ShockwaveFlash(path);
This will read the header of the SWF file, the header contains the following information about the file:
- [3B] Compression(None, ZLIB, LZMA)
- [1B] Version
- [4B] File length(Inclusive of Header 8B)
The frame record is also read at this point, regardless of whether the file is compressed or not.
Once the file has been initialized, the Disassemble method must be called for viewing, and editing the tags contained in the SWF file. This method should only be called once, no need for re-reading all the tags again.
flash.Disassemble();
After disassembly has completed, you are now able to view/modify/add any tags you want to the Tags property. The Tags property is of type List<TagItem>, any and all supported tags inherit from this type.
We can simply view what type of tag they are by accessing the Kind property, allowing us to file through the list without having to attempt an explicit cast.
As an example, let's enumerate through the Tags property, and find all the DoABCTag's
flash.Disassemble();
foreach(TagItem tag in flash.Tags)
{
if(tag.Kind == TagKind.DoABC)
{
var doABCTag = (DoABCTag)tag;
// We can edit, or just simply view the tag contents here.
}
}
After you've done all the tinkering you wanted to do, you're ready to assemble all the tags back into a proper SWF file. This can be achieved by calling the Assemble method.
A new FlashWriter instance can be created by providing a Stream to one of the constructors available. When creating the instance with a stream, you can also specify whether you want to keep the stream open with one of the provided constructors.
flash.Disassemble();
foreach(TagItem tag in flash.Tags)
{
if(tag.Kind == TagKind.DoABC)
{
var doABCTag = (DoABCTag)tag;
// We can edit, or just simply view the tag contents here.
}
}
string asmPath = @"C:\asm_Client.swf"
using(Stream fileStream = File.Open(asmPath, FileMode.Create))
using(var output = new FlashWriter(fileStream))
{
flash.Assemble(output);
// OR
// flash.Assemble(output, CompressionKind.None);
}