CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
山寨机中的战斗机! 程序优化工程师到底对IT界有没有贡献
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  C++ Builder >  基础类

求用C++Builder5/6找硬盘序列号???

楼主jlsnake(石头一样的意志)2003-08-03 15:57:30 在 C++ Builder / 基础类 提问

如题!!  
          请不要给我个http://......  
          也请不要给我个“看看原来的...”  
  谢谢!!(灌水无分) 问题点数:100、回复次数:8Top

1 楼annkie(无声的雨)回复于 2003-08-03 16:06:05 得分 10

nowcan的作品:  
  自己看去!  
   
  http://vip.6to23.com/NowCan1/code/diskid32.zip  
  读取硬盘的硬件序列号  
   
          这个程序是根据网上下载的一个for   VC的程序改编的。那是个著名的程序,估计很多人都知道-diskid32。但是这个程序里面问题很多,用BCB编译这个程序时会出现类型重复定义的错误。仔细一看,原来BCB已经对其中的某些类型定义过了,可以直接使用。因此,决定对它进行改写,让它适用于BCB。  
   
          我改写过后的程序只能用于WinNT/Win2000/WinXP,而不能用于Win9X,原因是我对进入ring0的原理不明白。  
   
          这里是改写前后的两个程序下载。  
   
  -*-*-PATCH-*-*-2002-02-26  
   
  我又找到一个用于Win9X的程序,不算长,就直接写在这儿了。  
   
  #include   <windows.h>  
  #include   <stdio.h>  
   
  WORD   pw[256];  
   
  static   DWORD   idt,   int_idt;  
  static   DWORD   Base;  
  static   WORD   Entry;  
   
  #pragma   warning   (disable:4035)    
  static   int   inp(WORD   rdx)  
  {  
  _asm   xor   eax,   eax  
  _asm   mov   dx,   rdx  
  _asm   in   al,   dx  
  }  
   
  static   WORD   inpw(WORD   rdx)  
  {  
  _asm   xor   eax,   eax  
  _asm   mov   dx,   rdx  
  _asm   in   ax,   dx  
  }  
   
  static   void   outp(WORD   rdx,   int   ral)  
  {  
  _asm   mov   dx,   rdx  
  _asm   mov   eax,   ral  
  _asm   out   dx,   al  
  }  
   
  static   int   WaitIde()  
  {  
  int   al;  
   
  while   ((al=inp(0x1F7))>=0x80)   ;  
  return   al;  
  }  
   
  static   void   ReadIDE()  
  {  
  int   al;  
  int   i;  
   
  WaitIde();  
  outp(0x1F6,0xA0);  
  al   =   WaitIde();  
  if   ((al&0x50)!=0x50)   return;  
   
  outp(0x1F6,0xA0);  
  outp(0x1F7,0xEC);  
  al   =   WaitIde();  
  if   ((al&0x58)!=0x58)   return;  
   
  for   (i=0;i<256;i++)   {  
  pw[i]   =   inpw(0x1F0);  
  }  
  }  
   
  static   void   __declspec(   naked   )   NowInRing0()  
  {  
  _asm   {  
  push   ebp    
  mov   ebp,esp  
   
  call   ReadIDE  
   
  cli  
  mov   ebx,   int_idt  
  mov   ax,   Entry  
  mov   word   ptr   [ebx-4],   ax  
  mov   eax,   Base  
  shr   eax,   16    
  mov   [ebx+2],   ax  
  sti  
  leave    
  iretd  
  }  
  }  
   
  void   GetIDEInfo()  
  {  
  DWORD   dwExcept;  
   
  dwExcept   =   (DWORD)NowInRing0;  
   
  _asm   {  
  mov   eax,   fs:[0]  
  push   eax    
  sidt   [esp-02h]    
  pop   ebx    
  mov   idt,   ebx  
  add   ebx,   0x1C  
  mov   int_idt,   ebx  
   
  mov   eax,   [ebx]    
  mov   [Base],   eax  
  mov   ax,   [ebx-4]    
  mov   [Entry],   ax  
   
  cli  
  mov   esi,   dwExcept  
  push   esi  
  mov   [ebx-4],   si  
  shr   esi,   16    
  mov   [ebx+2],   si    
  pop   esi  
  sti  
   
  int   3  
  }  
  }  
   
  main()  
  {  
  char   s[80];  
  register   i,j;  
   
  GetIDEInfo();  
   
  for   (i=0,j=0;i<10;i++)   {  
  s[j++]=pw[10+i]>>8;  
  s[j++]=pw[10+i]&0xFF;  
  }  
  s[j]   =   0;  
   
  printf("Serial=%s\n",   s);  
   
  return   0;  
  }  
   
   
  -*-*-PATCH-*-*-2002-02-26  
   
     
  Top

