첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestProject.zip
0.00MB

▶ Program.cs

using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;

namespace TestProject
{
    /// <summary>
    /// 프로그램
    /// </summary>
    class Program
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Import
        ////////////////////////////////////////////////////////////////////////////////////////// Static
        //////////////////////////////////////////////////////////////////////////////// Private

        #region 시스템 펌웨어 테이블 열거하기 - EnumSystemFirmwareTables(firmwareTableProviderSignature, firmwareTableBufferHandle, bufferSize)

        /// <summary>
        /// 시스템 펌웨어 테이블 열거하기
        /// </summary>
        /// <param name="firmwareTableProviderSignature">펌웨어 테이블 공급자 서명</param>
        /// <param name="firmwareTableBufferHandle">펌웨어 테이블 버퍼 핸들</param>
        /// <param name="bufferSize">버퍼 크기</param>
        /// <returns>처리 결과</returns>
        [DllImport("kernel32")]
        private static extern uint EnumSystemFirmwareTables
        (
            uint   firmwareTableProviderSignature,
            IntPtr firmwareTableBufferHandle,
            uint   bufferSize
        );

        #endregion
        #region 시스템 펌웨어 테이블 구하기 - GetSystemFirmwareTable(firmwareTableProviderSignature, firmwareTableID, firmwareTableBufferHandle, bufferSize)

        /// <summary>
        /// 시스템 펌웨어 테이블 구하기
        /// </summary>
        /// <param name="firmwareTableProviderSignature">펌웨어 테이블 공급자 서명</param>
        /// <param name="firmwareTableID">펌웨어 테이블 ID</param>
        /// <param name="firmwareTableBufferHandle">펌웨어 테이블 버퍼 핸들</param>
        /// <param name="bufferSize">버퍼 크기</param>
        /// <returns>처리 결과</returns>
        [DllImport("kernel32")]
        private static extern uint GetSystemFirmwareTable
        (
            uint   firmwareTableProviderSignature,
            uint   firmwareTableID,
            IntPtr firmwareTableBufferHandle,
            uint   bufferSize
        );

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Static
        //////////////////////////////////////////////////////////////////////////////// Private

        #region 프로그램 시작하기 - Main()

        /// <summary>
        /// 프로그램 시작하기
        /// </summary>
        private static void Main()
        {
            byte[] bufferByteArray = null;

            if(CheckMSDM(ref bufferByteArray))
            {
                Encoding encoding = Encoding.GetEncoding(0x4e4);

                string oemID      = encoding.GetString(bufferByteArray, 10, 6 );
                string productKey = encoding.GetString(bufferByteArray, 56, 29);

                Console.WriteLine($"OEM-ID      : {oemID}"     );
                Console.WriteLine($"Product-Key : {productKey}");
            }
            else
            {
                Console.WriteLine("MSDM Table Not Found!");
            }
        }

        #endregion
        #region MSDM 체크하기 - CheckMSDM(bufferByteArray)

        /// <summary>
        /// MSDM 체크하기
        /// </summary>
        /// <param name="bufferByteArray">버퍼 바이트 배열</param>
        /// <returns>처리 결과</returns>
        private static bool CheckMSDM(ref byte[] bufferByteArray)
        {
            uint firmwareTableProvider = 'A' << 24 | 'C' << 16 | 'P' << 8 | 'I';

            uint bufferActualSize = EnumSystemFirmwareTables(firmwareTableProvider, IntPtr.Zero, 0);

            IntPtr firmwareTableBufferHandle = Marshal.AllocHGlobal((int)bufferActualSize);

            bufferByteArray = new byte[bufferActualSize];

            EnumSystemFirmwareTables(firmwareTableProvider, firmwareTableBufferHandle, bufferActualSize);

            Marshal.Copy(firmwareTableBufferHandle, bufferByteArray, 0, bufferByteArray.Length);

            Marshal.FreeHGlobal(firmwareTableBufferHandle);

            string data = Encoding.GetEncoding(0x4e4).GetString(bufferByteArray);

            List<string> list = new List<string>();

            for(int i = 0; i <= data.Length - 1; i += 4)
            {
                list.Add(data.Substring(i, 4));
            }

            if(list.Contains("MSDM"))
            {
                uint firmwareTableID = BitConverter.ToUInt32(bufferByteArray, list.IndexOf("MSDM") * 4);

                bufferActualSize = GetSystemFirmwareTable(firmwareTableProvider, firmwareTableID, IntPtr.Zero, 0);

                bufferByteArray = new byte[bufferActualSize];

                firmwareTableBufferHandle = Marshal.AllocHGlobal((int)bufferActualSize);

                GetSystemFirmwareTable(firmwareTableProvider, firmwareTableID, firmwareTableBufferHandle, bufferActualSize);

                Marshal.Copy(firmwareTableBufferHandle, bufferByteArray, 0, bufferByteArray.Length);

                Marshal.FreeHGlobal(firmwareTableBufferHandle);                

                return true;
            }

            return false;
        } 

        #endregion
    }
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요