Harddisk manufacturing information library

Everything else that doesn't fall into one of the other PB categories.
Revolver
User
User
Posts: 22
Joined: Tue Apr 29, 2003 9:20 pm

Harddisk manufacturing information library

Post by Revolver »

I just finished version 1.0 of my DiskInfo library. This dll will give you details about hard disk drives attached to the IDE controllers of your pc. You can get it here:

http://diskinfo.nakatome.org/diskinfo.rar
or http://diskinfo.nakatome.org/diskinfo.zip
Don't forget to read readme.txt!

Here is an example (also provided in the archive) of how to use this library

Code: Select all

Structure DISK_INFO
  ModelNumber.b[64]
  SerialNumber.b[64]
  ControllerVersion.b[64]
  ControllerID.b
  BufferSize.l
  Type.b
  Sectors.l
  DiskSize1.l ; *COUGH* could use 64 bit integer support here !!
  DiskSize2.l
EndStructure

If OpenLibrary(0,"diskinfo.dll") = 0
  Debug "LIBRARY OPEN FAILED"
EndIf

; First you have to know how many hard disks are attached
; to the system. This will always be between 1 and 4.
DiskCount = CallFunction(0,"GetDiskCount")
Debug "Detected "+ Str(DiskCount) +" hard disk(s)"
Debug ""

; You can retrieve the data all at once by declaring the appropriate
; structure, and calling the GetDiskInfo() function. You can then
; get each piece of data out of the structure manually.

DiskInfo.DISK_INFO
ModelNumber.s       = Space(64)
SerialNumber.s      = Space(64)
ControllerVersion.s = Space(64)

For DiskID = 1 To DiskCount
  Debug "Disk - "+ Str(DiskID)
  Result = CallFunction(0,"GetDiskInfo",DiskID,@DiskInfo);
  
  CopyMemory(@DiskInfo\ModelNumber,      @ModelNumber,      64)
  CopyMemory(@DiskInfo\SerialNumber,     @SerialNumber,     64)
  CopyMemory(@DiskInfo\ControllerVersion,@ControllerVersion,64)
  
  Debug "  Model Number: "+ ModelNumber
  Debug "  Serial Number: "+ SerialNumber
  Debug "  Controller Version: "+ ControllerVersion
  
  Select DiskInfo\ControllerID
    Case 1: Debug "  This disk is on the Primary IDE Controller (Master)"
    Case 2: Debug "  This disk is on the Secondary IDE Controller (Slave)"
    Case 3: Debug "  This disk is on the Tertiary IDE Controller (Master)"
    Case 4: Debug "  This disk is on the Quaternary IDE Controller (Slave)"
  EndSelect
  
  Select DiskInfo\Type
    Case 0: Debug "  Type: Unknown"
    Case 1: Debug "  Type: Fixed"
    Case 2: Debug "  Type: Removable"
  EndSelect
  
  Debug "  Buffer Size: "+ Str(DiskInfo\BufferSize) +" bytes"
  Debug "  Disk Size: "+ StrF(DiskInfo\Sectors * 512,0) +" bytes" ; This little hack will work For drives up To 2TB large.
  ;Debug "  Disk Size: "+ Str(DiskInfo\DiskSize) +" bytes"         ; Hopefully by the time those are here, PB will have 64-bit
                                                                   ; integer support, so we don't have to do that hack!
  Debug ""
Next

; Or, you can get each piece of data one at a time. Useful
; if you only want to know certain things about the disk
DiskSize.l
DiskSerial.s = Space(64)
If CallFunction(0,"GetDiskSectors",1,@DiskSize)
  Debug "Disk 1 size: "+ StrF(DiskSize * 512,0) +" bytes"
EndIf
; If you only have 1 hard disk, this will show nothing
If CallFunction(0,"GetDiskSerial",2,@DiskSerial)
  Debug "Disk 2 serial: "+ DiskSerial
EndIf

CloseLibrary(0)

End
This has not been thoroughly tested, only on Windows XP SP1, and Windows 98. If you get it to work please post here with your operating system and hard disk specs!

Enjoy !

