示例#1
0
        public static byte[] CombineByteArray(byte[] b1, byte[] b2)
        {
            Buf b = new Buf();

            if (b1 != null)
            {
                b.Write(b1);
            }

            if (b2 != null)
            {
                b.Write(b2);
            }

            return(b.ByteData);
        }
示例#2
0
        public Buf Build()
        {
            int z;
            Buf b;

            this.fileList.Sort();

            z = 0;

            z += HamCore.HamcoreHeaderSize;

            z += sizeof(int);

            foreach (HamCoreBuilderFileEntry f in this.fileList)
            {
                z += Str.ShiftJisEncoding.GetByteCount(f.Name) + sizeof(int);
                z += sizeof(int);
                z += sizeof(int);
                z += sizeof(int);
            }
            foreach (HamCoreBuilderFileEntry f in this.fileList)
            {
                f.Offset = z;
                z       += (int)f.CompressedData.Size;
            }

            b = new Buf();
            b.Write(Str.ShiftJisEncoding.GetBytes(HamCore.HamcoreHeaderData));
            b.WriteInt((uint)this.fileList.Count);
            foreach (HamCoreBuilderFileEntry f in this.fileList)
            {
                b.WriteStr(f.Name, true);
                b.WriteInt(f.RawData.Size);
                b.WriteInt(f.CompressedData.Size);
                b.WriteInt((uint)f.Offset);
            }
            foreach (HamCoreBuilderFileEntry f in this.fileList)
            {
                b.Write(f.CompressedData.ByteData);
            }

            b.SeekToBegin();

            return(b);
        }
示例#3
0
文件: Secure.cs 项目: AcidCrash0/RPVN
        public byte[] Sign(byte[] data)
        {
            Buf b = new Buf(data);

            b.SeekToEnd();
            b.Write(keyData);

            return(Secure.HashSHA1(b.ByteData));
        }
示例#4
0
        public Buf ToBuf()
        {
            string s = ToString();

            Buf b = new Buf();

            byte[] bom = Str.GetBOM(this.Encoding);

            if (bom != null)
            {
                b.Write(bom);
            }

            b.Write(encoding.GetBytes(s));

            b.SeekToBegin();

            return(b);
        }
示例#5
0
文件: Secure.cs 项目: AcidCrash0/RPVN
        public static byte[] PkcsPadding(byte[] srcData, int destSize)
        {
            int srcSize = srcData.Length;

            if ((srcSize + 11) > destSize)
            {
                throw new OverflowException();
            }

            int randSize = destSize - srcSize - 3;

            byte[] rand = Secure.Rand((uint)randSize);

            Buf b = new Buf();

            b.WriteByte(0x00);
            b.WriteByte(0x02);
            b.Write(rand);
            b.WriteByte(0x00);
            b.Write(srcData);

            return(b.ByteData);
        }
示例#6
0
        public static byte[] ReadAllFromStream(Stream st)
        {
            byte[] tmp = new byte[32 * 1024];
            Buf    b   = new Buf();

            while (true)
            {
                int r = st.Read(tmp, 0, tmp.Length);

                if (r == 0)
                {
                    break;
                }

                b.Write(tmp, 0, r);
            }

            return(b.ByteData);
        }
示例#7
0
        public static Buf ReadFromStream(Stream st)
        {
            Buf ret  = new Buf();
            int size = 32767;

            while (true)
            {
                byte[] tmp = new byte[size];
                int    i   = st.Read(tmp, 0, tmp.Length);

                if (i <= 0)
                {
                    break;
                }

                Array.Resize <byte>(ref tmp, i);

                ret.Write(tmp);
            }

            ret.SeekToBegin();

            return(ret);
        }
示例#8
0
        public static byte[] PkcsPadding(byte[] srcData, int destSize)
        {
            int srcSize = srcData.Length;

            if ((srcSize + 11) > destSize)
            {
                throw new OverflowException();
            }

            int randSize = destSize - srcSize - 3;
            byte[] rand = Secure.Rand((uint)randSize);

            Buf b = new Buf();
            b.WriteByte(0x00);
            b.WriteByte(0x02);
            b.Write(rand);
            b.WriteByte(0x00);
            b.Write(srcData);

            return b.ByteData;
        }
示例#9
0
        public byte[] Sign(byte[] data)
        {
            Buf b = new Buf(data);
            b.SeekToEnd();
            b.Write(keyData);

            return Secure.HashSHA1(b.ByteData);
        }
示例#10
0
		public static Buf ReadFromStream(Stream st)
		{
			Buf ret = new Buf();
			int size = 32767;

			while (true)
			{
				byte[] tmp = new byte[size];
				int i = st.Read(tmp, 0, tmp.Length);

				if (i <= 0)
				{
					break;
				}

				Array.Resize<byte>(ref tmp, i);

				ret.Write(tmp);
			}

			ret.SeekToBegin();

			return ret;
		}
示例#11
0
		public void ReadToBuf(Buf buf, int size)
		{
			byte[] data = Read(size);

			buf.Write(data);
		}
示例#12
0
        public void ReadToBuf(Buf buf, int size)
        {
            byte[] data = Read(size);

            buf.Write(data);
        }
示例#13
0
		public Buf ToBuf()
		{
			string s = ToString();

			Buf b = new Buf();

			byte[] bom = Str.GetBOM(this.Encoding);

			if (bom != null)
			{
				b.Write(bom);
			}

			b.Write(encoding.GetBytes(s));

			b.SeekToBegin();

			return b;
		}