Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="buf"></param>
        /// <param name="pos"></param>
        /// <param name="len"></param>
        /// <returns></returns>
        public byte[] GetChecksum2(byte[] buf, int pos, int len)
        {
            byte[] buf1 = new byte[len + 4];
            for (int j = 0; j < len; j++)
            {
                buf1[j] = buf[pos + j];
            }
            MDFour mdFour = new MDFour(options);

            mdFour.Begin();
            if (options.checksumSeed != 0)
            {
                SIVAL(ref buf1, len, (UInt32)options.checksumSeed);
                len += 4;
            }
            int i;

            for (i = 0; i + CSUM_CHUNK <= len; i += CSUM_CHUNK)
            {
                mdFour.Update(buf1, i, CSUM_CHUNK);
            }
            if (len - i > 0 || options.protocolVersion >= 27)
            {
                mdFour.Update(buf1, i, (UInt32)(len - i));
            }
            return(mdFour.Result());
        }
Exemplo n.º 2
0
		public byte[] GetChecksum2(byte[] buf, int off, int len)
		{
			byte[] buf1 = new byte[len + 4];
			for(int j = 0; j < len ; j++)
				buf1[j] = buf[off + j];
			MDFour m = new MDFour(options);
			m.Begin();
			if(options.checksumSeed != 0)
			{
				SIVAL(ref buf1, len, (UInt32)options.checksumSeed);
				len += 4;
			}
			int i;
			for(i = 0; i + CSUM_CHUNK <= len; i += CSUM_CHUNK) 
				m.Update(buf1, i, CSUM_CHUNK);
			if (len - i > 0 || options.protocolVersion >= 27) 
				m.Update(buf1, i, (UInt32)(len-i));
			return m.Result();
		}
Exemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="sum"></param>
        /// <param name="size"></param>
        /// <returns></returns>
        public bool FileCheckSum(string fileName, ref byte[] sum, int size)
        {
            int    i;
            MDFour mdFour = new MDFour(options);

            sum = new byte[MD4_SUM_LENGTH];
            try
            {
                using (var fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    MapFile buf = new MapFile(fileStream, size, Options.MAX_MAP_SIZE, CSUM_CHUNK);
                    mdFour.Begin();

                    for (i = 0; i + CSUM_CHUNK <= size; i += CSUM_CHUNK)
                    {
                        int offset = buf.MapPtr(i, CSUM_CHUNK);
                        mdFour.Update(buf.p, offset, CSUM_CHUNK);
                    }

                    if (size - i > 0 || options.protocolVersion >= 27)
                    {
                        int offset = buf.MapPtr(i, size - i);
                        mdFour.Update(buf.p, offset, (UInt32)(size - i));
                    }

                    sum = mdFour.Result();

                    fileStream.Close();
                    //buf.UnMapFile(); //@fixed useless string
                    return(true);
                }
            }
            catch (Exception)
            {
            }
            return(false);
        }
Exemplo n.º 4
0
        public bool FileCheckSum(string fileName, ref byte[] sum, int size)
        {
            int    i;
            MDFour m = new MDFour(options);

            sum = new byte[MD4_SUM_LENGTH];
            Stream fd;

            try
            {
                fd = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
            } catch (Exception)
            {
                return(false);
            }
            MapFile buf = new MapFile(fd, size, Options.MAX_MAP_SIZE, CSUM_CHUNK);

            m.Begin();

            for (i = 0; i + CSUM_CHUNK <= size; i += CSUM_CHUNK)
            {
                int offset = buf.MapPtr(i, CSUM_CHUNK);
                m.Update(buf.p, offset, CSUM_CHUNK);
            }

            if (size - i > 0 || options.protocolVersion >= 27)
            {
                int offset = buf.MapPtr(i, size - i);
                m.Update(buf.p, offset, (UInt32)(size - i));
            }

            sum = m.Result();

            fd.Close();
            buf.UnMapFile();
            return(true);
        }
Exemplo n.º 5
0
		public bool FileCheckSum(string fileName, ref byte[] sum, int size)
		{
			int i;
			MDFour m =new MDFour(options);
			sum = new byte[MD4_SUM_LENGTH];
			Stream fd;
			try
			{
				fd = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
			} catch(Exception)
			{
				return false;
			}
			MapFile buf = new MapFile(fd, size, Options.MAX_MAP_SIZE, CSUM_CHUNK);
			m.Begin();

			for(i = 0; i + CSUM_CHUNK <= size; i += CSUM_CHUNK) 
			{
				int offset = buf.MapPtr(i, CSUM_CHUNK);
				m.Update(buf.p, offset, CSUM_CHUNK);
			}

			if (size - i > 0 || options.protocolVersion >= 27)
			{
				int offset = buf.MapPtr(i, size-i);
				m.Update(buf.p, offset, (UInt32)(size-i));
			}

			sum = m.Result();

			fd.Close();
			buf.UnMapFile();
			return true;
		}
Exemplo n.º 6
0
		public Sum(Options opt)
		{
			options = opt;
			md = new MDFour(opt);
		}
Exemplo n.º 7
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="sum"></param>
        /// <param name="size"></param>
        /// <returns></returns>
        public bool FileCheckSum(string fileName, ref byte[] sum, int size)
        {
            int i;
            MDFour mdFour = new MDFour(options);
            sum = new byte[MD4_SUM_LENGTH];
            try
            {
                using (var fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
                {

                    MapFile buf = new MapFile(fileStream, size, Options.MAX_MAP_SIZE, CSUM_CHUNK);
                    mdFour.Begin();

                    for (i = 0; i + CSUM_CHUNK <= size; i += CSUM_CHUNK)
                    {
                        int offset = buf.MapPtr(i, CSUM_CHUNK);
                        mdFour.Update(buf.p, offset, CSUM_CHUNK);
                    }

                    if (size - i > 0 || options.protocolVersion >= 27)
                    {
                        int offset = buf.MapPtr(i, size - i);
                        mdFour.Update(buf.p, offset, (UInt32)(size - i));
                    }

                    sum = mdFour.Result();

                    fileStream.Close();
                    //buf.UnMapFile(); //@fixed useless string
                    return true;
                }
            }
            catch (Exception)
            {
            }
            return false;

        }
Exemplo n.º 8
0
 public Sum(Options opt)
 {
     options = opt;
     md      = new MDFour(opt);
 }