(Don't worry Rings, this isn't the code you gave me. I was finally able to get that C++ code transformed into a DLL properly :)
Last edited by Revolver on Sun Jun 15, 2003 7:04 pm, edited 2 times in total.
Revolver
User
User
Posts: 22
Joined: Tue Apr 29, 2003 9:20 pm

Post by Revolver »

Also, don't be fooled. This is not the same thing as you can get with the API command GetVolumeInformation. That command only works for logical drive partitions. This will return the actual serial number for the hard disk itself, as issued by the company that manufactured it. Volume serial numbers will be changed any time the disk is reformatted or repartitioned. The serial number issued by this library will never change, unless they get a new hard drive :)
Last edited by Revolver on Sun Jun 15, 2003 7:00 pm, edited 2 times in total.
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

Very nice work Revolver!

This should be very handy to those wishing to protect software using a hardware fingerprint, etc...
--Kale

Image
User avatar
Rings
Moderator
Moderator
Posts: 1435
Joined: Sat Apr 26, 2003 1:11 am

Post by Rings »

Yes, i have written code for that in plain purebasic weeks ago.
[NUM] and Revolver owns it.Some day i will release it to everyone :)
SPAMINATOR NR.1
RJP Computing
Enthusiast
Enthusiast
Posts: 202
Joined: Sun Apr 27, 2003 4:44 am
Location: Michigan, USA
Contact:

Post by RJP Computing »

@Rings,
That would be great. Can't wait.

@Revolver
Looks nice.

Works on WinXP SP1 & IBM HD
Works on Win2K SP3 & WD HD

Thanks
-Ryan
RJP Computing

Ubuntu 8.10/WinXP, AMD Athlon 64 3000+, 1000MB RAM, AC 97 Audio, nVidia GeForce 7600GT 512MB
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Post by ricardo »

Hi Revolver,

Very nice job!!

How can i know on which of the hds of the array are my software installed?
I mean, i want to know only the serial of the hd where the software is.
ARGENTINA WORLD CHAMPION
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

Works fine on windows 2k and NT4 :lol:
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> i have written code for that in plain purebasic weeks ago.

Please release it soon. :) DLLs are good, but I don't really like them.
Revolver
User
User
Posts: 22
Joined: Tue Apr 29, 2003 9:20 pm

Post by Revolver »

ricardo: hmm, you could somehow find out which ide controller the virtual drive is using that your software is on, then cycle through the drives given by the dll until you find one that's ControllerID matches. I don't know how to get the ide controller id for a virtual drive though..
User avatar
Inner
PureBasic Expert
PureBasic Expert
Posts: 714
Joined: Fri Apr 25, 2003 4:47 pm
Location: New Zealand

Post by Inner »

Does it work on Cdrom drivers too ?
User avatar
Rings
Moderator
Moderator
Posts: 1435
Joined: Sat Apr 26, 2003 1:11 am

Post by Rings »

PB wrote:> i have written code for that in plain purebasic weeks ago.

Please release it soon. :) DLLs are good, but I don't really like them.
done.
viewtopic.php?p=28162#28162
SPAMINATOR NR.1
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

Thanks Rings! :D
Revolver
User
User
Posts: 22
Joined: Tue Apr 29, 2003 9:20 pm

Post by Revolver »

Inner wrote:Does it work on Cdrom drivers too ?
nope
TerryHough
Enthusiast
Enthusiast
Posts: 781
Joined: Fri Apr 25, 2003 6:51 pm
Location: NC, USA
Contact:

Post by TerryHough »

@Revolver

Your code works perfectly on my Win98SE system for the first hard
drive. The remaining hard drives attempt to display but the information
displayed is either blank, or completely inaccurate.

I just downloaded your zip file today so I should have the latest version
you have made available.

Do you have any suggestions as to why other drives misreport? In my
case I have three hard drives located on Primary (Master),
Primary (Slave), and Secondary (Master).

Thanks,
Terry
Jordi
User
User
Posts: 53
Joined: Sat Apr 26, 2003 10:19 am
Location: Cosmos

Post by Jordi »

Does anyone know where I can download the Revolver DISKINFO dll?

I need do a non professional protection system for Windows XP based system getting the HDD SN but it's not useful using Rings code in a no administration user, you need administration permissions to get the SN right. Is there any way to get the SN with this method?

Thks in advance!
Post Reply