Skip to content

Commit dbe5d64

Browse files
committed
Fixing injection process when .net 5.0 is installed
1 parent 9f13106 commit dbe5d64

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

Snoop.InjectorLauncher/ProcessWrapper.cs

+24-19
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public ProcessWrapper(Process process, IntPtr windowHandle)
1515

1616
this.Bitness = GetBitnessAsString(this.Process);
1717

18-
this.SupportedFrameworkName = GetTargetFramework(process);
18+
this.SupportedFrameworkName = GetSupportedTargetFramework(process);
1919
}
2020

2121
public static string GetBitnessAsString(Process process)
@@ -71,18 +71,25 @@ private static Process GetProcessFromWindowHandle(IntPtr windowHandle)
7171
return null;
7272
}
7373

74-
private static string GetTargetFramework(Process process)
74+
private static string GetSupportedTargetFramework(Process process)
7575
{
7676
var modules = NativeMethods.GetModules(process);
7777

7878
var wpfgfx_cor3Found = false;
79-
FileVersionInfo hostFxrVersionInfo = null;
79+
FileVersionInfo hostPolicyVersionInfo = null;
8080

8181
foreach (var module in modules)
8282
{
83-
if (module.szModule.Equals("hostfxr.dll", StringComparison.OrdinalIgnoreCase))
83+
#if DEBUG
84+
Trace.WriteLine(module.szExePath);
85+
var fileVersionInfo = FileVersionInfo.GetVersionInfo(module.szExePath);
86+
Trace.WriteLine($"File: {fileVersionInfo.FileMajorPart}.{fileVersionInfo.FileMinorPart}");
87+
Trace.WriteLine($"Prod: {fileVersionInfo.ProductMajorPart}.{fileVersionInfo.ProductMinorPart}");
88+
#endif
89+
90+
if (module.szModule.StartsWith("hostpolicy.dll", StringComparison.OrdinalIgnoreCase))
8491
{
85-
hostFxrVersionInfo = FileVersionInfo.GetVersionInfo(module.szExePath);
92+
hostPolicyVersionInfo = FileVersionInfo.GetVersionInfo(module.szExePath);
8693
}
8794

8895
if (module.szModule.StartsWith("wpfgfx_cor3.dll", StringComparison.OrdinalIgnoreCase))
@@ -91,30 +98,28 @@ private static string GetTargetFramework(Process process)
9198
}
9299

93100
if (wpfgfx_cor3Found
94-
&& !(hostFxrVersionInfo is null))
101+
&& hostPolicyVersionInfo != null)
95102
{
96103
break;
97104
}
98105
}
99106

100107
if (wpfgfx_cor3Found)
101108
{
102-
if (hostFxrVersionInfo == null)
109+
switch (hostPolicyVersionInfo?.ProductMajorPart)
103110
{
104-
return "netcoreapp3.0";
105-
}
111+
case 5:
112+
// we currently map from net 5 to netcoreapp 3.1
113+
return "netcoreapp3.1"; //return "net5.0";
114+
115+
case 3 when hostPolicyVersionInfo.ProductMinorPart >= 1:
116+
return "netcoreapp3.1";
106117

107-
switch (hostFxrVersionInfo.FileMajorPart)
108-
{
109118
case 3:
110-
if (hostFxrVersionInfo.FileMinorPart >= 100)
111-
{
112-
return "netcoreapp3.1";
113-
}
114-
else
115-
{
116-
return "netcoreapp3.0";
117-
}
119+
return "netcoreapp3.0";
120+
121+
default:
122+
return "netcoreapp3.0";
118123
}
119124
}
120125

0 commit comments

Comments
 (0)