Reimplemented NtSetSystemTime and KeQuerySystemTime

This should allow setting the Xbox system time without interfering with
the host system time.
This commit is contained in:
PatrickvL 2016-12-10 17:51:26 +01:00
parent 4bae6b721d
commit a5199b9d3a
4 changed files with 39 additions and 12 deletions

View File

@ -76,6 +76,9 @@ volatile bool g_bEmuException = false;
volatile bool g_bEmuSuspended = false;
volatile bool g_bPrintfOn = true;
// Delta added to host SystemTime, used in xboxkrnl::KeQuerySystemTime and xboxkrnl::NtSetSystemTime
LARGE_INTEGER HostSystemTimeDelta = {};
// Static Function(s)
static int ExitException(LPEXCEPTION_POINTERS e);

View File

@ -83,6 +83,9 @@ extern int g_iThreadNotificationCount;
extern DWORD_PTR g_CPUXbox;
extern DWORD_PTR g_CPUOthers;
// Delta added to host SystemTime, used in xboxkrnl::KeQuerySystemTime and xboxkrnl::NtSetSystemTime
extern LARGE_INTEGER HostSystemTimeDelta;
// NOTE: this is an arbitrary latency
#define XINPUT_SETSTATE_LATENCY 4
#define XINPUT_SETSTATE_SLOTS 16
@ -102,4 +105,5 @@ g_pXInputSetStateStatus[XINPUT_SETSTATE_SLOTS];
extern HANDLE g_hInputHandle[XINPUT_HANDLE_SLOTS];
extern void InitializeSectionStructures(void);
#endif

View File

@ -313,13 +313,14 @@ XBSYSAPI EXPORTNUM(128) xboxkrnl::VOID NTAPI xboxkrnl::KeQuerySystemTime
{
LOG_FUNC_ONE_ARG(CurrentTime);
// TODO: optimize for WinXP if speed ever becomes important here
if (CurrentTime != NULL)
{
LARGE_INTEGER HostSystemTime;
GetSystemTimeAsFileTime((LPFILETIME)&HostSystemTime); // Available since Windows 2000 (NOT on XP!)
SYSTEMTIME SystemTime;
GetSystemTime(&SystemTime);
SystemTimeToFileTime(&SystemTime, (LPFILETIME)CurrentTime);
// Apply the delta set in xboxkrnl::NtSetSystemTime to get the Xbox system time :
CurrentTime->QuadPart = HostSystemTime.QuadPart + HostSystemTimeDelta.QuadPart;
}
}
// ******************************************************************

View File

@ -1808,7 +1808,7 @@ XBSYSAPI EXPORTNUM(211) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtQueryInformationFil
LOG_FUNC_ARG(FileInfo)
LOG_FUNC_END;
// TODO: IIRC, this function is depreciated. Maybe we should just use
// TODO: IIRC, this function is deprecated. Maybe we should just use
// ZwQueryInformationFile instead?
// if(FileInfo != FilePositionInformation && FileInfo != FileNetworkOpenInformation)
@ -2167,12 +2167,31 @@ XBSYSAPI EXPORTNUM(228) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtSetSystemTime
LOG_FUNC_ARG_OUT(PreviousTime)
LOG_FUNC_END;
// Maybe it's not such a good idea to allow Cxbx to change your time
// clock. Might need admin privileges to do this.... dunno.
// TODO -oDxbx: Surely, we won't set the system time here, but we CAN remember a delta (and apply that in KeQuerySystemTime)
LOG_UNIMPLEMENTED();
NTSTATUS ret = STATUS_SUCCESS; // TODO : Does Xbox returns STATUS_PRIVILEGE_NOT_HELD (supports SeSystemtimePrivlege)?
NTSTATUS ret = STATUS_SUCCESS;
if (PreviousTime == NULL && SystemTime == NULL)
ret = STATUS_ACCESS_VIOLATION;
else
{
// Surely, we won't set the system time here, but we CAN remember a delta to the host system time;
LARGE_INTEGER HostSystemTime;
GetSystemTimeAsFileTime((LPFILETIME)&HostSystemTime); // Available since Windows 2000 (NOT on XP!)
// Is the previous time requested?
if (PreviousTime != NULL)
// Apply current HostSystemTimeDelta, same as in xboxkrnl::KeQuerySystemTime :
PreviousTime->QuadPart = HostSystemTime.QuadPart + HostSystemTimeDelta.QuadPart;
// Is a new time given?
if (SystemTime != NULL)
{
if (SystemTime->QuadPart > 0)
// Calculate new HostSystemTimeDelta, to be used in xboxkrnl::KeQuerySystemTime :
HostSystemTimeDelta.QuadPart = HostSystemTime.QuadPart - SystemTime->QuadPart;
else
ret = STATUS_INVALID_PARAMETER;
}
}
RETURN(ret);
}