2 楼domustdo(大头)回复于 2003-08-03 16:08:19 得分 80

直接从RING3获取硬盘序列号    
  作者:陆麟    
  --------------------------------------------------------------------------------  
   
  通常情况下,我们通过0XEC命令对IDE端口进行监测.获取硬盘信息.    
  一般情况下,我们就写个VXD或者DRIVER来完成.但是现在,通过MS的S.M.A.R.T.接口,我们可以直接从RING3调用API   DeviceIoControl()来获取硬盘信息.下面乃是我的例程:    
   
  *注:在WIN98SE,WINDOWS   ME中,S.M.A.R.T并不缺省安装.请将SMARTVSD.VXD拷贝到%SYSTEM%\IOSUBSYS目录下.    
  在WINDOWS2000下,由于非ADMINISTRATORS组的用户对硬盘连GENERIC_READ的权限也没有,所以请以ADMINISTRATOR登录后使用.    
  /*+++    
  HDID.CPP    
  Written   by   Lu   Lin    
  http://lu0.126.com    
  2000.11.3    
  ---*/    
  #include   <windows.h>    
  #include   <iostream.h>    
  #include   <stdio.h>    
   
  #define   DFP_GET_VERSION   0x00074080    
  #define   DFP_SEND_DRIVE_COMMAND   0x0007c084    
  #define   DFP_RECEIVE_DRIVE_DATA   0x0007c088    
   
  #pragma   pack(1)    
  typedef   struct   _GETVERSIONOUTPARAMS   {    
    BYTE   bVersion;     //   Binary   driver   version.    
    BYTE   bRevision;     //   Binary   driver   revision.    
    BYTE   bReserved;     //   Not   used.    
    BYTE   bIDEDeviceMap;   //   Bit   map   of   IDE   devices.    
    DWORD   fCapabilities;   //   Bit   mask   of   driver   capabilities.    
    DWORD   dwReserved[4];   //   For   future   use.    
  }   GETVERSIONOUTPARAMS,   *PGETVERSIONOUTPARAMS,   *LPGETVERSIONOUTPARAMS;    
   
  typedef   struct   _IDEREGS   {    
    BYTE   bFeaturesReg;     //   Used   for   specifying   SMART   "commands".    
    BYTE   bSectorCountReg;   //   IDE   sector   count   register    
    BYTE   bSectorNumberReg;   //   IDE   sector   number   register    
    BYTE   bCylLowReg;       //   IDE   low   order   cylinder   value    
    BYTE   bCylHighReg;     //   IDE   high   order   cylinder   value    
    BYTE   bDriveHeadReg;     //   IDE   drive/head   register    
    BYTE   bCommandReg;     //   Actual   IDE   command.    
    BYTE   bReserved;       //   reserved   for   future   use.     Must   be   zero.    
  }   IDEREGS,   *PIDEREGS,   *LPIDEREGS;    
   
  typedef   struct   _SENDCMDINPARAMS   {    
    DWORD   cBufferSize;     //   Buffer   size   in   bytes    
    IDEREGS   irDriveRegs;     //   Structure   with   drive   register   values.    
    BYTE   bDriveNumber;     //   Physical   drive   number   to   send    
                  //   command   to   (0,1,2,3).    
    BYTE   bReserved[3];     //   Reserved   for   future   expansion.    
    DWORD   dwReserved[4];     //   For   future   use.    
    //BYTE     bBuffer[1];       //   Input   buffer.    
  }   SENDCMDINPARAMS,   *PSENDCMDINPARAMS,   *LPSENDCMDINPARAMS;    
   
  typedef   struct   _DRIVERSTATUS   {    
    BYTE   bDriverError;     //   Error   code   from   driver,    
                  //   or   0   if   no   error.    
    BYTE   bIDEStatus;       //   Contents   of   IDE   Error   register.    
                  //   Only   valid   when   bDriverError    
                  //   is   SMART_IDE_ERROR.    
    BYTE   bReserved[2];     //   Reserved   for   future   expansion.    
    DWORD   dwReserved[2];     //   Reserved   for   future   expansion.    
  }   DRIVERSTATUS,   *PDRIVERSTATUS,   *LPDRIVERSTATUS;    
   
  typedef   struct   _SENDCMDOUTPARAMS   {    
    DWORD         cBufferSize;     //   Size   of   bBuffer   in   bytes    
    DRIVERSTATUS   DriverStatus;     //   Driver   status   structure.    
    BYTE       bBuffer[512];       //   Buffer   of   arbitrary   length    
                      //   in   which   to   store   the   data   read   from   the   drive.    
  }   SENDCMDOUTPARAMS,   *PSENDCMDOUTPARAMS,   *LPSENDCMDOUTPARAMS;    
   
  typedef   struct   _IDSECTOR   {    
    USHORT   wGenConfig;    
    USHORT   wNumCyls;    
    USHORT   wReserved;    
    USHORT   wNumHeads;    
    USHORT   wBytesPerTrack;    
    USHORT   wBytesPerSector;    
    USHORT   wSectorsPerTrack;    
    USHORT   wVendorUnique[3];    
    CHAR   sSerialNumber[20];    
    USHORT   wBufferType;    
    USHORT   wBufferSize;    
    USHORT   wECCSize;    
    CHAR   sFirmwareRev[8];    
    CHAR   sModelNumber[40];    
    USHORT   wMoreVendorUnique;    
    USHORT   wDoubleWordIO;    
    USHORT   wCapabilities;    
    USHORT   wReserved1;    
    USHORT   wPIOTiming;    
    USHORT   wDMATiming;    
    USHORT   wBS;    
    USHORT   wNumCurrentCyls;    
    USHORT   wNumCurrentHeads;    
    USHORT   wNumCurrentSectorsPerTrack;    
    ULONG   ulCurrentSectorCapacity;    
    USHORT   wMultSectorStuff;    
    ULONG   ulTotalAddressableSectors;    
    USHORT   wSingleWordDMA;    
    USHORT   wMultiWordDMA;    
    BYTE   bReserved[128];    
  }   IDSECTOR,   *PIDSECTOR;    
   
  Top

