Esempio n. 1
0
        public void GetEmptyHash()
        {
            byte[] emptyBytes = new byte[32768];

            var hash = BlockHashFilter.GetBlockHash(emptyBytes);

            var hashString = Convert.ToBase64String(hash);
        }
Esempio n. 2
0
        /// <summary>
        /// Calls the Filter() method of BlockHashFilter class for calculating the phone's block hashes.
        /// </summary>
        /// <param name="inputFile">The path to phone's memory file.</param>
        /// <param name="blocksize">The size of a memory block on phone.</param>
        /// <param name="slideAmount">The distance between the starting offsets of two consecutive blocks in memory.</param>
        /// <param name="nextStreamPosition">The starting position in memory of the block to be hashed.</param>
        /// <returns>A list of block hashes for the phone.</returns>
        public List <string> ComputeHashes(string inputFile, int blocksize, int slideAmount, ref long nextStreamPosition)
        {
            List <string> hashes = new List <string>();

            int countBlocks = 0;

            using (FileStream stream = File.Open(inputFile, FileMode.Open, FileAccess.Read, FileShare.Read)) {
                var block = new byte[blocksize];

                //Start where we left off. Should be zero for the first run of the method.
                stream.Position = nextStreamPosition;

                while (stream.Position < stream.Length && countBlocks < BLOCK_BUFFER)
                {
                    stream.Read(block, 0, blocksize);

                    byte[] hash = BlockHashFilter.GetBlockHash(block);

                    string hashString = Convert.ToBase64String(hash);

                    hashes.Add(hashString);

                    //Need this check. Otherwise it will not finish
                    if (stream.Position < stream.Length)
                    {
                        stream.Position = stream.Position - blocksize + slideAmount;
                    }

                    countBlocks++;

                    nextStreamPosition = stream.Position;
                }
            }

            return(hashes);
        }
Esempio n. 3
0
        public static void GetConstants()
        {
            int[] sizes = new int[] { 1, 4, 16 };//{32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768};

            using (PhoneDbDataContext dataContext = Dalbase.GetDataContext()) {
                for (int i = 0; i < sizes.Length; i++)
                {
                    for (int j = 0; j < 256; j++)
                    {
                        byte value = (byte)j;

                        byte[] bytes = (new byte[sizes[i]].Select(r => value)).ToArray();

                        var hash = BlockHashFilter.GetBlockHash(bytes);

                        var hashString = Convert.ToBase64String(hash);

                        var valString = "0x" + Convert.ToString(value, 16).PadLeft(2, '0');

                        dataContext.usp_Constants_Insert(valString, sizes[i], hashString);
                    }
                }
            }
        }