Article View: borland.public.cppbuilder.nativeapi
Article #7125Re: reading unique CPU number
From: Remy Lebeau (TeamB)
Date: Sun, 13 Mar 2005 20:58
Date: Sun, 13 Mar 2005 20:58
111 lines
3490 bytes
3490 bytes
<Harry> wrote in message news:423438a3@newsgroups.borland.com...
> Is there such thing as unique number on each Intel Pentium CPUs?
Only Intel Pentium 3 (and a few mobile Pentium 2) processors have a unique
serial number on each chip. However, it can be (and usually is) disabled by
the user in the BIOS settings. Intel dropped the feature in Pentium 4
because it was not widely accepted and caused a lot of controversy with
privacy advocates.
> If so how can we read that number within BCB?
(Untested):
#pragma pack(push, 1)
struct TCPUID
{
DWORD Version;
DWORD Other;
DWORD ExtendedFeatures;
DWORD Features;
};
#pragma pack(pop)
#pragma option push -w-
void __fastcall CPU_ID(TCPUID* CpuID)
{
__asm
{
PUSH EBX
PUSH EDI
MOV EDI, EAX
MOV EAX,1
DW 0xA20F
STOSD
MOV EAX, EBX
STOSD
MOV EAX, ECX
STOSD
MOV EAX, EDX
STOSD
POP EDI
POP EBX
}
}
void __fastcall CPU_Serial(unsigned __int64* SerialNumber)
{
__asm
{
PUSH EBX
PUSH EDI
MOV EDI, EAX
MOV EAX, 3
DW 0xA20F
MOV EAX, ECX
STOSD
MOV EAX, EDX
STOSD
POP EDI
POP EBX
}
}
bool IsCPUIDAvailable(void)
{
__asm
{
PUSHFD
POP EAX
MOV EDX, EAX
XOR EAX, 0x00200000
PUSH EAX
POPFD
PUSHFD
POP EAX
XOR EAX, EDX
SHR EAX, 21
}
}
bool GetCPUSerialNumber(unsigned __int64 *SerialNumber)
{
*SerialNumber = 0;
if( IsCPUIDAvailable() )
{
TCPUID CpuID;
memset(&CpuID, 0, sizeof(TCPUID));
CPU_ID(&CpuID);
if( CpuID.Features & 0x00040000 )
{
CPU_Serial(SerialNumber);
return true;
}
}
return false;
}
#pragma option pop
Then you can call it like this:
__int64 SerialNumber = 0;
if( GetCPUSerialNumber(&SerialNumber) )
// use serial number as needed...
Gambit
Technical Details
Message-ID:
<4234a95b$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!212.101.4.254.MISMATCH!solnet.ch!solnet.ch!news-zh.switch.ch!irazu.switch.ch!switch.ch!news.belwue.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<423438a3@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,13e124f8a5f82d75 X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <423438a3@newsgroups.borland.com> Subject: Re: reading unique CPU number Date: Sun, 13 Mar 2005 12:58:38 -0800 Lines: 113 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 68.69.17.41 Message-ID: <4234a95b$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1110747483 68.69.17.41 (13 Mar 2005 12:58:03 -0800) Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!212.101.4.254.MISMATCH!solnet.ch!solnet.ch!news-zh.switch.ch!irazu.switch.ch!switch.ch!news.belwue.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail