Updated conversion of object attributes

so that non-file API's do not try to map filenames.
Also used CxbxObjectAttributesToNT in more kernel functions.
This commit is contained in:
PatrickvL 2017-01-01 01:10:53 +01:00
parent 49969ea47d
commit 80eded53de
2 changed files with 45 additions and 66 deletions

View File

@ -317,34 +317,38 @@ NTSTATUS CxbxObjectAttributesToNT(
OUT NativeObjectAttributes& nativeObjectAttributes,
const std::string aFileAPIName)
{
NTSTATUS result = STATUS_SUCCESS;
std::string RelativeXboxPath;
std::wstring RelativeHostPath;
NtDll::HANDLE RootDirectory;
if (ObjectAttributes == NULL)
{
// When the pointer is nil, make sure we pass nil to Windows too :
nativeObjectAttributes.NtObjAttrPtr = NULL;
return result;
nativeObjectAttributes.NtObjAttrPtr = nullptr;
return STATUS_SUCCESS;
}
// Pick up the ObjectName, and let's see what to make of it :
std::string ObjectName = PSTRING_to_string(ObjectAttributes->ObjectName);
std::wstring RelativeHostPath;
NtDll::HANDLE RootDirectory = ObjectAttributes->RootDirectory;
// Is there a filename API given?
if (aFileAPIName.size() > 0)
{
// Then interpret the ObjectName as a filename, and update it to host relative :
NTSTATUS result = _CxbxConvertFilePath(ObjectName, /*OUT*/RelativeHostPath, /*OUT*/&RootDirectory, aFileAPIName);
if (FAILED(result))
return result;
}
else
// When not called from a file-handling API, just convert the ObjectName to a wide string :
RelativeHostPath = string_to_wstring(ObjectName);
// Copy the wide string to the unicode string
wcscpy_s(nativeObjectAttributes.wszObjectName, RelativeHostPath.c_str());
NtDll::RtlInitUnicodeString(&nativeObjectAttributes.NtUnicodeString, nativeObjectAttributes.wszObjectName);
// And initialize the NT ObjectAttributes with that :
InitializeObjectAttributes(&nativeObjectAttributes.NtObjAttr, &nativeObjectAttributes.NtUnicodeString, ObjectAttributes->Attributes, RootDirectory, NULL);
// ObjectAttributes are given, so make sure the pointer we're going to pass to Windows is assigned :
nativeObjectAttributes.NtObjAttrPtr = &nativeObjectAttributes.NtObjAttr;
RelativeXboxPath = PSTRING_to_string(ObjectAttributes->ObjectName);
result = _CxbxConvertFilePath(RelativeXboxPath, /*OUT*/RelativeHostPath, /*OUT*/&RootDirectory, aFileAPIName);
if (!FAILED(result))
{
// Copy relative path string to the unicode string
wcscpy_s(nativeObjectAttributes.wszObjectName, RelativeHostPath.c_str());
NtDll::RtlInitUnicodeString(&nativeObjectAttributes.NtUnicodeString, nativeObjectAttributes.wszObjectName);
// Initialize the NT ObjectAttributes
InitializeObjectAttributes(&nativeObjectAttributes.NtObjAttr, &nativeObjectAttributes.NtUnicodeString, ObjectAttributes->Attributes, RootDirectory, NULL);
}
return result;
return STATUS_SUCCESS;
}
int CxbxDeviceIndexByDevicePath(const char *XboxDevicePath)

View File

