得到CPU 及硬盘序列号(网友给的,未证实)

// CPU系列号:

FUNCTION GetCPUID: TCPUID; assembler; register;

asm

  PUSH    EBX         {Save affected register}

  PUSH    EDI

  MOV     EDI,EAX     {@Resukt}

  MOV     EAX,1       {0 cpu 厂商 1 cpu id 2 3}

  DW      $A20F       {CPUID Command}

  STOSD      {CPUID[1]}

  MOV     EAX,EBX

  STOSD               {CPUID[2]}

  MOV     EAX,ECX

  STOSD               {CPUID[3]}

  MOV     EAX,EDX

  STOSD               {CPUID[4]}

  POP     EDI         {Restore registers}

  POP     EBX

END;



function GetCPUIDStr: String;

var

  CPUID: TCPUID;

begin

  CPUID := GetCPUID;

  Result := IntToHex(CPUID[1], 8) + { IntToHex(CPUID[2], 8) + IntToHex(CPUID[3], 8) + }

    IntToHex(CPUID[4], 8);

end;
function GetIdeSerialNumber: PAnsiChar; // 获取硬盘的出厂系列号;

const

  IDENTIFY_BUFFER_SIZE = 512;

type

  TIDERegs = packed record

    bFeaturesReg: Byte;

    bSectorCountReg: Byte;

    bSectorNumberReg: Byte;

    bCylLowReg: Byte;

    bCylHighReg: Byte;

    bDriveHeadReg: Byte;

    bCommandReg: Byte;

    bReserved: Byte;

  end;



  TSendCmdInParams = packed record

    cBufferSize: dword;

    irDriveRegs: TIDERegs;

    bDriveNumber: Byte;

    bReserved: array [0 .. 2] of Byte;

    dwReserved: array [0 .. 3] of dword;

    bBuffer: array [0 .. 0] of Byte;

  end;



  TIdSector = packed record

    wGenConfig: Word;

    wNumCyls: Word;

    wReserved: Word;

    wNumHeads: Word;

    wBytesPerTrack: Word;

    wBytesPerSector: Word;

    wSectorsPerTrack: Word;

    wVendorUnique: array [0 .. 2] of Word;

    sSerialNumber: array [0 .. 19] of AnsiChar;

    wBufferType: Word;

    wBufferSize: Word;

    wECCSize: Word;

    sFirmwareRev: array [0 .. 7] of AnsiChar;

    sModelNumber: array [0 .. 39] of AnsiChar;

    wMoreVendorUnique: Word;

    wDoubleWordIO: Word;

    wCapabilities: Word;

    wReserved1: Word;

    wPIOTiming: Word;

    wDMATiming: Word;

    wBS: Word;

    wNumCurrentCyls: Word;

    wNumCurrentHeads: Word;

    wNumCurrentSectorsPerTrack: Word;

    ulCurrentSectorCapacity: dword;

    wMultSectorStuff: Word;

    ulTotalAddressableSectors: dword;

    wSingleWordDMA: Word;

    wMultiWordDMA: Word;

    bReserved: array [0 .. 127] of Byte;

  end;



  PIdSector = ^TIdSector;



  TDriverStatus = packed record

    bDriverError: Byte;

    bIDEStatus: Byte;

    bReserved: array [0 .. 1] of Byte;

    dwReserved: array [0 .. 1] of dword;

  end;



  TSendCmdOutParams = packed record

    cBufferSize: dword;

    DriverStatus: TDriverStatus;

    bBuffer: array [0 .. 0] of Byte;

  end;

var

  hDevice: THandle;

  cbBytesReturned: dword;

  SCIP: TSendCmdInParams;

  aIdOutCmd: array [0 .. (SizeOf(TSendCmdOutParams) + IDENTIFY_BUFFER_SIZE - 1) - 1] of Byte;

  IdOutCmd: TSendCmdOutParams absolute aIdOutCmd;



  procedure ChangeByteOrder(var Data; Size: Integer); // 函数中的过程

  var

    ptr: PAnsiChar;

    I: Integer;

    c: AnsiChar;

  begin

    ptr := @Data;

    for I := 0 to (Size shr 1) - 1 do

    begin

      c := ptr^;

      ptr^ := (ptr + 1)^;

      (ptr + 1)^ := c;

      Inc(ptr, 2);

    end;

  end;



begin // 函数主体

  Result := '';

  if Win32Platform = VER_PLATFORM_WIN32_NT then

  begin // Windows NT, Windows 2000

    hDevice := CreateFile('\\.\PhysicalDrive0', GENERIC_READ or GENERIC_WRITE,

      FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0);

  end

  else // Version Windows 95 OSR2, Windows 98

    hDevice := CreateFile('\\.\SMARTVSD', 0, 0, nil, CREATE_NEW, 0, 0);

  if hDevice = INVALID_HANDLE_VALUE then

    exit;

  try

    FillChar(SCIP, SizeOf(TSendCmdInParams) - 1, #0);

    FillChar(aIdOutCmd, SizeOf(aIdOutCmd), #0);

    cbBytesReturned := 0;

    with SCIP do

    begin

      cBufferSize := IDENTIFY_BUFFER_SIZE;

      with irDriveRegs do

      begin

        bSectorCountReg := 1;

        bSectorNumberReg := 1;

        bDriveHeadReg := $A0;

        bCommandReg := $EC;

      end;

    end;

    if not DeviceIoControl(hDevice, $0007C088, @SCIP, SizeOf(TSendCmdInParams) - 1, @aIdOutCmd,

      SizeOf(aIdOutCmd), cbBytesReturned, nil) then

      exit;

  finally

    CloseHandle(hDevice);

  end;

  with PIdSector(@IdOutCmd.bBuffer)^ do

  begin

    ChangeByteOrder(sSerialNumber, SizeOf(sSerialNumber));

    (PAnsiChar(@sSerialNumber) + SizeOf(sSerialNumber))^ := #0;

    Result := PAnsiChar(@sSerialNumber);

  end;

end;

 

你可能感兴趣的:(cpu)