[C++, C#, VB.NET, PowerShell] Read MSDM license information from BIOS ACPI tables

Discussion in 'Mixed Languages' started by Tito, Mar 24, 2013.

Tags:
  1. CODYQX4

    CODYQX4 MDL Developer

    Sep 4, 2009
    4,813
    45,775
    150
    #21 CODYQX4, Sep 21, 2013
    Last edited: Apr 12, 2019
    .
     
  2. Alphawaves

    Alphawaves Super Moderator/Developer
    Staff Member

    Aug 11, 2008
    6,218
    22,277
    210
    Well if it works better that way for MTK then cool.. :worthy:
     
  3. PAYMYRENT

    PAYMYRENT MDL Developer

    Jul 28, 2009
    1,460
    420
    60
    Did i get the .net coders started in the right direction?
     
  4. Alphawaves

    Alphawaves Super Moderator/Developer
    Staff Member

    Aug 11, 2008
    6,218
    22,277
    210
    Already knew.. :p Dont know what your code was looking for.. Did you ever try it ?
     
  5. PAYMYRENT

    PAYMYRENT MDL Developer

    Jul 28, 2009
    1,460
    420
    60
    nope i didnt have a windows 8 pc till now and as far as i know it just dumped the table and nothing more
     
  6. callemann

    callemann MDL Novice

    Feb 2, 2014
    1
    0
    0
    #26 callemann, Feb 3, 2014
    Last edited by a moderator: Apr 20, 2017
    Tested

    This one works - just corrected some small typos - have tested on W8:

    C#:
    Code:
     
    
            [DllImport("kernel32")]
            public static extern uint EnumSystemFirmwareTables(uint FirmwareTableProviderSignature, IntPtr pFirmwareTableBuffer, uint BufferSize);
            [DllImport("kernel32")]
            private static extern uint GetSystemFirmwareTable(uint FirmwareTableProviderSignature, uint FirmwareTableID, IntPtr pFirmwareTableBuffer, uint BufferSize);        /// <summary>
            /// Get the OEM:DM Product Key from the System Firmware MSDM Table
            /// </summary>
            /// <returns>List of all discovered Product Keys</returns>
            public static List<string> GetKeysFromMSDMWindows(ref byte[] buffer)
            {
                List<string> detectedKeys = new List<string>();
                // Read System Firmware
                uint firmwareTableProviderSignature = 0x41435049; // 'ACPI' in Hexadecimal
                uint bufferSize = EnumSystemFirmwareTables(firmwareTableProviderSignature, IntPtr.Zero, 0);
                IntPtr pFirmwareTableBuffer = Marshal.AllocHGlobal((int)bufferSize);
                buffer = new byte[bufferSize];
                EnumSystemFirmwareTables(firmwareTableProviderSignature, pFirmwareTableBuffer, bufferSize);
                Marshal.Copy(pFirmwareTableBuffer, buffer, 0, buffer.Length);
                Marshal.FreeHGlobal(pFirmwareTableBuffer);
                // Check for MSDM Table
                if (Encoding.ASCII.GetString(buffer).Contains("MSDM"))
                {
                    // Get MSDM Table
                    uint firmwareTableID = 0x4d44534d; // Reversed 'MSDM' in Hexadecimal
                    bufferSize = GetSystemFirmwareTable(firmwareTableProviderSignature, firmwareTableID, IntPtr.Zero, 0);
                    buffer = new byte[bufferSize];
                    pFirmwareTableBuffer = Marshal.AllocHGlobal((int)bufferSize);
                    GetSystemFirmwareTable(firmwareTableProviderSignature, firmwareTableID, pFirmwareTableBuffer, bufferSize);
                    Marshal.Copy(pFirmwareTableBuffer, buffer, 0, buffer.Length);
                    Marshal.FreeHGlobal(pFirmwareTableBuffer);
                    // Get OEM:DM Key
                    Encoding encoding = Encoding.GetEncoding(0x4e4);
                    detectedKeys.Add(encoding.GetString(buffer, 56, 29));
                }
                return detectedKeys;
            }
            public static void ShowMe()
            {
                byte[] buffer = null;
                if (GetKeysFromMSDMWindows(ref buffer) != null)
                {
                    Encoding encoding = Encoding.GetEncoding(0x4e4);
                    string signature = encoding.GetString(buffer, 0x0, 0x4);
                    int length = BitConverter.ToInt32(buffer, 0x4);
                    byte revision = (byte)buffer.GetValue(0x8);
                    byte checksum = (Byte)buffer.GetValue(0x9);
                    string oemid = encoding.GetString(buffer, 0xa, 0x6);
                    string oemtableid = encoding.GetString(buffer, 0x10, 0x8);
                    int oemrev = BitConverter.ToInt32(buffer, 0x18);
                    string creatorid = encoding.GetString(buffer, 0x1c, 0x4);
                    int creatorrev = BitConverter.ToInt32(buffer, 0x20);
                    int sls_version = BitConverter.ToInt32(buffer, 0x24);
                    int sls_reserved = BitConverter.ToInt32(buffer, 0x28);
                    int sls_datatype = BitConverter.ToInt32(buffer, 0x2C);
                    int sls_datareserved = BitConverter.ToInt32(buffer, 0x30);
                    int sls_datalength = BitConverter.ToInt32(buffer, 0x34);
                    string sls_data = encoding.GetString(buffer, 0x38, sls_datalength);
                    string result = "Signature         : " + signature +
                        "\nLength            : " + length +
                        "\nRevison           : " + revision.ToString("X") +
                        "\nChecksum          : " + checksum.ToString("X") +
                        "\nOEM ID            : " + oemid +
                        "\nOEM Table ID      : " + oemtableid +
                        "\nOEM Revision      : " + oemrev +
                        "\nCreator ID        : " + creatorid +
                        "\nCreator Revision  : " + creatorrev +
                        "\nSLS Version       : " + sls_version +
                        "\nSLS Reserved      : " + sls_reserved +
                        "\nSLS Datatype      : " + sls_datatype +
                        "\nSLS Data Reserved : " + sls_datareserved +
                        "\nSLS Data Length   : " + sls_datalength +
                        "\nKey               : " + sls_data;
                    Console.WriteLine(result);
                }
                else
                {
                    Console.WriteLine("MSDM Table Not Found!");
                }
                Console.ReadKey();
            }
    
    
    
    
     
  7. Tito

    Tito Super Mod / Adviser
    Staff Member

    Nov 30, 2009
    18,682
    18,581
    340
    #27 Tito, Jul 4, 2014
    Last edited by a moderator: Apr 20, 2017
    (OP)
    PowerShell

    Smallest code to handle the problem, inspired by this post:

    Code:
    (Get-WmiObject -query ‘select * from SoftwareLicensingService’).OA3xOriginalProductKey | Out-File OEMDM.txt
    Cons: Must be run from installed OS, no PE support.