获取各类硬件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

相关文章

IIS 7.0 及更高版本中的 FTP 状态代码

《IIS7.0及更高版本中的FTP状态代码》本文介绍IIS7.0中的FTP状态代码,方便大家在使用iis中发现ftp的问题... 简介尝试使用 FTP 访问运行 Internet Information Services (IIS) 7.0 或更高版本的服务器上的内容时,IIS 将返回指示响应状态的数字代

MySQL 添加索引5种方式示例详解(实用sql代码)

《MySQL添加索引5种方式示例详解(实用sql代码)》在MySQL数据库中添加索引可以帮助提高查询性能,尤其是在数据量大的表中,下面给大家分享MySQL添加索引5种方式示例详解(实用sql代码),... 在mysql数据库中添加索引可以帮助提高查询性能,尤其是在数据量大的表中。索引可以在创建表时定义,也可

使用C#删除Excel表格中的重复行数据的代码详解

《使用C#删除Excel表格中的重复行数据的代码详解》重复行是指在Excel表格中完全相同的多行数据,删除这些重复行至关重要,因为它们不仅会干扰数据分析,还可能导致错误的决策和结论,所以本文给大家介绍... 目录简介使用工具C# 删除Excel工作表中的重复行语法工作原理实现代码C# 删除指定Excel单元

Python实现一键PDF转Word(附完整代码及详细步骤)

《Python实现一键PDF转Word(附完整代码及详细步骤)》pdf2docx是一个基于Python的第三方库,专门用于将PDF文件转换为可编辑的Word文档,下面我们就来看看如何通过pdf2doc... 目录引言:为什么需要PDF转Word一、pdf2docx介绍1. pdf2docx 是什么2. by

使用Python获取JS加载的数据的多种实现方法

《使用Python获取JS加载的数据的多种实现方法》在当今的互联网时代,网页数据的动态加载已经成为一种常见的技术手段,许多现代网站通过JavaScript(JS)动态加载内容,这使得传统的静态网页爬取... 目录引言一、动态 网页与js加载数据的原理二、python爬取JS加载数据的方法(一)分析网络请求1

Spring Security介绍及配置实现代码

《SpringSecurity介绍及配置实现代码》SpringSecurity是一个功能强大的Java安全框架,它提供了全面的安全认证(Authentication)和授权(Authorizatio... 目录简介Spring Security配置配置实现代码简介Spring Security是一个功能强

MySQL查看表的最后一个ID的常见方法

《MySQL查看表的最后一个ID的常见方法》在使用MySQL数据库时,我们经常会遇到需要查看表中最后一个id值的场景,无论是为了调试、数据分析还是其他用途,了解如何快速获取最后一个id都是非常实用的技... 目录背景介绍方法一:使用MAX()函数示例代码解释适用场景方法二:按id降序排序并取第一条示例代码解

通过cmd获取网卡速率的代码

《通过cmd获取网卡速率的代码》今天从群里看到通过bat获取网卡速率两段代码,感觉还不错,学习bat的朋友可以参考一下... 1、本机有线网卡支持的最高速度:%v%@echo off & setlocal enabledelayedexpansionecho 代码开始echo 65001编码获取: >

Java集成Onlyoffice的示例代码及场景分析

《Java集成Onlyoffice的示例代码及场景分析》:本文主要介绍Java集成Onlyoffice的示例代码及场景分析,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要... 需求场景:实现文档的在线编辑,团队协作总结:两个接口 + 前端页面 + 配置项接口1:一个接口,将o

SpringBoot实现Kafka动态反序列化的完整代码

《SpringBoot实现Kafka动态反序列化的完整代码》在分布式系统中,Kafka作为高吞吐量的消息队列,常常需要处理来自不同主题(Topic)的异构数据,不同的业务场景可能要求对同一消费者组内的... 目录引言一、问题背景1.1 动态反序列化的需求1.2 常见问题二、动态反序列化的核心方案2.1 ht