Example #1
0
        public static Protocol Decode(Octets content)
        {
			Protocol prtc = null;
            int iType = 0;
            OctetsStream os = new OctetsStream(content);
            OctetsStream data = new OctetsStream();

            try
            {
                os.Begin();
                iType = (int)os.uncompact_uint32();
                os.unmarshal(data);
                os.Commit();

				prtc = Create(iType);
				if (prtc == null)
				{
					prtc = new ProtocolDefault();
				    Debug.Log(string.Format("Protocol type {0} not found", (NetProtocolType)iType));
				}
				else
					prtc.unmarshal(data);
            }
            catch (MarshalException)
            {
                os.Rollback();
                Debug.Log(string.Format("Protocol decode error, type {0}", (NetProtocolType)iType));
                prtc = null;
            }

            return prtc;
        }
Example #2
0
        public override void SetParameter(Octets param)
        {
            Octets k_ipad = new Octets(64);
            int keylen = param.size();

            if (keylen > 64)
            {
                Octets key = MD5Hash.Digest(param);
                k_ipad.replace(key);
                k_opad.replace(key);
                keylen = key.size();
            }
            else
            {
                k_ipad.replace(param);
                k_opad.replace(param);
            }

            int i = 0;
            for (; i < keylen; i++)
            {
                k_ipad.setByte(i, (byte)(k_ipad.getByte(i) ^ 0x36));
                k_opad.setByte(i, (byte)(k_opad.getByte(i) ^ 0x5c));
            }
            for (; i < 64; i++)
            {
                k_ipad.setByte(i, (byte)0x36);
                k_opad.setByte(i, (byte)0x5c);
            }
            k_ipad.resize(64);
            k_opad.resize(64);            
            md5hash.Update(k_ipad);
        }
Example #3
0
 public override Octets Final(Octets digest)
 {
     md5hash.Final(digest);
     MD5Hash ctx = new MD5Hash();
     ctx.Update(k_opad);
     ctx.Update(digest);
     return ctx.Final(digest);
 }
Example #4
0
	    internal bool Output(Octets data)
	    {
		    if (data.size() + obuffer.size() > obuffer.capacity())
                return false;
            osec.Update(data);
		    obuffer.insert(obuffer.size(), data);
		    return true;
	    }
Example #5
0
        internal void SetOSecurity(String type, Octets key)
	    {
		    lock (ilock)
		    {
			    osec = Security.Create(type);
			    osec.SetParameter(key);
		    }
	    }
Example #6
0
 protected NetSession(int isize, int osize, int ssize, Security ise, Security ose)
 {
     ibuffer = new Octets(isize);
     obuffer = new Octets(osize);
     isecbuf = new Octets(ssize);
     isec = (Security)ise.Clone();
     osec = (Security)ose.Clone();
 }
Example #7
0
	    public NetSession()
	    {
		    ibuffer = new Octets(DEFAULTIOBUF);
		    obuffer = new Octets(DEFAULTIOBUF);
		    isecbuf = new Octets(DEFAULTIOBUF);
            isec = Security.Create("NULLSECURITY");
            osec = Security.Create("NULLSECURITY");
	    }
Example #8
0
 public Response()
     : base(PROTOCOL_TYPE, 1024, 101)
 {
     identity = new Octets();
     userid = 0;
     algo = 0;
     response = new Octets();
     device_info = new Octets();
 }
Example #9
0
 public override OctetsStream unmarshal(OctetsStream os)
 {
     identity = os.unmarshal_Octets();
     userid = os.unmarshal_int();
     algo = os.unmarshal_sbyte();
     response = os.unmarshal_Octets();
     device_info = os.unmarshal_Octets();
     return os;
 }
Example #10
0
 public static Octets Digest(Octets o)
 {
     try
     {
         return new Octets(MD5.Create().ComputeHash(o.getBytes()));
     }
     catch (Exception) { }
     return new Octets();
 }
Example #11
0
 public override OctetsStream unmarshal(OctetsStream os)
 {
     nonce = os.unmarshal_Octets();
     version = os.unmarshal_uint();
     res_version = os.unmarshal_Octets();
     edition = os.unmarshal_Octets();
     algo = os.unmarshal_sbyte();
     server_time = os.unmarshal_uint();
     return os;
 }
