UnsafeNativeMethods
To perform a dynamic lookup of function addresses, the operating system provides two special Win32 APIs called GetModuleHandle and GetProcAddress.
Searching preload assemblies with GetModuleHandle and GetProcAddress
$assemblies = [AppDomain]::CurrentDomain.GetAssemblies()
$assemblies |
ForEach-Object {
$_.GlobalAssemblyCache
$_.Location
$_.GetTypes() |
ForEach-Object {
$_ | Get-Member -static | Where-Object {
$_.TypeName.Contains('Unsafe') -and $_.Name.Contains('GetProcAddress') -or $_.Name.Contains('GetModuleHandle')
} | Format-Table *
} 2> $null
}
The code does not run in PowerShell Core asSystem.dll isn't installed into the Global Assembly Cache (GAC) there by default.
Lookup function address
Next steps
DelegateType ReflectionLast updated