From 3119b6aafde26342b3f4a64d3aa3fced107b95c0 Mon Sep 17 00:00:00 2001 From: midipix Date: Jun 29 2016 23:16:41 +0000 Subject: __ntapi_tt_statfs: refactor, explicit string comparison. --- diff --git a/src/fs/ntapi_tt_statfs.c b/src/fs/ntapi_tt_statfs.c index df5a971..bc4fe51 100644 --- a/src/fs/ntapi_tt_statfs.c +++ b/src/fs/ntapi_tt_statfs.c @@ -23,7 +23,6 @@ int32_t __stdcall __ntapi_tt_statfs( nt_oa oa; nt_iosb iosb; nt_unicode_string * sdev; - uint32_t hash; wchar16_t * wch; wchar16_t * wch_mark; uint32_t offset; @@ -49,15 +48,15 @@ int32_t __stdcall __ntapi_tt_statfs( oa.sec_qos = 0; /* open file/folder */ - status = __ntapi->zw_open_file( - &hfile, - NT_SEC_SYNCHRONIZE | NT_FILE_READ_ATTRIBUTES | NT_FILE_READ_ACCESS, - &oa, - &iosb, - NT_FILE_SHARE_READ | NT_FILE_SHARE_WRITE, - NT_FILE_SYNCHRONOUS_IO_ALERT); - - if (status != NT_STATUS_SUCCESS) + if ((status = __ntapi->zw_open_file( + &hfile, + NT_SEC_SYNCHRONIZE + | NT_FILE_READ_ATTRIBUTES + | NT_FILE_READ_ACCESS, + &oa, + &iosb, + NT_FILE_SHARE_READ | NT_FILE_SHARE_WRITE, + NT_FILE_SYNCHRONOUS_IO_ALERT))) return status; statfs->flags_out = NT_STATFS_NEW_HANDLE; @@ -67,19 +66,18 @@ int32_t __stdcall __ntapi_tt_statfs( statfs->flags_in = flags; /* maximum component length, file system type */ - status = __ntapi->zw_query_volume_information_file( - hfile, - &iosb, - buffer, - buffer_size, - NT_FILE_FS_ATTRIBUTE_INFORMATION); - - if (status != NT_STATUS_SUCCESS) + if ((status = __ntapi->zw_query_volume_information_file( + hfile, + &iosb, + buffer, + buffer_size, + NT_FILE_FS_ATTRIBUTE_INFORMATION))) return status; fsai = (nt_fsai *)buffer; - statfs->f_type = 0; + statfs->f_type = 0; statfs->f_namelen = fsai->maximum_component_name_length; + statfs->nt_fstype_hash = __ntapi->tt_buffer_crc32( 0, &fsai->file_system_name, @@ -113,14 +111,12 @@ int32_t __stdcall __ntapi_tt_statfs( statfs->f_ffree = (size_t)statfs->f_files >> 4 << 3; /* file system size information */ - status = __ntapi->zw_query_volume_information_file( - hfile, - &iosb, - buffer, - buffer_size, - NT_FILE_FS_FULL_SIZE_INFORMATION); - - if (status != NT_STATUS_SUCCESS) + if ((status = __ntapi->zw_query_volume_information_file( + hfile, + &iosb, + buffer, + buffer_size, + NT_FILE_FS_FULL_SIZE_INFORMATION))) return status; fsfsi = (nt_fsfsi *)buffer; @@ -130,40 +126,43 @@ int32_t __stdcall __ntapi_tt_statfs( statfs->f_bsize = fsfsi->sectors_per_allocation_unit * fsfsi->bytes_per_sector; statfs->f_frsize = fsfsi->bytes_per_sector; - /* TODO: consolidate with istat */ /* system-unique device name */ - iosb.info = 0; - status = __ntapi->zw_query_object( - hfile, - NT_OBJECT_NAME_INFORMATION, - buffer, - buffer_size, - (uint32_t *)&iosb.info); - - if (status != NT_STATUS_SUCCESS) + if ((status = __ntapi->zw_query_object( + hfile, + NT_OBJECT_NAME_INFORMATION, + buffer, + buffer_size, + (uint32_t *)&iosb.info))) return status; sdev = (nt_unicode_string *)buffer; + wch = sdev->buffer; if (sdev->strlen < __DEVICE_PATH_PREFIX_LEN) return NT_STATUS_INVALID_HANDLE; - hash = __ntapi->tt_buffer_crc32( - 0, - sdev->buffer, - __DEVICE_PATH_PREFIX_LEN); - - if (hash != __DEVICE_PATH_PREFIX_HASH) + if ((wch[0] != '\\') + || (wch[1] != 'D') + || (wch[2] != 'e') + || (wch[3] != 'v') + || (wch[4] != 'i') + || (wch[5] != 'c') + || (wch[6] != 'e') + || (wch[7] != '\\')) return NT_STATUS_INVALID_HANDLE; - wch_mark = sdev->buffer + __DEVICE_PATH_PREFIX_LEN/sizeof(wchar16_t); - wch = wch_mark; - while (*wch != '\\') wch++; - statfs->dev_name_strlen = (uint16_t)((wch - sdev->buffer) * sizeof(uint16_t)); + wch_mark = &wch[8]; + wch = wch_mark; + + while (*wch != '\\') + wch++; + + statfs->dev_name_strlen = (uint16_t)((wch - sdev->buffer) * sizeof(uint16_t)); statfs->record_name_strlen = sdev->strlen - statfs->dev_name_strlen; statfs->dev_name_hash = __ntapi->tt_buffer_crc32( - hash,wch_mark, + __DEVICE_PATH_PREFIX_HASH, + wch_mark, sizeof(wchar16_t) * (wch - wch_mark)); /* copy device name (optional, no failure) */ @@ -204,17 +203,15 @@ int32_t __stdcall __ntapi_tt_statfs( *(--wch) = statfs->dev_name_strlen; offset = sizeof(nt_unicode_string) + statfs->dev_name_strlen; - status = __ntapi->tt_get_dos_drive_mount_points( - (void *)0, - (wchar16_t *)0, - (nt_mount_dev_name *)wch, - mnt_points_buffer, - buffer_size - offset); - - if (status != NT_STATUS_SUCCESS) + if ((status = __ntapi->tt_get_dos_drive_mount_points( + (void *)0, + (wchar16_t *)0, + (nt_mount_dev_name *)wch, + mnt_points_buffer, + buffer_size - offset))) return status; - offset = ((nt_mount_point_param *)mnt_points_buffer)->mount_points_offset; + offset = ((nt_mount_point_param *)mnt_points_buffer)->mount_points_offset; mnt_points = (nt_mount_points *)((uintptr_t)mnt_points_buffer + offset); status = __ntapi->tt_dev_mount_points_to_statfs(