3 楼domustdo(大头)回复于 2003-08-03 16:08:38 得分 0

/*+++    
  Global   vars    
  ---*/    
  GETVERSIONOUTPARAMS   vers;    
  SENDCMDINPARAMS   in;    
  SENDCMDOUTPARAMS   out;    
  HANDLE   h;    
  DWORD   i;    
  BYTE   j;    
   
  void   CopyRight(){    
    cerr<<endl<<"HDD   identifier   v1.0   for   WIN95/98/Me/NT/2000.   written   by   Lu   Lin"<<endl;    
    cerr<<"For   more   information,   please   visit   Inside   Programming:   http://lu0.126.com"<<endl;    
    cerr<<"2000.11.3"<<endl<<endl;    
  }    
  VOID   ChangeByteOrder(PCHAR   szString,   USHORT   uscStrSize)    
  {    
   
  USHORT   i;    
  CHAR   temp;    
   
    for   (i   =   0;   i   <   uscStrSize;   i+=2)    
    {    
      temp   =   szString[i];    
      szString[i]   =   szString[i+1];    
      szString[i+1]   =   temp;    
    }    
  }    
   
  void   DetectIDE(BYTE   bIDEDeviceMap){    
    if   (bIDEDeviceMap&1){    
      if   (bIDEDeviceMap&16){    
        cout<<"ATAPI   device   is   attached   to   primary   controller,   drive   0."<<endl;    
      }else{    
        cout<<"IDE   device   is   attached   to   primary   controller,   drive   0."<<endl;    
      }    
    }    
    if   (bIDEDeviceMap&2){    
      if   (bIDEDeviceMap&32){    
        cout<<"ATAPI   device   is   attached   to   primary   controller,   drive   1."<<endl;    
      }else{    
        cout<<"IDE   device   is   attached   to   primary   controller,   drive   1."<<endl;    
      }    
    }    
    if   (bIDEDeviceMap&4){    
      if   (bIDEDeviceMap&64){    
        cout<<"ATAPI   device   is   attached   to   secondary   controller,   drive   0."<<endl;    
      }else{    
        cout<<"IDE   device   is   attached   to   secondary   controller,   drive   0."<<endl;    
      }    
    }    
    if   (bIDEDeviceMap&8){    
      if   (bIDEDeviceMap&128){    
        cout<<"ATAPI   device   is   attached   to   secondary   controller,   drive   1."<<endl;    
      }else{    
        cout<<"IDE   device   is   attached   to   secondary   controller,   drive   1."<<endl;    
      }    
    }    
  }    
   
  void   hdid9x(){    
    ZeroMemory(&vers,sizeof(vers));    
    //We   start   in   95/98/Me    
    h=CreateFile("\\\\.\\Smartvsd",0,0,0,CREATE_NEW,0,0);    
    if   (!h){    
      cout<<"open   smartvsd.vxd   failed"<<endl;    
      exit(0);    
    }    
   
    if   (!DeviceIoControl(h,DFP_GET_VERSION,0,0,&vers,sizeof(vers),&i,0)){    
      cout<<"DeviceIoControl   failed:DFP_GET_VERSION"<<endl;    
      CloseHandle(h);    
      return;    
    }    
    //If   IDE   identify   command   not   supported,   fails    
    if   (!(vers.fCapabilities&1)){    
      cout<<"Error:   IDE   identify   command   not   supported.";    
      CloseHandle(h);    
      return;    
    }    
    //Display   IDE   drive   number   detected    
    DetectIDE(vers.bIDEDeviceMap);    
    //Identify   the   IDE   drives    
    for   (j=0;j<4;j++){    
      PIDSECTOR   phdinfo;    
      char   s[41];    
   
      ZeroMemory(&in,sizeof(in));    
      ZeroMemory(&out,sizeof(out));    
      if   (j&1){    
        in.irDriveRegs.bDriveHeadReg=0xb0;    
      }else{    
        in.irDriveRegs.bDriveHeadReg=0xa0;    
      }    
      if   (vers.fCapabilities&(16>>j)){    
        //We   don't   detect   a   ATAPI   device.    
        cout<<"Drive   "<<(int)(j+1)<<"   is   a   ATAPI   device,   we   don't   detect   it"<<endl;    
        continue;    
      }else{    
        in.irDriveRegs.bCommandReg=0xec;    
      }    
      in.bDriveNumber=j;    
      in.irDriveRegs.bSectorCountReg=1;    
      in.irDriveRegs.bSectorNumberReg=1;    
      in.cBufferSize=512;    
      if   (!DeviceIoControl(h,DFP_RECEIVE_DRIVE_DATA,&in,sizeof(in),&out,sizeof(out),&i,0)){    
        cout<<"DeviceIoControl   failed:DFP_RECEIVE_DRIVE_DATA"<<endl;    
        CloseHandle(h);    
        return;    
      }    
      phdinfo=(PIDSECTOR)out.bBuffer;    
      memcpy(s,phdinfo->sModelNumber,40);    
      s[40]=0;    
      ChangeByteOrder(s,40);    
      cout<<endl<<"Module   Number:"<<s<<endl;    
      memcpy(s,phdinfo->sFirmwareRev,8);    
      s[8]=0;    
      ChangeByteOrder(s,8);    
      cout<<"\tFirmware   rev:"<<s<<endl;    
      memcpy(s,phdinfo->sSerialNumber,20);    
      s[20]=0;    
      ChangeByteOrder(s,20);    
      cout<<"\tSerial   Number:"<<s<<endl;    
      cout<<"\tCapacity:"<<phdinfo->ulTotalAddressableSectors/2/1024<<"M"<<endl<<endl;    
    }    
   
    //Close   handle   before   quit    
    CloseHandle(h);    
    CopyRight();    
   
  }    
   
  void   hdidnt(){    
    char   hd[80];    
    PIDSECTOR   phdinfo;    
    char   s[41];    
   
    ZeroMemory(&vers,sizeof(vers));    
    //We   start   in   NT/Win2000    
    for   (j=0;j<4;j++){    
      sprintf(hd,"\\\\.\\PhysicalDrive%d",j);    
      h=CreateFile(hd,GENERIC_READ|GENERIC_WRITE,    
        FILE_SHARE_READ|FILE_SHARE_WRITE,0,OPEN_EXISTING,0,0);    
      if   (!h){    
        continue;    
      }    
      if   (!DeviceIoControl(h,DFP_GET_VERSION,0,0,&vers,sizeof(vers),&i,0)){    
        CloseHandle(h);    
        continue;    
      }    
      //If   IDE   identify   command   not   supported,   fails    
      if   (!(vers.fCapabilities&1)){    
        cout<<"Error:   IDE   identify   command   not   supported.";    
        CloseHandle(h);    
        return;    
      }    
      //Identify   the   IDE   drives    
      ZeroMemory(&in,sizeof(in));    
      ZeroMemory(&out,sizeof(out));    
      if   (j&1){    
        in.irDriveRegs.bDriveHeadReg=0xb0;    
      }else{    
        in.irDriveRegs.bDriveHeadReg=0xa0;    
      }    
      if   (vers.fCapabilities&(16>>j)){    
        //We   don't   detect   a   ATAPI   device.    
        cout<<"Drive   "<<(int)(j+1)<<"   is   a   ATAPI   device,   we   don't   detect   it"<<endl;    
        continue;    
      }else{    
        in.irDriveRegs.bCommandReg=0xec;    
      }    
      in.bDriveNumber=j;    
      in.irDriveRegs.bSectorCountReg=1;    
      in.irDriveRegs.bSectorNumberReg=1;    
      in.cBufferSize=512;    
      if   (!DeviceIoControl(h,DFP_RECEIVE_DRIVE_DATA,&in,sizeof(in),&out,sizeof(out),&i,0)){    
        cout<<"DeviceIoControl   failed:DFP_RECEIVE_DRIVE_DATA"<<endl;    
        CloseHandle(h);    
        return;    
      }    
      phdinfo=(PIDSECTOR)out.bBuffer;    
      memcpy(s,phdinfo->sModelNumber,40);    
      s[40]=0;    
      ChangeByteOrder(s,40);    
      cout<<endl<<"Module   Number:"<<s<<endl;    
      memcpy(s,phdinfo->sFirmwareRev,8);    
      s[8]=0;    
      ChangeByteOrder(s,8);    
      cout<<"\tFirmware   rev:"<<s<<endl;    
      memcpy(s,phdinfo->sSerialNumber,20);    
      s[20]=0;    
      ChangeByteOrder(s,20);    
      cout<<"\tSerial   Number:"<<s<<endl;    
      cout<<"\tCapacity:"<<phdinfo->ulTotalAddressableSectors/2/1024<<"M"<<endl<<endl;    
      CloseHandle(h);    
    }    
    CopyRight();    
  }    
   
  void   main(){    
    OSVERSIONINFO   VersionInfo;    
   
    ZeroMemory(&VersionInfo,sizeof(VersionInfo));    
    VersionInfo.dwOSVersionInfoSize=sizeof(VersionInfo);    
    GetVersionEx(&VersionInfo);    
   
    switch   (VersionInfo.dwPlatformId){    
    case   VER_PLATFORM_WIN32s:    
      cout<<"Win32s   is   not   supported   by   this   programm."<<endl;    
      return;    
    case   VER_PLATFORM_WIN32_WINDOWS:    
      hdid9x();    
      return;    
    case   VER_PLATFORM_WIN32_NT:    
      hdidnt();    
      return;    
    }    
  }    
   
  Top

