惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Schneier on Security
有赞技术团队
有赞技术团队
T
The Blog of Author Tim Ferriss
F
Fortinet All Blogs
D
DataBreaches.Net
F
Full Disclosure
腾讯CDC
博客园 - 【当耐特】
MyScale Blog
MyScale Blog
Stack Overflow Blog
Stack Overflow Blog
小众软件
小众软件
Hugging Face - Blog
Hugging Face - Blog
Last Week in AI
Last Week in AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
爱范儿
爱范儿
The GitHub Blog
The GitHub Blog
Engineering at Meta
Engineering at Meta
大猫的无限游戏
大猫的无限游戏
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
SegmentFault 最新的问题
The Register - Security
The Register - Security
WordPress大学
WordPress大学
博客园 - 聂微东
雷峰网
雷峰网
J
Java Code Geeks
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Privacy International News Feed
酷 壳 – CoolShell
酷 壳 – CoolShell
A
Arctic Wolf
Scott Helme
Scott Helme
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tor Project blog
博客园 - 三生石上(FineUI控件)
Know Your Adversary
Know Your Adversary
AWS News Blog
AWS News Blog
G
Google Developers Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
CERT Recently Published Vulnerability Notes
O
OpenAI News
Project Zero
Project Zero
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Application and Cybersecurity Blog
Application and Cybersecurity Blog
云风的 BLOG
云风的 BLOG
N
News and Events Feed by Topic
MongoDB | Blog
MongoDB | Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Microsoft Security Blog
Microsoft Security Blog
Cisco Talos Blog
Cisco Talos Blog
P
Palo Alto Networks Blog
Schneier on Security
Schneier on Security

博客园 - 懒蜜蜂

身份证校验规则 [转]扩展jQuery easyui datagrid增加动态改变列编辑的类型 在IIS 5.1/6上以FastCGI方式安装 PHP 如何修复.Net和COM之间枚举名称的问题(续) 通过修改IP/TCP包头伪造IP来与网页进行交互 如何修复.Net和COM之间枚举名称的问题 Compiling and Registering a Type Library Objective-C札记二-- Iphone中关于Layer的opaque属性 Xcode配置SVN作为版本控制 Emacs快捷键 Objective C中的札记--字符串连接,@selector中的冒号,时间转换,局部变量 使用GDataXML的设置 IPhone Exec_Bad_Access问题解决办法 Javascript中暂停功能的实现 - 懒蜜蜂 - 博客园 数据库基础理论--关系模式及范式 函数依赖(转) 数据库基础理论之--超键 候选键 主键 拷贝VMWare虚机(XP操作系统)之后网络不通
C#版的AMF消息封装
懒蜜蜂 · 2010-03-06 · via 博客园 - 懒蜜蜂

以下代码为转载

代码

   1class AMF_Post_Data  
   
2.    {  
   
3.        public List<byte> message;  
   
4.   
   
5.        /// <summary>  
   6.        /// 初始化Message  
   7.        /// </summary>  
   8.        /// <param name="at"></param>  
   9.        /// <param name="headers"></param>  
  10.        /// <param name="bodies"></param>  
  11.        public AMF_Post_Data(AMFType at, int headers, int bodies)  
  
12.        {  
  
13.            //AMF版本  
  14.            if (at == AMFType.AMF0)  
  
15.            {  
  
16.                message = new List<byte>(new byte[] { 0x000x00 });  
  
17.            }  
  
18.            else if (at == AMFType.AMF3)  
  
19.            {  
  
20.                message = new List<byte>(new byte[] { 0x000x03 });  
  
21.            }  
  
22.   
  
23.            //header数量  
  24.            message.Add(BitConverter.GetBytes(headers)[1]);  
  
25.            message.Add(BitConverter.GetBytes(headers)[0]);  
  
26.            //body数量  
  27.            message.Add(BitConverter.GetBytes(bodies)[1]);  
  
28.            message.Add(BitConverter.GetBytes(bodies)[0]);  
  
29.        }  
  
30.   
  
31.        /// <summary>  
  32.        /// 添加Target  
  33.        /// </summary>  
  34.        /// <param name="target"></param>  
  35.        /// <param name="Response"></param>  
  36.        public void AddTargetAndResponse(string target, string Response)  
  
37.        {  
  
38.            //添加Target长度  
  39.            message.Add(BitConverter.GetBytes(target.Length)[1]);  
  
40.            message.Add(BitConverter.GetBytes(target.Length)[0]);  
  
41.            //添加Target内容  
  42.            message.AddRange(Encoding.Default.GetBytes(target));  
  
43.   
  
44.            //添加Response长度  
  45.            message.Add(BitConverter.GetBytes(Response.Length)[1]);  
  
46.            message.Add(BitConverter.GetBytes(Response.Length)[0]);  
  
47.            //添加Response内容  
  48.            message.AddRange(Encoding.Default.GetBytes(Response));  
  
49.        }  
  
50.   
  
51.        /// <summary>  
  52.        /// 添加Body  
  53.        /// </summary>  
  54.        /// <param name="length"></param>  
  55.        /// <param name="Content"></param>  
  56.        public void AddBody(AMF_Post_Data_Body apdb)  
  
57.        {  
  
58.            message.AddRange(apdb.getLength());  
  
59.            message.AddRange(apdb.Content.ToArray());  
  
60.        }  
  
61.    }  
  
