# Copyright 2016, 2017 Google Inc. All Rights Reserved.## Licensed under the Apache License, Version 2.0 (the "License");# you may not use this file except in compliance with the License.# You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.

Set-StrictMode-VersionLatest

Import-Module"$PSScriptRoot\NtObjectManager.dll"

# We use this incase we're running on a downlevel PowerShell.functionGet-IsPSCore{return($PSVersionTable.Keys-contains"PSEdition")-and($PSVersionTable.PSEdition-ne'Desktop')}

<#
.SYNOPSIS
Get a list of ALPC Ports that can be opened by a specified token.
.DESCRIPTION
This cmdlet checks for all ALPC ports on the system and tries to determine if one or more specified tokens can connect to them.
If no tokens are specified then the current process token is used. This function searches handles for existing ALPC Port servers as you can't directly open the server object and just connecting might show inconsistent results.
.PARAMETER ProcessIds
Specify a list of process IDs to open for their tokens.
.PARAMETER ProcessNames
Specify a list of process names to open for their tokens.
.PARAMETER ProcessCommandLines
Specify a list of command lines to filter on find for the process tokens.
.PARAMETER Tokens
Specify a list token objects.
.PARAMETER Processes
Specify a list process objects to use for their tokens.
.INPUTS
None
.OUTPUTS
NtObjectManager.AccessCheckResult
.NOTES
For best results run this function as an administrator with SeDebugPrivilege available.
.EXAMPLE
Get-AccessibleAlpcPort
Get all ALPC Ports connectable by the current token.
.EXAMPLE
Get-AccessibleAlpcPort -ProcessIds 1234,5678
Get all ALPC Ports connectable by the process tokens of PIDs 1234 and 5678
#>functionGet-AccessibleAlpcPort{Param([Int32[]]$ProcessIds,[string[]]$ProcessNames,[string[]]$ProcessCommandLines,[NtApiDotNet.NtToken[]]$Tokens,[NtApiDotNet.NtProcess[]]$Processes)$access=Get-NtAccessMask-AlpcPortAccessConnect-ToGenericAccessGet-AccessibleObject-FromHandles-ProcessIds$ProcessIds-ProcessNames$ProcessNames`-ProcessCommandLines$ProcessCommandLines-Tokens$Tokens-Processes$Processes-TypeFilter"ALPC Port"-AccessRights$access}

<#
.SYNOPSIS
Set the state of a token's privileges.
.DESCRIPTION
This cmdlet will set the state of a token's privileges. This is commonly used to enable debug/backup privileges to perform privileged actions.
If no token is specified then the current process token is used.
.PARAMETER Privileges
A list of privileges to set their state.
.PARAMETER Token
Optional token object to use to set privileges. Must be accesible for AdjustPrivileges right.
.PARAMETER Attributes
Specify the actual attributes to set. Defaults to Enabled.
.INPUTS
None
.OUTPUTS
List of TokenPrivilege values indicating the new state of all privileges successfully modified.
.EXAMPLE
Set-NtTokenPrivilege SeDebugPrivilege
Enable SeDebugPrivilege on the current process token
.EXAMPLE
Set-NtTokenPrivilege SeDebugPrivilege -Attributes Disabled
Disable SeDebugPrivilege on the current process token
.EXAMPLE
Set-NtTokenPrivilege SeBackupPrivilege, SeRestorePrivilege -Token $token
Enable SeBackupPrivilege and SeRestorePrivilege on an explicit token object.
#>functionSet-NtTokenPrivilege{[CmdletBinding(DefaultParameterSetName="FromAttributes")]Param([Parameter(Mandatory=$true,Position=0)][NtApiDotNet.TokenPrivilegeValue[]]$Privileges,[NtApiDotNet.NtToken]$Token,[Parameter(ParameterSetName="FromAttributes")][NtApiDotNet.PrivilegeAttributes]$Attributes="Enabled",[Parameter(ParameterSetName="FromDisable")][switch]$Disable)if($null-eq$Token){$Token=Get-NtToken-Primary}else{$Token=$Token.Duplicate()}

<#
.SYNOPSIS
Get the state of a token's privileges.
.DESCRIPTION
This cmdlet will get the state of a token's privileges.
.PARAMETER Privileges
A list of privileges to get their state.
.PARAMETER Token
Optional token object to use to get privileges. Must be accesible for Query right.
.INPUTS
None
.OUTPUTS
List of TokenPrivilege values indicating the state of all privileges requested.
.EXAMPLE
Get-NtTokenPrivilege
Get all privileges on the current process token.
.EXAMPLE
Get-NtTokenPrivilege -Token $token
Get all privileges on an explicit token.
.EXAMPLE
Get-NtTokenPrivilege -Privileges SeDebugPrivilege
Get state of SeDebugPrivilege on the current process token
.EXAMPLE
Get-NtTokenPrivilege -Privileges SeBackupPrivilege, SeRestorePrivilege -Token $token
Get SeBackupPrivilege and SeRestorePrivilege status on an explicit token object.
#>functionGet-NtTokenPrivilege{Param([Parameter(Position=0)][NtApiDotNet.NtToken]$Token,[NtApiDotNet.TokenPrivilegeValue[]]$Privileges)if($null-eq$Token){$Token=Get-NtToken-Primary-AccessQuery}else{$Token=$Token.Duplicate()}

<#
.SYNOPSIS
Get a token's groups.
.DESCRIPTION
This cmdlet will get the groups for a token.
.PARAMETER Token
Optional token object to use to get groups. Must be accesible for Query right.
.PARAMETER Restricted
Return the restricted SID list.
.PARAMETER Capabilities
Return the capability SID list.
.PARAMETER Attributes
Specify attributes to filter group list on.
.INPUTS
None
.OUTPUTS
List of UserGroup values indicating the state of all groups.
.EXAMPLE
Get-NtTokenGroup
Get all groups on the current process token
.EXAMPLE
Get-NtTokenGroup -Token $token
Get groups on an explicit token object.
.EXAMPLE
Get-NtTokenGroup -Attributes Enabled
Get groups that are enabled.
#>functionGet-NtTokenGroup{[CmdletBinding(DefaultParameterSetName="Normal")]Param([Parameter(Position=0)][NtApiDotNet.NtToken]$Token,[Parameter(Mandatory,ParameterSetName="Restricted")][switch]$Restricted,[Parameter(Mandatory,ParameterSetName="Capabilities")][switch]$Capabilities,[NtApiDotNet.GroupAttributes]$Attributes=0)if($null-eq$Token){$Token=Get-NtToken-Primary-AccessQuery}else{$Token=$Token.Duplicate()}

<#
.SYNOPSIS
Sets a token's group state.
.DESCRIPTION
This cmdlet will sets the state of groups for a token.
.PARAMETER Token
Optional token object to use to set groups. Must be accesible for AdjustGroups right.
.PARAMETER Sid
Specify the list of SIDs to set.
.PARAMETER Attributes
Specify the attributes to set on the SIDs.
.INPUTS
None
.OUTPUTS
None
.EXAMPLE
Set-NtTokenGroup -Sid "WD" -Attributes 0
Set the Everyone SID to disabled.
.EXAMPLE
Set-NtTokenGroup -Sid "WD" -Attributes Enabled
Set the Everyone SID to enabled.
#>functionSet-NtTokenGroup{[CmdletBinding(DefaultParameterSetName="Normal")]Param([NtApiDotNet.NtToken]$Token,[Parameter(Mandatory,Position=0)][NtApiDotNet.Sid[]]$Sid,[Parameter(Mandatory,Position=1)][NtApiDotNet.GroupAttributes]$Attributes)if($null-eq$Token){$Token=Get-NtToken-Primary-AccessAdjustGroups}else{$Token=$Token.Duplicate()}

Use-NtObject($Token){$Token.SetGroups($Sid,$Attributes)}}

<#
.SYNOPSIS
Get a token's user SID or one of the other single SID values.
.DESCRIPTION
This cmdlet will get user SID for a token. Or one of the other SIDs such as Owner.
.PARAMETER Owner
Specify to get the owner.
.PARAMETER Group
Specify to get the default group.
.PARAMETER Integrity
Specify to get the integrity level.
.PARAMETER TrustLevel
Specify to get the process trust level.
.PARAMETER LogonId
Specify to get the logon SID.
.PARAMETER Package
Specify to get the AppContainer package SID.
.PARAMETER Token
Optional token object to use to get SID. Must be accesible for Query right.
.INPUTS
None
.OUTPUTS
NtApiDotNet.Sid
.EXAMPLE
Get-NtTokenSid
Get user SID on the current process token
.EXAMPLE
Get-NtTokenSid -Token $token
Get user SID on an explicit token object.
.EXAMPLE
Get-NtTokenSid -Group
Get the default group SID.
.EXAMPLE
Get-NtTokenSid -Owner
Get the default owner SID.
#>functionGet-NtTokenSid{[CmdletBinding(DefaultParameterSetName="User")]Param([Parameter(Position=0)][NtApiDotNet.NtToken]$Token,[Parameter(Mandatory,ParameterSetName="Owner")][switch]$Owner,[Parameter(Mandatory,ParameterSetName="Group")][switch]$Group,[Parameter(Mandatory,ParameterSetName="TrustLevel")][switch]$TrustLevel,[Parameter(Mandatory,ParameterSetName="Login")][switch]$LogonId,[Parameter(Mandatory,ParameterSetName="Integrity")][switch]$Integrity,[Parameter(Mandatory,ParameterSetName="Package")][switch]$Package,[switch]$ToSddl,[switch]$ToName)if($null-eq$Token){$Token=Get-NtToken-Primary-AccessQuery}else{$Token=$Token.Duplicate()}

<#
.SYNOPSIS
Set a token SID.
.DESCRIPTION
This cmdlet will set a SID on the token such as default owner or group.
.PARAMETER Owner
Specify to set the default owner.
.PARAMETER Group
Specify to set the default group.
.PARAMETER Integrity
Specify to set the integrity level.
.PARAMETER Token
Optional token object to use to set group. Must be accesible for AdjustDefault right.
.PARAMETER Sid
Specify the SID to set.
.INPUTS
None
.OUTPUTS
None
.EXAMPLE
Set-NtTokenSid -Owner -Sid "S-1-2-3-4"
Set default owner on the current process token
.EXAMPLE
Set-NtTokenOwner -Owner -Token $token -Sid "S-1-2-3-4"
Set default owner on an explicit token object.
.EXAMPLE
Set-NtTokenOwner -Group -Sid "S-1-2-3-4"
Set the default group.
#>functionSet-NtTokenSid{[CmdletBinding(DefaultParameterSetName="Normal")]Param([Parameter(Position=1)][NtApiDotNet.NtToken]$Token,[Parameter(Mandatory,Position=0)][NtApiDotNet.Sid]$Sid,[Parameter(Mandatory,ParameterSetName="Owner")][switch]$Owner,[Parameter(Mandatory,ParameterSetName="Group")][switch]$Group,[Parameter(Mandatory,ParameterSetName="Integrity")][switch]$Integrity)if($null-eq$Token){$Token=Get-NtToken-Primary-AccessAdjustDefault}else{$Token=$Token.Duplicate()}

<#
.SYNOPSIS
Get a token's default owner of group.
.DESCRIPTION
This cmdlet will get the default owner or group for a token.
.PARAMETER Group
Specify to get the default group rather than default owner.
.PARAMETER Token
Optional token object to use to get group. Must be accesible for Query right.
.INPUTS
None
.OUTPUTS
List of TokenPrivilege values indicating the state of all privileges requested.
.EXAMPLE
Get-NtTokenOwner
Get default owner on the current process token
.EXAMPLE
Get-NtTokenOwner -Token $token
Get default owner on an explicit token object.
.EXAMPLE
Get-NtTokenOwner -Group
Get the default group.
#>functionGet-NtTokenOwner{[CmdletBinding(DefaultParameterSetName="Normal")]Param([NtApiDotNet.NtToken]$Token,[switch]$Group)if($null-eq$Token){$Token=Get-NtToken-Primary-AccessQuery}else{$Token=$Token.Duplicate()}

<#
.SYNOPSIS
Remove privileges from a token.
.DESCRIPTION
This cmdlet will remove privileges from a token. Note that this completely removes the privilege, not just disable.
.PARAMETER Privileges
A list of privileges to remove.
.PARAMETER Token
Optional token object to use to remove privileges.
.INPUTS
None
.OUTPUTS
List of TokenPrivilege values indicating the new state of all privileges successfully modified.
.EXAMPLE
Remove-NtTokenPrivilege SeDebugPrivilege
Remove SeDebugPrivilege from the current process token
.EXAMPLE
Remove-NtTokenPrivilege SeBackupPrivilege, SeRestorePrivilege -Token $token
Remove SeBackupPrivilege and SeRestorePrivilege from an explicit token object.
#>functionRemove-NtTokenPrivilege{Param([Parameter(Mandatory=$true,Position=0)][NtApiDotNet.TokenPrivilegeValue[]]$Privileges,[NtApiDotNet.NtToken]$Token)if($null-eq$Token){$Token=Get-NtToken-Primary}else{$Token=$Token.Duplicate()}