4 楼domustdo(大头)回复于 2003-08-03 16:10:36 得分 5

另外你还可以到http://www.cppfans.com/articles/system/idehdparams.asp去看看,这里有另外一个完整的BCB工程"硬盘参数读取程序   -   硬盘型号、容量、序列号、固件版本等"  
  Top

5 楼sunmedia()回复于 2003-08-03 16:13:10 得分 5

楼上说的这个DLL文件,它只能在窗口模式下取到硬盘序列号,但在DOS模式下就没办法实现了。借这里我想问一下,有没有谁知道在控制台程序中,如何取到硬盘序列号呢?Top

6 楼jlsnake(石头一样的意志)回复于 2003-08-04 09:53:55 得分 0

谢谢Top

7 楼jlsnake(石头一样的意志)回复于 2003-08-04 09:56:06 得分 0

谢谢大头  
  大头大头,  
  下雨不愁。  
  你有雨伞,  
  我有大头。  
  :-)Top

8 楼domustdo(大头)回复于 2003-08-05 15:59:36 得分 0

嘻嘻,怎么都会唱这个啊:)Top

相关问题

  • 求C++ Builder的序列号!
  • 高分求用C#获取硬盘序列号和修改硬盘序列号得源码或方案
  • 硬盘序列号。。
  • 取得硬盘序列号的C#语法是什么??
  • 有谁知道:C#怎么读硬盘序列号?
  • C#中如何获取硬盘序列号?
  • 怎样用C#获取硬盘序列号?
  • 求硬盘序列号读取代码。---asp.net+c#
  • 请问我们平时获取的硬盘序列号是真正硬盘序列号,还是C盘序列号?
  • 如何用标准的C语言读取硬盘的序列号

关键词

  • 硬盘
  • 序列号
  • asm
  • word
  • rdx
  • waitide
  • 程序
  • al
  • outp
  • dx

得分解答快速导航

  • 帖主:jlsnake
  • annkie
  • domustdo
  • domustdo
  • sunmedia

相关链接

  • CSDN Blog
  • 技术文档
  • 代码下载
  • 第二书店
  • 读书频道

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo