Skip to content

Commit

Permalink
(#3526) Revise naming of new additions
Browse files Browse the repository at this point in the history
Simplify some naming, also add a constant (and comment) to clarify what
some of the p/invoke nonsense is doing.
  • Loading branch information
vexx32 committed Nov 6, 2024
1 parent dfd2e41 commit 19973c0
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/chocolatey/infrastructure.app/nuget/NugetCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public static IEnumerable<SourceRepository> GetRemoteRepositories(ChocolateyConf
{
// As this is a static method, we need to call the global SimpleInjector container to get a registered service.
var collectorService = SimpleInjectorContainer.Container.GetInstance<IProcessCollectorService>();
var processTree = collectorService.GetProcessesTree();
var processTree = collectorService.GetProcessTree();
"chocolatey".Log().Debug("Process Tree: {0}", processTree);

var userAgent = new StringBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ public interface IProcessCollectorService
/// <returns>
/// The found process tree, returning null from this will throw an exception in Chocolatey CLI.
/// </returns>
ProcessTree GetProcessesTree();
ProcessTree GetProcessTree();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class ProcessCollectorService : IProcessCollectorService
/// <remarks>
/// This method is not overridable on purpose, as once a tree is created it should not be changed.
/// </remarks>
public ProcessTree GetProcessesTree()
public ProcessTree GetProcessTree()
{
if (_processTree is null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,13 @@ public static Process GetParentProcess(IntPtr handle)
{
var processUtilities = new ParentProcessHelperInternal();

var status = NtQueryInformationProcess(handle, 0, ref processUtilities, Marshal.SizeOf(processUtilities), out _);
// https://learn.microsoft.com/en-us/windows/win32/api/winternl/nf-winternl-ntqueryinformationprocess#process_basic_information
// Retrieves a pointer to a PEB structure that can be used to determine whether the specified process is being debugged,
// and a unique value used by the system to identify the specified process.
// It also includes the `InheritedFromUniqueProcessId` value which we can use to look up the parent process directly.
const int processBasicInformation = 0;

var status = NtQueryInformationProcess(handle, processBasicInformation, ref processUtilities, Marshal.SizeOf(processUtilities), out _);

if (status != 0)
{
Expand Down

0 comments on commit 19973c0

Please sign in to comment.