Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/System.Management.Automation/engine/PSVersionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ static PSVersionInfo()
s_psVersionTable = new PSVersionHashTable(StringComparer.OrdinalIgnoreCase);

Assembly currentAssembly = typeof(PSVersionInfo).Assembly;
string productVersion = currentAssembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion;
ProductVersion = currentAssembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion;

// Get 'GitCommitId' and 'PSVersion' from the 'productVersion' assembly attribute.
//
Expand All @@ -93,11 +93,11 @@ static PSVersionInfo()
// productVersion = '6.0.0 SHA: f1ec9...' convert to GitCommitId = 'v6.0.0'
// PSVersion = '6.0.0'
string rawGitCommitId;
string mainVersion = productVersion.Substring(0, productVersion.IndexOf(' '));
string mainVersion = ProductVersion.Substring(0, ProductVersion.IndexOf(' '));

if (productVersion.Contains(" Commits: "))
if (ProductVersion.Contains(" Commits: "))
{
rawGitCommitId = productVersion.Replace(" Commits: ", "-").Replace(" SHA: ", "-g");
rawGitCommitId = ProductVersion.Replace(" Commits: ", "-").Replace(" SHA: ", "-g");
}
else
{
Expand Down Expand Up @@ -182,6 +182,8 @@ public static Version PSVersion
}
}

internal static string ProductVersion { get; }

internal static string GitCommitId
{
get
Expand Down
26 changes: 7 additions & 19 deletions src/System.Management.Automation/security/SecuritySupport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1336,39 +1336,27 @@ public enum ResolutionPurpose

internal static class AmsiUtils
{
private static string GetProcessHostName(string processName)
{
return string.Concat("PowerShell_", processName, ".exe_0.0.0.0");
}

internal static int Init()
{
Diagnostics.Assert(s_amsiContext == IntPtr.Zero, "Init should be called just once");

lock (s_amsiLockObject)
{
Process currentProcess = Process.GetCurrentProcess();
string hostname;
string appName;
try
{
hostname = string.Concat("PowerShell_", Environment.ProcessPath, "_",
currentProcess.MainModule.FileVersionInfo.ProductVersion);
}
catch (ComponentModel.Win32Exception)
{
// This exception can be thrown during thread impersonation (Access Denied for process module access).
hostname = GetProcessHostName(currentProcess.ProcessName);
appName = string.Concat("PowerShell_", Environment.ProcessPath, "_", PSVersionInfo.ProductVersion);
}
catch (FileNotFoundException)
catch (Exception)
{
// This exception can occur if the file is renamed or moved to some other folder
// (This has occurred during Exchange set up).
hostname = GetProcessHostName(currentProcess.ProcessName);
// Fall back to 'Process.ProcessName' in case 'Environment.ProcessPath' throws exception.
Process currentProcess = Process.GetCurrentProcess();
appName = string.Concat("PowerShell_", currentProcess.ProcessName, ".exe_", PSVersionInfo.ProductVersion);
}

AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit;

var hr = AmsiNativeMethods.AmsiInitialize(hostname, ref s_amsiContext);
var hr = AmsiNativeMethods.AmsiInitialize(appName, ref s_amsiContext);
if (!Utils.Succeeded(hr))
{
s_amsiInitFailed = true;
Expand Down
1 change: 0 additions & 1 deletion test/powershell/Host/Startup.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ Describe "Validate start of console host" -Tag CI {
if ($IsWindows) {
$allowedAssemblies += @(
'Microsoft.PowerShell.CoreCLR.Eventing.dll'
'System.Diagnostics.FileVersionInfo.dll'
'System.DirectoryServices.dll'
'System.Management.dll'
'System.Security.Claims.dll'
Expand Down