[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. Tito

    Tito Super Mod / Adviser
    Staff Member

    Nov 30, 2009
    17,499
    15,288
    340
    #1 Tito, Mar 24, 2013
    Last edited by a moderator: Apr 20, 2017
    C++

    Code:
    // ReadAcpi.cpp : Read MSDM license information from BIOS ACPI tables.
    //
    
    
    #include "stdafx.h"
    #include "Windows.h"
    
    
    
    
    int _tmain(int argc, _TCHAR* argv[])
    {
        DWORD FirmwareTableProviderSignature;
        PVOID pFirmwareTableBuffer;
        DWORD BufferSize;
        UINT  BytesWritten;
        DWORD FirmwareTableID;
        DWORD *pFirmwareTableID;
        BOOL  foundTable = FALSE;
        BOOL  verbose = FALSE;
    
    
        if (argc > 1) {
            if (wcscmp(argv[1], _T("-v")) == 0)
                verbose = TRUE;
        }
    
    
        FirmwareTableProviderSignature = 'ACPI';
        pFirmwareTableBuffer = NULL;
        BufferSize = NULL;
    
    
        // get buffer size, call with null values
        BufferSize = EnumSystemFirmwareTables(FirmwareTableProviderSignature, 
                                              NULL, 
                                              NULL);
        
        // alloc memory
        pFirmwareTableBuffer = malloc(BufferSize);
    
    
        // enum acpi tables
        BytesWritten = EnumSystemFirmwareTables(FirmwareTableProviderSignature, 
                                                pFirmwareTableBuffer, 
                                                BufferSize);
        
        // enumerate ACPI tables, look for MSDM table
        pFirmwareTableID = (DWORD*)pFirmwareTableBuffer;
        for (int i = 0; i < BytesWritten/4; i++)
        {
            FirmwareTableID = *pFirmwareTableID;
            if (verbose) printf("%.*s\n", 4, pFirmwareTableID);
            if (FirmwareTableID == _byteswap_ulong('MSDM')) {
                if (verbose) printf("Found MSDM table\n");
                foundTable = TRUE;
                break;
            }
            pFirmwareTableID++;
        }
    
    
    
    
        if (foundTable) {
            // get buffer size, call with null values
            BufferSize = GetSystemFirmwareTable (FirmwareTableProviderSignature, 
                                                 FirmwareTableID,
                                                 NULL,
                                                 NULL);
            // alloc memory
            pFirmwareTableBuffer = malloc(BufferSize);
    
    
            BytesWritten = GetSystemFirmwareTable(FirmwareTableProviderSignature,
                                                  FirmwareTableID,
                                                  pFirmwareTableBuffer,
                                                  BufferSize);
    
    
            /*
            Table description form Miocrosoft at: http://go.microsoft.com/fwlink/p/?LinkId=234834
            
            Microsoft Software Licensing Tables (SLIC and MSDM)
            http://msdn.microsoft.com/library/windows/hardware/hh673514
                                            Byte             Byte
            Field                            Lenght            Offset    Description
            ======                            =====            ======    ===========
            Signature                        4                0        MSDM
            Length                            4                4        Length, in bytes, of the entire table.
            Revision                        1                8        0x01
            Checksum                        1                9        Checksum of the entire table.
            OEMID                            6                10        An OEM-supplied string that identifies the OEM.
            OEM Table ID                    8                16        Optional motherboard/BIOS logical identifier.
            OEM Revision                    4                24        OEM revision number of the table for the supplied OEM Table ID.
            Creator ID                        4                28        Vendor ID of the utility that created the table.
            Creator Revision                4                32        Revision of the utility that created the table.
            Software Licensing Structure    Variable length    36        Proprietary data structure that contains all the licensing 
                                                                    data necessary to enable Windows activation. 
                                                                    Details can be found in the appropriate Microsoft OEM 
                                                                    licensing kit by first visiting the Microsoft OEM website
                                                                    (http://www.microsoft.com/oem/pages/index.aspx).
            */
    
    
            BYTE *Signature     = (BYTE*)memset(malloc(4+1), NULL, 4+1);
            UINT Length;
            BYTE Revision;
            BYTE Checksum;
            BYTE *OEMID         = (BYTE*)memset(malloc(6+1), NULL, 6+1);
            BYTE *OEMTbleID     = (BYTE*)memset(malloc(8+1), NULL, 8+1);
            BYTE OEMRev;
            BYTE *CreatorID     = (BYTE*)memset(malloc(4+1), NULL, 4+1);
            UINT CreatorRev;
            UINT SLS_Size = BytesWritten - 36;
            BYTE *SLS         = (BYTE*)memset(malloc(SLS_Size), NULL, SLS_Size);
            UINT SLS_Version;
            UINT SLS_Reserved;
            UINT SLS_DataType;
            UINT SLS_DataReserved;
            UINT SLS_DataLenght;
            BYTE *ProductKey = (BYTE*)memset(malloc(30+1), NULL, 30+1);
    
    
            
            memcpy_s(Signature, 4+1, (BYTE*)pFirmwareTableBuffer + 0, 4);
            Length = *(DWORD*)((BYTE*)pFirmwareTableBuffer + 4);
            Revision = *((BYTE*)pFirmwareTableBuffer + 8);
            Checksum = *((BYTE*)pFirmwareTableBuffer + 9);
            memcpy_s(OEMID, 6+1, (BYTE*)pFirmwareTableBuffer + 10, 6);
            memcpy_s(OEMTbleID, 8+1, (BYTE*)pFirmwareTableBuffer + 16, 8);
            OEMRev = *(DWORD*)((BYTE*)pFirmwareTableBuffer + 24);
            memcpy_s(CreatorID, 4+1, (BYTE*)pFirmwareTableBuffer + 28, 4);
            CreatorRev = *(DWORD*)((BYTE*)pFirmwareTableBuffer + 32);
            memcpy_s(SLS, SLS_Size, (BYTE*)pFirmwareTableBuffer + 36, SLS_Size);
            SLS_Version = *(DWORD*)((BYTE*)SLS);
            SLS_Reserved = *(DWORD*)((BYTE*)SLS + 4);
            SLS_DataType = *(DWORD*)((BYTE*)SLS + 8);
            SLS_DataReserved = *(DWORD*)((BYTE*)SLS + 12);
            SLS_DataLenght = *(DWORD*)((BYTE*)SLS + 16);
            memcpy_s(ProductKey, SLS_DataLenght, (BYTE*)SLS + 20, SLS_DataLenght);
    
    
            if (verbose) {
                printf("Signature         : %s\n", Signature);
                printf("Length            : %d\n", Length);
                printf("Revision          : %d\n", Revision);
                printf("Checksum          : %d\n", Checksum);
                printf("OEMID             : %s\n", OEMID);
                printf("OEM Table ID      : %s\n", OEMTbleID);
                printf("OEM Revision      : %d\n", OEMRev);
                printf("Creator ID        : %s\n", CreatorID);
                printf("Creator Revision  : %d\n", CreatorRev);
                printf("SLS Version       : %d\n", SLS_Version);
                printf("SLS Reserved      : %d\n", SLS_Reserved);
                printf("SLS Data Type     : %d\n", SLS_DataType);
                printf("SLS Data Reserved : %d\n", SLS_DataReserved);
                printf("SLS Data Lenght   : %d\n", SLS_DataLenght);
                printf("Key               : %s\n", ProductKey);
                /*printf ("\n\nPress [Enter] to continue . . .");
                fflush (stdout);
                getchar();*/
            } else {
                printf("%s", ProductKey);
            }
        }
    
    
        return 0;
    }
    
    By aghoneim; I have just copied his source.

    Source
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. PAYMYRENT

    PAYMYRENT MDL Developer

    Jul 28, 2009
    1,462
    419
    60
    If I remember I still have MasterDisaster's code to detect SLIC in .NET I bet it could be adapter seeing how it uses the same kernel32 functions. I will mess around with it and post when I have time!
     
  3. PAYMYRENT

    PAYMYRENT MDL Developer

    Jul 28, 2009
    1,462
    419
    60
    #3 PAYMYRENT, Mar 25, 2013
    Last edited by a moderator: Apr 20, 2017
    This *should* just return the table from memory and then you can parse the data how ever you like... I would like to know if it works though.

    When i get done modifying it


    I think its a good start!! Like I said I have no clue if it works!

    Code:
        Public Function Get_MSDM() As Byte()
            Dim firmwareProviderID As UInteger = Asc("A") Or Asc("C") Or Asc("P") Or Asc("I")
            Dim size As UInteger = EnumSystemFirmwareTables(firmwareProviderID, IntPtr.Zero, 0)
            Dim ptr As IntPtr = Marshal.AllocHGlobal(CInt(size))
            Dim buffer As Byte() = New Byte(size - 1) {}
            EnumSystemFirmwareTables(firmwareProviderID, ptr, size)
            Marshal.Copy(ptr, buffer, 0, buffer.Length)
            Marshal.FreeHGlobal(ptr)
            Dim str As String = System.Text.Encoding.GetEncoding(1252).GetString(buffer)
            Dim array As New ArrayList()
            For i As Integer = 0 To str.Length - 1 Step 4
                array.Add(str.Substring(i, 4))
            Next
            If array.Contains("MSDM") Then
                Dim tableID As UInteger = BitConverter.ToUInt32(buffer, array.IndexOf("MSDM") * 4)
                size = GetSystemFirmwareTable(firmwareProviderID, tableID, IntPtr.Zero, 0)
                Dim buffer2 As Byte() = New Byte(size - 1) {}
                ptr = Marshal.AllocHGlobal(CInt(size))
                GetSystemFirmwareTable(firmwareProviderID, tableID, ptr, size)
                Marshal.Copy(ptr, buffer2, 0, buffer2.Length)
                Marshal.FreeHGlobal(ptr)
                Return buffer2
            Else
                Return Nothing
            End If
    
        End Function
    
    
     
  4. Alphawaves

    Alphawaves Super Moderator/Developer
    Staff Member

    Aug 11, 2008
    5,885
    20,229
    180
    #4 Alphawaves, Sep 17, 2013
    Last edited by a moderator: Apr 20, 2017
    PMR it would work but have you tried your code???

    VB Version
    Code:
     Declare Auto Function EnumSystemFirmwareTables Lib "kernel32" Alias "EnumSystemFirmwareTables" (ByVal FirmwareTableProviderSignature As UInteger, ByVal pFirmwareTableBuffer As IntPtr, ByVal BufferSize As UInteger) As UInteger
        Declare Auto Function GetSystemFirmwareTable Lib "kernel32" Alias "GetSystemFirmwareTable" (ByVal FirmwareTableProviderSignature As UInteger, ByVal FirmwareTableID As UInteger, ByVal pFirmwareTableBuffer As IntPtr, ByVal BufferSize As UInteger) As UInteger
    
            Public Function checkMSDM(ByRef buffer As Byte()) As Boolean
            Dim firmwareProviderID As UInteger = Asc("A") << 24 Or Asc("C") << 16 Or Asc("P") << 8 Or Asc("I")
            Dim size As UInteger = EnumSystemFirmwareTables(firmwareProviderID, IntPtr.Zero, 0)
            Dim ptr As IntPtr = Marshal.AllocHGlobal(CInt(size))
            buffer = New Byte(size - 1) {}
            EnumSystemFirmwareTables(firmwareProviderID, ptr, size)
            Marshal.Copy(ptr, buffer, 0, buffer.Length)
            Marshal.FreeHGlobal(ptr)
            Dim str As String = System.Text.Encoding.GetEncoding(&H4e4).GetString(buffer)
            Dim array As New ArrayList()
            For i As Integer = 0 To str.Length - 1 Step 4
                array.Add(str.Substring(i, 4))
            Next
            If array.Contains("MSDM") Then
                Dim tableID As UInteger = BitConverter.ToUInt32(buffer, array.IndexOf("MSDM") * 4)
                size = GetSystemFirmwareTable(firmwareProviderID, tableID, IntPtr.Zero, 0)
                buffer = New Byte(size - 1) {}
                ptr = Marshal.AllocHGlobal(CInt(size))
                GetSystemFirmwareTable(firmwareProviderID, tableID, ptr, size)
                Marshal.Copy(ptr, buffer, 0, buffer.Length)
                Marshal.FreeHGlobal(ptr)
                Return True
            End If
            Return False
        End Function
    Usage:
    Code:
     Dim buffer As Byte()
            If checkMSDM(buffer) Then
                Dim encoding As Encoding = encoding.GetEncoding(&H4E4)
                Dim oemid = encoding.GetString(buffer, 10, 6)
                Dim dmkey = encoding.GetString(buffer, 56, 29)
                Console.WriteLine("OEM-ID: " & oemid)
                Console.WriteLine("Product Key: " & dmkey)
            Else
                Console.WriteLine("MSDM Table Not Found!")
            End If
            Console.ReadKey()
    C# Version:
    Code:
     [DllImport("kernel32")]
            private 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);
    
            private static bool checkMSDM(ref byte[] buffer)
            {
                uint firmwareTableProvider = 'A' << 24 | 'C' << 16 | 'P' << 8 | 'I';
                uint bSize = EnumSystemFirmwareTables(firmwareTableProvider, IntPtr.Zero, 0);
                IntPtr FirmwareTableBuffer = Marshal.AllocHGlobal((int)bSize);
                buffer = new byte[bSize];
                EnumSystemFirmwareTables(firmwareTableProvider, FirmwareTableBuffer, bSize);
                Marshal.Copy(FirmwareTableBuffer, buffer, 0, buffer.Length);
                Marshal.FreeHGlobal(FirmwareTableBuffer);
                string str = Encoding.GetEncoding(0x4e4).GetString(buffer);
                ArrayList array = new ArrayList();
                for (int i = 0; i <= str.Length - 1; i += 4)
                {
                    array.Add(str.Substring(i, 4));
                }
                if (array.Contains("MSDM"))
                {
                    uint firmwareTableID = BitConverter.ToUInt32(buffer, array.IndexOf("MSDM") * 4);
                    bSize = GetSystemFirmwareTable(firmwareTableProvider, firmwareTableID, IntPtr.Zero, 0);
                    buffer = new byte[bSize];
                    FirmwareTableBuffer = Marshal.AllocHGlobal((int)bSize);
                    GetSystemFirmwareTable(firmwareTableProvider, firmwareTableID, FirmwareTableBuffer, bSize);
                    Marshal.Copy(FirmwareTableBuffer, buffer, 0, buffer.Length);
                    Marshal.FreeHGlobal(FirmwareTableBuffer);                
                    return true;
                }
                return false;
            }       
    Usage:
    Code:
    byte[] buffer = null;
                    if (checkMSDM(ref buffer))
                    {               
                        Encoding encoding = Encoding.GetEncoding(0x4e4);
                        string oemid = encoding.GetString(buffer, 10, 6);
                        string dmkey = encoding.GetString(buffer, 56, 29);
                        Console.WriteLine("OEM-ID: " + oemid);
                        Console.WriteLine("Product-Key: " + dmkey);
                    }
                    else
                    {
                        Console.WriteLine("MSDM Table Not Found!");
                    }
                    Console.ReadKey();
    EDIT:
    Never wanted an 8 PC.. but id like one right now!!! cant test nowt!!! :laie:
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. Josh Cell

    Josh Cell MDL Developer

    Jan 8, 2011
    3,519
    7,103
    120
    #5 Josh Cell, Sep 17, 2013
    Last edited by a moderator: Apr 20, 2017

    Working on my Dell with W8 Core PKEY.....
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. user_hidden

    user_hidden MDL Expert

    Dec 18, 2007
    1,026
    977
    60
    @Alphawaves

    Vb version works on my win8x64 :)
     
  7. Alphawaves

    Alphawaves Super Moderator/Developer
    Staff Member

    Aug 11, 2008
    5,885
    20,229
    180
    Thanks for testing ;)
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  8. Alphawaves

    Alphawaves Super Moderator/Developer
    Staff Member

    Aug 11, 2008
    5,885
    20,229
    180
    #8 Alphawaves, Sep 18, 2013
    Last edited by a moderator: Apr 20, 2017
    Can someone check this new one
    C#:
    Code:
    private static bool checkMSDM(out byte[] buffer)
            {
                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);
                if (Encoding.ASCII.GetString(buffer).Contains("MSDM"))
                {
                    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);
                    return true;
                }
                return false;
            }
    Usage:
    Code:
    byte[] buffer = null;
                    if (checkMSDM(out buffer))
                    {               
                        Encoding encoding = Encoding.GetEncoding(0x4e4);
                        string oemid = encoding.GetString(buffer, 10, 6);
                        string dmkey = encoding.GetString(buffer, 56, 29);
                        Console.WriteLine("OEM-ID: " + oemid);
                        Console.WriteLine("Product-Key: " + dmkey);
                    }
                    else
                    {
                        Console.WriteLine("MSDM Table Not Found!");
                    }
                    Console.ReadKey();

    VB.NET

    Code:
     Private Shared Function checkMSDM(ByRef buffer As Byte()) As Boolean
            Dim firmwareTableProviderSignature As UInteger = &H41435049 'ACPI in Hexadecimal
            Dim bufferSize As UInteger = EnumSystemFirmwareTables(firmwareTableProviderSignature, IntPtr.Zero, 0)
            Dim pFirmwareTableBuffer As IntPtr = Marshal.AllocHGlobal(CInt(bufferSize))
            buffer = New Byte(bufferSize - 1) {}
            EnumSystemFirmwareTables(firmwareTableProviderSignature, pFirmwareTableBuffer, bufferSize)
            Marshal.Copy(pFirmwareTableBuffer, buffer, 0, buffer.Length)
            Marshal.FreeHGlobal(pFirmwareTableBuffer)
            If Encoding.ASCII.GetString(buffer).Contains("MSDM") Then
                Dim firmwareTableID As UInteger = &H4D44534D ' Reversed 'MSDM' in Hexadecimal
                bufferSize = GetSystemFirmwareTable(firmwareTableProviderSignature, firmwareTableID, IntPtr.Zero, 0)
                buffer = New Byte(bufferSize - 1) {}
                pFirmwareTableBuffer = Marshal.AllocHGlobal(CInt(bufferSize))
                GetSystemFirmwareTable(firmwareTableProviderSignature, firmwareTableID, pFirmwareTableBuffer, bufferSize)
                Marshal.Copy(pFirmwareTableBuffer, buffer, 0, buffer.Length)
                Marshal.FreeHGlobal(pFirmwareTableBuffer)
                Return True
            End If
            Return False
        End Function
    Usage:
    Code:
    Dim buffer As Byte()
            If checkMSDM(buffer) Then
                Dim encoding As Encoding = encoding.GetEncoding(&H4E4)
                Dim oemid = encoding.GetString(buffer, 10, 6)
                Dim dmkey = encoding.GetString(buffer, 56, 29)
                Console.WriteLine("OEM-ID: " & oemid)
                Console.WriteLine("Product Key: " & dmkey)
            Else
                Console.WriteLine("MSDM Table Not Found!")
            End If
            Console.ReadKey()

    Just had PM from MD with new method.. Just hope the conversion is ok and im retrieving it ok :)
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  9. user_hidden

    user_hidden MDL Expert

    Dec 18, 2007
    1,026
    977
    60
    new Vb code works ..... :)
     
  10. Tito

    Tito Super Mod / Adviser
    Staff Member

    Nov 30, 2009
    17,499
    15,288
    340
    Do you mean MasterDisaster?? Miss him a lot... :rolleyes:
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  11. Alphawaves

    Alphawaves Super Moderator/Developer
    Staff Member

    Aug 11, 2008
    5,885
    20,229
    180
    #11 Alphawaves, Sep 18, 2013
    Last edited: Sep 18, 2013
    Yes.. The Master himself..:worthy:
    Just hope he approves of my output.. :)
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  12. Alphawaves

    Alphawaves Super Moderator/Developer
    Staff Member

    Aug 11, 2008
    5,885
    20,229
    180
    #12 Alphawaves, Sep 18, 2013
    Last edited by a moderator: Apr 20, 2017
    Updated output, not tested as i dont have an MSDM Table, but would like any feedback on its output . Its for latest code: http://forums.mydigitallife.net/thr...OS-ACPI-tables?p=808817&viewfull=1#post808817

    C#
    Code:
     byte[] buffer;
                if (checkMSDM(out buffer))
                {
                    Encoding encoding = Encoding.GetEncoding(0x4e4);
                    string Signature = encoding.GetString(buffer, 0, 4);
                    string Length = encoding.GetString(buffer, 4, 4);
                    string Revision = encoding.GetString(buffer, 8, 1);
                    string Checksum = encoding.GetString(buffer, 9, 1);
                    string OEMID = encoding.GetString(buffer, 10, 6);
                    string OEMTbleID = encoding.GetString(buffer, 16, 8);
                    string OEMRev = encoding.GetString(buffer, 24, 4);
                    string CreatorID = encoding.GetString(buffer, 28, 4);
                    string CreatorRev = encoding.GetString(buffer, 32, 4);
                    string PKey = encoding.GetString(buffer, 56, 29);
                    string result = "Signature         : " + Signature + "\n" +
                       // "Length            : " + Length + "\n" +
                       // "Revision          : " + Revision + "\n" +
                       // "Checksum          : " + Checksum + "\n" +
                        "OEMID             : " + OEMID + "\n" +
                        "OEM Table ID      : " + OEMTbleID + "\n" +
                       // "OEM Revision      : " + OEMRev + "\n" +
                        "Creator ID        : " + CreatorID + "\n" +
                       // "Creator Revision  : " + CreatorRev + "\n" +
                        "Key               : " + PKey;
                    Console.WriteLine(result);            }
                else
                {
                    Console.WriteLine("MSDM Table Not Found!");
                }
                Console.ReadKey();
    VB.NET
    Code:
    Dim buffer As Byte()
            If checkMSDM(buffer) Then
                Dim encoding As Encoding = encoding.GetEncoding(&H4E4)
                Dim Signature As String = encoding.GetString(buffer, 0, 4)
                Dim Length As String = encoding.GetString(buffer, 4, 4)
                Dim Revision As String = encoding.GetString(buffer, 8, 1)
                Dim Checksum As String = encoding.GetString(buffer, 9, 1)
                Dim OEMID As String = encoding.GetString(buffer, 10, 6)
                Dim OEMTbleID As String = encoding.GetString(buffer, 16, 8)
                Dim OEMRev As String = encoding.GetString(buffer, 24, 4)
                Dim CreatorID As String = encoding.GetString(buffer, 28, 4)
                Dim CreatorRev As String = encoding.GetString(buffer, 32, 4)
                Dim PKey As String = encoding.GetString(buffer, 56, 29)
                Dim result As String = "Signature         : " & Signature & vbLf &
                   ' "Length            : " & Length & vbLf &
                   ' "Revision          : " & Revision & vbLf &
                   ' "Checksum          : " & Checksum & vbLf &
                    "OEMID             : " & OEMID & vbLf &
                    "OEM Table ID      : " & OEMTbleID & vbLf &
                   ' "OEM Revision      : " & OEMRev & vbLf &
                    "Creator ID        : " & CreatorID & vbLf &
                   ' "Creator Revision  : " & CreatorRev & vbLf &
                    "Key               : " & PKey
                Console.WriteLine(result)  
          Else
                Console.WriteLine("MSDM Table Not Found!")
            End If
            Console.ReadKey()
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  13. CODYQX4

    CODYQX4 MDL Developer

    Sep 4, 2009
    4,804
    45,146
    150
    #13 CODYQX4, Sep 18, 2013
    Last edited by a moderator: Sep 19, 2013
    Hm, I might add this as part of my License Backup and Restore code.

    So that, in the case of running into an OEM:DM key, I can avoid a prompt for it.

    I assume there can only be one OEM:DM key per PC, correct (I heard people having multiple SLIC before)?
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  14. Alphawaves

    Alphawaves Super Moderator/Developer
    Staff Member

    Aug 11, 2008
    5,885
    20,229
    180
    One key per PC..:D
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  15. Alphawaves

    Alphawaves Super Moderator/Developer
    Staff Member

    Aug 11, 2008
    5,885
    20,229
    180
    #15 Alphawaves, Sep 19, 2013
    Last edited by a moderator: Apr 20, 2017
    C# - VB.NET

    New output, fixed by MasterDisaster :)

    C#
    Code:
    private static bool checkMSDM(out byte[] buffer)
            {
                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);
                if (Encoding.ASCII.GetString(buffer).Contains("MSDM"))
                {
                    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);
                    return true;
                }
                return false;
            }
    Usage:
    Code:
    byte[] buffer;
                if (checkMSDM(out buffer))
                {
                    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();
    VB.NET
    Code:
    Private Shared Function checkMSDM(ByRef buffer As Byte()) As Boolean
            Dim firmwareTableProviderSignature As UInteger = &H41435049 'ACPI in Hexadecimal
            Dim bufferSize As UInteger = EnumSystemFirmwareTables(firmwareTableProviderSignature, IntPtr.Zero, 0)
            Dim pFirmwareTableBuffer As IntPtr = Marshal.AllocHGlobal(CInt(bufferSize))
            buffer = New Byte(bufferSize - 1) {}
            EnumSystemFirmwareTables(firmwareTableProviderSignature, pFirmwareTableBuffer, bufferSize)
            Marshal.Copy(pFirmwareTableBuffer, buffer, 0, buffer.Length)
            Marshal.FreeHGlobal(pFirmwareTableBuffer)
            If Encoding.ASCII.GetString(buffer).Contains("MSDM") Then
                Dim firmwareTableID As UInteger = &H4D44534D ' Reversed 'MSDM' in Hexadecimal
                bufferSize = GetSystemFirmwareTable(firmwareTableProviderSignature, firmwareTableID, IntPtr.Zero, 0)
                buffer = New Byte(bufferSize - 1) {}
                pFirmwareTableBuffer = Marshal.AllocHGlobal(CInt(bufferSize))
                GetSystemFirmwareTable(firmwareTableProviderSignature, firmwareTableID, pFirmwareTableBuffer, bufferSize)
                Marshal.Copy(pFirmwareTableBuffer, buffer, 0, buffer.Length)
                Marshal.FreeHGlobal(pFirmwareTableBuffer)
                Return True
            End If
            Return False
        End Function
    Usage:
    Code:
    Dim buffer As Byte()
            If checkMSDM(buffer) Then
                Dim encoding As Encoding = encoding.GetEncoding(&H4E4)
                Dim signature As String = encoding.GetString(buffer, &H0, &H4)
                Dim length As Integer = BitConverter.ToInt32(buffer, &H4)
                Dim revision As Byte = CByte(buffer.GetValue(&H8))
                Dim checksum As Byte = DirectCast(buffer.GetValue(&H9), [Byte])
                Dim oemid As String = encoding.GetString(buffer, &HA, &H6)
                Dim oemtableid As String = encoding.GetString(buffer, &H10, &H8)
                Dim oemrev As Integer = BitConverter.ToInt32(buffer, &H18)
                Dim creatorid As String = encoding.GetString(buffer, &H1C, &H4)
                Dim creatorrev As Integer = BitConverter.ToInt32(buffer, &H20)
                Dim sls_version As Integer = BitConverter.ToInt32(buffer, &H24)
                Dim sls_reserved As Integer = BitConverter.ToInt32(buffer, &H28)
                Dim sls_datatype As Integer = BitConverter.ToInt32(buffer, &H2C)
                Dim sls_datareserved As Integer = BitConverter.ToInt32(buffer, &H30)
                Dim sls_datalength As Integer = BitConverter.ToInt32(buffer, &H34)
                Dim sls_data As String = encoding.GetString(buffer, &H38, sls_datalength)
                Dim result As String = "Signature         : " & signature &
                    vbLf & "Length            : " & length &
                    vbLf & "Revison           : " & revision.ToString("X") &
                    vbLf & "Checksum          : " & checksum.ToString("X") &
                    vbLf & "OEM ID            : " & oemid &
                    vbLf & "OEM Table ID      : " & oemtableid &
                    vbLf & "OEM Revision      : " & oemrev &
                    vbLf & "Creator ID        : " & creatorid &
                    vbLf & "Creator Revision  : " & creatorrev &
                    vbLf & "SLS Version       : " & sls_version &
                    vbLf & "SLS Reserved      : " & sls_reserved &
                    vbLf & "SLS Datatype      : " & sls_datatype &
                    vbLf & "SLS Data Reserved : " & sls_datareserved &
                    vbLf & "SLS Data Length   : " & sls_datalength &
                    vbLf & "Key               : " & sls_data
                Console.WriteLine(result)
            Else
                Console.WriteLine("MSDM Table Not Found!")
            End If
            Console.ReadKey()
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  16. Josh Cell

    Josh Cell MDL Developer

    Jan 8, 2011
    3,519
    7,103
    120
    Nice work. I will test it ASAP... :D:D:D
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  17. Josh Cell

    Josh Cell MDL Developer

    Jan 8, 2011
    3,519
    7,103
    120
    Working as should. Thank you.

    Can I use something like that around the next A.T.M. version? :D:eek::worthy::eek::D
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  18. Alphawaves

    Alphawaves Super Moderator/Developer
    Staff Member

    Aug 11, 2008
    5,885
    20,229
    180
    #18 Alphawaves, Sep 19, 2013
    Last edited: Sep 19, 2013
    Sure Josh..:hug2::worthy:

    EDIT:
    Cleaned up thread, sorry if i removed anyones post.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  19. CODYQX4

    CODYQX4 MDL Developer

    Sep 4, 2009
    4,804
    45,146
    150
    #19 CODYQX4, Sep 21, 2013
    Last edited by a moderator: Apr 20, 2017
    I don't have VS setup to test, but does this look valid?

    Code:
    /// <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()
    {
    List<string> detectedKeys = new List<string>();
    
    // Read System Firmware
    uint firmwareTableProviderSignature = 0x41435049; // 'ACPI' in Hexadecimal
    uint bufferSize = NativeMethods.EnumSystemFirmwareTables(firmwareTableProviderSignature, IntPtr.Zero, 0);
    IntPtr pFirmwareTableBuffer = Marshal.AllocHGlobal((int)bufferSize);
    buffer = new byte[bufferSize];
    NativeMethods.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 = NativeMethods.GetSystemFirmwareTable(firmwareTableProviderSignature, firmwareTableID, IntPtr.Zero, 0);
    buffer = new byte[bufferSize];
    pFirmwareTableBuffer = Marshal.AllocHGlobal((int)bufferSize);
    NativeMethods.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;
    }
    
    I made it a List despite there never being more than one, because all other functions I wrote where this use return Lists. The NativeMethods just contain the DLL Imports.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  20. Alphawaves

    Alphawaves Super Moderator/Developer
    Staff Member

    Aug 11, 2008
    5,885
    20,229
    180
    It will only ever return one key, so why not just use the origianal code here ?
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...