Chinaunix首页 | 论坛 | 博客
  • 博客访问: 158985
  • 博文数量: 56
  • 博客积分: 2510
  • 博客等级: 少校
  • 技术积分: 502
  • 用 户 组: 普通用户
  • 注册时间: 2009-12-18 14:21
文章分类

全部博文(56)

文章存档

2010年(39)

2009年(17)

我的朋友

分类:

2009-12-24 12:36:30

#!/bin/perl

#use strict;


my %Tag_Name = (
0 => "End",
1 => "ShowFrame",
2 => "DefineShape",
4 => "PlaceObject",
5 => "RemoveObject",
6 => "DefineBits",
7 => "DefineButton",
8 => "JPEGTables",
9 => "SetBackgroundColor",
10 => "DefineFont",
11 => "DefineText",
12 => "DoAction",
13 => "DefineFontInfo",
14 => "DefineSound",
15 => "StartSound",
17 => "DefineButtonSound",
18 => "SoundStreamHead",
19 => "SoundStreamBlock",
20 => "DefineBitsLossless",
21 => "DefineBitsJPEG2",
22 => "DefineShape2",
23 => "DefineButtonCxform",
24 => "Protect",
26 => "PlaceObject2",
28 => "RemoveObject2",
32 => "DefineShape3",
33 => "DefineText2",
34 => "DefineButton2",
35 => "DefineBitsJPEG3",
36 => "DefineBitsLossless2",
37 => "DefineEditText",
39 => "DefineSprite",
43 => "FrameLabel",
45 => "SoundStreamHead2",
46 => "DefineMorphShape",
48 => "DefineFont2",
56 => "ExportAssets",
57 => "ImportAssets",
58 => "EnableDebugger",
59 => "DoInitAction",
60 => "DefineVideoStream",
61 => "VideoFrame",
62 => "DefineFontInfo2",
64 => "EnableDebugger2",
65 => "ScriptLimits",
66 => "SetTabIndex",
69 => "FileAttributes",
70 => "PlaceObject3",
71 => "ImportAssets2",
73 => "DefineFontAlignZones",
74 => "CSMTextSettings",
75 => "DefineFont3",
76 => "SymbolClass",
77 => "Metadata",
78 => "DefineScalingGrid",
82 => "DoABC",
83 => "DefineShape4",
84 => "DefineMorphShape2",
86 => "DefineSceneAndFrameLabelData",
87 => "DefineBinaryData",
88 => "DefineFontName",
89 => "StartSound2",
90 => "DefineBitsJPEG4",
91 => "DefineFont4",
);

my %Audio_Codec = (
0 => "Uncompressed, native-endian",
1 => "ADPCM ",
2 => "MP3",
3 => "Uncompressed, little-endian ",
4 => "Nellymoser 16 kHz ",
5 => "Nellymoser 8 kHz ",
6 => "Nellymoser ",
11 => "Speex ",
);

my %Sample_Rate = (
0 => "5.5 KHz",
1 => "11 kHz",
2 => "22 kHz",
3 => "44 kHz",
);

my %Bit_per_Sample = (
0 => "snd8Bit",
1 => "snd16Bit",
);

my %Channels = (
0 => "mono",
1 => "stereo",
);

open SWF_FILE,"<$ARGV[0]" or die "$!";
open PCM ,">01.pcm" or die "$!";

print "enter q or Q to quit!\n";
binmode SWF_FILE;
binmode PCM;

my $headerSize = 21;
my $buf;
read(SWF_FILE, $buf, $headerSize);
HeadParser($buf);
my $len_to_read = 2;
my $offset = $headerSize;

while(read(SWF_FILE, $buf, $len_to_read ))
{
    printf("\noffset:0x%-x\n", $offset);
    $len_to_read = TagParser($buf);
    $offset += $len_to_read + 2;
    #read(SWF_FILE, $buf, $len_to_read);

    $len_to_read = 2;
    #$pause = ;

    #print $pause;

    #if($pause =~ /^[q|Q]/)

    #{

    #    exit(0);

    #}

}
close(SWF_FILE);
close(PCM);

sub HeadParser{
    #print unpack("c3", $_[0]);

    my ($type,$version,$fileLen,$RECT,$frameRate,$frameCount) = unpack("a3C1I1a9S1S1",$_[0]);
    printf("Head:\n TYPE:%s\n VERS:%d\n LENG:%d\n FR :%d\n FC :%d\n\n", $type,$version,$fileLen,$frameRate,$frameCount);
    my ($Nbits,$Xmin,$Xmax,$Ymin,$Ymax) = unpack("a5C1C1C1C1",$RECT);
}



sub TagParser{#$_[0]:data

    my ($tag) = unpack("S1",$_[0]);
    #print($tag,"\n");

    my ($tag_type,$tag_len) = (($tag & 0xFFC)>>6,$tag & 0x3F);
    #print($tag_type,"\n",$tag_len,"\n");

    if($tag_len == 0x3f)
    {
        read(SWF_FILE, $tag_len2, 4);
        $offset += 4;
        $tag_len = unpack("I1",$tag_len2);
    }    
    
    printf("tagType: %s\n tagLen :%d\n",$Tag_Name{$tag_type},$tag_len);
    read(SWF_FILE, $buf, $tag_len);
    if($tag_type == 18 || $tag_type == 45)#SoundStreamHead

    {
        StreamHeadParser($buf);
        my $pause = <STDIN>;
    #    syswrite(PCM, $buf, $tag_len);#PCM可以如此保存

    }
    if($tag_type == 14)#DefinedSound

    {
        DefinedSoundParser($buf);
        my $pause = <STDIN>;
    }
    $tag_len;
}

sub StreamHeadParser{
    my($pBInfo, $audioInfo) = unpack ("C1C1",$_[0]);
    my($audio_type,$sample,$bits,$channel) =(($audioInfo&0xF0)>>4, ($audioInfo&0x0C)>>2,($audioInfo&0x02)>>1,($audioInfo&0x01)) ;
  printf(" Audio_Codec: %s\n SampleRate : %s\n Bits/Sample: %s\n Channel : %s\n",$Audio_Codec{$audio_type},$Sample_Rate{$sample},$Bit_per_Sample{$bits},$Channels{$channel});
}

sub DefinedSoundParser{
    my($audioInfo) = unpack ("C1",$_[0]);
    my($audio_type,$sample,$bits,$channel) =(($audioInfo&0xF0)>>4, ($audioInfo&0x0C)>>2,($audioInfo&0x02)>>1,($audioInfo&0x01)) ;
  printf(" Audio_Codec: %s\n SampleRate : %s\n Bits/Sample: %s\n Channel : %s\n",$Audio_Codec{$audio_type},$Sample_Rate{$sample},$Bit_per_Sample{$bits},$Channels{$channel});
}


阅读(1944) | 评论(0) | 转发(0) |
0

上一篇:url中汉字恢复

下一篇:C++/Java命名规则

给主人留下些什么吧!~~