<#
.SYNOPSIS
Set the integrity level of a token.
.DESCRIPTION
This cmdlet will set the integrity level of a token. If you want to raise the level you must have SeTcbPrivilege otherwise you can only lower it.
If no token is specified then the current process token is used.
.PARAMETER IntegrityLevel
Specify the integrity level.
.PARAMETER Token
Optional token object to use to set privileges. Must be accesible for AdjustDefault right.
.PARAMETER Adjustment
Increment or decrement the IL level from the base specified in -IntegrityLevel.
.PARAMETER IntegrityLevelRaw
Specify the integrity level as a raw value.
.INPUTS
None
.EXAMPLE
Set-NtTokenIntegrityLevel Low
Set the current token's integrity level to low.
.EXAMPLE
Set-NtTokenIntegrityLevel Low -Token $Token
Set a specific token's integrity level to low.
.EXAMPLE
Set-NtTokenIntegrityLevel Low -Adjustment -16
Set the current token's integrity level to low minus 16.
.EXAMPLE
Set-NtTokenIntegrityLevel -IntegrityLevelRaw 0x800
Set the current token's integrity level to 0x800.
#>functionSet-NtTokenIntegrityLevel{[CmdletBinding(DefaultParameterSetName="FromIL")]Param([Parameter(Mandatory=$true,Position=0,ParameterSetName="FromIL")][NtApiDotNet.TokenIntegrityLevel]$IntegrityLevel,[NtApiDotNet.NtToken]$Token,[Parameter(ParameterSetName="FromIL")][Int32]$Adjustment=0,[Parameter(Mandatory=$true,Position=0,ParameterSetName="FromRaw")][Int32]$IntegrityLevelRaw)switch($PSCmdlet.ParameterSetName){"FromIL"{$il_raw=$IntegrityLevel.ToInt32($null)+$Adjustment}"FromRaw"{$il_raw=$IntegrityLevelRaw}}

<#
.SYNOPSIS
Create a kernel crash dump.
.DESCRIPTION
This cmdlet will use the NtSystemDebugControl API to create a system kernel crash dump with specified options.
.PARAMETER Path
The NT native path to the crash dump file to create
.PARAMETER Flags
Optional flags to control what to dump
.PARAMETER PageFlags
Optional flags to control what additional pages to dump
.INPUTS
None
.EXAMPLE
New-NtKernelCrashDump \??\C:\memory.dmp
Create a new crash dump at c:\memory.dmp
.EXAMPLE
New-NtKernelCrashDump \??\C:\memory.dmp -Flags IncludeUserSpaceMemoryPages
Create a new crash dump at c:\memory.dmp including user memory pages.
#>functionNew-NtKernelCrashDump{Param([Parameter(Mandatory=$true,Position=0)][string]$Path,[NtApiDotNet.SystemDebugKernelDumpControlFlags]$Flags=0,[NtApiDotNet.SystemDebugKernelDumpPageControlFlags]$PageFlags=0)[NtApiDotNet.NtSystemInfo]::CreateKernelDump($Path,$Flags,$PageFlags)}

<#
.SYNOPSIS
Get security mitigations and token security information for processes.
.DESCRIPTION
This cmdlet will get the mitigation policies for processes it can access. The default is to return mitigations for all accessible processes.
.PARAMETER Name
The name of the processes to get mitigations for.
.PARAMETER ProcessId
One or more process IDs to get mitigations for.
.PARAMETER PageFlags
Optional flags to control what additional pages to dump
.INPUTS
None
.EXAMPLE
Get-NtProcessMitigations
Get all accessible process mitigations.
.EXAMPLE
Get-NtProcessMitigations -Name MicrosoftEdgeCP.exe
Get process mitigations for Edge content processes.
.EXAMPLE
Get-NtProcessMitigations -ProcessId 1234, 4568
Get process mitigations for two processes by ID.
#>functionGet-NtProcessMitigations{[CmdletBinding(DefaultParameterSetName="All")]Param([parameter(ParameterSetName="FromName")][string]$Name,[parameter(ParameterSetName="FromProcessId")][int[]]$ProcessId)Set-NtTokenPrivilegeSeDebugPrivilege|Out-Null

<#
.SYNOPSIS
Create a new security quality of service structure.
.DESCRIPTION
This cmdlet creates a new security quality of service structure structure based on its parameters
.PARAMETER ImpersonationLevel
The impersonation level, must be specified.
.PARAMETER ContextTrackingMode
Optional tracking mode, defaults to static tracking
.PARAMETER EffectiveOnly
Optional flag to specify if only the effective rights should be impersonated
.INPUTS
None
#>functionNew-NtSecurityQualityOfService{Param([Parameter(Mandatory=$true,Position=0)][NtApiDotNet.SecurityImpersonationLevel]$ImpersonationLevel,[NtApiDotNet.SecurityContextTrackingMode]$ContextTrackingMode="Static",[switch]$EffectiveOnly)

<#
.SYNOPSIS
Gets a list of system environment values
.DESCRIPTION
This cmdlet gets the list of system environment values. Note that this isn't the same as environment
variables, these are kernel values which represent current system state.
.PARAMETER Name
The name of the system environment value to get.
.INPUTS
None
#>functionGet-NtSystemEnvironmentValue{Param([Parameter(Position=0)][string]$Name=[System.Management.Automation.Language.NullString]::Value)Set-NtTokenPrivilegeSeSystemEnvironmentPrivilege|Out-Null$values=[NtApiDotNet.NtSystemInfo]::QuerySystemEnvironmentValueNamesAndValues()if($Name-eq[string]::Empty){$values}else{$values|Where-ObjectName-eq$Name}}

<#
.SYNOPSIS
Get a license value by name.
.DESCRIPTION
This cmdlet gets a license value by name
.PARAMETER Name
The name of the license value to get.
.INPUTS
None
.OUTPUTS
NtApiDotNet.NtKeyValue
#>functionGet-NtLicenseValue{Param([Parameter(Mandatory=$true,Position=0)][string]$Name)[NtApiDotNet.NtKey]::QueryLicenseValue($Name)}

<#
.SYNOPSIS
Create a new Win32 process configuration.
.DESCRIPTION
This cmdlet creates a new Win32 process configuration which you can then pass to New-Win32Process.
.PARAMETER CommandLine
The command line of the process to create.
.PARAMETER ApplicationName
Optional path to the application executable.
.PARAMETER ProcessSecurityDescriptor
Optional security descriptor for the process.
.PARAMETER ThreadSecurityDescriptor
Optional security descriptor for the initial thread.
.PARAMETER ParentProcess
Optional process to act as the parent, needs CreateProcess access to succeed.
.PARAMETER CreationFlags
Flags to affect process creation.
.PARAMETER TerminateOnDispose
Specify switch to terminate the process when the Win32Process object is disposed.
.PARAMETER Environment
Optional environment block for the new process.
.PARAMETER CurrentDirectory
Optional current directory for the new process.
.PARAMETER Desktop
Optional desktop for the new process.
.PARAMETER Title
Optional title for the new process.
.PARAMETER InheritHandles
Switch to specify whether to inherit handles into new process.
.PARAMETER InheritProcessHandle
Switch to specify whether the process handle is inheritable
.PARAMETER InheritThreadHandle
Switch to specify whether the thread handle is inheritable.
.PARAMETER MitigationOptions
Specify optional mitigation options.
.PARAMETER Win32kFilterFlags
Specify filter flags for Win32k filter
.PARAMETER Win32kFilterLevel
Specify the filter level for the Win32k filter.
.PARAMETER Token
Specify a token to start the process with.
.PARAMETER ProtectionLevel
Specify the protection level when creating a protected process.
.PARAMETER DebugObject
Specify a debug object to run the process under. You need to also specify DebugProcess or DebugOnlyThisProcess flags as well.
.PARAMETER NoTokenFallback
Specify to not fallback to using CreateProcessWithLogon if CreateProcessAsUser fails.
.PARAMETER AppContainerProfile
Specify an app container profile to use.
.PARAMETER ExtendedFlags
Specify extended creation flags.
.PARAMETER JobList
Specify list of jobs to assign the process to.
.INPUTS
None
.OUTPUTS
NtApiDotNet.Win32.Win32ProcessConfig
#>functionNew-Win32ProcessConfig{Param([Parameter(Mandatory=$true,Position=0)][string]$CommandLine,[string]$ApplicationName,[NtApiDotNet.SecurityDescriptor]$ProcessSecurityDescriptor,[NtApiDotNet.SecurityDescriptor]$ThreadSecurityDescriptor,[NtApiDotNet.NtProcess]$ParentProcess,[NtApiDotNet.Win32.CreateProcessFlags]$CreationFlags=0,[NtApiDotNet.Win32.ProcessMitigationOptions]$MitigationOptions=0,[switch]$TerminateOnDispose,[byte[]]$Environment,[string]$CurrentDirectory,[string]$Desktop,[string]$Title,[switch]$InheritHandles,[switch]$InheritProcessHandle,[switch]$InheritThreadHandle,[NtApiDotNet.Win32.Win32kFilterFlags]$Win32kFilterFlags=0,[int]$Win32kFilterLevel=0,[NtApiDotNet.NtToken]$Token,[NtApiDotNet.Win32.ProtectionLevel]$ProtectionLevel="WindowsPPL",[NtApiDotNet.NtDebug]$DebugObject,[switch]$NoTokenFallback,[NtApiDotNet.Win32.AppContainerProfile]$AppContainerProfile,[NtApiDotNet.Win32.ProcessExtendedFlags]$ExtendedFlags=0,[NtApiDotNet.ChildProcessMitigationFlags]$ChildProcessMitigations=0,[NtApiDotNet.NtJob[]]$JobList)$config=New-ObjectNtApiDotNet.Win32.Win32ProcessConfig$config.CommandLine=$CommandLineif(-not[string]::IsNullOrEmpty($ApplicationName)){$config.ApplicationName=$ApplicationName}$config.ProcessSecurityDescriptor=$ProcessSecurityDescriptor$config.ThreadSecurityDescriptor=$ThreadSecurityDescriptor$config.ParentProcess=$ParentProcess$config.CreationFlags=$CreationFlags$config.TerminateOnDispose=$TerminateOnDispose$config.Environment=$Environmentif(-not[string]::IsNullOrEmpty($Desktop)){$config.Desktop=$Desktop}if(-not[string]::IsNullOrEmpty($CurrentDirectory)){$config.CurrentDirectory=$CurrentDirectory}if(-not[string]::IsNullOrEmpty($Title)){$config.Title=$Title}$config.InheritHandles=$InheritHandles$config.InheritProcessHandle=$InheritProcessHandle$config.InheritThreadHandle=$InheritThreadHandle$config.MitigationOptions=$MitigationOptions$config.Win32kFilterFlags=$Win32kFilterFlags$config.Win32kFilterLevel=$Win32kFilterLevel$config.Token=$Token$config.ProtectionLevel=$ProtectionLevel$config.DebugObject=$DebugObject$config.NoTokenFallback=$NoTokenFallbackif($AppContainerProfile-ne$null){$config.AppContainerSid=$AppContainerProfile.Sid}$config.ExtendedFlags=$ExtendedFlags$config.ChildProcessMitigations=$ChildProcessMitigationsif($JobList-ne$null){$config.JobList.AddRange($JobList)}return$config}