Example #12
0
 public Challenge()
     : base(PROTOCOL_TYPE, 64, 101)
 {
     nonce = new Octets();
     version = 0;
     res_version = new Octets();
     edition = new Octets();
     algo = 0;
     server_time = 0;
 }
Example #13
0
 public override OctetsStream unmarshal(OctetsStream os)
 {
     serverList = os.unmarshal_Octets();
     version = os.unmarshal_Octets();
     versionList = os.unmarshal_Octets();
     serverListLength = os.unmarshal_uint();
     versionLength = os.unmarshal_uint();
     versionListLength = os.unmarshal_uint();
     return os;
 }
Example #14
0
        public DirInfo()
            : base(PROTOCOL_TYPE, 32768, 1)
        {
			serverList = new Octets();
			version = new Octets();
			versionList = new Octets();
			serverListLength = 0;
			versionLength = 0;
			versionListLength = 0;
        }
Example #15
0
 public override Octets Update(Octets o)
 {
     int len = o.size();
     for (int i = 0; i < len; i++)
     {
         index2 += perm[(++index1) & 0xff];
         byte k = perm[index1 & 0xff]; perm[index1 & 0xff] = perm[index2 & 0xff]; perm[index2 & 0xff] = k;
         byte j = (byte)(perm[index1 & 0xff] + perm[index2 & 0xff]);
         o.setByte(i, (byte)(o.getByte(i) ^ perm[j & 0xff]));
     }
     return o;
 }
Example #16
0
 public override void SetParameter(Octets o)
 {
     int keylen = o.size();
     byte j = 0;
     for (int i = 0; i < 256; i++) perm[i] = (byte)i;
     for (int i = 0; i < 256; i++)
     {
         j += perm[i];
         j += o.getByte(i % keylen);
         byte k; k = perm[i]; perm[i] = perm[j & 0xff]; perm[j & 0xff] = k;
     }
     index1 = index2 = 0;
 }
Example #17
0
        public static int ToOctets(IntPtr L)
        {
            IntPtr idptr = LuaDLL.lua_touserdata(L, 1);
            BinaryWriter self = default(BinaryWriter);
            System.Object temp = default(System.Object);
            if (objs.TryGetValue(idptr.ToInt64(), out temp))
            {
                self = (BinaryWriter)temp;
            }
            else
            {
                LuaStatic.traceback(L);
                LuaDLL.lua_error(L); return 1;
            }

            MemoryStream mms = (MemoryStream)self.BaseStream;
            Octets oc = new Octets(mms.GetBuffer(), 0, (int)mms.Length);

            LuaStatic.addGameObject2Lua(L, oc, "Octets");  // Octets未实现相应的lua接口,故在lua中使用此类型会找不到
            return 1;
        }
Example #18
0
 public virtual void GetParameter(Octets o) { }
Example #19
0
 public override Octets Update(Octets o)
 {
     context.insert(context.size(), o);
     return o;
 }
Example #20
0
		public override OctetsStream unmarshal(OctetsStream os)
		{
			data = os.unmarshal_Octets();
			localsid = os.unmarshal_uint();
			return os;
		}
Example #21
0
File: Random.cs Project: fengqk/Art
 public override Octets Update(Octets o)
 {
     r.NextBytes(o.buffer());
     return o;
 }
