コード例 #1
0
        /// <summary>
        /// Helper function for IsDescendantOfProcessHelper().
        /// This function prevents an edge case where a process has a parent process ID
        /// that refers to a descendant of itself. This can occur when the parent of a process
        /// is destroyed and the parent's pid is recycled and reused on a descendant.  The
        /// parent process ID value is never updated when the parent is destroyed. The solution
        /// is to make sure that parents are created before children, otherwise it is a cycle.
        /// </summary>
        /// <param name="processSearcher">Process searcher object.</param>
        /// <param name="descendant">Process ID of the descendant.</param>
        /// <param name="anscestor">Process ID of the ancestor.</param>
        /// <param name="previousCreationTime">Creation time of the previous call's descendant.</param>
        /// <returns>True if descendant is a descendant of ancestor.</returns>
        private static bool IsDescendantOfProcessHelper(
            ProcessSearcher processSearcher,
            uint descendant,
            uint anscestor,
            DateTime previousCreationTime)
        {
            List <ProcessInfo> results = processSearcher.GetResultsByID(descendant);

            foreach (ProcessInfo proc in results)
            {
                // Ensure this parent relationship is valid.
                if (proc.CreationDate <= previousCreationTime)
                {
                    if (descendant == anscestor)
                    {
                        return(true);
                    }
                    else if (descendant == proc.ParentID)
                    {
                        // If process is its own parent then we have a cycle, return false.
                        return(false);
                    }

                    return(IsDescendantOfProcessHelper(
                               processSearcher,
                               proc.ParentID,
                               anscestor,
                               proc.CreationDate));
                }
            }

            return(false);
        }
コード例 #2
0
        /// <summary>
        /// Constructs the PluginDebuggerHelper.
        /// </summary>
        /// <param name="dte">Automation object from Visual Studio.</param>
        /// <param name="properties">PropertyManager set to a valid project/platform.</param>
        protected PluginDebuggerBase(DTE2 dte, PropertyManager properties)
        {
            if (dte == null)
            {
                throw new ArgumentNullException("dte");
            }

            if (properties == null)
            {
                throw new ArgumentNullException("properties");
            }

            Dte = dte;

            // Every second, check for a new instance of the plug-in to attach to.
            // Note that although the timer itself runs on a separate thread, the event
            // is fired from the main UI thread during message processing, thus we do not
            // need to worry about threading issues.
            pluginFinderTimer_         = new Timer();
            pluginFinderTimer_.Tick   += new EventHandler(FindAndAttachToPlugin);
            pluginFinderForbiddenPids_ = new List <uint>();
            processSearcher_           = new ProcessSearcher();

            pluginFinderTimer_.Interval = InitialPluginCheckFrequency;
            pluginFinderTimer_.Start();
        }
コード例 #3
0
    /// <summary>
    /// Constructs the PluginDebuggerHelper.
    /// </summary>
    /// <param name="dte">Automation object from Visual Studio.</param>
    /// <param name="properties">PropertyManager set to a valid project/platform.</param>
    protected PluginDebuggerBase(DTE2 dte, PropertyManager properties)
    {
      if (dte == null)
      {
        throw new ArgumentNullException("dte");
      }

      if (properties == null)
      {
        throw new ArgumentNullException("properties");
      }

      Dte = dte;

      // Every second, check for a new instance of the plug-in to attach to.
      // Note that although the timer itself runs on a separate thread, the event
      // is fired from the main UI thread during message processing, thus we do not
      // need to worry about threading issues.
      pluginFinderTimer_ = new Timer();
      pluginFinderTimer_.Tick += new EventHandler(FindAndAttachToPlugin);
      pluginFinderForbiddenPids_ = new List<uint>();
      processSearcher_ = new ProcessSearcher();

      pluginFinderTimer_.Interval = InitialPluginCheckFrequency;
      pluginFinderTimer_.Start();
    }
コード例 #4
0
 /// <summary>
 /// This checks if the first argument is a descendant of the second, where
 /// both arguments are process IDs of two processes.
 /// </summary>
 /// <param name="processSearcher">Process searcher object.</param>
 /// <param name="descendant">Process ID of the descendant.</param>
 /// <param name="ancestor">Process ID of ancestor.</param>
 /// <returns>True if descendant is a descendant of ancestor.</returns>
 public static bool IsDescendantOfProcess(
     ProcessSearcher processSearcher,
     uint descendant,
     uint ancestor)
 {
     return(IsDescendantOfProcessHelper(
                processSearcher,
                descendant,
                ancestor,
                DateTime.UtcNow));
 }
コード例 #5
0
ファイル: Utility.cs プロジェクト: udiavr/nativeclient-sdk
    /// <summary>
    /// Helper function for IsDescendantOfProcessHelper().
    /// This function prevents an edge case where a process has a parent process ID
    /// that refers to a descendant of itself. This can occur when the parent of a process
    /// is destroyed and the parent's pid is recycled and reused on a descendant.  The
    /// parent process ID value is never updated when the parent is destroyed. The solution
    /// is to make sure that parents are created before children, otherwise it is a cycle.
    /// </summary>
    /// <param name="processSearcher">Process searcher object.</param>
    /// <param name="descendant">Process ID of the descendant.</param>
    /// <param name="anscestor">Process ID of the ancestor.</param>
    /// <param name="previousCreationTime">Creation time of the previous call's descendant.</param>
    /// <returns>True if descendant is a descendant of ancestor.</returns>
    private static bool IsDescendantOfProcessHelper(
        ProcessSearcher processSearcher,
        uint descendant,
        uint anscestor,
        DateTime previousCreationTime)
    {
      List<ProcessInfo> results = processSearcher.GetResultsByID(descendant);
      foreach (ProcessInfo proc in results)
      {
        // Ensure this parent relationship is valid.
        if (proc.CreationDate <= previousCreationTime)
        {
          if (descendant == anscestor)
          {
            return true;
          }
          else if (descendant == proc.ParentID)
          {
            // If process is its own parent then we have a cycle, return false.
            return false;
          }

          return IsDescendantOfProcessHelper(
              processSearcher,
              proc.ParentID,
              anscestor,
              proc.CreationDate);
        }
      }

      return false;
    }
コード例 #6
0
ファイル: Utility.cs プロジェクト: udiavr/nativeclient-sdk
 /// <summary>
 /// This checks if the first argument is a descendant of the second, where
 /// both arguments are process IDs of two processes.
 /// </summary>
 /// <param name="processSearcher">Process searcher object.</param>
 /// <param name="descendant">Process ID of the descendant.</param>
 /// <param name="ancestor">Process ID of ancestor.</param>
 /// <returns>True if descendant is a descendant of ancestor.</returns>
 public static bool IsDescendantOfProcess(
   ProcessSearcher processSearcher,
   uint descendant,
   uint ancestor)
 {
   return IsDescendantOfProcessHelper(
       processSearcher,
       descendant,
       ancestor,
       DateTime.UtcNow);
 }