<#
.SYNOPSIS
Create a new Win32 process.
.DESCRIPTION
This cmdlet creates a new Win32 process with an optional security descriptor.
.PARAMETER CommandLine
The command line of the process to create.
.PARAMETER ApplicationName
Optional path to the application executable.
.PARAMETER ProcessSecurityDescriptor
Optional security descriptor for the process.
.PARAMETER ThreadSecurityDescriptor
Optional security descriptor for the initial thread.
.PARAMETER ParentProcess
Optional process to act as the parent, needs CreateProcess access to succeed.
.PARAMETER CreationFlags
Flags to affect process creation.
.PARAMETER TerminateOnDispose
Specify switch to terminate the process when the Win32Process object is disposed.
.PARAMETER Environment
Optional environment block for the new process.
.PARAMETER CurrentDirectory
Optional current directory for the new process.
.PARAMETER Desktop
Optional desktop for the new process.
.PARAMETER Title
Optional title for the new process.
.PARAMETER InheritHandles
Switch to specify whether to inherit handles into new process.
.PARAMETER InheritProcessHandle
Switch to specify whether the process handle is inheritable
.PARAMETER InheritThreadHandle
Switch to specify whether the thread handle is inheritable.
.PARAMETER MitigationOptions
Specify optional mitigation options.
.PARAMETER ProtectionLevel
Specify the protection level when creating a protected process.
.PARAMETER DebugObject
Specify a debug object to run the process under. You need to also specify DebugProcess or DebugOnlyThisProcess flags as well.
.PARAMETER NoTokenFallback
Specify to not fallback to using CreateProcessWithLogon if CreateProcessAsUser fails.
.PARAMETER Token
Specify an explicit token to create the new process with.
.PARAMETER ExtendedFlags
Specify extended creation flags.
.PARAMETER JobList
Specify list of jobs to assign the process to.
.PARAMETER Config
Specify the configuration for the new process.
.PARAMETER Wait
Specify to wait for the process to exit.
.PARAMETER WaitTimeout
Specify the timeout to wait for the process to exit. Defaults to infinite.
.INPUTS
None
.OUTPUTS
NtApiDotNet.Win32.Win32Process
#>functionNew-Win32Process{[CmdletBinding(DefaultParameterSetName="FromArgs")]Param([Parameter(Mandatory=$true,Position=0,ParameterSetName="FromArgs")][string]$CommandLine,[Parameter(ParameterSetName="FromArgs")][string]$ApplicationName,[Parameter(ParameterSetName="FromArgs")][NtApiDotNet.SecurityDescriptor]$ProcessSecurityDescriptor,[Parameter(ParameterSetName="FromArgs")][NtApiDotNet.SecurityDescriptor]$ThreadSecurityDescriptor,[Parameter(ParameterSetName="FromArgs")][NtApiDotNet.NtProcess]$ParentProcess,[Parameter(ParameterSetName="FromArgs")][NtApiDotNet.Win32.CreateProcessFlags]$CreationFlags=0,[Parameter(ParameterSetName="FromArgs")][NtApiDotNet.Win32.ProcessMitigationOptions]$MitigationOptions=0,[Parameter(ParameterSetName="FromArgs")][switch]$TerminateOnDispose,[Parameter(ParameterSetName="FromArgs")][byte[]]$Environment,[Parameter(ParameterSetName="FromArgs")][string]$CurrentDirectory,[Parameter(ParameterSetName="FromArgs")][string]$Desktop,[Parameter(ParameterSetName="FromArgs")][string]$Title,[Parameter(ParameterSetName="FromArgs")][switch]$InheritHandles,[Parameter(ParameterSetName="FromArgs")][switch]$InheritProcessHandle,[Parameter(ParameterSetName="FromArgs")][switch]$InheritThreadHandle,[Parameter(ParameterSetName="FromArgs")][NtApiDotNet.NtToken]$Token,[Parameter(ParameterSetName="FromArgs")][NtApiDotNet.Win32.ProtectionLevel]$ProtectionLevel="WindowsPPL",[Parameter(ParameterSetName="FromArgs")][NtApiDotNet.NtDebug]$DebugObject,[Parameter(ParameterSetName="FromArgs")][switch]$NoTokenFallback,[Parameter(ParameterSetName="FromArgs")][NtApiDotNet.Win32.AppContainerProfile]$AppContainerProfile,[Parameter(ParameterSetName="FromArgs")][NtApiDotNet.Win32.ProcessExtendedFlags]$ExtendedFlags=0,[Parameter(ParameterSetName="FromArgs")][NtApiDotNet.ChildProcessMitigationFlags]$ChildProcessMitigations=0,[Parameter(ParameterSetName="FromArgs")][NtApiDotNet.NtJob[]]$JobList,[Parameter(Mandatory=$true,Position=0,ParameterSetName="FromConfig")][NtApiDotNet.Win32.Win32ProcessConfig]$Config,[switch]$Wait,[NtApiDotNet.NtWaitTimeout]$WaitTimeout=[NtApiDotNet.NtWaitTimeout]::Infinite)

<#
.SYNOPSIS
Create a new native NT process.
.DESCRIPTION
This cmdlet creates a new native NT process.
.PARAMETER Config
The configuration for the new process from New-NtProcessConfig.
.PARAMETER ReturnOnError
Specify to always return a result even on error.
.INPUTS
None
.OUTPUTS
NtApiDotNet.NtProcessCreateResult
#>functionNew-NtProcess{Param([Parameter(Mandatory=$true,Position=0)][NtApiDotNet.NtProcessCreateConfig]$Config,[switch]$ReturnOnError)[NtApiDotNet.NtProcess]::Create($Config,!$ReturnOnError)}

<#
.SYNOPSIS
Create a new EA buffer object for use with files.
.DESCRIPTION
This cmdlet creates a new extended attributes buffer object to set on file objects with the SetEa method or with New-NtFile.
.PARAMETER Entries
Optional Hashtable containing entries to initialize into the EA buffer.
.PARAMETER $ExistingBuffer
An existing buffer to initialize the new buffer from.
.INPUTS
None
.OUTPUTS
NtApiDotNet.EaBuffer
.EXAMPLE
New-NtEaBuffer
Create a new empty EaBuffer object
.EXAMPLE
New-NtEaBuffer @{ INTENTRY = 1234; STRENTRY = "ABC"; BYTEENTRY = [byte[]]@(1,2,3) }
Create a new EaBuffer object initialized with three separate entries.
#>functionNew-NtEaBuffer{[CmdletBinding(DefaultParameterSetName="FromEntries")]Param([Parameter(ParameterSetName="FromEntries",Position=0)][Hashtable]$Entries=@{},[Parameter(ParameterSetName="FromExisting",Position=0)][NtApiDotnet.Eabuffer]$ExistingBuffer)

<#
.SYNOPSIS
Create a new image section based on an existing file.
.DESCRIPTION
This cmdlet creates an image section based on an existing file.
.PARAMETER File
A file object to an image file to create.
.PARAMETER Path
A path to an image to create.
.PARAMETER Win32Path
Resolve path as a Win32 path
.PARAMETER ObjectPath
Specify an object path for the new section object.
.INPUTS
None
.OUTPUTS
NtApiDotNet.NtSection
.EXAMPLE
New-NtSectionImage -Path \??\c:\windows\notepad.exe
Creates a
.EXAMPLE
New-NtSectionImage -File $file
Creates a new image section from an open NtFile object.
#>functionNew-NtSectionImage{[CmdletBinding(DefaultParameterSetName="FromFile")]Param([Parameter(Position=0,ParameterSetName="FromFile",Mandatory=$true)][NtApiDotNet.NtFile]$File,[Parameter(Position=0,ParameterSetName="FromPath",Mandatory=$true)][string]$Path,[Parameter(ParameterSetName="FromPath")][switch]$Win32Path,[string]$ObjectPath)

<#
.SYNOPSIS
Opens an impersonation token from a process or thread using NtImpersonateThread
.DESCRIPTION
This cmdlet opens an impersonation token from a process using NtImpersonateThread. While SeDebugPrivilege
allows you to bypass the security of processes and threads it doesn't mean you can open the primary token.
This cmdlet allows you to get past that by getting a handle to the first thread and then impersonating it,
as long as the thread isn't impersonating something else you'll get back a copy of the primary token.
.PARAMETER ProcessId
A process to open to get the token from.
.PARAMETER ThreadId
A thread to open to get the token from.
.PARAMETER Access
Access rights for the opened token.
.INPUTS
None
.OUTPUTS
NtApiDotNet.NtToken
.EXAMPLE
Get-NtTokenFromProcess -ProcessId 1234
Gets token from process ID 1234.
.EXAMPLE
Get-NtTokenFromProcess -ProcessId 1234 -Access Query
Gets token from process ID 1234 with only Query access.
.EXAMPLE
Get-NtTokenFromProcess -ThreadId 1234
Gets token from process ID 1234.
#>functionGet-NtTokenFromProcess{[CmdletBinding(DefaultParameterSetName="FromProcess")]Param([Parameter(Position=0,ParameterSetName="FromProcess",Mandatory=$true)][ValidateScript({$_-ge0})][int]$ProcessId=-1,[Parameter(ParameterSetName="FromThread",Mandatory=$true)][ValidateScript({$_-ge0})][int]$ThreadId=-1,[NtApiDotNet.TokenAccessRights]$Access="MaximumAllowed")

<#
.SYNOPSIS
Prints the details of the current token.
.DESCRIPTION
This cmdlet opens the current token and prints basic details about it. This is similar to the Windows whoami
command but runs in process and will print information about the current thread token if you're impersonating.
.PARAMETER All
Show all information.
.PARAMETER User
Show user information.
.PARAMETER Group
Show group information. Also prints capability sids and restricted sids if a sandboxed token.
.PARAMETER Privilege
Show privilege information.
.PARAMETER Integrity
Show integrity information.
.PARAMETER SecurityAttributes
Show token security attributes.
.PARAMETER TrustLevel
Show token trust level.
.OUTPUTS
Text data
.EXAMPLE
Show-NtTokenEffective
Show only the user name of the current token.
.EXAMPLE
Show-NtTokenEffective -All
Show the user, groups, privileges and integrity of the current token.
.EXAMPLE
Show-NtTokenEffective -User -Group
Show the user and groups of the current token.
#>functionShow-NtTokenEffective{Param([switch]$All,[switch]$Group,[switch]$Privilege,[switch]$User,[switch]$Integrity,[switch]$SecurityAttributes,[switch]$TrustLevel)

<#
.SYNOPSIS
Shows an object's security descriptor in a UI.
.DESCRIPTION
This cmdlet displays the security descriptor for an object in the standard Windows UI. If an object is passed
and the handle grants WriteDac access then the viewer will also allows you to modify the security descriptor.
.PARAMETER Object
Specify an object to use for the security descriptor.
.PARAMETER SecurityDescriptor
Specify a security descriptor.
.PARAMETER Type
Specify the NT object type for the security descriptor.
.PARAMETER Name
Optional name to display with the security descriptor.
.PARAMETER Wait
Optionally wait for the user to close the UI.
.PARAMETER ReadOnly
Optionally force the viewer to be read-only when passing an object with WriteDac access.
.OUTPUTS
None
.EXAMPLE
Show-NtSecurityDescriptor $obj
Show the security descriptor of an object.
.EXAMPLE
Show-NtSecurityDescriptor $obj -ReadOnly
Show the security descriptor of an object as read only.
.EXAMPLE
Show-NtSecurityDescriptor $obj.SecurityDescriptor -Type $obj.NtType
Show the security descriptor for an object via it's properties.
#>functionShow-NtSecurityDescriptor{[CmdletBinding(DefaultParameterSetName="FromObject")]Param([Parameter(Position=0,ParameterSetName="FromObject",Mandatory=$true)][NtApiDotNet.NtObject]$Object,[Parameter(ParameterSetName="FromObject")][switch]$ReadOnly,[Parameter(Position=0,ParameterSetName="FromAccessCheck",Mandatory=$true)][NtObjectManager.AccessCheckResult]$AccessCheckResult,[Parameter(Position=0,ParameterSetName="FromSecurityDescriptor",Mandatory=$true)][NtApiDotNet.SecurityDescriptor]$SecurityDescriptor,[Parameter(Position=1,ParameterSetName="FromSecurityDescriptor")][NtApiDotNet.NtType]$Type,[Parameter(ParameterSetName="FromSecurityDescriptor")][string]$Name="Object",[switch]$Wait)

