在Win9x/NT下获取硬盘物理序列号

善良的阳光之夜

善良的阳光之夜

2016-02-19 15:04

下面图老师小编要跟大家分享在Win9x/NT下获取硬盘物理序列号,简单的过程中其实暗藏玄机,还是要细心学习,喜欢还请记得收藏哦!

  本文代码在Win2k下试验成功.

(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/bianchengyuyan/)

  

#include WinIOCtl.h
#include stdio.h
#pragma inline
//---------------------------------------------------------------------------
// IDE NT/2000/XP专用变量
#define GETVERSIONOUTPARAMS   GETVERSIONINPARAMS
#define DFP_GET_VERSION     SMART_GET_VERSION
#define DFP_SEND_DRIVE_COMMAND SMART_SEND_DRIVE_COMMAND
#define DFP_RCV_DRIVE_DATA   SMART_RCV_DRIVE_DATA
const WORD IDE_ATAPI_IDENTIFY = 0xA1;  // 读取ATAPI设备的命令
const WORD IDE_ATA_IDENTIFY  = 0xEC;  // 读取ATA设备的命令
const int MAX_IDE_DRIVES = 4;
// SCSI专用变量
const DWORD FILE_DEVICE_SCSI       = 0x0000001B;
const DWORD IOCTL_SCSI_MINIPORT_IDENTIFY = ((FILE_DEVICE_SCSI 16) + 0x0501);
const DWORD IOCTL_SCSI_MINIPORT     = 0x0004D008; // see NTDDSCSI.H for definition
const DWORD SENDIDLENGTH = sizeof(SENDCMDOUTPARAMS) + IDENTIFY_BUFFER_SIZE;
typedef struct _SRB_IO_CONTROL
{
  ULONG HeaderLength;
  UCHAR Signature[8];
  ULONG Timeout;
  ULONG ControlCode;
  ULONG ReturnCode;
  ULONG Length;
}SRB_IO_CONTROL, *PSRB_IO_CONTROL;
// 读取的主函数
void __fastcall ReadPhysicalDrive(TStrings *pSerList, TStrings *pModeList);
// 辅助函数
char *__fastcall ConvertToString(DWORD dwDiskData[256], int nFirstIndex, int nLastIndex);
// NT/2000/XP函数
void __fastcall ReadPhysicalDriveOnNT(TStrings *pSerList, TStrings *pModeList);
bool __fastcall DoIdentify(HANDLE hPhysicalDriveIOCTL, PSENDCMDINPARAMS pSCIP,
    PSENDCMDOUTPARAMS pSCOP, BYTE btIDCmd,
    BYTE btDriveNum, PDWORD lpcbBYTEsReturned);
// Windows 9X函数
void __fastcall ReadPhysicalDriveOnW9X(TStrings *pSerList, TStrings *pModeList);
void __fastcall ReadPhysicalDriveOnW9X_Ring0(bool IsFirst, WORD BaseAddress,
    BYTE MoS, bool &IsIDEExist, bool &IsDiskExist, WORD *OutData);
// SCSI读取函数(for NT/2000/XP)
String __fastcall ReadIDEDriveAsScsiDriveOnNT();
//---------------------------------------------------------------------------
// ReadPhysicalDrive
void __fastcall ReadPhysicalDrive(TStrings *pSerList, TStrings *pModeList)
{
  switch(Win32Platform)
  {
    case VER_PLATFORM_WIN32_WINDOWS:
      ReadPhysicalDriveOnW9X(pSerList, pModeList);
      break;
    case VER_PLATFORM_WIN32_NT:
      ReadPhysicalDriveOnNT(pSerList, pModeList);
      break;
    default:
      break;
  }
}
//---------------------------------------------------------------------------
// ConvertToString
char *__fastcall ConvertToString(DWORD dwDiskData[256], int nFirstIndex, int nLastIndex)
{
  static char szResBuf[1024];
  int nIndex = 0;
  int nPosition = 0;
  // Each integer has two characters stored in it backwards
  for(nIndex = nFirstIndex; nIndex = nLastIndex; nIndex++)
  {
    // Get high BYTE for 1st character
    szResBuf[nPosition] = (char)(dwDiskData[nIndex] / 256);
    nPosition++;
    // Get low BYTE for 2nd character
    szResBuf[nPosition] = (char)(dwDiskData[nIndex] % 256);
    nPosition++;
  }
  // End the string
  szResBuf[nPosition] = '
展开更多 50%)
分享

猜你喜欢

在Win9x/NT下获取硬盘物理序列号

编程语言 网络编程
在Win9x/NT下获取硬盘物理序列号

用C#获取硬盘序列号,CPU序列号,网卡MAC地址的源码

编程语言 网络编程
用C#获取硬盘序列号,CPU序列号,网卡MAC地址的源码

s8lol主宰符文怎么配

英雄联盟 网络游戏
s8lol主宰符文怎么配

Win8.1下Office2024序列号修改方法

windows系统
Win8.1下Office2024序列号修改方法

PHP+Apache在Win9X配置安装

PHP
PHP+Apache在Win9X配置安装

lol偷钱流符文搭配推荐

英雄联盟 网络游戏
lol偷钱流符文搭配推荐

读取软硬光盘序列号

编程语言 网络编程
读取软硬光盘序列号

Win8/Win8.1下快速更换Office2024序列号

windows系统
Win8/Win8.1下快速更换Office2024序列号

lolAD刺客新符文搭配推荐

英雄联盟
lolAD刺客新符文搭配推荐

关闭Word2007浮动工具栏

关闭Word2007浮动工具栏

12306网上订火车票攻略

12306网上订火车票攻略
下拉加载更多内容 ↓