public string GetBytesCode() { StringBuilder code = new StringBuilder(); SwfReader Reader = new SwfReader(this.File); Swf swf = null; try { swf = Reader.ReadSwf(); } catch (Exception Ex){ throw new Exception(Ex.ToString()); } IEnumerator enumerator = swf.Tags.GetEnumerator(); while (enumerator.MoveNext()) { BaseTag current = (BaseTag)enumerator.Current; if (current.ActionRecCount != 0) { IEnumerator currentenumerator = current.GetEnumerator(); while (currentenumerator.MoveNext()) { Decompiler decompiler = new Decompiler(swf.Version); foreach (BaseAction action in decompiler.Decompile((byte[])currentenumerator.Current)) { code.AppendLine(action.ToString()); } } } } return code.ToString(); }
private void ReadSwf(Swf swf) { this.labelVersion.Text = swf.Version.ToString(); this.labelFileSize.Text = swf.Header.FileSize.ToString(); this.labelFps.Text = swf.Header.Fps.ToString(); this.labelWidth.Text = swf.Header.Size.Rectangle.Width.ToString(); this.labelHeight.Text = swf.Header.Size.Rectangle.Height.ToString(); this.labelFrameCnt.Text = swf.Header.Frames.ToString(); this.labelSignature.Text = swf.Header.Signature; this.labelASbytes.Text = swf.ActionCount.ToString(); this.listBoxActions.Items.Clear(); BaseTagCollection tags = swf.Tags; int i = 0; for (; i < tags.Count; i++) { BaseTag tag = tags[i]; int code = tag.TagCode; if (code != -1) { SwfDotNet.IO.Tags.TagCodeEnum val = SwfDotNet.IO.Tags.TagCodeEnum.DefineBits; val = (SwfDotNet.IO.Tags.TagCodeEnum)System.Enum.Parse(val.GetType(), code.ToString()); this.listBoxActions.Items.Add(val.ToString()); if (tag is SetBackgroundColorTag) { this.listBoxActions.Items.Add(" R:" + ((SetBackgroundColorTag)tag).RGB.red + " G:" + ((SetBackgroundColorTag)tag).RGB.green + " B:" + ((SetBackgroundColorTag)tag).RGB.blue); } if (tag is FrameLabelTag) { this.listBoxActions.Items.Add(" Name: " + ((FrameLabelTag)tag).Name); } if (((SwfDotNet.IO.Tags.BaseTag)tag) is DefineFontInfo2Tag) { this.listBoxActions.Items.Add(" FontName: " + ((DefineFontInfo2Tag)tag).FontName); } if (((SwfDotNet.IO.Tags.BaseTag)tag).ActionRecCount != 0) { IEnumerator enum2 = ((SwfDotNet.IO.Tags.BaseTag)tag).GetEnumerator(); while (enum2.MoveNext()) { SwfDotNet.IO.ByteCode.Decompiler dc = new SwfDotNet.IO.ByteCode.Decompiler(swf.Version); ArrayList actions = dc.Decompile((byte[])enum2.Current); foreach (BaseAction obj in actions) { this.listBoxActions.Items.Add(" " + obj.ToString()); } } } } } this.labelTagsCnt.Text = i.ToString(); }
private void buttonGenerate_Click(object sender, EventArgs e) { int numImg = 0; int numSound = 0; int numActionScript = 0; string fileName = textBoxSwf.Text; string outputDir = textBoxDir.Text; TestPath(fileName, outputDir); if (log.IsDebugEnabled) log.Debug("**************** Start to decompile file " + fileName); listViewPix.Items.Clear(); listViewSounds.Items.Clear(); listViewActionScript.Items.Clear(); SwfReader swfReader = null; try { Cursor.Current = Cursors.WaitCursor; //var flvReader = new FlvReader(fileName); //var flv = flvReader.ReadFlv(); swfReader = new SwfReader(fileName); // Create a swf stream reader Swf swf = swfReader.ReadSwf(); // Read the completed swf file //Read headers infos labelSwfVersion.Text = swf.Version.ToString(); labelSwfDim.Text = swf.Header.Width + "x" + swf.Header.Height; labelSwfFps.Text = swf.Header.Fps.ToString(); labelSwfFrames.Text = swf.Header.Frames.ToString(); labelSwfSize.Text = swf.Header.FileSize.ToString(); labelSwfSign.Text = swf.Header.Signature; //Read tags info IEnumerator tagsEnu = swf.Tags.GetEnumerator(); //Browse swf tags list while (tagsEnu.MoveNext()) { var tag = (BaseTag) tagsEnu.Current; if (tag is SetBackgroundColorTag) { Color bgColor = ((SetBackgroundColorTag) tag).RGB.ToWinColor(); labelSwfBgColor.Text = "R:" + bgColor.R + " G:" + bgColor.G + " B:" + bgColor.B; } else if (tag is DefineBitsJpeg2Tag) { numImg++; string outfileName = outputDir + GetRandomName() + ".jpg"; ((DefineBitsJpeg2Tag) tag).DecompileToFile(outfileName); string shortName = Path.GetFileName(outfileName); var listViewItem1 = new ListViewItem(new[] {shortName, "jpg"}, -1); listViewPix.Items.Add(listViewItem1); } else if (tag is DefineSoundTag) //Extract a sound file: { numSound++; string outfileName = outputDir + GetRandomName(); var soundTag = (DefineSoundTag) tag; if (soundTag.SoundFormat == SoundCodec.MP3) outfileName += ".mp3"; else outfileName += ".wav"; soundTag.DecompileToFile(outfileName); string shortName = Path.GetFileName(outfileName); var listViewItem1 = new ListViewItem(new[] {shortName, ""}, -1); listViewSounds.Items.Add(listViewItem1); } //If tag contains action script... if (tag.ActionRecCount != 0) { var sb = new StringBuilder(); IEnumerator enum2 = tag.GetEnumerator(); while (enum2.MoveNext()) { var dc = new Decompiler(swf.Version); ArrayList actions = dc.Decompile((byte[]) enum2.Current); foreach (BaseAction obj in actions) { sb.AppendLine(obj.ToString()); } } string outfileName = outputDir + GetRandomName() + ".as"; var writer = new StreamWriter(outfileName); writer.Write(sb.ToString()); writer.Close(); numActionScript++; string shortName = Path.GetFileName(outfileName); var listViewItem1 = new ListViewItem(new[] {shortName, ""}, -1); listViewActionScript.Items.Add(listViewItem1); } } Cursor.Current = Cursors.Default; string mssg = "Swf decompiler extracts:\n"; mssg += numImg + " pictures files\n"; mssg += numSound + " sound files\n"; mssg += numActionScript + " action script blocks\n"; MessageBox.Show(mssg, "Decompilation finished", MessageBoxButtons.OK, MessageBoxIcon.Information); } finally { if (swfReader != null) swfReader.Close(); // Closing stream reader Cursor.Current = Cursors.Default; } }