switch($PsCmdlet.ParameterSetName){"FromObject"{if(!$Object.IsAccessMaskGranted([NtApiDotNet.GenericAccessRights]::ReadControl)){Write-Error"Object doesn't have Read Control access."return}# For some reason ALPC ports can't be passed to child processes. So instead pass as an SD.if($Object.NtType.Name-eq"ALPC Port"){Show-NtSecurityDescriptor$Object.SecurityDescriptor$Object.NtType-Name$Object.Name-Wait:$Waitreturn}Use-NtObject($obj=$Object.Duplicate()){$cmdline=[string]::Format("ViewSecurityDescriptor {0}",$obj.Handle.DangerousGetHandle())if($ReadOnly){$cmdline+=" --readonly"}$config=New-Win32ProcessConfig$cmdline-ApplicationName"$PSScriptRoot\ViewSecurityDescriptor.exe"-InheritHandles$config.AddInheritedHandle($obj)|Out-NullUse-NtObject($p=New-Win32Process-Config$config){if($Wait){$p.Process.Wait()|Out-Null}}}}"FromSecurityDescriptor"{if($Type-eq$null){$Type=$SecurityDescriptor.NtType}

<#
.SYNOPSIS
Gets an IO control code structure.
.DESCRIPTION
This cmdlet gets an IO control code structure from a code or from its constituent parts.
.PARAMETER ControlCode
Specify the control code for the structure.
.PARAMETER DeviceType
Specify the device type component.
.PARAMETER Function
Specify the function code component.
.PARAMETER Method
Specify the control method component.
.PARAMETER Access
Specify the access component.
.PARAMETER LookupName
Specify to try and lookup a known name for the IO control code. If no name found will just return an empty string.
.PARAMETER All
Specify to return all known IO control codes with names.
.OUTPUTS
NtApiDotNet.NtIoControlCode
.EXAMPLE
Get-NtIoControlCode 0x110028
Get the IO control code structure for a control code.
.EXAMPLE
Get-NtIoControlCode 0x110028 -LookupName
Get the IO control code structure for a control code and lookup its name (if known).
.EXAMPLE
Get-NtIoControlCode -DeviceType NAMED_PIPE -Function 10 -Method Buffered -Access Any
Get the IO control code structure from component parts.
.EXAMPLE
Get-NtIoControlCode -DeviceType NAMED_PIPE -Function 10 -Method Buffered -Access Any -LookupName
Get the IO control code structure from component parts and lookup its name (if known).
#>functionGet-NtIoControlCode{[CmdletBinding(DefaultParameterSetName="FromCode")]Param([Parameter(Position=0,ParameterSetName="FromCode",Mandatory=$true)][int]$ControlCode,[Parameter(ParameterSetName="FromParts",Mandatory=$true)][NtApiDotNet.FileDeviceType]$DeviceType,[Parameter(ParameterSetName="FromParts",Mandatory=$true)][int]$Function,[Parameter(ParameterSetName="FromParts",Mandatory=$true)][NtApiDotNet.FileControlMethod]$Method,[Parameter(ParameterSetName="FromParts",Mandatory=$true)][NtApiDotNet.FileControlAccess]$Access,[Parameter(ParameterSetName="FromParts")][Parameter(ParameterSetName="FromCode")][switch]$LookupName,[Parameter(ParameterSetName="FromAll",Mandatory=$true)][switch]$All)$result=switch($PsCmdlet.ParameterSetName){"FromCode"{[NtApiDotNet.NtIoControlCode]::new($ControlCode)}"FromParts"{[NtApiDotNet.NtIoControlCode]::new($DeviceType,$Function,$Method,$Access)}"FromAll"{[NtApiDotNet.NtWellKnownIoControlCodes]::GetKnownControlCodes()}}

<#
.SYNOPSIS
Export details about an object to re-import in another process.
.DESCRIPTION
This function generates a short JSON string which can be used to duplicate into another process
using the Import-NtObject function. The handle must be valid when the import function is executed.
.PARAMETER Object
Specify the object to export.
.OUTPUTS
string
.EXAMPLE
Export-NtObject $obj
Export an object to a JSON string.
#>functionExport-NtObject{param([Parameter(Position=0,Mandatory=$true)][NtApiDotNet.NtObject]$Object)$obj=[PSCustomObject]@{ProcessId=$PID;Handle=$Object.Handle.DangerousGetHandle().ToInt32()}$obj|ConvertTo-Json-Compress}

<#
.SYNOPSIS
Imports an object exported with Export-NtObject.
.DESCRIPTION
This function accepts a JSON string exported from Export-NtObject which allows an object to be
duplicated between PowerShell instances. You can also specify the PID and handle separetly.
.PARAMETER Object
Specify the object to import as a JSON string.
.PARAMETER ProcessId
Specify the process ID to import from.
.PARAMETER Handle
Specify the handle value to import from.
.OUTPUTS
NtApiDotNet.NtObject (the best available type).
.EXAMPLE
Import-NtObject '{"ProcessId":3300,"Handle":2660}'
Import an object from a JSON string.
.EXAMPLE
Import-NtObject -ProcessId 3300 -Handle 2660
Import an object from separate PID and handle values.
#>functionImport-NtObject{[CmdletBinding(DefaultParameterSetName="FromObject")]param([Parameter(Position=0,Mandatory,ParameterSetName="FromObject")][string]$Object,[Parameter(Position=0,Mandatory,ParameterSetName="FromPid")][int]$ProcessId,[Parameter(Position=1,Mandatory,ParameterSetName="FromPid")][int]$Handle)switch($PSCmdlet.ParameterSetName){"FromObject"{$obj=ConvertFrom-Json$ObjectImport-NtObject-ProcessId$obj.ProcessId-Handle$obj.Handle}"FromPid"{Use-NtObject($generic=[NtApiDotNet.NtGeneric]::DuplicateFrom($ProcessId,$Handle)){$generic.ToTypedObject()}}}}

<#
.SYNOPSIS
Gets the execution alias information from a name.
.DESCRIPTION
This cmdlet looks up an execution alias and tries to parse its reparse point to extract internal information.
.PARAMETER AliasName
The alias name to lookup. Can be either a full path to the alias or a name which will be found in the WindowsApps
folder.
.EXAMPLE
Get-ExecutionAlias ubuntu.exe
Get the ubuntu.exe execution alias from local appdata.
.EXAMPLE
Get-ExecutionAlias c:\path\to\alias.exe
Get the alias.exe execution alias from an absolute path.
#>functionGet-ExecutionAlias{Param([Parameter(Mandatory=$true,Position=0)][string]$AliasName)

<#
.SYNOPSIS
Creates a new execution alias information or updates and existing one.
.DESCRIPTION
This cmdlet creates a new execution alias for a packaged application.
.PARAMETER PackageName
The name of the UWP package.
.PARAMETER EntryPoint
The entry point of the application
.PARAMETER Target
The target executable path
.PARAMETER AppType
The application type.
.PARAMETER Version
Version number
.EXAMPLE
Set-ExecutionAlias c:\path\to\alias.exe -PackageName test -EntryPoint test!test -Target c:\test.exe -Flags 48 -Version 3
Set the alias.exe execution alias.
#>functionSet-ExecutionAlias{Param([Parameter(Mandatory=$true,Position=0)][string]$Path,[Parameter(Mandatory=$true,Position=1)][string]$PackageName,[Parameter(Mandatory=$true,Position=2)][string]$EntryPoint,[Parameter(Mandatory=$true,Position=3)][string]$Target,[NtApiDotNet.ExecutionAliasAppType]$AppType="Desktop",[Int32]$Version=3)

<#
.SYNOPSIS
Display a UI viewer for a NT token.
.DESCRIPTION
This function will create an instance of the TokenViewer application to display the opened token.
.PARAMETER Token
The token to view.
.PARAMETER Text
Additional text to show in title bar for this token.
.PARAMETER Process
The process to display the token for.
.PARAMETER ProcessId
A process ID of a process to display the token for.
.PARAMETER Name
The name of a process to display the token for.
.PARAMETER MaxTokens
When getting the name/command line only display at most this number of tokens.
.PARAMETER All
Show dialog with all access tokens.
.PARAMETER RunAsAdmin
When showing all tokens elevate the process to admin.
.INPUTS
None
.OUTPUTS
None
.EXAMPLE
Show-NtToken
Display the primary token for the current process.
.EXAMPLE
Show-NtToken -ProcessId 1234
Display the primary token for the process with PID 1234.
.EXAMPLE
Show-NtToken -Process $process
Display the primary token for the process specified with an NtProcess object.
.EXAMPLE
$ps | Select-Object -First 5 | Show-NtToken
Display the first 5 primary tokens from a list of processes.
.EXAMPLE
Show-NtToken -Token $token
Display the token specified with an NtToken object.
.EXAMPLE
Show-NtToken -Name "notepad.exe"
Display the primary tokens from accessible processes named notepad.exe.
.EXAMPLE
Show-NtToken -Name "notepad.exe" -MaxTokens 5
Display up to 5 primary tokens from accessible processes named notepad.exe.
.EXAMPLE
Show-NtToken -All
Show a list of all accessible tokens to choose from.
#>functionShow-NtToken{[CmdletBinding(DefaultParameterSetName="FromPid")]param([Parameter(Mandatory=$true,Position=0,ParameterSetName="FromToken",ValueFromPipeline=$true)][NtApiDotNet.NtToken]$Token,[Parameter(Mandatory=$true,Position=0,ParameterSetName="FromProcess",ValueFromPipeline=$true)][NtApiDotNet.NtProcess]$Process,[Parameter(Position=0,ParameterSetName="FromPid")][int]$ProcessId=$pid,[Parameter(Mandatory=$true,ParameterSetName="FromName")][string]$Name,[Parameter(Mandatory=$true,ParameterSetName="FromCommandLine")][string]$CommandLine,[Parameter(ParameterSetName="FromName")][Parameter(ParameterSetName="FromCommandLine")][int]$MaxTokens=0,[Parameter(ParameterSetName="All")][switch]$All,[Parameter(ParameterSetName="All")][switch]$RunAsAdmin)

<#
.SYNOPSIS
Invokes a script block while impersonating a token.
.DESCRIPTION
This cmdlet invokes a script block while impersonating a token.
.PARAMETER Token
The token to impersonate, if the token is a primary token it will be duplicated.
.PARAMETER Script
The script block to execute during impersonation.
.PARAMETER ImpersonationLevel
When the token is duplicated specify the impersonation level to use.
.OUTPUTS
Result of the script block.
.EXAMPLE
Invoke-NtToken -Token $token -Script { Get-NtFile \Path\To\File }
Open a file under impersonation.
.EXAMPLE
Invoke-NtToken -Token $token -ImpersonationLevel Identification -Script { Get-NtToken -Impersonation -OpenAsSelf }
Open the impersontation token under identification level impersonation.
#>functionInvoke-NtToken{param([Parameter(Mandatory=$true,Position=0)][NtApiDotNet.NtToken]$Token,[Parameter(Mandatory=$true,Position=1)][ScriptBlock]$Script,[NtApiDotNet.SecurityImpersonationLevel]$ImpersonationLevel="Impersonation")

<#
.SYNOPSIS
Displays a mapped section in a UI.
.DESCRIPTION
This cmdlet displays a section object inside a UI from where the data can be inspected or edited.
.PARAMETER Section
Specify a section object.
.PARAMETER Wait
Optionally wait for the user to close the UI.
.PARAMETER ReadOnly
Optionally force the viewer to be read-only when passing a section with Map Write access.
.PARAMETER Path
Path to a file to view as a section.
.PARAMETER ObjPath
Path to a object name to view as a section.
.OUTPUTS
None
.EXAMPLE
Show-NtSection $section
Show the mapped section.
.EXAMPLE
Show-NtSection $section -ReadOnly
Show the mapped section as read only.
.EXAMPLE
Show-NtSection $section -Wait
Show the mapped section and wait for the viewer to exit.
.EXAMPLE
Show-NtSection ([byte[]]@(0, 1, 2, 3))
Show an arbitrary byte array in the viewer.
.EXAMPLE
Show-NtSection path\to\file.bin
Show an arbitrary file in the viewer.
#>functionShow-NtSection{[CmdletBinding(DefaultParameterSetName="FromSection")]Param([Parameter(Position=0,Mandatory=$true,ParameterSetName="FromSection")][NtApiDotNet.NtSection]$Section,[Parameter(ParameterSetName="FromSection")][switch]$ReadOnly,[Parameter(Position=0,Mandatory=$true,ParameterSetName="FromData")][byte[]]$Data,[Parameter(Position=0,Mandatory=$true,ParameterSetName="FromFile")][string]$Path,[Parameter(Position=0,Mandatory=$true,ParameterSetName="FromPath")][string]$ObjPath,[switch]$Wait)switch($PSCmdlet.ParameterSetName){"FromSection"{if(!$Section.IsAccessGranted("MapRead")){Write-Error"Section doesn't have Map Read access."return}Use-NtObject($obj=$Section.Duplicate()){$obj.Inherit=$true$cmdline=[string]::Format("EditSection --handle {0}",$obj.Handle.DangerousGetHandle())if($ReadOnly){$cmdline+=" --readonly"}$config=New-Win32ProcessConfig$cmdline-ApplicationName"$PSScriptRoot\EditSection.exe"-InheritHandles$config.InheritHandleList.Add($obj.Handle.DangerousGetHandle())Use-NtObject($p=New-Win32Process-Config$config){if($Wait){$p.Process.Wait()|Out-Null}}}}"FromData"{if($Data.Length-eq0){return}$tempfile=New-TemporaryFile$path=$tempfile.FullName[System.IO.File]::WriteAllBytes($path,$Data)Use-NtObject($p=New-Win32Process"EditSection --delete --file=""$path"""-ApplicationName"$PSScriptRoot\EditSection.exe"){if($Wait){$p.Process.Wait()|Out-Null}}}"FromFile"{$Path=Resolve-Path$Pathif($Path-ne""){Use-NtObject($p=New-Win32Process"EditSection --file=""$Path"""-ApplicationName"$PSScriptRoot\EditSection.exe"){if($Wait){$p.Process.Wait()|Out-Null}}}}"FromPath"{Use-NtObject($p=New-Win32Process"EditSection --path=""$ObjPath"""-ApplicationName"$PSScriptRoot\EditSection.exe"){if($Wait){$p.Process.Wait()|Out-Null}}}}}

<#
.SYNOPSIS
Resolve the address of a list of objects.
.DESCRIPTION
This cmdlet resolves the kernel address for a list of objects. This is an expensive operation so it's designed to
be
.PARAMETER Objects
The list of objects to resolve.
.PARAMETER PassThru
Write the object addresses to the object. Normally no output is generated.
.OUTPUTS
Int64 - If PassThru specified.
.EXAMPLE
Resolve-NtObjectAddress $obj1, $obj2; $obj1.Address
Resolve the address of two objects.
#>functionResolve-NtObjectAddress{[CmdletBinding()]param([parameter(Mandatory=$true,Position=0,ValueFromPipeline=$true)][NtApiDotNet.NtObject[]]$Objects,[switch]$PassThru)BEGIN{$objs=@()}PROCESS{$objs+=$Objects}END{[NtApiDotNet.NtSystemInfo]::ResolveObjectAddress([NtApiDotNet.NtObject[]]$objs)if($PassThru){$objs|Select-Object-ExpandPropertyAddress|Write-Output}}}

<#
.SYNOPSIS
Get the security descriptor from an object.
.DESCRIPTION
This cmdlet gets the security descriptor from an object with specified list of security information.
.PARAMETER Object
The object to get the security descriptor from.
.PARAMETER SecurityInformation
The security information to get from the object.
.PARAMETER ToSddl
Convert the security descriptor to an SDDL string.
.PARAMETER Process
Specify process to a read a security descriptor from memory.
.PARAMETER Address
Specify the address in the process to read the security descriptor.
.PARAMETER Path
Specify an object path to get the security descriptor from.
.PARAMETER TypeName
Specify the type name of the object at Path. Needed if the module cannot automatically determine the NT type to open.
.INPUTS
NtApiDotNet.NtObject[]
.OUTPUTS
NtApiDotNet.SecurityDescriptor
string
.EXAMPLE
Get-NtSecurityDescriptor $obj
Get the security descriptor with default security information.
.EXAMPLE
Get-NtSecurityDescriptor $obj Dacl,Owner,Group
Get the security descriptor with DACL, OWNER and GROUP values.
.EXAMPLE
Get-NtSecurityDescriptor $obj Dacl -ToSddl
Get the security descriptor with DACL and output as an SDDL string.
.EXAMPLE
Get-NtSecurityDescriptor \BaseNamedObjects\ABC
Get the security descriptor from path \BaseNamedObjects\ABC.
.EXAMPLE
Get-NtSecurityDescriptor \??\C:\Windows -TypeName File
Get the security descriptor from c:\windows. Needs explicit NtType name of File to work.
.EXAMPLE
@($obj1, $obj2) | Get-NtSecurityDescriptor
Get the security descriptors from an array of objects.
.EXAMPLE
Get-NtSecurityDescriptor -Process $process -Address 0x12345678
Get the security descriptor from another process at address 0x12345678.
#>functionGet-NtSecurityDescriptor{[CmdletBinding(DefaultParameterSetName="FromObject")]param([parameter(Mandatory,Position=0,ValueFromPipeline,ParameterSetName="FromObject")][NtApiDotNet.NtObject]$Object,[parameter(Position=1,ParameterSetName="FromObject")][NtApiDotNet.SecurityInformation]$SecurityInformation="AllBasic",[parameter(Mandatory,ParameterSetName="FromProcess")][NtApiDotNet.NtProcess]$Process,[parameter(Mandatory,ParameterSetName="FromProcess")][int64]$Address,[parameter(Mandatory,Position=0,ParameterSetName="FromPath")][string]$Path,[parameter(ParameterSetName="FromPath")][string]$TypeName,[parameter(Mandatory,ParameterSetName="FromPid")][alias("pid")][int]$ProcessId,[parameter(Mandatory,ParameterSetName="FromTid")][alias("tid")][int]$ThreadId,[switch]$ToSddl)PROCESS{$sd=switch($PsCmdlet.ParameterSetName){"FromObject"{$Object.GetSecurityDescriptor($SecurityInformation)}"FromProcess"{[NtApiDotNet.SecurityDescriptor]::new($Process,[IntPtr]::new($Address))}"FromPath"{Use-NtObject($obj=Get-NtObject-Path$Path-TypeName$TypeName-AccessReadControl){$obj.GetSecurityDescriptor($SecurityInformation)}}"FromPid"{Use-NtObject($obj=Get-NtProcess-ProcessId$ProcessId-AccessReadControl){$obj.GetSecurityDescriptor($SecurityInformation)}}"FromTid"{Use-NtObject($obj=Get-NtThread-ThreadId$ThreadId-AccessReadControl){$obj.GetSecurityDescriptor($SecurityInformation)}}}if($ToSddl){$sd.ToSddl($SecurityInformation)}else{$sd}}}

<#
.SYNOPSIS
Set the security descriptor for an object.
.DESCRIPTION
This cmdlet sets the security descriptor for an object with specified list of security information.
.PARAMETER Object
The object to set the security descriptor to.
.PARAMETER SecurityInformation
The security information to set obj the object.
.PARAMETER Path
Specify an object path to set the security descriptor to.
.PARAMETER TypeName
Specify the type name of the object at Path. Needed if the module cannot automatically determine the NT type to open.
.PARAMETER SecurityDescriptor
The security descriptor to set. Can specify an SDDL string which will be auto-converted.
.INPUTS
NtApiDotNet.NtObject[]
.OUTPUTS
None
.EXAMPLE
Set-NtSecurityDescriptor $obj $sd Dacl
Set the DACL of an object using a SecurityDescriptor object.
.EXAMPLE
Set-NtSecurityDescriptor $obj "D:(A;;GA;;;WD)" Dacl
Set the DACL of an object based on an SDDL string.
#>functionSet-NtSecurityDescriptor{[CmdletBinding(DefaultParameterSetName="ToObject")]param([parameter(Mandatory,Position=0,ValueFromPipeline,ParameterSetName="ToObject")][NtApiDotNet.NtObject]$Object,[parameter(Mandatory,Position=0,ParameterSetName="ToPath")][string]$Path,[parameter(Mandatory,Position=1)][NtApiDotNet.SecurityDescriptor]$SecurityDescriptor,[parameter(Mandatory,Position=2)][NtApiDotNet.SecurityInformation]$SecurityInformation,[parameter(ParameterSetName="ToPath")][string]$TypeName)PROCESS{switch($PsCmdlet.ParameterSetName){"ToObject"{$Object.SetSecurityDescriptor($SecurityDescriptor,$SecurityInformation)}"ToPath"{$access=[NtApiDotNet.GenericAccessRights]::WriteDacif(($SecurityInformation-band"Owner, Label")-ne0){$access=$access-bor"WriteOwner"}if(($SecurityInformation-band"Sacl")-ne0){$access=$access-bor"AccessSystemSecurity"}

<#
.SYNOPSIS
Allocates a new block of virtual memory.
.DESCRIPTION
This cmdlet allocates a new block of virtual memory in a specified process with specified set of protection. Returns the address.
.PARAMETER Size
The size of the allocated memory region.
.PARAMETER BaseAddress
Optional address to allocate the memory at. Can be 0 which requests the kernel to pick an address.
.PARAMETER Process
The process to allocate the memory in, defaults to current process.
.PARAMETER AllocationType
The type of allocation to make. Defaults to Reserve and Commit.
.PARAMETER Protection
The protection for the memory region. Defaults to ReadWrite.
.OUTPUTS
int64
.EXAMPLE
$addr = Add-NtVirtualMemory 0x10000
Allocate a block 0x10000 in size.
.EXAMPLE
$addr = Add-NtVirtualMemory 0x10000 -Process $process
Allocate a block 0x10000 in size in the specified process.
.EXAMPLE
$addr = Add-NtVirtualMemory 0x10000 -AllocationType Reserve
Reserve a block 0x10000 in size but don't yet commit it.
.EXAMPLE
$addr = Add-NtVirtualMemory 0x10000 -Protection ExecuteReadWrite
Allocate a block 0x10000 in size with Read, Write and Execution protection.
#>functionAdd-NtVirtualMemory{param([parameter(Mandatory,Position=0)][int64]$Size,[int64]$BaseAddress,[NtApiDotNet.NtProcess]$Process=[NtApiDotnet.NtProcess]::Current,[NtApiDotNet.MemoryAllocationType]$AllocationType="Reserve, Commit",[NtApiDotNet.MemoryAllocationProtect]$Protection="ReadWrite")$Process.AllocateMemory($BaseAddress,$Size,$AllocationType,$Protection)}

<#
.SYNOPSIS
Deallocates a block of virtual memory.
.DESCRIPTION
This cmdlet deallocates a block of virtual memory in a specified process.
.PARAMETER Size
The size of the region to decommit. Only valid when FreeType is Decommit.
.PARAMETER Address
The address to deallocate the memory at.
.PARAMETER Process
The process to deallocate the memory in, defaults to current process.
.PARAMETER MemoryType
The type of allocation operation to perform. Release frees the memory while
Decommit makes it inaccessible.
.OUTPUTS
None
.EXAMPLE
Remove-NtVirtualMemory $addr
Free block at $addr
.EXAMPLE
Remove-NtVirtualMemory $addr -Process $process
Free a block in the specified process.
.EXAMPLE
Remove-NtVirtualMemory $addr -Size 0x1000 -FreeType Decommit
Decommit a 4096 byte block at $addr
#>functionRemove-NtVirtualMemory{param([parameter(Mandatory,Position=0)][int64]$Address,[int64]$Size,[NtApiDotNet.MemoryFreeType]$FreeType="Release",[NtApiDotNet.NtProcess]$Process=[NtApiDotnet.NtProcess]::Current)$Process.FreeMemory($Address,$Size,$FreeType)}

<#
.SYNOPSIS
Get information about a virtual memory region by address or for the entire process.
.DESCRIPTION
This cmdlet gets information about a virtual memory region or all regions in a process.
.PARAMETER Address
The address to get information about.
.PARAMETER Process
The process to query for memory information, defaults to current process.
.PARAMETER All
Show all memory regions.
.PARAMETER IncludeFree
When showing all memory regions specify to include free regions as well.
.OUTPUTS
NtApiDotNet.MemoryInformation
.EXAMPLE
Get-NtVirtualMemory $addr
Get the memory information for the specified address.
.EXAMPLE
Get-NtVirtualMemory $addr -Process $process
Get the memory information for the specified address in another process.
.EXAMPLE
Get-NtVirtualMemory -All
Get all memory information.
.EXAMPLE
Get-NtVirtualMemory -All -Process $process
Get all memory information in another process.
.EXAMPLE
Get-NtVirtualMemory -All -Process $process -IncludeFree
Get all memory information in another process including free regions.
#>functionGet-NtVirtualMemory{[CmdletBinding()]param([parameter(Mandatory,Position=0,ParameterSetName="FromAddress")][int64]$Address,[NtApiDotNet.NtProcess]$Process=[NtApiDotnet.NtProcess]::Current,[parameter(Mandatory,ParameterSetName="All")][switch]$All,[parameter(ParameterSetName="All")][switch]$IncludeFree)switch($PsCmdlet.ParameterSetName){"FromAddress"{$Process.QueryMemoryInformation($Address)}"All"{$Process.QueryAllMemoryInformation($IncludeFree)}}}

<#
.SYNOPSIS
Set protection flags for a virtual memory region.
.DESCRIPTION
This cmdlet sets protection flags for a region of virtual memory in the current process or another specified process.
.PARAMETER Address
The address location to set the memory protection.
.PARAMETER Size
The size of the memory region to set.
.PARAMETER Process
The process to set the memory in, defaults to current process.
.PARAMETER Protection
Specify the new protection for the memory region.
.OUTPUTS
NtApiDotNet.MemoryAllocationProtect - The previous memory protection setting.
.EXAMPLE
Set-NtVirtualMemory $addr 0x1000 ExecuteRead
Sets the protection of a memory region to ExecuteRead.
#>functionSet-NtVirtualMemory{[CmdletBinding()]param([parameter(Mandatory,Position=0)][int64]$Address,[parameter(Mandatory,Position=1)][int64]$Size,[parameter(Mandatory,Position=2)][NtApiDotNet.MemoryAllocationProtect]$Protection,[NtApiDotNet.NtProcess]$Process=[NtApiDotnet.NtProcess]::Current)$Process.ProtectMemory($Address,$Size,$Protection)}

<#
.SYNOPSIS
Reads bytes from a virtual memory region.
.DESCRIPTION
This cmdlet reads the bytes from a region of virtual memory in the current process or another specified process.
.PARAMETER Address
The address location to read.
.PARAMETER Size
The size of the memory to read. This is the maximum, if the memory address is invalid the returned buffer can be smaller.
.PARAMETER Process
The process to read from, defaults to current process.
.PARAMETER ReadAll
Specify to ensure you read all the requested memory from the process.
.OUTPUTS
byte[] - The array of read bytes. The size of the output might be smaller than the requested size.
.EXAMPLE
Read-NtVirtualMemory $addr 0x1000
Read up to 4096 from $addr.
.EXAMPLE
Read-NtVirtualMemory $addr 0x1000 -Process $process
Read up to 4096 from $addr in another process.
.EXAMPLE
Read-NtVirtualMemory $addr 0x1000 -ReadAll
Read up to 4096 from $addr, fail if can't read all the bytes.
#>functionRead-NtVirtualMemory{[CmdletBinding()]param([parameter(Mandatory,Position=0)][int64]$Address,[parameter(Mandatory,Position=1)][int]$Size,[NtApiDotNet.NtProcess]$Process=[NtApiDotnet.NtProcess]::Current,[switch]$ReadAll)$Process.ReadMemory($Address,$Size,$ReadAll)}

<#
.SYNOPSIS
Get the embedded signature information from a file.
.DESCRIPTION
This cmdlet gets the embedded authenticode signature information from a file. This differs
from Get-AuthenticodeSignature in that it doesn't take into account catalog signing which is
important for tracking down PP and PPL executables.
.PARAMETER FullName
The path to the file to extract the signature from.
#>functionGet-EmbeddedAuthenticodeSignature{[CmdletBinding()]param([parameter(Mandatory,Position=0,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)][string]$FullName)PROCESS{$content_type=[System.Security.Cryptography.X509Certificates.X509ContentType]::Unknowntry{$path=Resolve-Path$FullName$content_type=[System.Security.Cryptography.X509Certificates.X509Certificate2]::GetCertContentType($Path)}catch{}

<#
.SYNOPSIS
Get the name for a SID.
.DESCRIPTION
This cmdlet looks up a name for a SID and returns the name with a source for where the name came from.
.PARAMETER Sid
The SID to lookup the name for.
.PARAMETER BypassCache
Specify to bypass the name cache for this lookup.
.OUTPUTS
NtApiDotNet.SidName - The looked up SID name.
.EXAMPLE
Get-NtSidName "S-1-1-0"
Lookup the name for the SID S-1-1-0.
.EXAMPLE
Get-NtSidName "S-1-1-0" -BypassCache
Lookup the name for the SID S-1-1-0 without checking the name cache.
#>functionGet-NtSidName{[CmdletBinding()]Param([parameter(Mandatory,Position=0,ValueFromPipelineByPropertyName)][NtApiDotNet.Sid]$Sid,[switch]$BypassCache)

PROCESS{[NtApiDotNet.NtSecurity]::GetNameForSid($Sid,$BypassCache)}}

<#
.SYNOPSIS
Creates a symbol resolver for a process.
.DESCRIPTION
This cmdlet creates a new symbol resolver for the given process.
.PARAMETER Process
The process to create the symbol resolver on. If not specified then the current process is used.
.PARAMETER DbgHelpPath
Specify path to a dbghelp DLL to use for symbol resolving. This should be ideally the dbghelp from debugging tool for Windows
which will allow symbol servers however you can use the system version if you just want to pull symbols locally.
.PARAMETER SymbolPath
Specify path for the symbols. If not specified it will first use the _NT_SYMBOL_PATH environment variable then use the
default of 'srv*https://msdl.microsoft.com/download/symbols'
.OUTPUTS
NtApiDotNet.Win32.ISymbolResolver - The symbol resolver. Dispose after use.
.EXAMPLE
New-SymbolResolver
Get a symbol resolver for the current process with default settings.
.EXAMPLE
New-SymbolResolver -SymbolPath "c:\symbols"
Get a symbol resolver specifying for the current process specifying symbols in c:\symbols.
.EXAMPLE
New-SymbolResolver -Process $p -DbgHelpPath "c:\path\to\dbghelp.dll" -SymbolPath "srv*c:\symbols*https://blah.com/symbols"
Get a symbol resolver specifying a dbghelp path and symbol path and a specific process.
#>functionNew-SymbolResolver{Param([NtApiDotNet.NtProcess]$Process,[string]$DbgHelpPath,[string]$SymbolPath)if($DbgHelpPath-eq""){$DbgHelpPath=$Script:GlobalDbgHelpPath}if($SymbolPath-eq""){$SymbolPath=$env:_NT_SYMBOL_PATHif($SymbolPath-eq""){$SymbolPath=$Script:GlobalSymbolPath}}if($Process-eq$null){$Process=Get-NtProcess-Current}[NtApiDotNet.Win32.SymbolResolver]::Create($Process,$DbgHelpPath,$SymbolPath)}

<#
.SYNOPSIS
Creates a NDR parser for a process.
.DESCRIPTION
This cmdlet creates a new NDR parser for the given process.
.PARAMETER Process
The process to create the NDR parser on. If not specified then the current process is used.
.PARAMETER SymbolResolver
Specify a symbol resolver for the parser. Note that this should be a resolver for the same process as we're parsing.
.PARAMETER ParserFlags
Specify flags which affect the parsing operation.
.OUTPUTS
NtApiDotNet.Ndr.NdrParser - The NDR parser.
.EXAMPLE
$ndr = New-NdrParser
Get an NDR parser for the current process.
.EXAMPLE
New-NdrParser -Process $p -SymbolResolver $resolver
Get an NDR parser for a specific process with a known resolver.
#>functionNew-NdrParser{Param([NtApiDotNet.NtProcess]$Process,[NtApiDotNet.Win32.ISymbolResolver]$SymbolResolver,[NtApiDotNet.Ndr.NdrParserFlags]$ParserFlags=0)[NtApiDotNet.Ndr.NdrParser]::new($Process,$SymbolResolver,$ParserFlags)}

<#
.SYNOPSIS
Get a mapped view of a section.
.DESCRIPTION
This cmdlet calls the Map method on a section to map it into memory.
.PARAMETER Section
The section object to map.
.PARAMETER Protection
The protection of the mapping.
.PARAMETER Process
Optional process to map the section into. Default is the current process.
.PARAMETER ViewSize
The size of the view to map, 0 means map the entire section.
.PARAMETER BaseAddress
Base address for the mapping, 0 means pick a location.
.PARAMETER ZeroBits
The number of zero bits in the mapping address.
.PARAMETER CommitSize
The size of memory to commit from the section.
.PARAMETER SectionOffset
Offset into the section for the base address.
.PARAMETER SectionInherit
Inheritance flags for the section.
.PARAMETER AllocationType
The allocation type for the mapping.
.OUTPUTS
NtApiDotNet.NtMappedSection - The mapped section.
.EXAMPLE
Get-NtMappedSection -Section $sect -Protection ReadWrite
Map the section as Read/Write.
.EXAMPLE
Get-NtMappedSection -Section $sect -Protection ReadWrite -ViewSize 4096
Map the first 4096 bytes of the section as Read/Write.
.EXAMPLE
Get-NtMappedSection -Section $sect -Protection ReadWrite -SectionOffset (64*1024)
Map the section starting from offset 64k.
#>functionGet-NtMappedSection{Param([parameter(Mandatory,Position=0)][NtApiDotNet.NtSection]$Section,[parameter(Mandatory,Position=1)][NtApiDotNet.MemoryAllocationProtect]$Protection,[NtApiDotNet.NtProcess]$Process,[IntPtr]$ViewSize=0,[IntPtr]$BaseAddress=0,[IntPtr]$ZeroBits=0,[IntPtr]$CommitSize=0,[NtApiDotNet.LargeInteger]$SectionOffset,[NtApiDotNet.SectionInherit]$SectionInherit=[NtApiDotNet.SectionInherit]::ViewUnmap,[NtApiDotNet.AllocationType]$AllocationType="None")

<#
.SYNOPSIS
Get registered WNF subscription.
.DESCRIPTION
This cmdlet gets the registered WNF entries or a specific entry from a state name.
.PARAMETER StateName
The statename to get.
.PARAMETER DontCheckExists
Specify to not check that the WNF entry exists.
.PARAMETER Name
Lookup the state name from a well known text name.
.OUTPUTS
NtApiDotNet.NtWnf
.EXAMPLE
Get-NtWnf
Get all registered WNF entries.
.EXAMPLE
Get-NtWnf 0x12345678
Get a WNF entry from a state name.
.EXAMPLE
Get-NtWnf 0x12345678 -DontCheckExists
Get a WNF entry from a state name but don't check if it exists.
.EXAMPLE
Get-NtWnf "WNF_AOW_BOOT_PROGRESS"
Get a WNF entry from a name.
#>functionGet-NtWnf{[CmdletBinding(DefaultParameterSetName="All")]Param([parameter(Position=0,Mandatory,ParameterSetName="StateName")][uint64]$StateName,[parameter(ParameterSetName="StateName")][parameter(ParameterSetName="Name")][switch]$DontCheckExists,[parameter(Position=0,Mandatory,ParameterSetName="Name")][string]$Name)switch($PSCmdlet.ParameterSetName){"All"{[NtApiDotNet.NtWnf]::GetRegisteredNotifications()}"StateName"{[NtApiDotNet.NtWnf]::Open($StateName,-not$DontCheckExists)}"Name"{[NtApiDotNet.NtWnf]::Open($Name,-not$DontCheckExists)}}}

<#
.SYNOPSIS
Get the cached signing level for a file.
.DESCRIPTION
This cmdlet gets the cached signing level for a specified file.
.PARAMETER Path
The file to get the cached signing level from.
.PARAMETER Win32Path
Specify to treat Path as a Win32 path.
.PARAMETER FromEa
Specify whether to the read the cached signing level from the extended attribute.
.OUTPUTS
NtApiDotNet.CachedSigningLevel
.EXAMPLE
Get-NtCachedSigningLevel \??\c:\path\to\file.dll
Get the cached signing level from \??\c:\path\to\file.dll
.EXAMPLE
Get-NtCachedSigningLevel c:\path\to\file.dll -Win32Path
Get the cached signing level from c:\path\to\file.dll converting from a win32 path.
.EXAMPLE
Get-NtCachedSigningLevel \??\c:\path\to\file.dll -FromEa
Get the cached signing level from \??\c:\path\to\file.dll using the extended attribute.
#>functionGet-NtCachedSigningLevel{Param([parameter(Position=0,Mandatory)][string]$Path,[switch]$Win32Path,[switch]$FromEa)

<#
.SYNOPSIS
Adds an ACE to a security descriptor DACL.
.DESCRIPTION
This cmdlet adds a new ACE to a security descriptor DACL.
.PARAMETER SecurityDescriptor
The security descriptor to add the ACE to.
.PARAMETER Sid
The SID to add to the ACE.
.PARAMETER Name
The username to add to the ACE.
.PARAMETER KnownSid
A known SID to add to the ACE.
.PARAMETER AccessMask
The access mask for the ACE.
.PARAMETER GenericAccess
A generic access mask for the ACE.
.PARAMETER Type
The type of the ACE.
.PARAMETER Flags
The flags for the ACE.
.PARAMETER Condition
The condition string for the ACE.
.INPUTS
None
.OUTPUTS
None
.EXAMPLE
Add-NtSecurityDescriptorDaclAce -SecurityDescriptor $sd -Sid "S-1-1-0" -AccessMask 0x1234
Adds an access allowed ACE to the DACL for SID S-1-1-0 and mask of 0x1234
.EXAMPLE
Add-NtSecurityDescriptorDaclAce -SecurityDescriptor $sd -Sid "S-1-1-0" -AccessMask (Get-NtAccessMask -FileAccess ReadData)
Adds an access allowed ACE to the DACL for SID S-1-1-0 and mask for the file ReadData access right.
#>functionAdd-NtSecurityDescriptorDaclAce{[CmdletBinding(DefaultParameterSetName="FromSid")]Param([parameter(Position=0,Mandatory)][NtApiDotNet.SecurityDescriptor]$SecurityDescriptor,[parameter(Mandatory,ParameterSetName="FromSid")][NtApiDotNet.Sid]$Sid,[parameter(Mandatory,ParameterSetName="FromName")][string]$Name,[parameter(Mandatory,ParameterSetName="FromKnownSid")][NtApiDotNet.KnownSidValue]$KnownSid,[NtApiDotNet.AccessMask]$AccessMask=0,[NtApiDotNet.GenericAccessRights]$GenericAccess=0,[NtApiDotNet.AceType]$Type="Allowed",[NtApiDotNet.AceFlags]$Flags="None",[string]$Condition)

switch($PSCmdlet.ParameterSetName){"FromSid"{# Do nothing.}"FromName"{$Sid=Get-NtSid-Name$Name}"FromKnownSid"{$Sid=Get-NtSid-KnownSid$KnownSid}}

<#
.SYNOPSIS
Creates a new "fake" NT type object.
.DESCRIPTION
This cmdlet creates a new "fake" NT type object which can be used to do access checking for objects which aren't real NT types.
.PARAMETER Name
The name of the "fake" type.
.PARAMETER GenericRead
The value of GenericRead for the GENERIC_MAPPING.
.PARAMETER GenericWrite
The value of GenericWrite for the GENERIC_MAPPING.
.PARAMETER GenericExecute
The value of GenericExecute for the GENERIC_MAPPING.
.PARAMETER GenericAll
The value of GenericAll for the GENERIC_MAPPING.
.PARAMETER AccessRightsType
The enumerated type
.INPUTS
None
.OUTPUTS
NtApiDotNet.NtType
#>functionNew-NtType{Param([parameter(Position=0,Mandatory)][string]$Name,[System.Type]$AccessRightsType=[NtApiDotNet.GenericAccessRights],[NtApiDotNet.AccessMask]$GenericRead=0,[NtApiDotNet.AccessMask]$GenericWrite=0,[NtApiDotNet.AccessMask]$GenericExecute=0,[NtApiDotNet.AccessMask]$GenericAll=0)

<#
.SYNOPSIS
Gets an ALPC server port.
.DESCRIPTION
This cmdlet gets an ALPC server port by name. As you can't directly open the server end of the port this function goes through
all handles and tries to extract the port from the hosting process. This might require elevated privileges, especially debug
privilege, to work correctly.
.PARAMETER Path
The path to the ALPC server port to get.
.PARAMETER ProcessId
The process ID of the process to query for ALPC servers.
.INPUTS
None
.OUTPUTS
NtApiDotNet.NtAlpc
.EXAMPLE
Get-NtAlpcServer
Gets all ALPC server objects accessible to the current process.
.EXAMPLE
Get-NtAlpcServer "\RPC Control\atsvc"
Gets the "\RPC Control\atsvc" ALPC server.
.EXAMPLE
Get-NtAlpcServer -ProcessId 1234
Gets all ALPC servers from PID 1234.
#>functionGet-NtAlpcServer{[CmdletBinding(DefaultParameterSetName="All")]Param([parameter(Mandatory,Position=0,ParameterSetName="FromPath")][string]$Path,[parameter(Mandatory,Position=0,ParameterSetName="FromProcessId")][alias("pid")][int]$ProcessId=-1)

<#
.SYNOPSIS
Gets the endpoints for a RPC interface from the local endpoint mapper or by brute force.
.DESCRIPTION
This cmdlet gets the endpoints for a RPC interface from the local endpoint mapper. Not all RPC interfaces
are registered in the endpoint mapper so it might not show. You can use the -FindAlpcPort command to try
and brute force an ALPC port for the interface.
.PARAMETER InterfaceId
The UUID of the RPC interface.
.PARAMETER InterfaceVersion
The version of the RPC interface.
.PARAMETER Server
Parsed NDR server.
.PARAMETER Binding
A RPC binding string to query all endpoints from.
.PARAMETER AlpcPort
An ALPC port name. Can contain a full path as long as the string contains \RPC Control\ (case sensitive).
.PARAMETER FindAlpcPort
Use brute force to find a valid ALPC endpoint for the interface.
.INPUTS
None or NtApiDotNet.Ndr.NdrRpcServerInterface
.OUTPUTS
NtApiDotNet.Win32.RpcEndpoint[]
.EXAMPLE
Get-RpcEndpoint
Get all RPC registered RPC endpoints.
.EXAMPLE
Get-RpcEndpoint $Server
Get RPC endpoints for a parsed NDR server interface.
.EXAMPLE
Get-RpcEndpoint "A57A4ED7-0B59-4950-9CB1-E600A665154F"
Get RPC endpoints for a specified interface ID ignoring the version.
.EXAMPLE
Get-RpcEndpoint "A57A4ED7-0B59-4950-9CB1-E600A665154F" "1.0"
Get RPC endpoints for a specified interface ID and version.
.EXAMPLE
Get-RpcEndpoint "A57A4ED7-0B59-4950-9CB1-E600A665154F" "1.0" -FindAlpcPort
Get ALPC RPC endpoints for a specified interface ID and version by brute force.
.EXAMPLE
Get-RpcEndpoint -Binding "ncalrpc:[RPC_PORT]"
Get RPC endpoints for exposed over ncalrpc with name RPC_PORT.
.EXAMPLE
Get-RpcEndpoint -AlpcPort "RPC_PORT"
Get RPC endpoints for exposed over ALPC with name RPC_PORT.
#>functionGet-RpcEndpoint{[CmdletBinding(DefaultParameterSetName="All")]Param([parameter(Mandatory,Position=0,ParameterSetName="FromId")][parameter(Mandatory,Position=0,ParameterSetName="FromIdAndVersion")][string]$InterfaceId,[parameter(Mandatory,Position=1,ParameterSetName="FromIdAndVersion")][Version]$InterfaceVersion,[parameter(Mandatory,Position=0,ParameterSetName="FromServer",ValueFromPipeline)][NtApiDotNet.Ndr.NdrRpcServerInterface]$Server,[parameter(Mandatory,ParameterSetName="FromBinding")][string]$Binding,[parameter(Mandatory,ParameterSetName="FromAlpc")][string]$AlpcPort,[parameter(ParameterSetName="FromIdAndVersion")][parameter(ParameterSetName="FromServer")][switch]$FindAlpcPort)

<#
.SYNOPSIS
Get the RPC servers from a DLL.
.DESCRIPTION
This cmdlet parses the RPC servers from a DLL. Note that in order to parse 32 bit DLLs you must run this module in 32 bit PowerShell.
.PARAMETER FullName
The path to the DLL.
.PARAMETER DbgHelpPath
Specify path to a dbghelp DLL to use for symbol resolving. This should be ideally the dbghelp from debugging tool for Windows
which will allow symbol servers however you can use the system version if you just want to pull symbols locally.
.PARAMETER SymbolPath
Specify path for the symbols. If not specified it will first use the _NT_SYMBOL_PATH environment variable then use the
default of 'srv*https://msdl.microsoft.com/download/symbols'
.PARAMETER AsText
Return the results as text rather than objects.
.PARAMETER RemoveComments
When outputing as text remove comments from the output.
.PARAMETER ParseClients
Also parse client interface information, otherwise only servers are returned.
.PARAMETER IgnoreSymbols
Don't resolve any symbol information.
.PARAMETER SerializedPath
Path to a serialized representation of the RPC servers.
.INPUTS
string[] List of paths to DLLs.
.OUTPUTS
RpcServer[] The parsed RPC servers.
.EXAMPLE
Get-RpcServer c:\windows\system32\rpcss.dll
Get the list of RPC servers from rpcss.dll.
.EXAMPLE
Get-RpcServer c:\windows\system32\rpcss.dll -AsText
Get the list of RPC servers from rpcss.dll, return it as text.
.EXAMPLE
Get-ChildItem c:\windows\system32\*.dll | Get-RpcServer
Get the list of RPC servers from all DLLs in system32, return it as text.
.EXAMPLE
Get-RpcServer c:\windows\system32\rpcss.dll -DbgHelpPath c:\windbg\x64\dbghelp.dll
Get the list of RPC servers from rpcss.dll, specifying a different DBGHELP for symbol resolving.
.EXAMPLE
Get-RpcServer c:\windows\system32\rpcss.dll -SymbolPath c:\symbols
Get the list of RPC servers from rpcss.dll, specifying a different symbol path.
.EXAMPLE
Get-RpcServer -SerializedPath rpc.bin
Get the list of RPC servers from the serialized file rpc.bin.
#>functionGet-RpcServer{[CmdletBinding(DefaultParameterSetName="FromDll")]Param([parameter(Mandatory=$true,Position=0,ValueFromPipeline,ValueFromPipelineByPropertyName,ParameterSetName="FromDll")][alias("Path")][string]$FullName,[parameter(ParameterSetName="FromDll")][string]$DbgHelpPath,[parameter(ParameterSetName="FromDll")][string]$SymbolPath,[parameter(ParameterSetName="FromDll")][switch]$AsText,[parameter(ParameterSetName="FromDll")][switch]$RemoveComments,[parameter(ParameterSetName="FromDll")][switch]$ParseClients,[parameter(ParameterSetName="FromDll")][switch]$IgnoreSymbols,[parameter(Mandatory=$true,ParameterSetName="FromSerialized")][string]$SerializedPath)

<#
.SYNOPSIS
Set a list RPC servers to a file for storage.
.DESCRIPTION
This cmdlet serializes a list of RPC servers to a file. This can be restored using Get-RpcServer -SerializedPath.
.PARAMETER Path
The path to the output file.
.PARAMETER Server
The list of servers to serialize.
.INPUTS
RpcServer[] List of paths to DLLs.
.OUTPUTS
None
.EXAMPLE
Set-RpcServer -Server $server -Path rpc.bin
Serialize servers to file rpc.bin.
#>functionSet-RpcServer{Param([parameter(Mandatory=$true,Position=0,ValueFromPipeline)][NtApiDotNet.Win32.RpcServer[]]$Server,[parameter(Mandatory=$true,Position=1)][string]$Path)

<#
.SYNOPSIS
Gets a list of ALPC RPC servers.
.DESCRIPTION
This cmdlet gets a list of ALPC RPC servers. This relies on being able to access the list of ALPC ports in side a process so might need elevated privileges.
.PARAMETER ProcessId
The ID of a process to query for ALPC servers.
.INPUTS
None
.OUTPUTS
NtApiDotNet.Win32.RpcAlpcServer[]
.EXAMPLE
Get-RpcAlpcServer
Get all ALPC RPC servers.
.EXAMPLE
Get-RpcAlpcServer -ProcessId 1234
Get all ALPC RPC servers in process ID 1234.
#>functionGet-RpcAlpcServer{[CmdletBinding(DefaultParameterSetName="All")]Param([parameter(Mandatory,Position=0,ParameterSetName="FromProcessId")][int]$ProcessId)

<#
.SYNOPSIS
Sets the global symbol resolver paths.
.DESCRIPTION
This cmdlet sets the global symbol resolver paths. This allows you to specify symbol resolver paths for cmdlets which support it.
.PARAMETER DbgHelpPath
Specify path to a dbghelp DLL to use for symbol resolving. This should be ideally the dbghelp from debugging tool for Windows
which will allow symbol servers however you can use the system version if you just want to pull symbols locally.
.PARAMETER SymbolPath
Specify path for the symbols.
.INPUTS
None
.OUTPUTS
None
.EXAMPLE
Set-GlobalSymbolResolver -DbgHelpPath c:\windbg\x64\dbghelp.dll
Specify the global dbghelp path.
.EXAMPLE
Set-GlobalSymbolResolver -DbgHelpPath dbghelp.dll -SymbolPath "c:\symbols"
Specify the global dbghelp path using c:\symbols to source the symbol files.
#>functionSet-GlobalSymbolResolver{Param([parameter(Mandatory,Position=0)][string]$DbgHelpPath,[parameter(Position=1)][string]$SymbolPath)

<#
.SYNOPSIS
Gets a list of running services.
.DESCRIPTION
This cmdlet gets a list of running services. It can also include in the list non-active services.
.PARAMETER IncludeNonActive
Specify to return all services including non-active ones.
.PARAMETER Driver
Specify to include drivers.
.PARAMETER State
Specify the state of the services to get.
.PARAMETER ServiceType
Specify to filter the services to specific types only.
.PARAMETER Name
Specify names to lookup.
.INPUTS
None
.OUTPUTS
NtApiDotNet.Win32.RunningService[]
.EXAMPLE
Get-RunningService
Get all running services.
.EXAMPLE
Get-RunningService -IncludeNonActive
Get all services including non-active services.
.EXAMPLE
Get-RunningService -Driver
Get all running drivers.
.EXAMPLE
Get-RunningService -Name Fax
Get the Fax running service.
.EXAMPLE
Get-RunningService -State All -ServiceType UserService
Get all user services.
#>functionGet-RunningService{[CmdletBinding(DefaultParameterSetName="All")]Param([parameter(ParameterSetName="All")][switch]$IncludeNonActive,[parameter(ParameterSetName="All")][switch]$Driver,[parameter(ParameterSetName="FromArgs")][NtApiDotNet.Win32.ServiceState]$State="Active",[parameter(Mandatory,ParameterSetName="FromArgs")][NtApiDotNet.Win32.ServiceType]$ServiceType=0,[parameter(ParameterSetName="FromName",Position=0)][string[]]$Name)

<#
.SYNOPSIS
Duplicates a token to a new token.
.DESCRIPTION
This cmdlet duplicates a token to another with specified
.PARAMETER Token
Specify the token to duplicate. If not specified will use the current process token.
.PARAMETER ImpersonationLevel
If specified will duplicate the token as an impersonation token.
.PARAMETER Primary
If specified will duplicate the token as a primary token.
.PARAMETER Access
Specify the access to the new token object.
.PARAMETER Inherit
Specify the token handle is inheritable.
.PARAMETER SecurityDescriptor
Specify the new token's security descriptor.
.INPUTS
None
.OUTPUTS
NtApiDotNet.NtToken
.EXAMPLE
Copy-NtToken -Primary
Copy the current token as a primary token.
.EXAMPLE
Copy-NtToken -ImpersonationLevel Impersonation
Copy the current token as a primary token.
.EXAMPLE
Copy-NtToken -Primary -Token $token
Copy an existing token as a primary token.
#>functionCopy-NtToken{[CmdletBinding(DefaultParameterSetName="Impersonation")]Param([NtApiDotNet.NtToken]$Token,[parameter(Mandatory,ParameterSetName="Impersonation",Position=0)][NtApiDotNet.SecurityImpersonationLevel]$ImpersonationLevel,[parameter(Mandatory,ParameterSetName="Primary")][switch]$Primary,[NtApiDotNet.TokenAccessRights]$Access="MaximumAllowed",[switch]$Inherit,[NtApiDotNet.SecurityDescriptor]$SecurityDescriptor)

<#
.SYNOPSIS
Gets an object from a handle in the current process.
.DESCRIPTION
This cmdlet creates an object for a handle in the current process.
.PARAMETER Handle
Specify the handle in the current process.
.PARAMETER OwnsHandle
Specify the own the handle (closed when object is disposed).
.INPUTS
None
.OUTPUTS
NtApiDotNet.NtObject
.EXAMPLE
Get-NtObjectFromHandle -Handle 0x1234
Get an object from handle 0x1234.
.EXAMPLE
Get-NtObjectFromHandle -Handle 0x1234 -OwnsHandle
Get an object from handle 0x1234 and owns the handle.
#>functionGet-NtObjectFromHandle{Param([parameter(Mandatory,Position=0)][IntPtr]$Handle,[switch]$OwnsHandle)

<#
.SYNOPSIS
Starts a new Win32 process which is a child of a process meeting a set of criteria.
.DESCRIPTION
This cmdlet starts a new Win32 process which is a child of a process meeting a set of criteria such as user account, privileges and groups. You can use this as an admin to get a system process spawned on the current desktop.
.PARAMETER CommandLine
The command line of the process to create.
.PARAMETER CreationFlags
Flags to affect process creation.
.PARAMETER TerminateOnDispose
Specify switch to terminate the process when the Win32Process object is disposed.
.PARAMETER Desktop
Optional desktop for the new process.
.PARAMETER RequiredPrivilege
Optional list of privileges the parent process must have to create the child.
.PARAMETER RequiredGroup
Optional list of groups the parent process must have to create the child.
.INPUTS
None
.OUTPUTS
NtApiDotNet.Win32.Win32Process
.EXAMPLE
Start-Win32ChildProcess cmd.exe
Start a new child process as the system user.
.EXAMPLE
Start-Win32ChildProcess cmd.exe -User LS
Start a new child process as the local service user.
.EXAMPLE
Start-Win32ChildProcess cmd.exe -RequiredPrivilege SeAssignPrimaryTokenPrivilege
Start a new child process as the system user with SeAssignPrimaryTokenPrivilege.
.EXAMPLE
Start-Win32ChildProcess cmd.exe -RequiredGroup BA
Start a new child process as the system user with the builtin administrators group.
#>functionStart-Win32ChildProcess{Param([parameter(Mandatory,Position=0)][string]$CommandLine,[NtApiDotNet.Sid]$User="SY",[NtApiDotNet.TokenPrivilegeValue[]]$RequiredPrivilege,[NtApiDotNet.Sid[]]$RequiredGroup,[string]$Desktop="WinSta0\Default",[NtApiDotNet.Win32.CreateProcessFlags]$CreationFlags="NewConsole",[switch]$TerminateOnDispose)

<#
.SYNOPSIS
Get the values from a registry key.
.DESCRIPTION
This cmdlet will get one more values from a registry key.
.PARAMETER Key
The base key to query the values from.
.PARAMETER Name
The name of the value to query. If not specified then returns all values.
.PARAMETER AsString
Output the values as strings.
.INPUTS
NtKeyValue
.EXAMPLE
Get-NtKeyValue $key
Get all values from a key.
.EXAMPLE
Get-NtKeyValue $key -AsString
Get all values from a key as a string.
.EXAMPLE
Get-NtKeyValue $key -Name ""
Get the default value from a key.
.EXAMPLE
Get-NtKeyValue $key -Name MyValue
Get the MyValue value from a key.
#>functionGet-NtKeyValue{[CmdletBinding(DefaultParameterSetName="All")]Param([parameter(Mandatory,Position=0)][NtApiDotNet.NtKey]$Key,[parameter(ParameterSetName="FromName",Position=1)][string]$Name,[switch]$AsString)$values=switch($PSCmdlet.ParameterSetName){"All"{$Key.QueryValues()}"FromName"{@($Key.QueryValue($Name))}}if($AsString){foreach($vin$values){$v.ToString()|Write-Output}}else{$values|Write-Output}}

<#
.SYNOPSIS
Get a specified information for an object.
.DESCRIPTION
This cmdlet requests specified information through the QueryInformation system call for an object type. It can return the data as a
buffer or a byte array.
.PARAMETER InformationClass
Specify the information class to query.
.PARAMETER Object
Specify the object to query.
.PARAMETER AsBuffer
Specify to return the information as an allocated buffer.
.PARAMETER InitBuffer
Specify a buffer to initialize the query.
.PARAMETER QueryLength
Specify the length of the query buffer if it needs to be fixed.
.INPUTS
None
.OUTPUTS
byte[] or SafeBuffer
.EXAMPLE
Get-NtObjectInformation $p 1
Query information class #1 on object $p as a byte array.
.EXAMPLE
Get-NtObjectInformation $p 1 -AsBuffer
Query information class #1 on object $p as a buffer.
.EXAMPLE
Get-NtObjectInformation $p 1 -QueryLength 1000
Query information class #1 on object $p as a byte array with an initial size of 1000.
#>functionGet-NtObjectInformation{Param([parameter(Mandatory,Position=0)][NtApiDotNet.NtObject]$Object,[parameter(Mandatory,Position=1)][int]$InformationClass,[switch]$AsBuffer,[byte[]]$InitBuffer,[int]$QueryLength)if($null-eq$InitBuffer-and$QueryLength-gt0){$InitBuffer=New-Objectbyte[]$QueryLength}if($AsBuffer){$Object.QueryRawBuffer($InformationClass,$InitBuffer)}else{$Object.QueryRawBytes($InformationClass,$InitBuffer)}}

<#
.SYNOPSIS
Get a specified mitigation policy value for a process.
.DESCRIPTION
This cmdlet queries for a specific mitigation policy value from a process. The result is an enumeration or a raw value depending on the request.
.PARAMETER Process
Specify the process to query. Defaults to the current process.
.PARAMETER Policy
Specify the mitigation policy.
.PARAMETER AsRaw
Specify the query the policy as a raw integer.
.INPUTS
None
.OUTPUTS
An enumerated value or an integer.
.EXAMPLE
Get-NtProcessMitigationPolicy Signature
Query the signature mitigation policy for the current process.
.EXAMPLE
Get-NtProcessMitigationPolicy Signature -Process $p
Query the signature mitigation policy for a specified process.
.EXAMPLE
Get-NtProcessMitigationPolicy Signature -Process-AsRaw
Query the signature mitigation policy for the current process as a raw integer.
#>functionGet-NtProcessMitigationPolicy{[CmdletBinding()]Param([parameter(Mandatory,Position=0)][NtApiDotNet.ProcessMitigationPolicy]$Policy,[parameter(ValueFromPipeline)][NtApiDotNet.NtProcess]$Process,[switch]$AsRaw)

<#
.SYNOPSIS
Get an appcontainer profile for a specified package name.
.DESCRIPTION
This cmdlet gets an appcontainer profile for a specified package name.
.PARAMETER Name
Specify appcontainer name to use for the profile.
.INPUTS
None
.OUTPUTS
NtApiDotNet.Win32.AppContainerProfile
.EXAMPLE
Get-AppContainerProfile
Get appcontainer profiles for all installed packages.
.EXAMPLE
Get-AppContainerProfile -Name Package_aslkjdskjds
Get an appcontainer profile from a package name.
#>functionGet-AppContainerProfile{[CmdletBinding(DefaultParameterSetName="All")]Param([parameter(ParameterSetName="All")][switch]$AllUsers,[parameter(Mandatory,Position=0,ParameterSetName="FromName",ValueFromPipelineByPropertyName,ValueFromPipeline)][string]$Name)

<#
.SYNOPSIS
Create a new appcontainer profile for a specified package name.
.DESCRIPTION
This cmdlet create a new appcontainer profile for a specified package name. If the profile already exists it'll open it.
.PARAMETER Name
Specify appcontainer name to use for the profile.
.PARAMETER DisplayName
Specify the profile display name.
.PARAMETER Description
Specify the profile description.
.PARAMETER DeleteOnClose
Specify the profile should be deleted when closed.
.PARAMETER TemporaryProfile
Specify to create a temporary profile. Close the profile after use to delete it.
.INPUTS
None
.OUTPUTS
NtApiDotNet.Win32.AppContainerProfile
.EXAMPLE
New-AppContainerProfile -Name Package_aslkjdskjds
Create a new AppContainer profile with a specified name.
.EXAMPLE
Get-AppContainerProfile -TemporaryProfile
Create a new temporary profile.
#>functionNew-AppContainerProfile{[CmdletBinding(DefaultParameterSetName="FromName")]Param([parameter(Mandatory,Position=0,ParameterSetName="FromName")][string]$Name,[parameter(Position=1,ParameterSetName="FromName")][string]$DisplayName="DisplayName",[parameter(Position=2,ParameterSetName="FromName")][string]$Description="Description",[parameter(ParameterSetName="FromName")][NtApiDotNet.Sid[]]$Capabilities,[parameter(ParameterSetName="FromName")][switch]$DeleteOnClose,[parameter(Mandatory,ParameterSetName="FromTemp")][switch]$TemporaryProfile)

<#
.SYNOPSIS
Get a RPC client object based on a parsed RPC server.
.DESCRIPTION
This cmdlet creates a new RPC client from a parsed RPC server. The client object contains methods
to call RPC methods. The client starts off disconnected. You need to pass the client to Connect-RpcClient to
connect to the server. If you specify an interface ID and version then a generic client will be created which
allows simple calls to be made without requiring the NDR data.
.PARAMETER Server
Specify the RPC server to base the client on.
.PARAMETER NamespaceName
Specify the name of the compiled namespace for the client.
.PARAMETER ClientName
Specify the class name of the compiled client.
.PARAMETER IgnoreCache
Specify to ignore the compiled client cache and regenerate the source code.
.PARAMETER InterfaceId
Specify the interface ID for a generic client.
.PARAMETER InterfaceVersion
Specify the interface version for a generic client.
.PARAMETER Provider
Specify a Code DOM provider. Defaults to C#.
.PARAMETER Flags
Specify optional flags for the built client class.
.PARAMETER EnableDebugging
Specify to enable debugging on the compiled code.
.INPUTS
None
.OUTPUTS
NtApiDotNet.Win32.Rpc.RpcClientBase
.EXAMPLE
Get-RpcClient -Server $Server
Create a new RPC client from a parsed RPC server.
#>functionGet-RpcClient{[CmdletBinding(DefaultParameterSetName="FromServer")]Param([parameter(Mandatory,Position=0,ParameterSetName="FromServer",ValueFromPipeline)][NtApiDotNet.Win32.RpcServer]$Server,[parameter(ParameterSetName="FromServer")][string]$NamespaceName,[parameter(ParameterSetName="FromServer")][string]$ClientName,[parameter(ParameterSetName="FromServer")][switch]$IgnoreCache,[parameter(Mandatory,Position=0,ParameterSetName="FromIdAndVersion")][string]$InterfaceId,[parameter(Mandatory,Position=1,ParameterSetName="FromIdAndVersion")][Version]$InterfaceVersion,[parameter(ParameterSetName="FromServer")][System.CodeDom.Compiler.CodeDomProvider]$Provider,[parameter(ParameterSetName="FromServer")][NtApiDotNet.Win32.Rpc.RpcClientBuilderFlags]$Flags="GenerateConstructorProperties, StructureReturn, HideWrappedMethods, UnsignedChar, NoNamespace",[switch]$EnableDebugging)

<#
.SYNOPSIS
Close an object handle.
.DESCRIPTION
This cmdlet closes an object handle. It supports closing a handle locally or in another process as long
as duplicate handle access is granted.
.PARAMETER Object
Specify the object to close.
.PARAMETER Process
Specify the process where the handle to close is located.
.PARAMETER ProcessId
Specify the process ID where the handle to close is located.
.PARAMETER Handle
Specify the handle value to close in another process.
.INPUTS
None
.OUTPUTS
None
.EXAMPLE
Close-NtObject -Object $obj
Close an object in the current process.
.EXAMPLE
Close-NtObject -Handle 0x1234 -Process $proc
Close handle 0x1234 in another process.
.EXAMPLE
Close-NtObject -Handle 0x1234 -ProcessId 684
Close handle 0x1234 in process with ID 684.
#>functionClose-NtObject{[CmdletBinding(DefaultParameterSetName="FromProcess")]Param([parameter(Mandatory,Position=0,ParameterSetName="FromObject")][NtApiDotNet.NtObject]$Object,[parameter(Mandatory,Position=0,ParameterSetName="FromProcess")][NtApiDotNet.NtProcess]$Process,[parameter(Mandatory,Position=0,ParameterSetName="FromProcessId")][int]$ProcessId,[parameter(Mandatory,Position=1,ParameterSetName="FromProcess")][parameter(Mandatory,Position=1,ParameterSetName="FromProcessId")][IntPtr]$Handle)