示例#1
0
        private AMFObject ReadAmf3Object()
        {
            AMFObject result;
            int       v = ReadUInt29();

            if ((v & 3) == 1)
            {
                result = classDefinitions[v >> 2].Clone();
            }
            else
            {
                int    nkeys = v >> 4;
                string name  = ReadParamName();
                result = new AMFObject(name);

                for (int i = 0; i < nkeys; i++)
                {
                    result.AddKey(ReadParamName());
                }

                classDefinitions.Add(result);
            }


            for (int i = 0; i < result.KeyCount; i++)
            {
                object obj = ReadParamValue();
                //Console.WriteLine(result.keys[i] + '=' + (obj == null ? "null" : obj.ToString()));
                result.Properties.Add(result.Key(i), obj);
            }
            return(result);
        }
示例#2
0
 private void OutAMF0Object(object obj)
 {
     if (obj is String)
     {
         output.Add((byte)AMF0Type.StringMarker);
         OutString((String)obj);
     }
     else if (obj is double)
     {
         output.Add((byte)AMF0Type.NumberMarker);
         byte[] bytes;
         if (double.IsNaN((double)obj))
         {
             bytes = new byte[8] {
                 0x7F, 0xFF, 0xFF, 0xFF, 0xE0, 0, 0, 0
             }
         }
         ;
         else
         {
             bytes = BitConverter.GetBytes((double)obj);
             Array.Reverse(bytes);
         }
         output.AddRange(bytes);
     }
     else if (obj == null)
     {
         output.Add((byte)AMF0Type.NullMarker);
     }
     else
     if (obj is Array)
     {
         output.Add((byte)AMF0Type.StrictArrayMarker);
         object[] arr = (object[])obj;
         OutInt32(arr.Length);
         foreach (object obj2 in arr)
         {
             OutAMF0Object(obj2);
         }
     }
     else
     if (obj is AMFObject)
     {
         output.Add((byte)AMF0Type.ObjectMarker);
         AMFObject ao = (AMFObject)obj;
         foreach (KeyValuePair <string, object> kv in ao.Properties)
         {
             OutString(kv.Key);
             OutAMF0Object(kv.Value);
         }
         OutShort(0);        //??
         output.Add((byte)AMF0Type.ObjectEndMarker);
     }
     else
     {
         throw new NotImplementedException();
     }
 }
示例#3
0
        private void OutParamValue(AMFObject obj)
        {
            output.Add((byte)AMF3Type.ObjectMarker);
            int v = obj.Properties.Count << 4 | 3;

            OutUInt29(v);
            OutParamName(obj.Name);
            OutDict(obj.Properties);
        }
示例#4
0
        private AMFObject ReadAmf0Object()
        {
            string name = ReadString();
            // TODO: check if exists
            AMFObject result = ReadAmf0AnonymousObject();

            result.Name = name;
            return(result);
        }
示例#5
0
        public AMFObject Clone()
        {
            AMFObject res = new AMFObject(Name);

            res.Properties = new Dictionary <string, object>();
            for (int i = 0; i < keys.Count; i++)
            {
                res.keys.Add(keys[i]);
            }
            return(res);
        }
示例#6
0
        public static AMFObject GetResponse(string url, byte[] postData)
        {
            Log.Debug("get webdata from {0}", url);

            HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;

            if (request == null)
            {
                return(null);
            }
            request.Method          = "POST";
            request.ContentType     = "application/x-amf";
            request.UserAgent       = OnlineVideoSettings.Instance.UserAgent;
            request.Timeout         = 15000;
            request.ContentLength   = postData.Length;
            request.ProtocolVersion = HttpVersion.Version10;
            request.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate");

            Stream requestStream = request.GetRequestStream();

            requestStream.Write(postData, 0, postData.Length);
            requestStream.Close();
            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            {
                Stream responseStream;
                if (response.ContentEncoding.ToLower().Contains("gzip"))
                {
                    responseStream = new System.IO.Compression.GZipStream(response.GetResponseStream(), System.IO.Compression.CompressionMode.Decompress);
                }
                else if (response.ContentEncoding.ToLower().Contains("deflate"))
                {
                    responseStream = new System.IO.Compression.DeflateStream(response.GetResponseStream(), System.IO.Compression.CompressionMode.Decompress);
                }
                else
                {
                    responseStream = response.GetResponseStream();
                }


                AMFDeserializer des = new AMFDeserializer(responseStream);
                AMFObject       obj = des.Deserialize();
                return(obj);
            }
        }
示例#7
0
        private AMFObject ReadAmf0AnonymousObject()
        {
            AMFObject result   = new AMFObject(String.Empty);
            bool      endFound = false;

            do
            {
                string key = this.ReadString();
                object obj = ReadParamValue();
                if (obj is AmfEndOfObject)
                {
                    endFound = true;
                }
                else
                {
                    result.Add(key, obj);
                }
            }while (!endFound);
            classDefinitions.Add(result);

            return(result);
        }
示例#8
0
        public byte[] Serialize(AMFObject obj, string target, string hash)
        {
            output.Clear();

            OutShort(Convert.ToInt16(AMFVersion.AMF3)); // AMF version 3
            OutShort(0);                                //headercount
            OutShort(1);                                //responsecount
            OutString(target);
            OutString("/1");
            OutShort(0); //??

            int lengthpos = output.Count;

            OutShort(0xA00); //array
            OutShort(0);     //??
            OutShort(0x202); //??
            OutString(hash);

            output.Add((byte)AMF0Type.AvmplusObjectMarker); //switch to AMF3?
            OutParamValue(obj);
            OutShort((short)(output.Count - lengthpos), lengthpos);

            return(output.ToArray());
        }
示例#9
0
 public byte[] Serialize(AMFObject obj, string hash)
 {
     return(Serialize(obj, "com.brightcove.experience.ExperienceRuntimeFacade.getDataForExperience", hash));
 }