Exemplo n.º 1
0
        [Test]         // https://bugzilla.novell.com/show_bug.cgi?id=322672
        public void BaseDisposeCalled()
        {
            MyMemoryStream ms = new MyMemoryStream();

            Assert.IsFalse(ms.DisposedCalled, "Before");
            ms.Close();
            Assert.IsTrue(ms.DisposedCalled, "After");
        }
Exemplo n.º 2
0
    /// <summary>
    /// 封装数据包。
    /// </summary>
    /// <param name="data"></param>
    /// <returns></returns>
    private byte[] makeData(byte[] data)
    {
        bool isCompress = false;

        if (data.Length > 200)
        {
            isCompress = true;
            data       = ZlibHelper.CompressBytes(data);
        }
        data = SecurityUtil.Xor(data);               //加密
        ushort crc     = Crc16.CalculateCrc16(data); //校验码。
        ushort bodyLen = (ushort)(data.Length + 3);  //包体长度

        MyMemoryStream m = new MyMemoryStream();

        m.WriteUShort(bodyLen);
        m.WriteBool(isCompress);
        m.WriteUShort(crc);
        m.Write(data, 0, data.Length);
        data = m.ToArray();
        m.Close();

        return(data);
    }
Exemplo n.º 3
0
        public static byte[] m00000b(byte[] argBuffer)
        {
            //检查执行程序集是否与调用程序集相同,不同则退出
            Assembly callingAssembly = Assembly.GetCallingAssembly();
            Assembly executingAssembly = Assembly.GetExecutingAssembly();
            if ((callingAssembly != executingAssembly) && !IsAssemblyEqual(executingAssembly, callingAssembly))
            {
                return null;
            }

            MyMemoryStream myStream = new MyMemoryStream(argBuffer);
            byte[] buffer = new byte[0];
            int num = myStream.ReadFullByte();

            //如果以这个序列开头
            if (num == 0x4034b50)
            {
                short num2 = (short) myStream.ReadLowByte();
                int num3 = myStream.ReadLowByte();
                int num4 = myStream.ReadLowByte();
                if (((num != 0x4034b50) || (num2 != 20)) || ((num3 != 0) || (num4 != 8)))
                {
                    throw new FormatException("Wrong Header Signature");
                }
                myStream.ReadFullByte();
                myStream.ReadFullByte();
                myStream.ReadFullByte();
                int num5 = myStream.ReadFullByte();
                int count = myStream.ReadLowByte();
                int num7 = myStream.ReadLowByte();
                if (count > 0)
                {
                    byte[] buffer2 = new byte[count];
                    myStream.Read(buffer2, 0, count);
                }
                if (num7 > 0)
                {
                    byte[] buffer3 = new byte[num7];
                    myStream.Read(buffer3, 0, num7);
                }
                byte[] buffer4 = new byte[(uint) (myStream.Length - myStream.Position)];
                myStream.Read(buffer4, 0, buffer4.Length);

                c00000e ce = new c00000e(buffer4);
                buffer = new byte[num5];
                ce.m00000d(buffer, 0, buffer.Length);
                buffer4 = null;
            }
            else
            {
                int num8 = num >> 0x18;
                num -= num8 << 0x18;

                //如果以这个序列开头
                if (num == 0x7d7a7b)
                {
                    switch (num8)
                    {
                        case 1:
                        {
                            int num12;
                            int num9 = myStream.ReadFullByte();
                            buffer = new byte[num9];
                            for (int i = 0; i < num9; i += num12)
                            {
                                int num11 = myStream.ReadFullByte();
                                num12 = myStream.ReadFullByte();
                                byte[] buffer5 = new byte[num11];
                                myStream.Read(buffer5, 0, buffer5.Length);
                                new c00000e(buffer5).m00000d(buffer, i, num12);
                            }
                            break;
                        }
                        case 2:
                        {
                            byte[] buffer6 = new byte[] { 0x69, 140, 0x88, 0xa1, 0x68, 0xb9, 0xe3, 0xd3 };
                            byte[] buffer7 = new byte[] { 0x7d, 0xb0, 0xa8, 0x17, 0xda, 0x54, 0xc5, 0x3e };
                            using (DESCryptoHelper cc = new DESCryptoHelper())
                            {
                                using (ICryptoTransform transform = cc.m000009(buffer6, buffer7, true))
                                {
                                    buffer = m00000b(transform.TransformFinalBlock(argBuffer, 4, argBuffer.Length - 4));
                                }
                            }
                            break;
                        }
                    }
                    if (num8 != 3)
                    {
                        goto Label_02E3;
                    }
                    byte[] buffer9 = new byte[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
                    byte[] buffer10 = new byte[] { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 };
                    using (RijndaelCryptHelper cb = new RijndaelCryptHelper())
                    {
                        using (ICryptoTransform transform2 = cb.CreateCryptor(buffer9, buffer10, true))
                        {
                            buffer = m00000b(transform2.TransformFinalBlock(argBuffer, 4, argBuffer.Length - 4));
                        }
                        goto Label_02E3;
                    }
                }
                throw new FormatException("Unknown Header");
            }
            Label_02E3:
            myStream.Close();
            myStream = null;
            return buffer;
        }
Exemplo n.º 4
0
		[Test] // https://bugzilla.novell.com/show_bug.cgi?id=322672
		public void BaseDisposeCalled ()
		{
			MyMemoryStream ms = new MyMemoryStream ();
			Assert.IsFalse (ms.DisposedCalled, "Before");
			ms.Close ();
			Assert.IsTrue (ms.DisposedCalled, "After");
		}