Skip to content

Instantly share code, notes, and snippets.

@lwalthert
Forked from newyear2006/GetACPI-OEMKey.PS1
Created June 22, 2016 11:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lwalthert/fe52f7fa98b4ea491345a0518750baa9 to your computer and use it in GitHub Desktop.
Save lwalthert/fe52f7fa98b4ea491345a0518750baa9 to your computer and use it in GitHub Desktop.
$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