Ejemplo n.º 1
0
        /// <summary>
        /// Calls ComputeHahses() method of BlockHashFilter class to calculate phone's block hashes, calls GetHashRunId() to insert phone's
        /// record to the database, calls InsertHahses() of DatabaseAccess to insert the block hashes into the database and HashRunUpdate() of
        /// DatabaseAccess to update the number of blocks and time to hash fields in the database.
        /// </summary>
        /// <param name="file">The BinaryFile reference corresponding to the 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="hashRunId">The ID of the row to which the block hashes of the phone are to be inserted.</param>
        /// <param name="pid">Phone id to be used.</param>
        /// <param name="memId">Memory id for the phone.</param>
        public void ProcessFile(BinaryFile file, int blockSize, int slideAmount, int hashRunId, int pid, string memId)
        {
            //The starting point in the phone file stream. Needed to maintain position state across multiple calls of the method.
            long nextStreamPosition = 0;
            long lastStreamPositon  = -1;
            int  blockIndex         = 0;

            DateTime start = DateTime.Now;

            while (lastStreamPositon < nextStreamPosition)
            {
                lastStreamPositon = nextStreamPosition;

                List <string> hashes = ComputeHashes(file.Path, blockSize, slideAmount, ref nextStreamPosition);

                if (hashes.Count == 0)
                {
                    continue;
                }
#if _USESQLSERVER_
                long numBlocks = hashes.Count;

                List <HashInfo> hashInfos = new List <HashInfo>();

                for (int k = 0; k < hashes.Count; k++)
                {
                    hashInfos.Add(new HashInfo {
                        BlockIndex = blockIndex, Hash = hashes[k], HashRunId = hashRunId
                    });

                    blockIndex++;
                }

                BulkInsertBase bulky = BulkInsertBase.Load(hashInfos);

                bulky.Flush();
#else
                List <BlockHashFilter.UnfilterdBlockResult> stored = new List <BlockHashFilter.UnfilterdBlockResult>();
                try {
                    blockIndex = DatabaseAccess.InsertHashes(hashes, hashRunId, stored);
                } catch (ThreadAbortException e) {
                    DatabaseAccess.ForgetPhone(memId, pid, hashRunId);
                    throw e;
                }
                if (blockIndex < 0)
                {
                    DatabaseAccess.ForgetPhone(memId, pid, hashRunId);
                    return;
                }
                storedBlocks = stored;
#endif
            }

            DateTime end               = DateTime.Now;
            TimeSpan duration          = end - start;
            long     timeToHashSeconds = Convert.ToInt32(Math.Round(duration.TotalSeconds));

#if _USESQLSERVER_
            using (PhoneDbDataContext dataContext = Dalbase.GetDataContext()) {
                dataContext.usp_HashRun_Update(hashRunId, blockIndex, timeToHashSeconds);
            }
#else
            DatabaseAccess.HashRunUpdate(hashRunId, blockIndex, (int)timeToHashSeconds);
#endif
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Calls ComputeHahses() method of BlockHashFilter class to calculate phone's block hashes, calls GetHashRunId() to insert phone's
        /// record to the database, calls InsertHahses() of DatabaseAccess to insert the block hashes into the database.
        /// </summary>
        /// <param name="file">The BinaryFile reference corresponding to the 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>
        /// <returns>The PhoneId of the phone, i.e. the row ID of the phone's record in the database.</returns>
        public int ProcessFile(BinaryFile file, int blockSize, int slideAmount)
        {
            int phoneId = GetPhoneId(file);

            DateTime start = DateTime.Now;
            List<string> hashes = BlockHashFilter.ComputeHashes(file.Path, blockSize, slideAmount);
            DateTime end = DateTime.Now;

            TimeSpan duration = end - start;
            long numBlocks = hashes.Count;
            long timeToHashSeconds = Convert.ToInt32(Math.Round(duration.TotalSeconds));
            string hashType = "sha1";

            int hashRunId = GetHashRunId(blockSize, phoneId, file.MemoryId, slideAmount, numBlocks, timeToHashSeconds,
                                         hashType, "");

            #if _USESQLSERVER_
            List<HashInfo> hashInfos = new List<HashInfo>();

            for (int k = 0; k < hashes.Count; k++) {
                hashInfos.Add(new HashInfo { BlockIndex = k, Hash = hashes[k], HashRunId = hashRunId });
            }

            BulkInsertBase bulky = BulkInsertBase.Load(hashInfos);

            bulky.Flush();
            #else
            DatabaseAccess.InsertHashes(hashes, hashRunId);
            #endif

            return phoneId;
        }
Ejemplo n.º 3
0
        public int ProcessFile(BinaryFile file, string notes)
        {
            int phoneId = GetPhoneId(file);

            // TODO: We assume a single block size, a single slide amount!
            for (int i = 0; i < BlockSizes.Length; i++) {
                for (int j = 0; j < SlideAmounts.Length; j++) {
                    if (SlideAmounts[j] > BlockSizes[i])
                        continue;

                    if (!UseSlide && SlideAmounts[j] != BlockSizes[i])
                        continue;

                    int hashRunId = GetHashRunId(BlockSizes[i], phoneId, file.MemoryId, SlideAmounts[j], -1, -1,
                                                 "sha1", notes);

                    ProcessFile(file, BlockSizes[i], SlideAmounts[j], hashRunId, phoneId, file.MemoryId);

                }
            }

            return phoneId;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Calls ComputeHahses() method of BlockHashFilter class to calculate phone's block hashes, calls GetHashRunId() to insert phone's
        /// record to the database, calls InsertHahses() of DatabaseAccess to insert the block hashes into the database and HashRunUpdate() of
        /// DatabaseAccess to update the number of blocks and time to hash fields in the database.
        /// </summary>
        /// <param name="file">The BinaryFile reference corresponding to the 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="hashRunId">The ID of the row to which the block hashes of the phone are to be inserted.</param>
        /// <param name="pid">Phone id to be used.</param>
        /// <param name="memId">Memory id for the phone.</param>
        public void ProcessFile(BinaryFile file, int blockSize, int slideAmount, int hashRunId, int pid, string memId)
        {
            //The starting point in the phone file stream. Needed to maintain position state across multiple calls of the method.
            long nextStreamPosition = 0;
            long lastStreamPositon = -1;
            int blockIndex = 0;

            DateTime start = DateTime.Now;

            while (lastStreamPositon < nextStreamPosition) {

                lastStreamPositon = nextStreamPosition;

                List<string> hashes = ComputeHashes(file.Path, blockSize, slideAmount, ref nextStreamPosition);

                if (hashes.Count == 0)
                    continue;
            #if _USESQLSERVER_
                long numBlocks = hashes.Count;

                List<HashInfo> hashInfos = new List<HashInfo>();

                for (int k = 0; k < hashes.Count; k++) {
                    hashInfos.Add(new HashInfo { BlockIndex = blockIndex, Hash = hashes[k], HashRunId = hashRunId });

                    blockIndex++;
                }

                BulkInsertBase bulky = BulkInsertBase.Load(hashInfos);

                bulky.Flush();
            #else
                List<BlockHashFilter.UnfilterdBlockResult> stored = new List<BlockHashFilter.UnfilterdBlockResult>();
                try {
                    blockIndex = DatabaseAccess.InsertHashes(hashes, hashRunId, stored);
                } catch (ThreadAbortException e) {
                    DatabaseAccess.ForgetPhone(memId, pid, hashRunId);
                    throw e;
                }
                if (blockIndex < 0) {
                    DatabaseAccess.ForgetPhone(memId, pid, hashRunId);
                    return;
                }
                storedBlocks = stored;
            #endif

            }

            DateTime end = DateTime.Now;
            TimeSpan duration = end - start;
            long timeToHashSeconds = Convert.ToInt32(Math.Round(duration.TotalSeconds));

            #if _USESQLSERVER_
            using (PhoneDbDataContext dataContext = Dalbase.GetDataContext()) {
                dataContext.usp_HashRun_Update(hashRunId, blockIndex, timeToHashSeconds);
            }
            #else
            DatabaseAccess.HashRunUpdate(hashRunId, blockIndex, (int) timeToHashSeconds);
            #endif
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Gets the ID of the phone by adding its information to the database table and getting the corresponding row ID.
        /// </summary>
        /// <param name="file">The BinaryFile reference for the phone's memory file.</param>
        /// <returns>The ID corresponding to the phone, from the database.</returns>
        public int GetPhoneId(BinaryFile file)
        {
            #if _USESQLSERVER_
            using (PhoneDbDataContext dataContext = Dalbase.GetDataContext()) {
                var results = dataContext.usp_Phone_Insert(file.Make, file.Model, file.SubId,
                                             string.Format("Inserted on {0}", DateTime.Now));

                return (from result in results select result.phoneId).Single();
            }
            #else
            return DatabaseAccess.PhoneInsert(file.Make, file.Model, file.SubId,
                                              string.Format("Inserted on {0}", DateTime.Now));
            #endif
        }