获取各类硬件ID汇编代码

2024-06-14 15:18

本文主要是介绍获取各类硬件ID汇编代码,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

{-----------------------------------------------------------------------------
作者:sushengmiyan 2013.01.26
备注:
功能:硬件信息获取单元
-----------------------------------------------------------------------------}unit ApplicationHardWareInfo;interface
usesWindows, SysUtils, Classes, Registry, Nb30, WinSock;typeTCPUID = array[1..4] of Longint;function GetCPUID: TCPUID; assembler; register;
type//CPUID信息类TCPUIDInfo = classprivateFCPUID: TCPUID;FCPUIDStr: string;procedure SetCPU(AHandle: THandle; CpuNo: Integer);function CPUIDTostr(ACPUID: TCPUID): string;function GetComputerBasicFrequency: string;function GetCPUType: string;publicfunction GetCPUIDstr: string;property CPUFrequency: string read GetComputerBasicFrequency;property ProcessorType: string read GetCPUType;constructor Create;end;//mac地址信息类TMacAdressInfo = classprivateFMacAdress: string;function GetMacPhysicalAddress(Alana: Integer = 0): string;function GetMacAddress: string;publicproperty MacAdrress: string read GetMacAddress;constructor Create;end;//用户信息类TPCUserInfo = classprivatefunction GetUserName: string;function GetHostIP: string;function GetWindowsVertion: string;publicproperty UserName: string read GetUserName;property HostIP: string read GetHostIP;property WindowsVertion: string read GetWindowsVertion;constructor Create;end;implementation{ TCPUIDInfo }
{----------------------------------------------------------------------------\-
作者:sushengmiyan 2013.01.26
参数:None
返回:TCPUID
功能:汇编方式获取CPUID
\-----------------------------------------------------------------------------}function GetCPUID: TCPUID;
asmPUSH    EBX         {Save affected register}PUSH    EDIMOV     EDI,EAX     {@Resukt}MOV     EAX,1DW      $A20F       {CPUID Command}STOSD                {CPUID[1]}MOV     EAX,EBXSTOSD               {CPUID[2]}MOV     EAX,ECXSTOSD               {CPUID[3]}MOV     EAX,EDXSTOSD               {CPUID[4]}POP     EDI         {Restore registers}POP     EBX
end;{----------------------------------------------------------------------------\-
作者:sushengmiyan 2013.01.26
参数:ACPUID: TCPUID
返回:string
功能:将十六进制的CPUID转换为字符串
\-----------------------------------------------------------------------------}function TCPUIDInfo.CPUIDTostr(ACPUID: TCPUID): string;
beginResult := '';Result := IntToHex(ACPUID[1] , 8) + IntToHex(ACPUID[2] , 8) + IntToHex(ACPUID[3], 8) + IntToHex(ACPUID[4] , 8);
end;{----------------------------------------------------------------------------\-
作者:sushengmiyan 2013.01.26
参数:None
返回:string
功能:处理器类型
\-----------------------------------------------------------------------------}function TCPUIDInfo.GetCPUType: string;
varsysteminfo: SYSTEM_INFO;
begin//获得CPU型号GetSystemInfo(systeminfo);Result := IntToStr(systeminfo.dwProcessorType)
end;{----------------------------------------------------------------------------\-
作者:sushengmiyan 2013.01.26
参数:None
返回:string
功能:CPU频率
\-----------------------------------------------------------------------------}function TCPUIDInfo.GetComputerBasicFrequency: string;
constDelayTime = 500;
varTimerHi, TimerLo: DWORD;PriorityClass, Priority: Integer;dSpeed: Double;
beginPriorityClass := GetPriorityClass(GetCurrentProcess);Priority := GetThreadPriority(GetCurrentThread);SetPriorityClass(GetCurrentProcess, REALTIME_PRIORITY_CLASS);SetThreadPriority(GetCurrentThread, THREAD_PRIORITY_TIME_CRITICAL);Sleep(10);asmdw 310Fh // RDTSC指令mov TimerLo, eaxmov TimerHi, edxend;Sleep(DelayTime);asmdw 310Fh // rdtscsub eax, TimerLosbb edx, TimerHimov TimerLo, eaxmov TimerHi, edxend;SetThreadPriority(GetCurrentThread, Priority);SetPriorityClass(GetCurrentProcess, PriorityClass);dSpeed := TimerLo / (1000.0 * DelayTime);Result := FormatFloat('0.00' , dSpeed / 1024) + ' GHz';
end;{----------------------------------------------------------------------------\-
作者:sushengmiyan 2013.01.26
参数:AOwner: TComponent
返回:None
功能:初始化
\-----------------------------------------------------------------------------}constructor TCPUIDInfo.Create;
beginFCPUID := GetCPUID;FCPUIDStr := CPUIDTostr(FCPUID);
end;{----------------------------------------------------------------------------\-
作者:sushengmiyan 2013.01.26
参数:None
返回:string    CPUID字符串
功能:对外函数,调用这个方法就能得到CPUID
\-----------------------------------------------------------------------------}function TCPUIDInfo.GetCPUIDstr: string;
beginSetCPU(GetCurrentProcess , 1);Result := CPUIDTostr(GetCPUID);
end;{----------------------------------------------------------------------------\-
作者:sushengmiyan 2013.01.26
参数:AHandle: THandle; CpuNo: Integer
返回:None
功能:设置使用哪个cpu默认是第一个(推荐)
\-----------------------------------------------------------------------------}procedure TCPUIDInfo.SetCPU(AHandle: THandle; CpuNo: Integer);
varProcessAffinity: Cardinal;_SystemAffinity: Cardinal;
begin//通过设置进程或线程的亲缘性(affinity),使进程或线程在指定的CPU(核)上运行GetProcessAffinityMask(AHandle , ProcessAffinity, _SystemAffinity) ;ProcessAffinity := CpuNo;SetProcessAffinityMask(AHandle , ProcessAffinity);
end;{ TMacAdressInfo }
{----------------------------------------------------------------------------\-
作者:sushengmiyan 2013.01.26
参数:None
返回:None
功能:初始化
\-----------------------------------------------------------------------------}constructor TMacAdressInfo.Create;
beginFMacAdress := GetMacPhysicalAddress;
end;{----------------------------------------------------------------------------\-
作者:sushengmiyan 2013.01.26
参数:None
返回:string
功能:返回Mac地址
\-----------------------------------------------------------------------------}function TMacAdressInfo.GetMacAddress: string;
beginResult := FMacAdress;
end;{----------------------------------------------------------------------------\-
作者:sushengmiyan 2013.01.26
参数:Alana: Integer = 0
返回:string
功能:通过LANA号获取Mac物理地址 (内存方式获取),整体步骤如下:一、枚举系统上可用的所有LANA编号二、重置计划使用的每个LANA编号三、适配器命令获取网卡地址
\-----------------------------------------------------------------------------}function TMacAdressInfo.GetMacPhysicalAddress(Alana: Integer = 0): string;
varNCB: TNCB;//Netbios控制块AdapterStatus: TAdapterStatus;//取网卡状态LanaEnum: TLanaEnum; //LANA枚举值I: Integer;
beginResult := '';Try{ http://blog.csdn.net/sushengmiyan/article/details/8543811一、枚举LANA值①.申请分配一个TNCB结构           NCB: TNCB;②.将TNCB结构变量初始化成O        ZeroMemory(@NCB , SizeOf(NCB));③.置命令为NCBENUM                NCB.ncb_Command := chr(NCBENUM);④.为ncb_buffer分配LANA_ENUM      NCB.ncb_buffer := @LANAENUM;⑤.为NCB_length制定长度           NCB.NCB_length := Sizeof(LANAENUM);⑥.调用Netbios函数获取Netbios     CRC := NetBios(@NCB);⑦.返回值NRC_GOODRET表示成功      NCB.ncb_retcode = Chr(NRC_GOODRET)}ZeroMemory(@NCB , SizeOf(NCB));NCB.ncb_Command := Chr(NCBENUM);NCB.ncb_buffer := @LANAENUM;NCB.NCB_length := Sizeof(LANAENUM);NetBios(@NCB);if not (NCB.ncb_retcode = Chr(NRC_GOODRET)) then Exit;{ http://blog.csdn.net/sushengmiyan/article/details/8543811二、重置计划使用的每个LANA编号①.申请分配一个TNCB结构           NCB: TNCB;②.将TNCB结构变量初始化成O        ZeroMemory(@NCB , SizeOf(NCB));③.置命令为NCBRESET               NCB.ncb_Command := chr(NCBRESET);④.给命令设置LANA编号             NCB.ncb_lana_num := LanaEnum.lana[Alana];⑤.调用Netbios函数获取Netbios     CRC := NetBios(@NCB);⑥.返回值NRC_GOODRET表示成功      NCB.ncb_retcode = Chr(NRC_GOODRET)}ZeroMemory(@NCB , SizeOf(NCB));NCb.ncb_Command := Chr(NCBRESET);NCB.ncb_lana_num := LanaEnum.lana[Alana];Netbios(@NCB);if not (NCB.ncb_retcode = Chr(NRC_GOODRET)) then Exit;{ http://blog.csdn.net/sushengmiyan/article/details/8543811三、使用TAdapterStatus结构获取网卡地址①.申请分配一个TNCB结构           NCB: TNCB;②.将TNCB结构变量初始化成O        ZeroMemory(@NCB , SizeOf(NCB));③.置命令为NCBASTAT               NCB.ncb_Command := chr(NCBASTAT);④.为ncb_buffer分配LANA_ENUM      NCB.ncb_buffer := @LANAENUM;⑤.设置ncb_callname               NCB.ncb_callname := '* ' + #0;⑥.为ncb_buffer分配AdapterStatus  NCB.ncb_buffer := @AdapterStatus;⑦.为NCB_length制定长度           NCB.NCB_length := Sizeof(AdapterStatus);⑧.调用Netbios函数获取Netbios     CRC := NetBios(@NCB);}ZeroMemory(@NCB , SizeOf(NCB));NCb.ncb_Command := chr(NCBASTAT);NCB.ncb_lana_num := LANAENUM.lana[Alana];NCB.ncb_callname[0] := '*';//不明白为何如此设置,*代表啥子?//有懂的可以邮件分享 429119108@qq.com   O(∩_∩)O谢谢NCB.ncb_buffer := @AdapterStatus;NCB.ncb_length := SizeOf(AdapterStatus);NetBios(@NCB);//获取形如AA-BB-CC-DD-EE-FF形式的mac物理地址字符串Result := '';for I := 0 to 5 doif SameStr(Result , '') thenResult := Result + IntToHex(Integer(AdapterStatus.adapter_address[I]) , 2)elseResult := Result + '-' + IntToHex(Integer(AdapterStatus.adapter_address[I]) , 2);FinallyEnd;
end;{ TPCUserInfo }{----------------------------------------------------------------------------\-
作者:sushengmiyan 2013.01.26
参数:None
返回:None
功能:创建
\-----------------------------------------------------------------------------}constructor TPCUserInfo.Create;
beginend;{----------------------------------------------------------------------------\-
作者:sushengmiyan 2013.01.26
参数:None
返回:string
功能:得到主机IP
\-----------------------------------------------------------------------------}function TPCUserInfo.GetHostIP: string;
varsHostName: string;WSAData: TWSAData;HostEnt: PHostEnt;
beginsHostName := UserName;Result := '';WSAStartup(2 , WSAData);HostEnt := GetHostByName(PChar(sHostName));if HostEnt <> nil thenbeginwith HostEnt^ doResult:= Format('%d.%d.%d.%d' , [Byte(h_addr^[0]) , Byte(h_addr^[1]), Byte(h_addr^[2]) , Byte(h_addr^[3])]);end;WSACleanup;
end;{----------------------------------------------------------------------------\-
作者:sushengmiyan 2013.01.26
参数:None
返回:None
功能:获取用户名
\-----------------------------------------------------------------------------}function TPCUserInfo.GetUserName;
varName: PChar;Size: DWORD;
beginGetMem(Name , 255);//申请内存Size := 255;GetComputerName(Name , Size);Result := Name;FreeMem(Name); //记得释放内存
end;{----------------------------------------------------------------------------\-
作者:sushengmiyan 2013.01.26
参数:None
返回:string
功能:返回操作系统类型
\-----------------------------------------------------------------------------}function TPCUserInfo.GetWindowsVertion: string;function GetWindowsVersionString: string;varoSVersion: TOSVersionInfoA;beginResult := '';oSversion.dwOSVersionInfoSize := SizeOf(TOSVersionInfoA);if GetVersionExA(oSVersion) thenwith oSVersion doResult := Trim(Format('%s', [szCSDVersion]));end;
varAWin32Version: Extended;sWin: string;
beginsWin := 'Windows';AWin32Version := StrToFloat(Format('%d.%d', [Win32MajorVersion, Win32MinorVersion]));case Win32Platform ofVER_PLATFORM_WIN32s:Result := sWin + '32';VER_PLATFORM_WIN32_WINDOWS:beginif AWin32Version = 4.0 thenResult := sWin + '95'else if AWin32Version = 4.1 thenResult := sWin + '98'else if AWin32Version = 4.9 thenResult := sWin + 'Me'elseResult := sWin + '9x';end;VER_PLATFORM_WIN32_NT:beginif AWin32Version = 3.51 thenResult := sWin + 'NT 3.51'else if AWin32Version = 4.0 thenResult := sWin + 'NT 4.0'else if AWin32Version = 5.0 thenResult := sWin + '2000'else if AWin32Version = 5.1 thenResult := sWin + 'XP'else if AWin32Version = 5.2 thenResult := sWin + '2003'else if AWin32Version = 6.0 thenResult := sWin + 'Vista'else if AWin32Version = 6.1 thenResult := sWin + '7'elseResult := sWin;endelseResult := sWin;end;Result := Result + '  ' + GetWindowsVersionString;
end;end.




void CMyDlg::OnButton7() //VC 内联汇编获取CPU机器码。。强大
{
char h1[260];
unsigned long s1,s2,s3,s4;
__asm
{
mov eax,00h
xor edx,edx
cpuid
mov s1, edx
mov s2, eax
}
__asm
{
mov eax,01h
xor ecx,ecx
xor edx,edx
cpuid
mov s3, edx
mov s4, ecx
}
sprintf(h1,"%X%X%X%X",s1,s2,s3,s4);
a.MsgBox (h1);//这个MsgBox 函数不是VB的,我封装的,到时候会在VC板块里面放出,我写了一个VC梦类模块,把VC里面的常用操作封装为了一个开源的类,调用起来很方便的,会找到VB的感觉,VC6.0也会变得各种简单起来。。。
}


这篇关于获取各类硬件ID汇编代码的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1060768

相关文章

Django开发时如何避免频繁发送短信验证码(python图文代码)

《Django开发时如何避免频繁发送短信验证码(python图文代码)》Django开发时,为防止频繁发送验证码,后端需用Redis限制请求频率,结合管道技术提升效率,通过生产者消费者模式解耦业务逻辑... 目录避免频繁发送 验证码1. www.chinasem.cn避免频繁发送 验证码逻辑分析2. 避免频繁

精选20个好玩又实用的的Python实战项目(有图文代码)

《精选20个好玩又实用的的Python实战项目(有图文代码)》文章介绍了20个实用Python项目,涵盖游戏开发、工具应用、图像处理、机器学习等,使用Tkinter、PIL、OpenCV、Kivy等库... 目录① 猜字游戏② 闹钟③ 骰子模拟器④ 二维码⑤ 语言检测⑥ 加密和解密⑦ URL缩短⑧ 音乐播放

Python使用Tenacity一行代码实现自动重试详解

《Python使用Tenacity一行代码实现自动重试详解》tenacity是一个专为Python设计的通用重试库,它的核心理念就是用简单、清晰的方式,为任何可能失败的操作添加重试能力,下面我们就来看... 目录一切始于一个简单的 API 调用Tenacity 入门:一行代码实现优雅重试精细控制:让重试按我

Python获取浏览器Cookies的四种方式小结

《Python获取浏览器Cookies的四种方式小结》在进行Web应用程序测试和开发时,获取浏览器Cookies是一项重要任务,本文我们介绍四种用Python获取浏览器Cookies的方式,具有一定的... 目录什么是 Cookie?1.使用Selenium库获取浏览器Cookies2.使用浏览器开发者工具

Java获取当前时间String类型和Date类型方式

《Java获取当前时间String类型和Date类型方式》:本文主要介绍Java获取当前时间String类型和Date类型方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,... 目录Java获取当前时间String和Date类型String类型和Date类型输出结果总结Java获取

C#监听txt文档获取新数据方式

《C#监听txt文档获取新数据方式》文章介绍通过监听txt文件获取最新数据,并实现开机自启动、禁用窗口关闭按钮、阻止Ctrl+C中断及防止程序退出等功能,代码整合于主函数中,供参考学习... 目录前言一、监听txt文档增加数据二、其他功能1. 设置开机自启动2. 禁止控制台窗口关闭按钮3. 阻止Ctrl +

Python实现MQTT通信的示例代码

《Python实现MQTT通信的示例代码》本文主要介绍了Python实现MQTT通信的示例代码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一... 目录1. 安装paho-mqtt库‌2. 搭建MQTT代理服务器(Broker)‌‌3. pytho

MySQL进行数据库审计的详细步骤和示例代码

《MySQL进行数据库审计的详细步骤和示例代码》数据库审计通过触发器、内置功能及第三方工具记录和监控数据库活动,确保安全、完整与合规,Java代码实现自动化日志记录,整合分析系统提升监控效率,本文给大... 目录一、数据库审计的基本概念二、使用触发器进行数据库审计1. 创建审计表2. 创建触发器三、Java

python生成随机唯一id的几种实现方法

《python生成随机唯一id的几种实现方法》在Python中生成随机唯一ID有多种方法,根据不同的需求场景可以选择最适合的方案,文中通过示例代码介绍的非常详细,需要的朋友们下面随着小编来一起学习学习... 目录方法 1:使用 UUID 模块(推荐)方法 2:使用 Secrets 模块(安全敏感场景)方法

一文详解如何使用Java获取PDF页面信息

《一文详解如何使用Java获取PDF页面信息》了解PDF页面属性是我们在处理文档、内容提取、打印设置或页面重组等任务时不可或缺的一环,下面我们就来看看如何使用Java语言获取这些信息吧... 目录引言一、安装和引入PDF处理库引入依赖二、获取 PDF 页数三、获取页面尺寸(宽高)四、获取页面旋转角度五、判断