コード例 #1
0
        /// <summary>
        /// Determines the file name for a file handle. Because the used native function NtQueryObject may
        /// block on various file types, the function is executed in a thread.
        /// </summary>
        /// <param name="handle">Handle of the file, which name is to be determined.</param>
        /// <param name="fileName">The name of the file, the object handle points to. If the name could not be determined, an empty string.</param>
        /// <param name="wait">Time in ms this function waits for the scheduled thread to finish.</param>
        /// <returns>true if and only the file name yould be determined (the scheduled thread finished within the specified time).</returns>
        private static bool GetFileNameFromHandle(IntPtr handle, out string fileName, int wait)
        {
            FileNameFromHandleWorker worker = new FileNameFromHandleWorker(handle);
            Thread thread = new Thread(worker.DoWork);

            thread.Start();

            if (thread.Join(wait))
            {
                fileName = worker.FileName;
                return(true);
            }
            else
            {
                Logger.Log(LogLevel.Debug, "Name for handle " + handle.ToString() + " could not be determined within " + wait + " ms - aborting thread...");

                if (worker.Abort())
                {
                    Logger.Log(LogLevel.Debug, "Thread successfully aborted.");
                }
                else
                {
                    Logger.Log(LogLevel.Debug, "Thread could not be aborted.");
                }

                fileName = string.Empty;
                return(false);
            }
        }
コード例 #2
0
        /// <summary>
        /// Determines the file name for a file handle. Because the used native function NtQueryObject may
        /// block on various file types, the function is executed in a thread.
        /// </summary>
        /// <param name="handle">Handle of the file, which name is to be determined.</param>
        /// <param name="fileName">The name of the file, the object handle points to. If the name could not be determined, an empty string.</param>
        /// <param name="wait">Time in ms this function waits for the scheduled thread to finish.</param>
        /// <returns>true if and only the file name yould be determined (the scheduled thread finished within the specified time).</returns>
        private static bool GetFileNameFromHandle(IntPtr handle, out string fileName, int wait)
        {
            FileNameFromHandleWorker worker = new FileNameFromHandleWorker(handle);
            Thread thread = new Thread(worker.DoWork);

            thread.Start();

            if (thread.Join(wait))
            {
                fileName = worker.FileName;
                return true;
            }
            else
            {
                Logger.Log(LogLevel.Debug, "Name for handle " + handle.ToString() + " could not be determined within " + wait + " ms - aborting thread...");

                if (worker.Abort())
                    Logger.Log(LogLevel.Debug, "Thread successfully aborted.");
                else
                    Logger.Log(LogLevel.Debug, "Thread could not be aborted.");

                fileName = string.Empty;
                return false;
            }
        }