flat assembler
Message board for the users of flat assembler.

Index > Windows > Harddrive Serial Number in Fasm

Author
Thread Post new topic Reply to topic
Fungos Bauux



Joined: 19 Jan 2005
Posts: 31
Location: CWB
Fungos Bauux
Hi, anyone has any hd serial retriever in fasm?

See this one:
http://www.winsim.com/diskid32/diskid32.html

Any ports?
Post 10 Jan 2006, 18:23
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
r22



Joined: 27 Dec 2004
Posts: 805
r22
If you're talking about the serial number that appears in the command prompt like.
C:\>dir
Volume in drive C has no label.
Volume Serial Number is C1FB-05A6
Directory of C:\

Then there's a simple API in kernel32.dll you can use.
From the windows SDK
Quote:

The GetVolumeInformation function retrieves information about a file system and volume that have a specified root directory.


BOOL GetVolumeInformation(
LPCTSTR lpRootPathName,
LPTSTR lpVolumeNameBuffer,
DWORD nVolumeNameSize,
LPDWORD lpVolumeSerialNumber,
LPDWORD lpMaximumComponentLength,
LPDWORD lpFileSystemFlags,
LPTSTR lpFileSystemNameBuffer,
DWORD nFileSystemNameSize
);

Parameters
lpRootPathName
[in] A pointer to a string that contains the root directory of the volume to be described.
If this parameter is NULL, the root of the current directory is used. A trailing backslash is required. For example, you would specify \\MyServer\MyShare as \\MyServer\MyShare\, or the C drive as "C:\".

lpVolumeNameBuffer
[out] A pointer to a buffer that receives the name of a specified volume.
nVolumeNameSize
[in] The length of a volume name buffer, in TCHARs.
This parameter is ignored if the volume name buffer is not supplied.

lpVolumeSerialNumber
[out] A pointer to a variable that receives the volume serial number.
This parameter can be NULL if the serial number is not required.

Windows Me/98/95: If the queried volume is a network drive, the serial number is not returned.
lpMaximumComponentLength
[out] A pointer to a variable that receives the maximum length, in TCHARs, of a file name component supported by a specified file system.
A file name component is the portion of a file name between backslashes.

The value that is stored in variable pointed to by *lpMaximumComponentLength is used to indicate that long names are supported by a specified file system. For example, for a FAT file system that supports long names, the function stores the value 255, rather than the previous 8.3 indicator. Long names can also be supported on systems that use the NTFS file system.

lpFileSystemFlags
[out] A pointer to a variable that receives flags associated with the specified file system.
This parameter can be one or more of the following flags; however, FS_FILE_COMPRESSION and FS_VOL_IS_COMPRESSED are mutually exclusive.

Value Meaning
FILE_NAMED_STREAMS The file system supports named streams.
FILE_READ_ONLY_VOLUME The specified volume is read-only.
Windows 2000/NT and Windows Me/98/95: This value is not supported.
FILE_SUPPORTS_OBJECT_IDS The file system supports object identifiers.
FILE_SUPPORTS_REPARSE_POINTS The file system supports re-parse points.
FILE_SUPPORTS_SPARSE_FILES The file system supports sparse files.
FILE_VOLUME_QUOTAS The file system supports disk quotas.
FS_CASE_IS_PRESERVED The file system preserves the case of file names when it places a name on disk.
FS_CASE_SENSITIVE The file system supports case-sensitive file names.
FS_FILE_COMPRESSION The file system supports file-based compression.
FS_FILE_ENCRYPTION The file system supports the Encrypted File System (EFS).
FS_PERSISTENT_ACLS The file system preserves and enforces access control lists (ACL). For example, the NTFS file system preserves and enforces ACLs, and the FAT file system does not.
FS_UNICODE_STORED_ON_DISK The file system supports Unicode in file names as they appear on disk.
FS_VOL_IS_COMPRESSED The specified volume is a compressed volume; for example, a DoubleSpace volume.