@ -232,23 +232,21 @@ XBSYSAPI EXPORTNUM(189) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtCreateEvent
// initialize object attributes
NativeObjectAttributes nativeObjectAttributes;
NTSTATUS ret = CxbxObjectAttributesToNT(ObjectAttributes, /*var*/nativeObjectAttributes);
CxbxObjectAttributesToNT(ObjectAttributes, /*var*/nativeObjectAttributes);
if (ret == STATUS_SUCCESS)
{
// TODO : Is this the correct ACCESS_MASK? :
const ACCESS_MASK DesiredAccess = EVENT_ALL_ACCESS;
// TODO : Is this the correct ACCESS_MASK? :
const ACCESS_MASK DesiredAccess = EVENT_ALL_ACCESS;
// redirect to Win2k/XP
ret = NtDll::NtCreateEvent(
/*OUT*/EventHandle,
DesiredAccess,
nativeObjectAttributes.NtObjAttrPtr,
(NtDll::EVENT_TYPE)EventType,
InitialState);
// TODO : Instead of the above, we should consider using the Ke*Event APIs, but
// that would require us to create the event's kernel object with the Ob* api's too!
}
// redirect to Win2k/XP
NTSTATUS ret = NtDll::NtCreateEvent(
/*OUT*/EventHandle,
DesiredAccess,
nativeObjectAttributes.NtObjAttrPtr,
(NtDll::EVENT_TYPE)EventType,
InitialState);
// TODO : Instead of the above, we should consider using the Ke*Event APIs, but
// that would require us to create the event's kernel object with the Ob* api's too!
if (FAILED(ret))
EmuWarning("NtCreateEvent Failed!");
@ -305,33 +303,9 @@ XBSYSAPI EXPORTNUM(192) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtCreateMutant
LOG_FUNC_ARG(InitialOwner)
LOG_FUNC_END;
char *szBuffer = (ObjectAttributes != NULL) ? ObjectAttributes->ObjectName->Buffer : nullptr;
wchar_t wszObjectName[MAX_PATH];
NtDll::UNICODE_STRING NtUnicodeString;
NtDll::OBJECT_ATTRIBUTES NtObjAttr;
// initialize object attributes
if (szBuffer != nullptr)
{
mbstowcs(/*Dest=*/wszObjectName, /*Source=*/DrivePrefix.c_str(), /*MaxCount=*/DrivePrefix.length());
mbstowcs(/*Dest=*/wszObjectName + DrivePrefix.length(), /*Source=*/szBuffer, /*MaxCount=*/MAX_PATH);
NtDll::RtlInitUnicodeString(&NtUnicodeString, wszObjectName);
InitializeObjectAttributes(&NtObjAttr, &NtUnicodeString, ObjectAttributes->Attributes, ObjectAttributes->RootDirectory, nullptr);
}
NtObjAttr.RootDirectory = 0;
// TODO : Replace above with :
//
// // initialize object attributes
// NativeObjectAttributes nativeObjectAttributes;
// NTSTATUS ret = CxbxObjectAttributesToNT(ObjectAttributes, /*var*/nativeObjectAttributes);
// if (ret == STATUS_SUCCESS)
// {
NativeObjectAttributes nativeObjectAttributes;
CxbxObjectAttributesToNT(ObjectAttributes, /*var*/nativeObjectAttributes);
// TODO : Is this the correct ACCESS_MASK? :
const ACCESS_MASK DesiredAccess = MUTANT_ALL_ACCESS;
@ -340,7 +314,7 @@ XBSYSAPI EXPORTNUM(192) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtCreateMutant
NTSTATUS ret = NtDll::NtCreateMutant(
/*OUT*/MutantHandle,
DesiredAccess,
(szBuffer != 0) ? &NtObjAttr : nullptr,
nativeObjectAttributes.NtObjAttrPtr,
InitialOwner);
if (FAILED(ret))
@ -372,13 +346,14 @@ XBSYSAPI EXPORTNUM(193) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtCreateSemaphore
// TODO : Is this the correct ACCESS_MASK? :
const ACCESS_MASK DesiredAccess = SEMAPHORE_ALL_ACCESS;
// TODO : Call CxbxObjectAttributesToNT on ObjectAttributes?
NativeObjectAttributes nativeObjectAttributes;
CxbxObjectAttributesToNT(ObjectAttributes, nativeObjectAttributes);
// redirect to Win2k/XP
NTSTATUS ret = NtDll::NtCreateSemaphore(
/*OUT*/SemaphoreHandle,
DesiredAccess,
(NtDll::POBJECT_ATTRIBUTES)ObjectAttributes,
(NtDll::POBJECT_ATTRIBUTES)nativeObjectAttributes.NtObjAttrPtr,
InitialCount,
MaximumCount);
@ -410,7 +385,7 @@ XBSYSAPI EXPORTNUM(194) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtCreateTimer
const ACCESS_MASK DesiredAccess = TIMER_ALL_ACCESS;
NativeObjectAttributes nativeObjectAttributes;
CxbxObjectAttributesToNT(ObjectAttributes, nativeObjectAttributes, "NtCreateTimer");
CxbxObjectAttributesToNT(ObjectAttributes, nativeObjectAttributes);
// redirect to Windows NT
// TODO : Untested
@ -418,7 +393,7 @@ XBSYSAPI EXPORTNUM(194) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtCreateTimer
(
/*OUT*/TimerHandle,
DesiredAccess,
(NtDll::POBJECT_ATTRIBUTES)&nativeObjectAttributes,
(NtDll::POBJECT_ATTRIBUTES)nativeObjectAttributes.NtObjAttrPtr,
(NtDll::TIMER_TYPE)TimerType
);