From ef03f83cc940d87f75140b7a8bc1199f4ff22aab Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Wed, 17 Feb 2016 20:21:40 -0600 Subject: [PATCH] Directly link with ntdll on Windows --- Makefile.am | 5 +- include/wimlib/win32_common.h | 172 ++++++++++++++-------------------- src/wimboot.c | 2 +- src/win32_apply.c | 148 ++++++++++++++--------------- src/win32_capture.c | 114 +++++++++++----------- src/win32_common.c | 129 +------------------------ 6 files changed, 205 insertions(+), 365 deletions(-) diff --git a/Makefile.am b/Makefile.am index 2987b100..32f0fc33 100644 --- a/Makefile.am +++ b/Makefile.am @@ -173,9 +173,11 @@ libwim_la_SOURCES += src/wimboot.c \ include/wimlib/win32_common.h \ include/wimlib/win32_vss.h \ include/wimlib/wof.h +PLATFORM_LIBS = -lmsvcrt -lntdll else libwim_la_SOURCES += src/unix_apply.c \ src/unix_capture.c +PLATFORM_LIBS = endif libwim_la_CFLAGS = \ @@ -195,7 +197,8 @@ libwim_la_LIBADD = \ $(LIBNTFS_3G_LIBS) \ $(LIBFUSE_LIBS) \ $(LIBRT_LIBS) \ - $(LIBCRYPTO_LIBS) + $(LIBCRYPTO_LIBS) \ + $(PLATFORM_LIBS) if ENABLE_SSSE3_SHA1 libwim_la_SOURCES += src/sha1-ssse3.asm diff --git a/include/wimlib/win32_common.h b/include/wimlib/win32_common.h index e669d522..df8b0cb7 100644 --- a/include/wimlib/win32_common.h +++ b/include/wimlib/win32_common.h @@ -13,97 +13,11 @@ #ifdef ERROR # undef ERROR #endif -#include "wimlib/types.h" #include "wimlib/win32.h" -/* ntdll functions */ - -extern NTSTATUS (WINAPI *func_NtCreateFile)(PHANDLE FileHandle, - ACCESS_MASK DesiredAccess, - POBJECT_ATTRIBUTES ObjectAttributes, - PIO_STATUS_BLOCK IoStatusBlock, - PLARGE_INTEGER AllocationSize, - ULONG FileAttributes, - ULONG ShareAccess, - ULONG CreateDisposition, - ULONG CreateOptions, - PVOID EaBuffer, - ULONG EaLength); - -#ifndef FILE_OPENED -# define FILE_OPENED 0x00000001 -#endif +/* ntdll definitions */ -extern NTSTATUS (WINAPI *func_NtOpenFile) (PHANDLE FileHandle, - ACCESS_MASK DesiredAccess, - POBJECT_ATTRIBUTES ObjectAttributes, - PIO_STATUS_BLOCK IoStatusBlock, - ULONG ShareAccess, - ULONG OpenOptions); - -extern NTSTATUS (WINAPI *func_NtReadFile) (HANDLE FileHandle, - HANDLE Event, - PIO_APC_ROUTINE ApcRoutine, - PVOID ApcContext, - PIO_STATUS_BLOCK IoStatusBlock, - PVOID Buffer, - ULONG Length, - PLARGE_INTEGER ByteOffset, - PULONG Key); - -extern NTSTATUS (WINAPI *func_NtWriteFile) (HANDLE FileHandle, - HANDLE Event, - PIO_APC_ROUTINE ApcRoutine, - PVOID ApcContext, - PIO_STATUS_BLOCK IoStatusBlock, - PVOID Buffer, - ULONG Length, - PLARGE_INTEGER ByteOffset, - PULONG Key); - -extern NTSTATUS (WINAPI *func_NtQueryInformationFile)(HANDLE FileHandle, - PIO_STATUS_BLOCK IoStatusBlock, - PVOID FileInformation, - ULONG Length, - FILE_INFORMATION_CLASS FileInformationClass); - -extern NTSTATUS (WINAPI *func_NtQuerySecurityObject)(HANDLE handle, - SECURITY_INFORMATION SecurityInformation, - PSECURITY_DESCRIPTOR SecurityDescriptor, - ULONG Length, - PULONG LengthNeeded); - -extern NTSTATUS (WINAPI *func_NtQueryDirectoryFile) (HANDLE FileHandle, - HANDLE Event, - PIO_APC_ROUTINE ApcRoutine, - PVOID ApcContext, - PIO_STATUS_BLOCK IoStatusBlock, - PVOID FileInformation, - ULONG Length, - FILE_INFORMATION_CLASS FileInformationClass, - BOOLEAN ReturnSingleEntry, - PUNICODE_STRING FileName, - BOOLEAN RestartScan); - -extern NTSTATUS (WINAPI *func_NtQueryVolumeInformationFile) (HANDLE FileHandle, - PIO_STATUS_BLOCK IoStatusBlock, - PVOID FsInformation, - ULONG Length, - FS_INFORMATION_CLASS FsInformationClass); - -extern NTSTATUS (WINAPI *func_NtSetInformationFile)(HANDLE FileHandle, - PIO_STATUS_BLOCK IoStatusBlock, - PVOID FileInformation, - ULONG Length, - FILE_INFORMATION_CLASS FileInformationClass); - -extern NTSTATUS (WINAPI *func_NtSetSecurityObject)(HANDLE Handle, - SECURITY_INFORMATION SecurityInformation, - PSECURITY_DESCRIPTOR SecurityDescriptor); - -extern NTSTATUS (WINAPI *func_NtClose) (HANDLE Handle); - -extern DWORD (WINAPI *func_RtlNtStatusToDosError)(NTSTATUS status); +#define FILE_OPENED 0x00000001 typedef struct _RTLP_CURDIR_REF { LONG RefCount; @@ -116,21 +30,6 @@ typedef struct _RTL_RELATIVE_NAME_U { PRTLP_CURDIR_REF CurDirRef; } RTL_RELATIVE_NAME_U, *PRTL_RELATIVE_NAME_U; -extern BOOLEAN (WINAPI *func_RtlDosPathNameToNtPathName_U) - (IN PCWSTR DosName, - OUT PUNICODE_STRING NtName, - OUT PCWSTR *PartName, - OUT PRTL_RELATIVE_NAME_U RelativeName); - -extern NTSTATUS (WINAPI *func_RtlDosPathNameToNtPathName_U_WithStatus) - (IN PCWSTR DosName, - OUT PUNICODE_STRING NtName, - OUT PCWSTR *PartName, - OUT PRTL_RELATIVE_NAME_U RelativeName); - -extern NTSTATUS (WINAPI *func_RtlCreateSystemVolumeInformationFolder) - (PCUNICODE_STRING VolumeRootPath); - #define FSCTL_SET_PERSISTENT_VOLUME_STATE 0x90238 #define PERSISTENT_VOLUME_STATE_SHORT_NAME_CREATION_DISABLED 0x00000001 @@ -142,6 +41,73 @@ typedef struct _FILE_FS_PERSISTENT_VOLUME_INFORMATION { ULONG Reserved; } FILE_FS_PERSISTENT_VOLUME_INFORMATION, *PFILE_FS_PERSISTENT_VOLUME_INFORMATION; +/* ntdll functions */ + +NTSTATUS +NTAPI +NtReadFile(IN HANDLE FileHandle, + IN HANDLE Event OPTIONAL, + IN PIO_APC_ROUTINE ApcRoutine OPTIONAL, + IN PVOID ApcContext OPTIONAL, + OUT PIO_STATUS_BLOCK IoStatusBlock, + OUT PVOID Buffer, + IN ULONG Length, + IN PLARGE_INTEGER ByteOffset OPTIONAL, + IN PULONG Key OPTIONAL); + +NTSTATUS +NTAPI +NtWriteFile(IN HANDLE FileHandle, + IN HANDLE Event OPTIONAL, + IN PIO_APC_ROUTINE ApcRoutine OPTIONAL, + IN PVOID ApcContext OPTIONAL, + OUT PIO_STATUS_BLOCK IoStatusBlock, + IN PVOID Buffer, + IN ULONG Length, + IN PLARGE_INTEGER ByteOffset OPTIONAL, + IN PULONG Key OPTIONAL); + +NTSTATUS +NTAPI +NtQueryDirectoryFile(IN HANDLE FileHandle, + IN HANDLE EventHandle OPTIONAL, + IN PIO_APC_ROUTINE ApcRoutine OPTIONAL, + IN PVOID ApcContext OPTIONAL, + OUT PIO_STATUS_BLOCK IoStatusBlock, + OUT PVOID FileInformation, + IN ULONG Length, + IN FILE_INFORMATION_CLASS FileInformationClass, + IN BOOLEAN ReturnSingleEntry, + IN PUNICODE_STRING FileName OPTIONAL, + IN BOOLEAN RestartScan); + +NTSTATUS +NTAPI +NtQuerySecurityObject(IN HANDLE Handle, + IN SECURITY_INFORMATION SecurityInformation, + OUT PSECURITY_DESCRIPTOR SecurityDescriptor, + IN ULONG Length, + OUT PULONG ResultLength); + +NTSTATUS +NTAPI +NtSetSecurityObject(IN HANDLE Handle, + IN SECURITY_INFORMATION SecurityInformation, + IN PSECURITY_DESCRIPTOR SecurityDescriptor); + +/* Dynamically loaded ntdll functions */ + +extern NTSTATUS (WINAPI *func_RtlDosPathNameToNtPathName_U_WithStatus) + (IN PCWSTR DosName, + OUT PUNICODE_STRING NtName, + OUT PCWSTR *PartName, + OUT PRTL_RELATIVE_NAME_U RelativeName); + +extern NTSTATUS (WINAPI *func_RtlCreateSystemVolumeInformationFolder) + (PCUNICODE_STRING VolumeRootPath); + +/* Other utility functions */ + extern int win32_path_to_nt_path(const wchar_t *win32_path, UNICODE_STRING *nt_path); diff --git a/src/wimboot.c b/src/wimboot.c index e8fecaf9..1650de99 100644 --- a/src/wimboot.c +++ b/src/wimboot.c @@ -586,7 +586,7 @@ retry: status = (*func_RtlCreateSystemVolumeInformationFolder)(&str); - err2 = (*func_RtlNtStatusToDosError)(status); + err2 = RtlNtStatusToDosError(status); if (err2 == ERROR_SUCCESS) { if (!already_retried) { already_retried = true; diff --git a/src/win32_apply.c b/src/win32_apply.c index afa11ac7..fbed6b9c 100644 --- a/src/win32_apply.c +++ b/src/win32_apply.c @@ -995,18 +995,18 @@ open_target_directory(struct win32_apply_ctx *ctx) /* Don't use FILE_OPEN_REPARSE_POINT here; we want the extraction to * happen at the directory "pointed to" by the reparse point. */ - status = (*func_NtCreateFile)(&ctx->h_target, - FILE_TRAVERSE, - &ctx->attr, - &ctx->iosb, - NULL, - 0, - FILE_SHARE_VALID_FLAGS, - FILE_OPEN_IF, - FILE_DIRECTORY_FILE | - FILE_OPEN_FOR_BACKUP_INTENT, - NULL, - 0); + status = NtCreateFile(&ctx->h_target, + FILE_TRAVERSE, + &ctx->attr, + &ctx->iosb, + NULL, + 0, + FILE_SHARE_VALID_FLAGS, + FILE_OPEN_IF, + FILE_DIRECTORY_FILE | + FILE_OPEN_FOR_BACKUP_INTENT, + NULL, + 0); if (!NT_SUCCESS(status)) { winnt_error(status, L"Can't open or create directory \"%ls\"", ctx->common.target); @@ -1021,7 +1021,7 @@ static void close_target_directory(struct win32_apply_ctx *ctx) { if (ctx->h_target) { - (*func_NtClose)(ctx->h_target); + NtClose(ctx->h_target); ctx->h_target = NULL; ctx->attr.RootDirectory = NULL; } @@ -1104,9 +1104,8 @@ adjust_compression_attribute(HANDLE h, const struct wim_dentry *dentry, /* Get current attributes */ - status = (*func_NtQueryInformationFile)(h, &ctx->iosb, - &info, sizeof(info), - FileBasicInformation); + status = NtQueryInformationFile(h, &ctx->iosb, &info, sizeof(info), + FileBasicInformation); if (NT_SUCCESS(status) && compressed == !!(info.FileAttributes & FILE_ATTRIBUTE_COMPRESSED)) { @@ -1192,10 +1191,10 @@ remove_conflicting_short_name(const struct wim_dentry *dentry, struct win32_appl ctx->pathbuf.Length = ((u8 *)end - (u8 *)ctx->pathbuf.Buffer); /* Open the conflicting file (by short name). */ - status = (*func_NtOpenFile)(&h, GENERIC_WRITE | DELETE, - &ctx->attr, &ctx->iosb, - FILE_SHARE_VALID_FLAGS, - FILE_OPEN_REPARSE_POINT | FILE_OPEN_FOR_BACKUP_INTENT); + status = NtOpenFile(&h, GENERIC_WRITE | DELETE, + &ctx->attr, &ctx->iosb, + FILE_SHARE_VALID_FLAGS, + FILE_OPEN_REPARSE_POINT | FILE_OPEN_FOR_BACKUP_INTENT); if (!NT_SUCCESS(status)) { winnt_warning(status, L"Can't open \"%ls\"", current_path(ctx)); goto out; @@ -1209,8 +1208,8 @@ remove_conflicting_short_name(const struct wim_dentry *dentry, struct win32_appl /* Try to remove the short name on the conflicting file. */ retry: - status = (*func_NtSetInformationFile)(h, &ctx->iosb, info, bufsize, - FileShortNameInformation); + status = NtSetInformationFile(h, &ctx->iosb, info, bufsize, + FileShortNameInformation); if (status == STATUS_INVALID_PARAMETER && !retried) { @@ -1228,7 +1227,7 @@ retry: retried = true; goto retry; } - (*func_NtClose)(h); + NtClose(h); out: build_extraction_path(dentry, ctx); return status; @@ -1278,8 +1277,8 @@ set_short_name(HANDLE h, const struct wim_dentry *dentry, memcpy(info->FileName, dentry->d_short_name, dentry->d_short_name_nbytes); retry: - status = (*func_NtSetInformationFile)(h, &ctx->iosb, info, bufsize, - FileShortNameInformation); + status = NtSetInformationFile(h, &ctx->iosb, info, bufsize, + FileShortNameInformation); if (NT_SUCCESS(status)) return 0; @@ -1356,19 +1355,19 @@ do_create_file(PHANDLE FileHandle, ULONG CreateOptions, struct win32_apply_ctx *ctx) { - return (*func_NtCreateFile)(FileHandle, - DesiredAccess | SYNCHRONIZE, - &ctx->attr, - &ctx->iosb, - AllocationSize, - FileAttributes, - FILE_SHARE_VALID_FLAGS, - CreateDisposition, - CreateOptions | - FILE_OPEN_FOR_BACKUP_INTENT | - FILE_OPEN_REPARSE_POINT, - NULL, - 0); + return NtCreateFile(FileHandle, + DesiredAccess | SYNCHRONIZE, + &ctx->attr, + &ctx->iosb, + AllocationSize, + FileAttributes, + FILE_SHARE_VALID_FLAGS, + CreateDisposition, + CreateOptions | + FILE_OPEN_FOR_BACKUP_INTENT | + FILE_OPEN_REPARSE_POINT, + NULL, + 0); } /* Like do_create_file(), but builds the extraction path of the @dentry first. @@ -1429,33 +1428,31 @@ retry: FILE_BASIC_INFORMATION basic_info = { .FileAttributes = FILE_ATTRIBUTE_NORMAL }; - status = (*func_NtSetInformationFile)(h, &ctx->iosb, - &basic_info, - sizeof(basic_info), - FileBasicInformation); + status = NtSetInformationFile(h, &ctx->iosb, &basic_info, + sizeof(basic_info), + FileBasicInformation); if (!NT_SUCCESS(status)) { winnt_error(status, L"Can't reset attributes of \"%ls\" " "to prepare for deletion", current_path(ctx)); - (*func_NtClose)(h); + NtClose(h); return WIMLIB_ERR_SET_ATTRIBUTES; } FILE_DISPOSITION_INFORMATION disp_info = { .DoDeleteFile = TRUE }; - status = (*func_NtSetInformationFile)(h, &ctx->iosb, - &disp_info, - sizeof(disp_info), - FileDispositionInformation); + status = NtSetInformationFile(h, &ctx->iosb, &disp_info, + sizeof(disp_info), + FileDispositionInformation); if (!NT_SUCCESS(status)) { winnt_error(status, L"Can't set delete-on-close " "disposition on \"%ls\"", current_path(ctx)); - (*func_NtClose)(h); + NtClose(h); return WIMLIB_ERR_SET_ATTRIBUTES; } } - status = (*func_NtClose)(h); + status = NtClose(h); if (unlikely(!NT_SUCCESS(status))) { winnt_error(status, L"Error closing \"%ls\" after setting " "delete-on-close disposition", current_path(ctx)); @@ -1524,7 +1521,7 @@ do_set_reparse_point(const struct wim_dentry *dentry, status = winnt_fsctl(h, FSCTL_SET_REPARSE_POINT, rpbuf, rpbuflen, NULL, 0, NULL); - (*func_NtClose)(h); + NtClose(h); if (NT_SUCCESS(status)) return 0; @@ -1598,7 +1595,7 @@ create_empty_streams(const struct wim_dentry *dentry, if (ret) return ret; - (*func_NtClose)(h); + NtClose(h); } } @@ -1676,9 +1673,9 @@ retry: if (!(ctx->common.extract_flags & WIMLIB_EXTRACT_FLAG_NO_ATTRIBUTES)) { FILE_BASIC_INFORMATION basic_info = { .FileAttributes = FILE_ATTRIBUTE_NORMAL }; - (*func_NtSetInformationFile)(h, &ctx->iosb, &basic_info, - sizeof(basic_info), - FileBasicInformation); + NtSetInformationFile(h, &ctx->iosb, &basic_info, + sizeof(basic_info), + FileBasicInformation); } /* Also try to remove the directory's DACL. This isn't supposed @@ -1696,8 +1693,8 @@ retry: .Sacl = 0, .Dacl = 0, }; - (*func_NtSetSecurityObject)(h, DACL_SECURITY_INFORMATION, - (void *)&desc); + NtSetSecurityObject(h, DACL_SECURITY_INFORMATION, + (void *)&desc); } } @@ -1709,7 +1706,7 @@ retry: ret = adjust_compression_attribute(h, dentry, ctx); out: - (*func_NtClose)(h); + NtClose(h); return ret; } @@ -1784,7 +1781,7 @@ create_nondirectory_inode(HANDLE *h_ret, const struct wim_dentry *dentry, return 0; out_close: - (*func_NtClose)(h); + NtClose(h); out: return ret; } @@ -1817,9 +1814,8 @@ create_link(HANDLE h, const struct wim_dentry *dentry, * STATUS_INFO_LENGTH_MISMATCH when FileNameLength * happens to be 2 */ - status = (*func_NtSetInformationFile)(h, &ctx->iosb, - info, bufsize, - FileLinkInformation); + status = NtSetInformationFile(h, &ctx->iosb, info, bufsize, + FileLinkInformation); if (NT_SUCCESS(status)) return 0; winnt_error(status, L"Failed to create link \"%ls\"", @@ -1833,7 +1829,7 @@ create_link(HANDLE h, const struct wim_dentry *dentry, if (ret) return ret; - (*func_NtClose)(h2); + NtClose(h2); return 0; } } @@ -1890,7 +1886,7 @@ create_nondirectory(struct wim_inode *inode, struct win32_apply_ctx *ctx) if (!ret && unlikely(ctx->common.extract_flags & WIMLIB_EXTRACT_FLAG_WIMBOOT)) ret = set_backed_from_wim(h, inode, ctx); - (*func_NtClose)(h); + NtClose(h); return ret; } @@ -1925,7 +1921,7 @@ static void close_handles(struct win32_apply_ctx *ctx) { for (unsigned i = 0; i < ctx->num_open_handles; i++) - (*func_NtClose)(ctx->open_handles[i]); + NtClose(ctx->open_handles[i]); } /* Prepare to read the next blob, which has size @blob_size, into an in-memory @@ -2027,9 +2023,8 @@ begin_extract_blob_instance(const struct blob_descriptor *blob, /* Allocate space for the data. */ alloc_info.AllocationSize.QuadPart = blob->size; - (*func_NtSetInformationFile)(h, &ctx->iosb, - &alloc_info, sizeof(alloc_info), - FileAllocationInformation); + NtSetInformationFile(h, &ctx->iosb, &alloc_info, sizeof(alloc_info), + FileAllocationInformation); return 0; } @@ -2318,10 +2313,10 @@ extract_chunk(const void *chunk, size_t size, void *_ctx) while (bytes_remaining) { ULONG count = min(0xFFFFFFFF, bytes_remaining); - status = (*func_NtWriteFile)(ctx->open_handles[i], - NULL, NULL, NULL, - &ctx->iosb, bufptr, count, - NULL, NULL); + status = NtWriteFile(ctx->open_handles[i], + NULL, NULL, NULL, + &ctx->iosb, bufptr, count, + NULL, NULL); if (!NT_SUCCESS(status)) { winnt_error(status, L"Error writing data to target volume"); return WIMLIB_ERR_WRITE; @@ -2527,7 +2522,7 @@ retry: } } - (*func_NtClose)(h); + NtClose(h); return status; } @@ -2758,7 +2753,7 @@ set_security_descriptor(HANDLE h, const void *_desc, */ retry: - status = (*func_NtSetSecurityObject)(h, info, desc); + status = NtSetSecurityObject(h, info, desc); if (NT_SUCCESS(status)) goto out_maybe_free_desc; @@ -2845,9 +2840,8 @@ do_apply_metadata_to_file(HANDLE h, const struct wim_inode *inode, info.FileAttributes = FILE_ATTRIBUTE_NORMAL; } - status = (*func_NtSetInformationFile)(h, &ctx->iosb, - &info, sizeof(info), - FileBasicInformation); + status = NtSetInformationFile(h, &ctx->iosb, &info, sizeof(info), + FileBasicInformation); /* On FAT volumes we get STATUS_INVALID_PARAMETER if we try to set * attributes on the root directory. (Apparently because FAT doesn't * actually have a place to store those attributes!) */ @@ -2905,7 +2899,7 @@ apply_metadata_to_file(const struct wim_dentry *dentry, ret = do_apply_metadata_to_file(h, inode, ctx); - (*func_NtClose)(h); + NtClose(h); return ret; } diff --git a/src/win32_capture.c b/src/win32_capture.c index 4bc0f7c2..06a5f343 100644 --- a/src/win32_capture.c +++ b/src/win32_capture.c @@ -269,8 +269,8 @@ winnt_openat(HANDLE cur_dir, const wchar_t *path, size_t path_nchars, options |= FILE_SEQUENTIAL_ONLY; } retry: - status = (*func_NtOpenFile)(h_ret, perms, &attr, &iosb, - FILE_SHARE_VALID_FLAGS, options); + status = NtOpenFile(h_ret, perms, &attr, &iosb, + FILE_SHARE_VALID_FLAGS, options); if (!NT_SUCCESS(status)) { /* Try requesting fewer permissions */ if (status == STATUS_ACCESS_DENIED || @@ -332,14 +332,14 @@ read_winnt_stream_prefix(const struct windows_file *file, u64 bytes_remaining; int ret; - status = (*func_NtOpenFile)(&h, FILE_READ_DATA | SYNCHRONIZE, - &attr, &iosb, - FILE_SHARE_VALID_FLAGS, - FILE_OPEN_REPARSE_POINT | - FILE_OPEN_FOR_BACKUP_INTENT | - FILE_SYNCHRONOUS_IO_NONALERT | - FILE_SEQUENTIAL_ONLY | - (file->is_file_id ? FILE_OPEN_BY_FILE_ID : 0)); + status = NtOpenFile(&h, FILE_READ_DATA | SYNCHRONIZE, + &attr, &iosb, + FILE_SHARE_VALID_FLAGS, + FILE_OPEN_REPARSE_POINT | + FILE_OPEN_FOR_BACKUP_INTENT | + FILE_SYNCHRONOUS_IO_NONALERT | + FILE_SEQUENTIAL_ONLY | + (file->is_file_id ? FILE_OPEN_BY_FILE_ID : 0)); if (unlikely(!NT_SUCCESS(status))) { if (status == STATUS_SHARING_VIOLATION) { ERROR("Can't open %ls for reading:\n" @@ -365,8 +365,8 @@ read_winnt_stream_prefix(const struct windows_file *file, count = min(sizeof(buf), bytes_remaining); retry_read: - status = (*func_NtReadFile)(h, NULL, NULL, NULL, - &iosb, buf, count, NULL, NULL); + status = NtReadFile(h, NULL, NULL, NULL, + &iosb, buf, count, NULL, NULL); if (unlikely(!NT_SUCCESS(status))) { if (status == STATUS_END_OF_FILE) { ERROR("%ls: File was concurrently truncated", @@ -404,7 +404,7 @@ read_winnt_stream_prefix(const struct windows_file *file, if (ret) break; } - (*func_NtClose)(h); + NtClose(h); return ret; } @@ -512,8 +512,8 @@ winnt_get_short_name(HANDLE h, struct wim_dentry *dentry) u8 buf[128] _aligned_attribute(8); const FILE_NAME_INFORMATION *info; - status = (*func_NtQueryInformationFile)(h, &iosb, buf, sizeof(buf), - FileAlternateNameInformation); + status = NtQueryInformationFile(h, &iosb, buf, sizeof(buf), + FileAlternateNameInformation); info = (const FILE_NAME_INFORMATION *)buf; if (NT_SUCCESS(status) && info->FileNameLength != 0) { dentry->d_short_name = utf16le_dupz(info->FileName, @@ -594,11 +594,11 @@ winnt_load_security_descriptor(HANDLE h, struct wim_inode *inode, * ntdll function and therefore not officially part of the Win32 API. * Oh well. */ - while (!(NT_SUCCESS(status = (*func_NtQuerySecurityObject)(h, - requestedInformation, - (PSECURITY_DESCRIPTOR)buf, - bufsize, - &len_needed)))) + while (!NT_SUCCESS(status = NtQuerySecurityObject(h, + requestedInformation, + (PSECURITY_DESCRIPTOR)buf, + bufsize, + &len_needed))) { switch (status) { case STATUS_BUFFER_TOO_SMALL: @@ -685,10 +685,10 @@ winnt_recurse_directory(HANDLE h, /* Using NtQueryDirectoryFile() we can re-use the same open handle, * which we opened with FILE_FLAG_BACKUP_SEMANTICS. */ - while (NT_SUCCESS(status = (*func_NtQueryDirectoryFile)(h, NULL, NULL, NULL, - &iosb, buf, bufsize, - FileNamesInformation, - FALSE, NULL, FALSE))) + while (NT_SUCCESS(status = NtQueryDirectoryFile(h, NULL, NULL, NULL, + &iosb, buf, bufsize, + FileNamesInformation, + FALSE, NULL, FALSE))) { const FILE_NAMES_INFORMATION *info = buf; for (;;) { @@ -756,18 +756,17 @@ file_has_ino_and_dev(HANDLE h, u64 ino, u64 dev) FILE_INTERNAL_INFORMATION int_info; FILE_FS_VOLUME_INFORMATION vol_info; - status = (*func_NtQueryInformationFile)(h, &iosb, - &int_info, sizeof(int_info), - FileInternalInformation); + status = NtQueryInformationFile(h, &iosb, &int_info, sizeof(int_info), + FileInternalInformation); if (!NT_SUCCESS(status)) return false; if (int_info.IndexNumber.QuadPart != ino) return false; - status = (*func_NtQueryVolumeInformationFile)(h, &iosb, - &vol_info, sizeof(vol_info), - FileFsVolumeInformation); + status = NtQueryVolumeInformationFile(h, &iosb, + &vol_info, sizeof(vol_info), + FileFsVolumeInformation); if (!(NT_SUCCESS(status) || status == STATUS_BUFFER_OVERFLOW)) return false; @@ -839,17 +838,17 @@ winnt_relativize_link_target(const wchar_t *target, size_t target_nbytes, name.MaximumLength = name.Length; /* Try opening the file */ - status = (*func_NtOpenFile) (&h, - FILE_READ_ATTRIBUTES | FILE_TRAVERSE, - &attr, - &iosb, - FILE_SHARE_VALID_FLAGS, - FILE_OPEN_FOR_BACKUP_INTENT); + status = NtOpenFile(&h, + FILE_READ_ATTRIBUTES | FILE_TRAVERSE, + &attr, + &iosb, + FILE_SHARE_VALID_FLAGS, + FILE_OPEN_FOR_BACKUP_INTENT); if (NT_SUCCESS(status)) { /* Reset root directory */ if (attr.RootDirectory) - (*func_NtClose)(attr.RootDirectory); + NtClose(attr.RootDirectory); attr.RootDirectory = h; name.Buffer = (wchar_t *)p; name.Length = 0; @@ -863,7 +862,7 @@ winnt_relativize_link_target(const wchar_t *target, size_t target_nbytes, out_close_root_dir: if (attr.RootDirectory) - (*func_NtClose)(attr.RootDirectory); + NtClose(attr.RootDirectory); while (p > target && *(p - 1) == L'\\') p--; return p; @@ -1197,11 +1196,11 @@ winnt_scan_data_streams(HANDLE h, const wchar_t *path, size_t path_nchars, goto unnamed_only; /* Get a buffer containing the stream information. */ - while (!NT_SUCCESS(status = (*func_NtQueryInformationFile)(h, - &iosb, - buf, - bufsize, - FileStreamInformation))) + while (!NT_SUCCESS(status = NtQueryInformationFile(h, + &iosb, + buf, + bufsize, + FileStreamInformation))) { switch (status) { @@ -1486,9 +1485,8 @@ get_file_info(HANDLE h, struct file_info *info) NTSTATUS status; FILE_ALL_INFORMATION all_info; - status = (*func_NtQueryInformationFile)(h, &iosb, &all_info, - sizeof(all_info), - FileAllInformation); + status = NtQueryInformationFile(h, &iosb, &all_info, sizeof(all_info), + FileAllInformation); if (unlikely(!NT_SUCCESS(status) && status != STATUS_BUFFER_OVERFLOW)) return status; @@ -1515,9 +1513,9 @@ get_volume_information(HANDLE h, const wchar_t *full_path, NTSTATUS status; /* Get volume flags */ - status = (*func_NtQueryVolumeInformationFile)(h, &iosb, attr_info, - sizeof(_attr_info), - FileFsAttributeInformation); + status = NtQueryVolumeInformationFile(h, &iosb, attr_info, + sizeof(_attr_info), + FileFsAttributeInformation); if (NT_SUCCESS(status)) { ctx->vol_flags = attr_info->FileSystemAttributes; ctx->is_ntfs = (attr_info->FileSystemNameLength == 4 * sizeof(wchar_t)) && @@ -1528,9 +1526,9 @@ get_volume_information(HANDLE h, const wchar_t *full_path, } /* Get volume ID. */ - status = (*func_NtQueryVolumeInformationFile)(h, &iosb, &vol_info, - sizeof(vol_info), - FileFsVolumeInformation); + status = NtQueryVolumeInformationFile(h, &iosb, &vol_info, + sizeof(vol_info), + FileFsVolumeInformation); if ((NT_SUCCESS(status) || status == STATUS_BUFFER_OVERFLOW) && (iosb.Information >= offsetof(FILE_FS_VOLUME_INFORMATION, VolumeSerialNumber) + @@ -1693,7 +1691,7 @@ winnt_build_dentry_tree_recursive(struct wim_dentry **root_ret, * ERROR_SHARING_VIOLATION if there are any open handles to the * file, we have to close the file and re-open it later if * needed. */ - (*func_NtClose)(h); + NtClose(h); h = NULL; ret = winnt_scan_efsrpc_raw_data(inode, full_path, full_path_nchars, ctx); @@ -1734,7 +1732,7 @@ winnt_build_dentry_tree_recursive(struct wim_dentry **root_ret, /* Re-open the directory with FILE_LIST_DIRECTORY access. */ if (h) { - (*func_NtClose)(h); + NtClose(h); h = NULL; } status = winnt_openat(cur_dir, relative_path, @@ -1763,7 +1761,7 @@ out_progress: ret = do_capture_progress(ctx->params, WIMLIB_SCAN_DENTRY_EXCLUDED, NULL); out: if (likely(h)) - (*func_NtClose)(h); + NtClose(h); if (unlikely(ret)) { free_dentry_tree(root, ctx->params->blob_table); root = NULL; @@ -2400,7 +2398,7 @@ load_files_from_mft(const wchar_t *path, struct ntfs_inode_map *inode_map) ret = 0; out: FREE(out); - (*func_NtClose)(h); + NtClose(h); return ret; } @@ -2631,7 +2629,7 @@ generate_wim_structures_recursive(struct wim_dentry **root_ret, goto out; } ret = winnt_load_security_descriptor(h, inode, path, ctx); - (*func_NtClose)(h); + NtClose(h); if (ret) goto out; @@ -2848,7 +2846,7 @@ win32_build_dentry_tree(struct wim_dentry **root_ret, get_volume_information(h, path, &ctx); - (*func_NtClose)(h); + NtClose(h); #ifdef ENABLE_FAST_MFT_SCAN if (ctx.is_ntfs && !_wgetenv(L"WIMLIB_DISABLE_QUERY_FILE_LAYOUT")) { diff --git a/src/win32_common.c b/src/win32_common.c index 628f1f0b..086397ab 100644 --- a/src/win32_common.c +++ b/src/win32_common.c @@ -92,110 +92,6 @@ win32_release_capture_and_apply_privileges(void) /* ntdll.dll */ -NTSTATUS (WINAPI *func_NtCreateFile)(PHANDLE FileHandle, - ACCESS_MASK DesiredAccess, - POBJECT_ATTRIBUTES ObjectAttributes, - PIO_STATUS_BLOCK IoStatusBlock, - PLARGE_INTEGER AllocationSize, - ULONG FileAttributes, - ULONG ShareAccess, - ULONG CreateDisposition, - ULONG CreateOptions, - PVOID EaBuffer, - ULONG EaLength); - -NTSTATUS (WINAPI *func_NtOpenFile) (PHANDLE FileHandle, - ACCESS_MASK DesiredAccess, - POBJECT_ATTRIBUTES ObjectAttributes, - PIO_STATUS_BLOCK IoStatusBlock, - ULONG ShareAccess, - ULONG OpenOptions); - -NTSTATUS (WINAPI *func_NtReadFile) (HANDLE FileHandle, - HANDLE Event, - PIO_APC_ROUTINE ApcRoutine, - PVOID ApcContext, - PIO_STATUS_BLOCK IoStatusBlock, - PVOID Buffer, - ULONG Length, - PLARGE_INTEGER ByteOffset, - PULONG Key); - -NTSTATUS (WINAPI *func_NtWriteFile) (HANDLE FileHandle, - HANDLE Event, - PIO_APC_ROUTINE ApcRoutine, - PVOID ApcContext, - PIO_STATUS_BLOCK IoStatusBlock, - PVOID Buffer, - ULONG Length, - PLARGE_INTEGER ByteOffset, - PULONG Key); - -NTSTATUS (WINAPI *func_NtQueryInformationFile)(HANDLE FileHandle, - PIO_STATUS_BLOCK IoStatusBlock, - PVOID FileInformation, - ULONG Length, - FILE_INFORMATION_CLASS FileInformationClass); - -NTSTATUS (WINAPI *func_NtQuerySecurityObject)(HANDLE handle, - SECURITY_INFORMATION SecurityInformation, - PSECURITY_DESCRIPTOR SecurityDescriptor, - ULONG Length, - PULONG LengthNeeded); - -NTSTATUS (WINAPI *func_NtQueryDirectoryFile) (HANDLE FileHandle, - HANDLE Event, - PIO_APC_ROUTINE ApcRoutine, - PVOID ApcContext, - PIO_STATUS_BLOCK IoStatusBlock, - PVOID FileInformation, - ULONG Length, - FILE_INFORMATION_CLASS FileInformationClass, - BOOLEAN ReturnSingleEntry, - PUNICODE_STRING FileName, - BOOLEAN RestartScan); - -NTSTATUS (WINAPI *func_NtQueryVolumeInformationFile) (HANDLE FileHandle, - PIO_STATUS_BLOCK IoStatusBlock, - PVOID FsInformation, - ULONG Length, - FS_INFORMATION_CLASS FsInformationClass); - -NTSTATUS (WINAPI *func_NtSetInformationFile)(HANDLE FileHandle, - PIO_STATUS_BLOCK IoStatusBlock, - PVOID FileInformation, - ULONG Length, - FILE_INFORMATION_CLASS FileInformationClass); - -NTSTATUS (WINAPI *func_NtSetSecurityObject)(HANDLE Handle, - SECURITY_INFORMATION SecurityInformation, - PSECURITY_DESCRIPTOR SecurityDescriptor); - -static NTSTATUS (WINAPI *func_NtFsControlFile) (HANDLE FileHandle, - HANDLE Event, - PIO_APC_ROUTINE ApcRoutine, - PVOID ApcContext, - PIO_STATUS_BLOCK IoStatusBlock, - ULONG FsControlCode, - PVOID InputBuffer, - ULONG InputBufferLength, - PVOID OutputBuffer, - ULONG OutputBufferLength); - -static NTSTATUS (WINAPI *func_NtWaitForSingleObject) (HANDLE Handle, - BOOLEAN Alertable, - PLARGE_INTEGER Timeout); - -NTSTATUS (WINAPI *func_NtClose) (HANDLE Handle); - -DWORD (WINAPI *func_RtlNtStatusToDosError)(NTSTATUS status); - -BOOLEAN (WINAPI *func_RtlDosPathNameToNtPathName_U) - (IN PCWSTR DosName, - OUT PUNICODE_STRING NtName, - OUT PCWSTR *PartName, - OUT PRTL_RELATIVE_NAME_U RelativeName); - NTSTATUS (WINAPI *func_RtlDosPathNameToNtPathName_U_WithStatus) (IN PCWSTR DosName, OUT PUNICODE_STRING NtName, @@ -227,22 +123,7 @@ struct dll_spec { struct dll_spec ntdll_spec = { .name = L"ntdll.dll", .syms = { - DLL_SYM(NtCreateFile, true), - DLL_SYM(NtOpenFile, true), - DLL_SYM(NtReadFile, true), - DLL_SYM(NtWriteFile, true), - DLL_SYM(NtQueryInformationFile, true), - DLL_SYM(NtQuerySecurityObject, true), - DLL_SYM(NtQueryDirectoryFile, true), - DLL_SYM(NtQueryVolumeInformationFile, true), - DLL_SYM(NtSetInformationFile, true), - DLL_SYM(NtSetSecurityObject, true), - DLL_SYM(NtFsControlFile, true), - DLL_SYM(NtWaitForSingleObject, true), - DLL_SYM(NtClose, true), - DLL_SYM(RtlNtStatusToDosError, true), DLL_SYM(RtlCreateSystemVolumeInformationFolder, false), - DLL_SYM(RtlDosPathNameToNtPathName_U, true), DLL_SYM(RtlDosPathNameToNtPathName_U_WithStatus, false), /* Not present on XP */ {NULL, NULL}, }, @@ -351,8 +232,7 @@ win32_path_to_nt_path(const wchar_t *win32_path, UNICODE_STRING *nt_path) nt_path, NULL, NULL); } else { - if ((*func_RtlDosPathNameToNtPathName_U)(win32_path, nt_path, - NULL, NULL)) + if (RtlDosPathNameToNtPathName_U(win32_path, nt_path, NULL, NULL)) status = STATUS_SUCCESS; else status = STATUS_NO_MEMORY; @@ -549,14 +429,13 @@ winnt_fsctl(HANDLE h, u32 code, const void *in, u32 in_size, IO_STATUS_BLOCK iosb; NTSTATUS status; - status = (*func_NtFsControlFile)(h, NULL, NULL, NULL, &iosb, code, - (void *)in, in_size, - out, out_size_avail); + status = NtFsControlFile(h, NULL, NULL, NULL, &iosb, code, + (void *)in, in_size, out, out_size_avail); if (status == STATUS_PENDING) { /* Beware: this case is often encountered with remote * filesystems, but rarely with local filesystems. */ - status = (*func_NtWaitForSingleObject)(h, FALSE, NULL); + status = NtWaitForSingleObject(h, FALSE, NULL); if (NT_SUCCESS(status)) { status = iosb.Status; } else { -- 2.43.0