-
-
Save lwalthert/fe52f7fa98b4ea491345a0518750baa9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$SFTCode = @" | |
[DllImport("kernel32")] public static extern uint EnumSystemFirmwareTables (uint FirmwareTableProviderSignature, IntPtr pFirmwareTableBuffer, uint BufferSize); | |
[DllImport("kernel32")] public static extern uint GetSystemFirmwareTable (uint FirmwareTableProviderSignature, uint FimrwareTableID, IntPtr pFirmwareTableBuffer, uint BufferSize); | |
"@ | |
$SFT = Add-Type -MemberDefinition $SFTCode -Name "SFTKlasse" -Language CSharp -UsingNamespace "System.Reflection", "System.Diagnostics", "System.Collections.Generic" -PassThru | |
# 0×41435049=ACPI ? https://github.com/michaelforney/coreboot/blob/master/src/include/cbmem.h | |
$firmwareTableProviderSignature = 0x41435049 | |
$StructSize = $SFT::EnumSystemFirmwareTables($firmwareTableProviderSignature, [IntPtr]::Zero, 0) | |
try | |
{ | |
$StructPtr = [Runtime.InteropServices.Marshal]::AllocHGlobal($StructSize) | |
} | |
catch [OutOfMemoryException] | |
{ | |
throw Error[0] | |
} | |
$buffer = New-Object Byte[]($StructSize) | |
$SFT::EnumSystemFirmwareTables($firmwareTableProviderSignature, $StructPtr, $StructSize) | |
[Runtime.InteropServices.Marshal]::Copy($StructPtr, $buffer, 0, $StructSize) | |
[Runtime.InteropServices.Marshal]::FreeHGlobal($StructPtr) | |
if (([System.Text.Encoding]::ASCII).GetString($buffer).Contains("MSDM")) | |
{ | |
$firmwareTableMSDMID = 0x4d44534d | |
$StructSize = $SFT::GetSystemFirmwareTable($firmwareTableProviderSignature, $firmwareTableMSDMID, [IntPtr]::Zero, 0) | |
try | |
{ | |
$StructPtr = [Runtime.InteropServices.Marshal]::AllocHGlobal($StructSize) | |
} | |
catch [OutOfMemoryException] | |
{ | |
throw Error[0] | |
} | |
$buffer = New-Object Byte[]($StructSize) | |
$SFT::GetSystemFirmwareTable($firmwareTableProviderSignature, $firmwareTableMSDMID, $StructPtr, $StructSize) | |
[Runtime.InteropServices.Marshal]::Copy($StructPtr, $buffer, 0, $StructSize) | |
[Runtime.InteropServices.Marshal]::FreeHGlobal($StructPtr) | |
$encoding = [System.Text.Encoding]::GetEncoding(0x4e4) | |
$key = $encoding.GetString($buffer, 56, 29) | |
} | |
$key |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment