diff --git a/sys/Ds4Pdo.cpp b/sys/Ds4Pdo.cpp index b82e770..a6b226a 100644 --- a/sys/Ds4Pdo.cpp +++ b/sys/Ds4Pdo.cpp @@ -24,6 +24,7 @@ * SOFTWARE. */ +#include #include "Ds4Pdo.hpp" #include "trace.h" #include "Ds4Pdo.tmh" @@ -32,7 +33,6 @@ #include - PCWSTR ViGEm::Bus::Targets::EmulationTargetDS4::_deviceDescription = L"Virtual DualShock 4 Controller"; ViGEm::Bus::Targets::EmulationTargetDS4::EmulationTargetDS4(ULONG Serial, LONG SessionId, USHORT VendorId, @@ -1127,6 +1127,41 @@ NTSTATUS ViGEm::Bus::Targets::EmulationTargetDS4::SubmitReportImpl(PVOID NewRepo return status; } +VOID ViGEm::Bus::Targets::EmulationTargetDS4::ReverseByteArray(PUCHAR Array, INT Length) +{ + const auto s = static_cast(ExAllocatePoolWithTag( + NonPagedPool, + sizeof(UCHAR) * Length, + 'U4SD' + )); + INT c, d; + + if (s == nullptr) + return; + + for (c = Length - 1, d = 0; c >= 0; c--, d++) + *(s + d) = *(Array + c); + + for (c = 0; c < Length; c++) + *(Array + c) = *(s + c); + + ExFreePoolWithTag(s, 'U4SD'); +} + +VOID ViGEm::Bus::Targets::EmulationTargetDS4::GenerateRandomMacAddress(PMAC_ADDRESS Address) +{ + // Vendor "C0:13:37" + Address->Vendor0 = 0xC0; + Address->Vendor1 = 0x13; + Address->Vendor2 = 0x37; + + ULONG seed = KeQueryPerformanceCounter(NULL).LowPart; + + Address->Nic0 = RtlRandomEx(&seed) % 0xFF; + Address->Nic1 = RtlRandomEx(&seed) % 0xFF; + Address->Nic2 = RtlRandomEx(&seed) % 0xFF; +} + VOID ViGEm::Bus::Targets::EmulationTargetDS4::PendingUsbRequestsTimerFunc( _In_ WDFTIMER Timer ) diff --git a/sys/Ds4Pdo.hpp b/sys/Ds4Pdo.hpp index 918f7a2..9a8d5db 100644 --- a/sys/Ds4Pdo.hpp +++ b/sys/Ds4Pdo.hpp @@ -29,11 +29,22 @@ #include "EmulationTargetPDO.hpp" #include -#include "Util.h" - namespace ViGEm::Bus::Targets { + // + // Represents a MAC address. + // + typedef struct _MAC_ADDRESS + { + UCHAR Vendor0; + UCHAR Vendor1; + UCHAR Vendor2; + UCHAR Nic0; + UCHAR Nic1; + UCHAR Nic2; + } MAC_ADDRESS, * PMAC_ADDRESS; + constexpr unsigned char hid_get_report_id(struct _URB_CONTROL_VENDOR_OR_CLASS_REQUEST* pReq) { return pReq->Value & 0xFF; @@ -126,5 +137,9 @@ namespace ViGEm::Bus::Targets MAC_ADDRESS _HostMacAddress; static EVT_WDF_TIMER PendingUsbRequestsTimerFunc; + + static VOID ReverseByteArray(PUCHAR Array, INT Length); + + static VOID GenerateRandomMacAddress(PMAC_ADDRESS Address); }; } diff --git a/sys/Util.h b/sys/Util.h deleted file mode 100644 index 958333a..0000000 --- a/sys/Util.h +++ /dev/null @@ -1,49 +0,0 @@ -/* -* Virtual Gamepad Emulation Framework - Windows kernel-mode bus driver -* -* MIT License -* -* Copyright (c) 2016-2020 Nefarius Software Solutions e.U. and Contributors -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all -* copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ - - -#pragma once - -// -// Represents a MAC address. -// -typedef struct _MAC_ADDRESS -{ - UCHAR Vendor0; - UCHAR Vendor1; - UCHAR Vendor2; - UCHAR Nic0; - UCHAR Nic1; - UCHAR Nic2; -} MAC_ADDRESS, *PMAC_ADDRESS; - - -EXTERN_C_START - -VOID ReverseByteArray(PUCHAR Array, INT Length); -VOID GenerateRandomMacAddress(PMAC_ADDRESS Address); - -EXTERN_C_END diff --git a/sys/ViGEmBus.vcxproj b/sys/ViGEmBus.vcxproj index ce0016e..bd58440 100644 --- a/sys/ViGEmBus.vcxproj +++ b/sys/ViGEmBus.vcxproj @@ -194,7 +194,6 @@ - @@ -207,7 +206,6 @@ - diff --git a/sys/ViGEmBus.vcxproj.filters b/sys/ViGEmBus.vcxproj.filters index 100aa27..66f8fd6 100644 --- a/sys/ViGEmBus.vcxproj.filters +++ b/sys/ViGEmBus.vcxproj.filters @@ -39,9 +39,6 @@ Header Files - - Header Files - Header Files\Common @@ -71,9 +68,6 @@ - - Source Files - Source Files\Targets diff --git a/sys/busenum.h b/sys/busenum.h index 6381911..4f452ad 100644 --- a/sys/busenum.h +++ b/sys/busenum.h @@ -39,13 +39,11 @@ #include "Queue.hpp" #include #include -#include "Util.h" #pragma region Macros -#define VIGEM_POOL_TAG 0x45476956 // "EGiV" #define DRIVERNAME "ViGEm: " #pragma endregion diff --git a/sys/util.c b/sys/util.c deleted file mode 100644 index 7dc7379..0000000 --- a/sys/util.c +++ /dev/null @@ -1,62 +0,0 @@ -/* -* Virtual Gamepad Emulation Framework - Windows kernel-mode bus driver -* -* MIT License -* -* Copyright (c) 2016-2020 Nefarius Software Solutions e.U. and Contributors -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all -* copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ - - -#include -#include "busenum.h" -#include "util.tmh" - - -VOID ReverseByteArray(PUCHAR Array, INT Length) -{ - PUCHAR s = (PUCHAR)ExAllocatePoolWithTag(NonPagedPool, sizeof(UCHAR) * Length, VIGEM_POOL_TAG); - INT c, d; - - if (s == NULL) - return; - - for (c = Length - 1, d = 0; c >= 0; c--, d++) - *(s + d) = *(Array + c); - - for (c = 0; c < Length; c++) - *(Array + c) = *(s + c); - - ExFreePoolWithTag(s, VIGEM_POOL_TAG); -} - -VOID GenerateRandomMacAddress(PMAC_ADDRESS Address) -{ - // Vendor "C0:13:37" - Address->Vendor0 = 0xC0; - Address->Vendor1 = 0x13; - Address->Vendor2 = 0x37; - - ULONG seed = KeQueryPerformanceCounter(NULL).LowPart; - - Address->Nic0 = RtlRandomEx(&seed) % 0xFF; - Address->Nic1 = RtlRandomEx(&seed) % 0xFF; - Address->Nic2 = RtlRandomEx(&seed) % 0xFF; -}