Example #22
0
        internal Octets Update(Octets oin)
        {
            legacy_in.insert(legacy_in.size(), oin);
            blen_totol = (uint)(legacy_in.size() * 8 - l);
            legacy_in.reserve(legacy_in.size() + 3);
            lbuf = legacy_in.buffer();
            rptr = 0;
            blen = 7;
            Octets oout = oin;
            oout.clear();
            uint histhead = histptr;

            while (blen_totol > blen)
            {
                adjust_l = l;
                adjust_rptr = rptr;
                uint val = fetch();

                if (val < 0x80000000)
                {
                    if (!passbits(8))
                        break;
                    history[histptr++] = (byte)(val >> 24);
                    continue;
                }
                if (val < 0xc0000000)
                {
                    if (!passbits(9))
                        break;
                    history[histptr++] = (byte)(((val >> 23) | 0x80) & 0xff);
                    continue;
                }

                uint len = 0, off = 0;
                if (val >= 0xf0000000)
                {
                    if (!passbits(10))
                        break;
                    off = (val >> 22) & 0x3f;
                    if (off == (uint)MPPC.CTRL_OFF_EOB)
                    {
                        uint advance = 8 - (l & 7);
                        if (advance < 8)
                            if (!passbits(advance))
                                break;
                        oout.insert(oout.size(), history, (int)histhead, (int)(histptr - histhead));
                        if (histptr == (uint)MPPC.MPPC_HIST_LEN)
                            histptr = 0;
                        histhead = histptr;
                        continue;
                    }
                }
                else if (val >= 0xe0000000)
                {
                    if (!passbits(12))
                        break;
                    off = ((val >> 20) & 0xff) + 64;
                }
                else if (val >= 0xc0000000)
                {
                    if (!passbits(16))
                        break;
                    off = ((val >> 16) & 0x1fff) + 320;
                }

                val = fetch();
                if (val < 0x80000000)
                {
                    if (!passbits(1))
                        break;
                    len = 3;
                }
                else if (val < 0xc0000000)
                {
                    if (!passbits(4))
                        break;
                    len = 4 | ((val >> 28) & 3);
                }
                else if (val < 0xe0000000)
                {
                    if (!passbits(6))
                        break;
                    len = 8 | ((val >> 26) & 7);
                }
                else if (val < 0xf0000000)
                {
                    if (!passbits(8))
                        break;
                    len = 16 | ((val >> 24) & 15);
                }
                else if (val < 0xf8000000)
                {
                    if (!passbits(10))
                        break;
                    len = 32 | ((val >> 22) & 0x1f);
                }
                else if (val < 0xfc000000)
                {
                    if (!passbits(12))
                        break;
                    len = 64 | ((val >> 20) & 0x3f);
                }
                else if (val < 0xfe000000)
                {
                    if (!passbits(14))
                        break;
                    len = 128 | ((val >> 18) & 0x7f);
                }
                else if (val < 0xff000000)
                {
                    if (!passbits(16))
                        break;
                    len = 256 | ((val >> 16) & 0xff);
                }
                else if (val < 0xff800000)
                {
                    if (!passbits(18))
                        break;
                    len = 0x200 | ((val >> 14) & 0x1ff);
                }
                else if (val < 0xffc00000)
                {
                    if (!passbits(20))
                        break;
                    len = 0x400 | ((val >> 12) & 0x3ff);
                }
                else if (val < 0xffe00000)
                {
                    if (!passbits(22))
                        break;
                    len = 0x800 | ((val >> 10) & 0x7ff);
                }
                else if (val < 0xfff00000)
                {
                    if (!passbits(24))
                        break;
                    len = 0x1000 | ((val >> 8) & 0xfff);
                }
                else
                {
                    l = adjust_l;
                    rptr = adjust_rptr;
                    break;
                }

                if (histptr < off || histptr + len > (uint)MPPC.MPPC_HIST_LEN)
                    break;
                // Array.Copy(history, histptr - off, history, histptr, histptr - histhead);
                LameCopy(history, (int)histptr, (int)(histptr - off), (int)len);
                // Array.Copy(history, histptr - off, history, histptr, len);
                histptr += len;
            }

            oout.insert(oout.size(), history, (int)histhead, (int)(histptr - histhead));
            legacy_in.erase(0, (int)rptr);
            return oout;
        }
Example #23
0
		public MarshalData()
			: base(PROTOCOL_TYPE, 65536, 1)
		{
			data = new Octets();
			localsid = 0;
		}
Example #24
0
 public override void SetParameter(Octets o)
 {
     
 }
Example #25
0
 public override Octets Update(Octets o)
 {
     decompress.Update(o);
     return o;
 }
Example #26
0
 public override void SetParameter(Octets o)
 {
     arc4.SetParameter(o);
 }
Example #27
0
 public virtual Octets Update(Octets o) { return o; }
Example #28
0
 public override Octets Update(Octets o)
 {
     md5hash.Update(o);
     return o;
 }
Example #29
0
 public virtual Octets Final(Octets o) { return o; }
Example #30
0
 public override Octets Final(Octets digest)
 {
     digest.replace(md5.ComputeHash(context.getBytes()));
     context.clear();
     return digest;
 }