lpFileSystemNameBuffer
[out] Pointer to a buffer that receives the name of the file system (such as the FAT file system or the NTFS file system).
nFileSystemNameSize
[in] Length of the file system name buffer, in TCHARs. This parameter is ignored if the file system name buffer is not supplied.


Here's an easy to read VB6 code snippet.
Converting it to ASM should be no trouble.
Quote:

Public Declare Function GetVolumeSerialNumber Lib "kernel32" Alias "GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As Long, ByVal nVolumeNameSize As Long, lpVolumeSerialNumber As Long, ByVal lpMaximumComponentLength As Long, ByVal lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As Long, ByVal nFileSystemNameSize As Long) As Long

Public Function VolumeSerial(DriveLetter) As Long
Dim Serial As Long
Call GetVolumeSerialNumber(UCase(DriveLetter) & ":\", 0&, 0&, Serial, 0&, 0&, 0&, 0&)
VolumeSerial = Serial
End Function

Post 10 Jan 2006, 21:00
View user's profile Send private message AIM Address Yahoo Messenger Reply with quote
Fungos Bauux



Joined: 19 Jan 2005
Posts: 31
Location: CWB
Fungos Bauux
Thanks, but this serial changes with every volume change. The serial number from diskid32 is a internal vendor serial code with vendor string.
Post 10 Jan 2006, 21:14
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
RedGhost



Joined: 18 May 2005
Posts: 443
Location: BC, Canada
RedGhost
i dont know about HDD serials but GetCurrentHwProfile returns a globally unique identifier (GUID) based on many aspects of hardware which i once used for a per-computer password/login for an application i didnt want leaked

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/getcurrenthwprofile.asp

_________________
redghost.ca
Post 10 Jan 2006, 22:45
View user's profile Send private message AIM Address MSN Messenger Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2140
Location: Estonia
Madis731
Code:
Drive Model Number________________: Maxtor 6B300S0
Drive Serial Number_______________: B60LWM8H
Drive Controller Revision Number__: BANC1B10
Controller Buffer Size on Drive___: 16777216 bytes
Drive Type________________________: Fixed
Physical Geometry:     16383 Cylinders     16 Heads     63 Sectors per track

Computer ID_______________________: 116244297
    

6B300S0 - you mean this? Its also possible with Windows API, because if you check your HDD's properties it shows up there too.
If you mean this B60LWM8H, then I don't know how to get it, but there was a bit easier method as I recall.

...but what is Computer ID in this app and where is my drive size?
Post 11 Jan 2006, 09:32
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
Fungos Bauux



Joined: 19 Jan 2005
Posts: 31
Location: CWB
Fungos Bauux
Quote:

but GetCurrentHwProfile returns a globally unique identifier (GUID) based on many aspects of hardware which i once used for a per-computer password/login for an application i didnt want leaked


@RedGhost: I want to do something like yours, it worked? Razz Do you like this solution?

Quote:

If you mean this B60LWM8H, then I don't know how to get it, but there was a bit easier method as I recall.

...but what is Computer ID in this app and where is my drive size?

This "Computer ID" is calculed using "Drive Serial Number" and "Drive Model Number" (vendor name only).

see:

Code:
      char *p = HardDriveSerialNumber;

      if ( ! strncmp (HardDriveSerialNumber, "WD-W", 4)) p += 5;
      for ( ; p && *p; p++)
      {
         if ('-' == *p) continue;
         id *= 10;
         switch (*p)
         {
            case '0': id += 0; break;
            case '1': id += 1; break;
            case '2': id += 2; break;
            case '3': id += 3; break;
            case '4': id += 4; break;
            case '5': id += 5; break;
            case '6': id += 6; break;
            case '7': id += 7; break;
            case '8': id += 8; break;
            case '9': id += 9; break;
            case 'a': case 'A': id += 10; break;
            case 'b': case 'B': id += 11; break;
            case 'c': case 'C': id += 12; break;
            case 'd': case 'D': id += 13; break;
            case 'e': case 'E': id += 14; break;
            case 'f': case 'F': id += 15; break;
            case 'g': case 'G': id += 16; break;
            case 'h': case 'H': id += 17; break;
            case 'i': case 'I': id += 18; break;
            case 'j': case 'J': id += 19; break;
            case 'k': case 'K': id += 20; break;
            case 'l': case 'L': id += 21; break;
            case 'm': case 'M': id += 22; break;
            case 'n': case 'N': id += 23; break;
            case 'o': case 'O': id += 24; break;
            case 'p': case 'P': id += 25; break;
            case 'q': case 'Q': id += 26; break;
            case 'r': case 'R': id += 27; break;
            case 's': case 'S': id += 28; break;
            case 't': case 'T': id += 29; break;
            case 'u': case 'U': id += 30; break;
            case 'v': case 'V': id += 31; break;
            case 'w': case 'W': id += 32; break;
            case 'x': case 'X': id += 33; break;
            case 'y': case 'Y': id += 34; break;
            case 'z': case 'Z': id += 35; break;
         }                            
      }
   }

   id %= 100000000;
   if (strstr (HardDriveModelNumber, "IBM-"))
      id += 300000000;
   else if (strstr (HardDriveModelNumber, "MAXTOR") ||
            strstr (HardDriveModelNumber, "Maxtor"))
      id += 400000000;
   else if (strstr (HardDriveModelNumber, "WDC "))
      id += 500000000;
   else
      id += 600000000;
    
