mirror of
https://github.com/nefarius/ViGEmBus.git
synced 2025-08-10 00:52:17 +00:00
Hardened device type checks
Removed obsolete code
This commit is contained in:
@@ -540,6 +540,11 @@ bool ViGEm::Bus::Core::EmulationTargetPDO::GetPdoBySerial(
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ViGEm::Bus::Core::EmulationTargetPDO::GetPdoByTypeAndSerial(IN WDFDEVICE ParentDevice, IN VIGEM_TARGET_TYPE Type, IN ULONG SerialNo, OUT EmulationTargetPDO** Object)
|
||||
{
|
||||
return (GetPdoBySerial(ParentDevice, SerialNo, Object) && (*Object)->GetType() == Type);
|
||||
}
|
||||
|
||||
NTSTATUS ViGEm::Bus::Core::EmulationTargetPDO::EvtDevicePrepareHardware(
|
||||
_In_ WDFDEVICE Device,
|
||||
_In_ WDFCMRESLIST ResourcesRaw,
|
||||
|
||||
@@ -53,8 +53,13 @@ namespace ViGEm::Bus::Core
|
||||
EmulationTargetPDO(ULONG Serial, LONG SessionId, USHORT VendorId, USHORT ProductId);
|
||||
|
||||
virtual ~EmulationTargetPDO() = default;
|
||||
|
||||
static bool GetPdoBySerial(IN WDFDEVICE ParentDevice, IN ULONG SerialNo, OUT EmulationTargetPDO** Object);
|
||||
|
||||
static bool GetPdoByTypeAndSerial(
|
||||
IN WDFDEVICE ParentDevice,
|
||||
IN VIGEM_TARGET_TYPE Type,
|
||||
IN ULONG SerialNo,
|
||||
OUT EmulationTargetPDO** Object
|
||||
);
|
||||
|
||||
virtual NTSTATUS PdoPrepareDevice(PWDFDEVICE_INIT DeviceInit,
|
||||
PUNICODE_STRING DeviceId,
|
||||
@@ -110,6 +115,12 @@ namespace ViGEm::Bus::Core
|
||||
|
||||
static EVT_WDF_DEVICE_CONTEXT_CLEANUP EvtDeviceContextCleanup;
|
||||
|
||||
static bool GetPdoBySerial(
|
||||
IN WDFDEVICE ParentDevice,
|
||||
IN ULONG SerialNo,
|
||||
OUT EmulationTargetPDO** Object
|
||||
);
|
||||
|
||||
protected:
|
||||
static const ULONG _maxHardwareIdLength = 0xFF;
|
||||
|
||||
|
||||
@@ -162,7 +162,7 @@ VOID Bus_EvtIoDeviceControl(
|
||||
break;
|
||||
}
|
||||
|
||||
if (!EmulationTargetPDO::GetPdoBySerial(Device, xusbSubmit->SerialNo, &pdo))
|
||||
if (!EmulationTargetPDO::GetPdoByTypeAndSerial(Device, Xbox360Wired, xusbSubmit->SerialNo, &pdo))
|
||||
status = STATUS_DEVICE_DOES_NOT_EXIST;
|
||||
else
|
||||
status = pdo->SubmitReport(xusbSubmit);
|
||||
@@ -217,7 +217,14 @@ VOID Bus_EvtIoDeviceControl(
|
||||
break;
|
||||
}
|
||||
|
||||
status = Bus_QueueNotification(Device, xusbNotify->SerialNo, Request);
|
||||
if (!EmulationTargetPDO::GetPdoByTypeAndSerial(Device, Xbox360Wired, xusbNotify->SerialNo, &pdo))
|
||||
status = STATUS_DEVICE_DOES_NOT_EXIST;
|
||||
else
|
||||
{
|
||||
status = pdo->EnqueueNotification(Request);
|
||||
|
||||
status = (NT_SUCCESS(status)) ? STATUS_PENDING : status;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -259,7 +266,7 @@ VOID Bus_EvtIoDeviceControl(
|
||||
break;
|
||||
}
|
||||
|
||||
if (!EmulationTargetPDO::GetPdoBySerial(Device, ds4Submit->SerialNo, &pdo))
|
||||
if (!EmulationTargetPDO::GetPdoByTypeAndSerial(Device, DualShock4Wired, ds4Submit->SerialNo, &pdo))
|
||||
status = STATUS_DEVICE_DOES_NOT_EXIST;
|
||||
else
|
||||
status = pdo->SubmitReport(ds4Submit);
|
||||
@@ -314,7 +321,14 @@ VOID Bus_EvtIoDeviceControl(
|
||||
break;
|
||||
}
|
||||
|
||||
status = Bus_QueueNotification(Device, ds4Notify->SerialNo, Request);
|
||||
if (!EmulationTargetPDO::GetPdoByTypeAndSerial(Device, DualShock4Wired, ds4Notify->SerialNo, &pdo))
|
||||
status = STATUS_DEVICE_DOES_NOT_EXIST;
|
||||
else
|
||||
{
|
||||
status = pdo->EnqueueNotification(Request);
|
||||
|
||||
status = (NT_SUCCESS(status)) ? STATUS_PENDING : status;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -355,21 +369,12 @@ VOID Bus_EvtIoDeviceControl(
|
||||
break;
|
||||
}
|
||||
|
||||
if (!EmulationTargetPDO::GetPdoBySerial(Device, pXusbGetUserIndex->SerialNo, &pdo))
|
||||
if (!EmulationTargetPDO::GetPdoByTypeAndSerial(Device, Xbox360Wired, pXusbGetUserIndex->SerialNo, &pdo))
|
||||
{
|
||||
status = STATUS_DEVICE_DOES_NOT_EXIST;
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
// Poor man's RTTI check
|
||||
//
|
||||
if (pdo->GetType() != Xbox360Wired)
|
||||
{
|
||||
status = STATUS_INVALID_DEVICE_REQUEST;
|
||||
break;
|
||||
}
|
||||
|
||||
status = static_cast<EmulationTargetXUSB*>(pdo)->GetUserIndex(&pXusbGetUserIndex->UserIndex);
|
||||
}
|
||||
|
||||
|
||||
@@ -367,71 +367,3 @@ EXTERN_C NTSTATUS Bus_UnPlugDevice(
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
//
|
||||
// Sends a report update to an XUSB PDO.
|
||||
//
|
||||
EXTERN_C NTSTATUS Bus_XusbSubmitReport(WDFDEVICE Device, ULONG SerialNo, PXUSB_SUBMIT_REPORT Report, BOOLEAN FromInterface)
|
||||
{
|
||||
TraceEvents(TRACE_LEVEL_VERBOSE, TRACE_BUSENUM, "%!FUNC! Entry");
|
||||
|
||||
return Bus_SubmitReport(Device, SerialNo, Report, FromInterface);
|
||||
}
|
||||
|
||||
//
|
||||
// Queues an inverted call to receive XUSB-specific updates.
|
||||
//
|
||||
EXTERN_C NTSTATUS Bus_QueueNotification(WDFDEVICE Device, ULONG SerialNo, WDFREQUEST Request)
|
||||
{
|
||||
NTSTATUS status;
|
||||
EmulationTargetPDO* pdo;
|
||||
|
||||
TraceDbg(TRACE_BUSENUM, "%!FUNC! Entry");
|
||||
|
||||
// Validate child
|
||||
if (!EmulationTargetPDO::GetPdoBySerial(Device, SerialNo, &pdo))
|
||||
{
|
||||
TraceEvents(TRACE_LEVEL_ERROR,
|
||||
TRACE_BUSENUM,
|
||||
"PDO with serial %d not found",
|
||||
SerialNo);
|
||||
return STATUS_NO_SUCH_DEVICE;
|
||||
}
|
||||
|
||||
status = pdo->EnqueueNotification(Request);
|
||||
|
||||
status = (NT_SUCCESS(status)) ? STATUS_PENDING : status;
|
||||
|
||||
TraceDbg(TRACE_BUSENUM, "%!FUNC! Exit with status %!STATUS!", status);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
//
|
||||
// Sends a report update to a DS4 PDO.
|
||||
//
|
||||
NTSTATUS Bus_Ds4SubmitReport(WDFDEVICE Device, ULONG SerialNo, PDS4_SUBMIT_REPORT Report, BOOLEAN FromInterface)
|
||||
{
|
||||
TraceEvents(TRACE_LEVEL_VERBOSE, TRACE_BUSENUM, "%!FUNC! Entry");
|
||||
|
||||
return Bus_SubmitReport(Device, SerialNo, Report, FromInterface);
|
||||
}
|
||||
|
||||
EXTERN_C NTSTATUS Bus_SubmitReport(WDFDEVICE Device, ULONG SerialNo, PVOID Report, BOOLEAN FromInterface)
|
||||
{
|
||||
EmulationTargetPDO* pdo;
|
||||
|
||||
UNREFERENCED_PARAMETER(FromInterface);
|
||||
|
||||
// Validate child
|
||||
if (!EmulationTargetPDO::GetPdoBySerial(Device, SerialNo, &pdo))
|
||||
{
|
||||
TraceEvents(TRACE_LEVEL_ERROR,
|
||||
TRACE_BUSENUM,
|
||||
"PDO with serial %d not found",
|
||||
SerialNo);
|
||||
return STATUS_NO_SUCH_DEVICE;
|
||||
}
|
||||
|
||||
return pdo->SubmitReport(Report);
|
||||
}
|
||||
|
||||
@@ -102,29 +102,6 @@ Bus_UnPlugDevice(
|
||||
_Out_ size_t* Transferred
|
||||
);
|
||||
|
||||
NTSTATUS
|
||||
Bus_QueueNotification(
|
||||
WDFDEVICE Device,
|
||||
ULONG SerialNo,
|
||||
WDFREQUEST Request
|
||||
);
|
||||
|
||||
NTSTATUS
|
||||
Bus_SubmitReport(
|
||||
WDFDEVICE Device,
|
||||
ULONG SerialNo,
|
||||
PVOID Report,
|
||||
_In_ BOOLEAN FromInterface
|
||||
);
|
||||
|
||||
VOID
|
||||
Bus_PdoStageResult(
|
||||
_In_ PINTERFACE InterfaceHeader,
|
||||
_In_ VIGEM_PDO_STAGE Stage,
|
||||
_In_ ULONG Serial,
|
||||
_In_ NTSTATUS Status
|
||||
);
|
||||
|
||||
#pragma endregion
|
||||
|
||||
EXTERN_C_END
|
||||
|
||||
Reference in New Issue
Block a user