62.   
  
63.    class AMF_Post_Data_Body  
  
64.    {  
  
65.        private byte[] length = new byte[4];  
  
66.        public List<byte> Content = new List<byte>();  
  
67.   
  
68.        /// <summary>  
  69.        /// 初始化Body  
  70.        /// </summary>  
  71.        /// <param name="dt"></param>  
  72.        /// <param name="ArrayLength"></param>  
  73.        public AMF_Post_Data_Body(DataType dt, int ArrayLength)  
  
74.        {  
  
75.            //添加类型标识  
  76.            Content.Add((byte)dt);  
  
77.   
  
78.            //数组的话添加长度  
  79.            if (dt == DataType.Array)  
  
80.            {  
  
81.                Content.Add(BitConverter.GetBytes(ArrayLength)[3]);  
  
82.                Content.Add(BitConverter.GetBytes(ArrayLength)[2]);  
  
83.                Content.Add(BitConverter.GetBytes(ArrayLength)[1]);  
  
84.                Content.Add(BitConverter.GetBytes(ArrayLength)[0]);  
  
85.            }  
  
86.        }  
  
87.   
  
88.        public void AddData(DataType dt, string value)  
  
89.        {  
  
90.            //添加类型标识  
  91.            Content.Add((byte)dt);  
  
92.   
  
93.            switch (dt)  
  
94.            {  
  
95.                case DataType.Number:  
  
96.                    AddData_Number(double.Parse(value));  
  
97.                    break;  
  
98.                case DataType.String:  
  
99.                    AddData_String(value);  
 
100.                    break;  
 
101.                case DataType.Boolean:  
 
102.                    AddData_Boolean(Boolean.Parse(value));  
 
103.                    break;  
 
104.            }  
 
105.        }  
 
106.  
 
107.        #region 更种类型处理方法  
 
108.        /// <summary>  
 109.        /// Boolean  
 110.        /// </summary>  
 111.        /// <param name="p"></param>  
 112.        private void AddData_Boolean(bool p)  
 
113.        {  
 
114.            if (p)  
 
115.                Content.Add(0x01);  
 
116.            else  
 
117.                Content.Add(0x00);  
 
118.        }  
 
119.        /// <summary>  
 120.        /// String  
 121.        /// </summary>  
 122.        /// <param name="value"></param>  
 123.        private void AddData_String(string value)  
 
124.        {  
 
125.            //添加长度  
 126.            Content.Add(BitConverter.GetBytes(value.Length)[1]);  
 
127.            Content.Add(BitConverter.GetBytes(value.Length)[0]);  
 
128.            //添加内容  
 129.            Content.AddRange(Encoding.Default.GetBytes(value));  
 
130.        }  
 
131.        /// <summary>  
 132.        /// Number  
 133.        /// </summary>  
 134.        /// <param name="p"></param>  
 135.        private void AddData_Number(double p)  
 
136.        {  
 
137.            byte[] b = new byte[8];  
 
138.            b = BitConverter.GetBytes(p);  
 
139.            for (int i = 7; i > -1; i--)  
 
140.            {  
 
141.                Content.Add(b[i]);  
 
142.            }  
 
143.        }  
 
144.        #endregion  
 
145.   
 
146.        public byte[] getLength()  
 
147.        {  
 
148.            length[0= BitConverter.GetBytes(Content.Count)[3];  
 
149.            length[1= BitConverter.GetBytes(Content.Count)[2];  
 
150.            length[2= BitConverter.GetBytes(Content.Count)[1];  
 
151.            length[3= BitConverter.GetBytes(Content.Count)[0];  
 
152.   
 
153.            return length;  
 
154.        }  
 
155.    }  
 
156.  
 
157.    #region 类型枚举  
 
158.    public enum AMFType  
 
159.    {  
 
160.        AMF0,  
 
161.        AMF3  
 
162.    }  
 
163.   
 
164.    public enum DataType  
 
165.    {  
 
166.        Number = 0,  
 
167.        Boolean = 1,  
 
168.        String = 2,  
 
169.        UntypedObject = 3,  
 
170.        MovieClip = 4,  
 
171.        Null = 5,  
 
172.        Undefined = 6,  
 
173.        ReferencedObject = 7,  
 
174.        MixedArray = 8,  
 
175.        End = 9,  
 
176.        Array = 10,//0x0A  
 177.        Date = 11,//0x0B  
 178.        LongString = 12,//0x0C  
 179.        TypeAsObject = 13,//0x0D  
 180.        Recordset = 14,//0x0E  
 181.        Xml = 15,//0x0F  
 182.        TypedObject = 16,//0x10  
 183.        AMF3data = 17//0x11  
 184.    }  
 
185.    #endregion