Post 11 Jan 2006, 12:38
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2140
Location: Estonia
Madis731
First I thought suggesting you to use the output of that program for your needs, but seeing this code WOW! ... now I remember why I chose ASM:
Code:
...
;The whole case tree can be packed into this:
;[eax] contains some value 0-9,A-Z,a-z
  movzx edx,byte[eax]
  cmp   dl,'A'
  jb    @f
  or    dl,20h
  sub   dl,'a'-10
@@:
  sub   dl,30h
  add   [id],dl
...
    
Post 11 Jan 2006, 13:31
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
Fungos Bauux



Joined: 19 Jan 2005
Posts: 31
Location: CWB
Fungos Bauux
Yes Smile I understand your feelings, this is why Im trying getting back to asm and want to do this thing 100% in fasm.
Post 11 Jan 2006, 17:23
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
RedGhost



Joined: 18 May 2005
Posts: 443
Location: BC, Canada
RedGhost
Fungos Bauux wrote:
Quote:

but GetCurrentHwProfile returns a globally unique identifier (GUID) based on many aspects of hardware which i once used for a per-computer password/login for an application i didnt want leaked


@RedGhost: I want to do something like yours, it worked? Razz Do you like this solution?


yeah i figured thats why you might want a serial, yeah it worked fine for me as i recall, but the GUID returned in GetCurrentHwProfile is unique per computer and is very long (which is good!), i also like the fact its based on many hardware components not just the HDD

_________________
redghost.ca
Post 11 Jan 2006, 18:06
View user's profile Send private message AIM Address MSN Messenger Reply with quote
Fungos Bauux



Joined: 19 Jan 2005
Posts: 31
Location: CWB
Fungos Bauux
Thanks RedGhost, I will try implement using this one.
Post 11 Jan 2006, 18:10
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2140
Location: Estonia
Madis731
I hope you won't throw a user away when he changes a USB-stick Razz
Usually when HDD-s crash - I make "ghosts" out of them and boot with another HDD as if nothing has happened. This might be a problem, when programs are calculating GUID checksums Sad but well...security is the most important thing Wink
Post 12 Jan 2006, 11:27
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
Fungos Bauux



Joined: 19 Jan 2005
Posts: 31
Location: CWB
Fungos Bauux
Hm, GUID will change with little hardware changes? I wont use hdd serial anymore because these problems, but will windows keep its guid ?
Post 12 Jan 2006, 16:09
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
bzdashek



Joined: 15 Feb 2012
Posts: 147
Location: Tolstokvashino, Russia
bzdashek
So, how's your progress, comrade?
Post 16 Apr 2012, 19:19
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.