summaryrefslogtreecommitdiffstats
path: root/src/hdwin32.c
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2011-06-30 09:11:10 +0200
committerChristophe Grenier <grenier@cgsecurity.org>2011-06-30 09:11:10 +0200
commitfef758b100e987748dfa468ecfcacb0f8c036248 (patch)
tree051e05f213cba18562651ad01fd53a05c62573a2 /src/hdwin32.c
parentb163fd1ee3cb7d55c0966b209d23ce6486de7e0c (diff)
Read HDD serial number and firmware revision (Windows)
Diffstat (limited to 'src/hdwin32.c')
-rw-r--r--src/hdwin32.c23
1 files changed, 9 insertions, 14 deletions
diff --git a/src/hdwin32.c b/src/hdwin32.c
index 0cf5393..91a28b9 100644
--- a/src/hdwin32.c
+++ b/src/hdwin32.c
@@ -75,28 +75,22 @@ void file_win32_disk_get_model(HANDLE handle, disk_t *dev, const int verbose)
log_info("IOCTL_STORAGE_QUERY_PROPERTY:\n");
dump_log(&buffer, cbBytesReturned);
}
+ buffer[(cbBytesReturned < sizeof(buffer) ? cbBytesReturned : sizeof(buffer)-1)]='\0';
+ if(descrip->SerialNumberOffset!=0 && descrip->SerialNumberOffset!=0xffffffff)
+ dev->serial_no=strip_dup(&buffer[descrip->SerialNumberOffset]);
+ if(descrip->ProductIdOffset!=0)
+ dev->fw_rev=strip_dup(&buffer[descrip->ProductRevisionOffset]);
if(offsetVendor>0)
- {
- for(lenVendor=0; offsetVendor+lenVendor < sizeof(buffer) &&
- offsetVendor+lenVendor < cbBytesReturned &&
- buffer[offsetVendor+lenVendor] != '\0';
- lenVendor++);
- }
+ lenVendor=strlen(&buffer[offsetVendor]);
if(offsetProduct>0)
- {
- for(lenProduct=0; offsetProduct+lenProduct < sizeof(buffer) &&
- offsetProduct+lenProduct < cbBytesReturned &&
- buffer[offsetProduct+lenProduct] != '\0';
- lenProduct++);
- }
-
+ lenProduct=strlen(&buffer[offsetProduct]);
if(lenVendor+lenProduct>0)
{
- int i;
dev->model = (char*) MALLOC(lenVendor+1+lenProduct+1);
dev->model[0]='\0';
if(lenVendor>0)
{
+ int i;
memcpy(dev->model, &buffer[offsetVendor], lenVendor);
dev->model[lenVendor]='\0';
for(i=lenVendor-1;i>=0 && dev->model[i]==' ';i--);
@@ -106,6 +100,7 @@ void file_win32_disk_get_model(HANDLE handle, disk_t *dev, const int verbose)
}
if(lenProduct>0)
{
+ int i;
strncat(dev->model, &buffer[offsetProduct],lenProduct);
for(i=strlen(dev->model)-1;i>=0 && dev->model[i]==' ';i--);
dev->model[++i]='\0';