From 6d7b25a3385063936dac3bfdffd007ad50fdce0a Mon Sep 17 00:00:00 2001 From: gibbed Date: Mon, 20 Jan 2014 06:08:24 -0800 Subject: [PATCH] Minor corrections to NtCreateFile, NtQueryDirectory. --- src/xenia/kernel/xboxkrnl_io.cc | 27 ++++++++++++++------------- src/xenia/xbox.h | 2 +- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/xenia/kernel/xboxkrnl_io.cc b/src/xenia/kernel/xboxkrnl_io.cc index 09b48431e..0efe28e4e 100644 --- a/src/xenia/kernel/xboxkrnl_io.cc +++ b/src/xenia/kernel/xboxkrnl_io.cc @@ -66,7 +66,8 @@ SHIM_CALL NtCreateFile_shim( Entry* entry; XFile* root_file = NULL; - if (attrs.root_directory != 0xFFFFFFFD) { // ObDosDevices + if (attrs.root_directory != 0xFFFFFFFD && // ObDosDevices + attrs.root_directory != 0) { result = state->object_table()->GetObject( attrs.root_directory, (XObject**)&root_file); XEASSERT(XSUCCEEDED(result)); @@ -130,7 +131,7 @@ SHIM_CALL NtOpenFile_shim( char* object_name = attrs.object_name.Duplicate(); XELOGD( - "watNtOpenFile(%.8X, %.8X, %.8X(%s), %.8X, %d)", + "NtOpenFile(%.8X, %.8X, %.8X(%s), %.8X, %d)", handle_ptr, desired_access, object_attributes_ptr, @@ -512,11 +513,17 @@ SHIM_CALL NtQueryDirectoryFile_shim( uint32_t file_info_ptr = SHIM_GET_ARG_32(5); uint32_t length = SHIM_GET_ARG_32(6); uint32_t file_name_ptr = SHIM_GET_ARG_32(7); - uint64_t sp = ppc_state->r[1]; + uint32_t sp = (uint32_t)ppc_state->r[1]; uint32_t restart_scan = SHIM_MEM_32(sp + 0x54); + char* file_name = NULL; + if (file_name_ptr != 0) { + X_ANSI_STRING xas(SHIM_MEM_BASE, file_name_ptr); + file_name = xas.Duplicate(); + } + XELOGD( - "NtQueryDirectoryFile(%.8X, %.8X, %.8X, %.8X, %.8X, %.8X, %d, %.8X, %d)", + "NtQueryDirectoryFile(%.8X, %.8X, %.8X, %.8X, %.8X, %.8X, %d, %.8X(%s), %d)", file_handle, event_handle, apc_routine, @@ -525,22 +532,15 @@ SHIM_CALL NtQueryDirectoryFile_shim( file_info_ptr, length, file_name_ptr, + !file_name ? "(null)" : file_name, restart_scan); if (length < 72) { SHIM_SET_RETURN_32(X_STATUS_INFO_LENGTH_MISMATCH); + xe_free(file_name); return; } - const char* file_name = NULL; - if (file_name_ptr != 0) { - // it's a PANSI_STRING or whatever. - if (SHIM_MEM_16(file_name_ptr + 0) != 0 || - SHIM_MEM_16(file_name_ptr + 2) != 0) { - file_name = (const char*)SHIM_MEM_ADDR(SHIM_MEM_32(file_name_ptr + 4)); - } - } - X_STATUS result = X_STATUS_UNSUCCESSFUL; uint32_t info = 0; @@ -569,6 +569,7 @@ SHIM_CALL NtQueryDirectoryFile_shim( file->Release(); } + xe_free(file_name); SHIM_SET_RETURN_32(result); } diff --git a/src/xenia/xbox.h b/src/xenia/xbox.h index f86b7b426..ebf2f816f 100644 --- a/src/xenia/xbox.h +++ b/src/xenia/xbox.h @@ -211,7 +211,7 @@ public: buffer = 0; } char* Duplicate() { - if (buffer == NULL) { + if (buffer == NULL || length == 0) { return NULL; } auto copy = (char*)xe_calloc(length+1);