日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

获取CPUID序列号的两种办法

發布時間:2023/12/10 编程问答 57 豆豆
生活随笔 收集整理的這篇文章主要介紹了 获取CPUID序列号的两种办法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

? ? Win32k 平臺上,獲取CPUID的辦法主要有兩種,一種是利用 WMI 另一種是利用 x86 匯編的 cpuid 指令,而最快的辦法就是通過匯編了,而且 WMI 與匯編之間效率上的差距的確有點讓人難以忍受,WMI 獲取 CPUID 的效率幾乎接近了一秒鐘,而利用 cpuid 指令的辦法,大概是幾個 us 時間的問題,這種令人咋舌的巨大差異,讓人有些難以忍受。

using System; using System.Management; using System.Runtime.InteropServices;static class Program {[DllImport("kernel32.dll", SetLastError = false)]private static extern bool VirtualProtect(IntPtr lpAddress, uint dwSize, uint flNewProtect, out uint lpflOldProtect);[UnmanagedFunctionPointer(CallingConvention.Cdecl)]public delegate int __cpuid(ref int s1, ref int s2);static void Main(){/*pushadmov eax, 01hxor ecx, ecxxor edx, edxcpuidmov ecx, dword ptr[ebp + 8]mov dword ptr[ecx], edxmov ecx, dword ptr[ebp + 0Ch]mov dword ptr[ecx], eaxpopad*/byte[] shellcode = { 96, 184, 1, 0, 0, 0, 51, 201, 51, 210, 15, 162, 139, 77, 8, 137, 17, 139, 77, 12, 137, 1, 97, 195 };IntPtr address = GCHandle.Alloc(shellcode, GCHandleType.Pinned).AddrOfPinnedObject();VirtualProtect(address, (uint)shellcode.Length, 0x40, out uint lpflOldProtect);__cpuid cpuid = (__cpuid)Marshal.GetDelegateForFunctionPointer(address, typeof(__cpuid));int s1 = 0;int s2 = 0;for (int i = 0; i < 100000; i++){cpuid(ref s1, ref s2);}Console.Write("asm: {0}", s1.ToString("X2") + s2.ToString("X2"));using (ManagementClass mc = new ManagementClass("Win32_Processor")){ManagementObjectCollection moc = mc.GetInstances();foreach (ManagementObject mo in moc){Console.WriteLine(", wmi: {0}", mo.Properties["ProcessorId"].Value.ToString());}}Console.ReadKey(false);} }

總結

以上是生活随笔為你收集整理的获取CPUID序列号的两种办法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。