-
Notifications
You must be signed in to change notification settings - Fork 0
/
ParentProcessUtilities.cs
63 lines (57 loc) · 2.05 KB
/
ParentProcessUtilities.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Decompiled with JetBrains decompiler
// Type: OculusTrayTool.ParentProcessUtilities
// Assembly: OculusTrayTool, Version=0.87.8.0, Culture=neutral, PublicKeyToken=null
// MVID: E8946A27-16D6-4BF6-9D7B-70CB25A977E0
// Assembly location: C:\Program Files (x86)\Oculus Tray Tool\OculusTrayTool.exe
using Microsoft.VisualBasic.CompilerServices;
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.InteropServices;
#nullable disable
namespace OculusTrayTool
{
public struct ParentProcessUtilities
{
internal IntPtr Reserved1;
internal IntPtr PebBaseAddress;
internal IntPtr Reserved2_0;
internal IntPtr Reserved2_1;
internal IntPtr UniqueProcessId;
internal IntPtr InheritedFromUniqueProcessId;
[DllImport("ntdll.dll")]
private static extern int NtQueryInformationProcess(
IntPtr processHandle,
int processInformationClass,
ref ParentProcessUtilities processInformation,
int processInformationLength,
out int returnLength);
public static Process GetParentProcess()
{
return ParentProcessUtilities.GetParentProcess(Process.GetCurrentProcess().Handle);
}
public static Process GetParentProcess(int id)
{
return ParentProcessUtilities.GetParentProcess(Process.GetProcessById(id).Handle);
}
public static Process GetParentProcess(IntPtr handle)
{
ParentProcessUtilities processInformation = new ParentProcessUtilities();
int error = ParentProcessUtilities.NtQueryInformationProcess(handle, 0, ref processInformation, Marshal.SizeOf<ParentProcessUtilities>(processInformation), out int _);
if (error != 0)
throw new Win32Exception(error);
Process parentProcess;
try
{
parentProcess = Process.GetProcessById(processInformation.InheritedFromUniqueProcessId.ToInt32());
}
catch (ArgumentException ex)
{
ProjectData.SetProjectError((Exception) ex);
parentProcess = (Process) null;
ProjectData.ClearProjectError();
}
return parentProcess;
}
}
}