分享
 
 
 

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

王朝system·作者佚名  2008-06-01
窄屏简体版  字體: |||超大  

本文代码经ccrun(老妖)在Win2k下试验成功.

#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] = '\0';

// Cut off the trailing blanks

for(nIndex = nPosition - 1; nIndex > 0 && ' ' == szResBuf[nIndex]; nIndex--)

szResBuf[nIndex] = '\0';

return szResBuf;

}

//---------------------------------------------------------------------------

// Winndows NT4/2000/XP 代码

//---------------------------------------------------------------------------

// ReadPhysicalDriveOnNT

void __fastcall ReadPhysicalDriveOnNT(TStrings *pSerList, TStrings *pModeList)

{

// 输出参数

BYTE btIDOutCmd[sizeof(SENDCMDOUTPARAMS) + IDENTIFY_BUFFER_SIZE - 1];

for(int nDrive=0; nDrive < MAX_IDE_DRIVES; nDrive++)

{

HANDLE hPhysicalDriveIOCTL;

char szDriveName[32];

sprintf(szDriveName, "\\\\.\\PhysicalDrive%d", nDrive);

hPhysicalDriveIOCTL = CreateFile(szDriveName,

GENERIC_READ GENERIC_WR99vE,

FILE_SHARE_READ FILE_SHARE_WR99vE, NULL,

OPEN_EXISTING, 0, NULL);

if(hPhysicalDriveIOCTL != INVALID_HANDLE_VALUE)

{

DWORD dwBytesReturned = 0;

GETVERSIONOUTPARAMS gvopVersionParams;

// Get the version, etc of PhysicalDrive IOCTL

ZeroMemory(&gvopVersionParams, sizeof(GETVERSIONOUTPARAMS));

if(!DeviceIoControl(hPhysicalDriveIOCTL, DFP_GET_VERSION,

&nb

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有