2023-01-03 05:35:53 +01:00
|
|
|
#include <windows.h>
|
|
|
|
#include <cfgmgr32.h>
|
2023-01-07 06:52:08 +01:00
|
|
|
#include <usbioctl.h>
|
2023-01-03 05:35:53 +01:00
|
|
|
|
2023-01-07 06:52:08 +01:00
|
|
|
#include "hook/table.h"
|
|
|
|
#include "hook/iohook.h"
|
|
|
|
#include "hooklib/setupapi.h"
|
|
|
|
|
|
|
|
#include "util/dprintf.h"
|
|
|
|
#include "util/str.h"
|
|
|
|
#include "es3sec.h"
|
|
|
|
|
2023-03-10 08:46:37 +01:00
|
|
|
#define DONGLE_STR_IDX_MANUFACTURER 1
|
|
|
|
#define DONGLE_STR_IDX_PRODUCT 2
|
|
|
|
#define DONGLE_STR_IDX_SERIAL_NUMBER 3
|
|
|
|
|
2023-01-26 03:09:38 +01:00
|
|
|
static const wchar_t DEVNAME_HUB[] = L"$hub";
|
|
|
|
static const wchar_t DEVNAME_HUB_[] = L"\\\\.\\$hub";
|
|
|
|
static const wchar_t DEVNAME_DONGLE[] = L"$dongle";
|
2023-03-10 08:46:37 +01:00
|
|
|
static const wchar_t HUB_HCD_DRIVER_KEY[] = L"{36fc9e60-c465-11cf-8056-444553540000}\\0001";
|
|
|
|
// This is what a real dongle is set to
|
|
|
|
static const wchar_t HUB_NODE_CONNECTION_DRIVER_KEY[] = L"{c8b76578-d062-4834-0001-f8b6f2162a22}\\0003";
|
2023-01-26 03:09:38 +01:00
|
|
|
static const wchar_t root_hub_name[] = L"Fake Root Hub";
|
2023-03-10 08:46:37 +01:00
|
|
|
static const wchar_t FILLER_LANGIDS[] = L"\uffff\uffff";
|
2023-01-26 03:09:38 +01:00
|
|
|
static const DEVINST HUB_DEVINST = 573;
|
|
|
|
static const DEVINST DONGLE_DEVINST = 5730;
|
2023-01-07 06:52:08 +01:00
|
|
|
static struct es3sec_config config;
|
|
|
|
static HANDLE dongle_fd;
|
|
|
|
static HANDLE hub_fd;
|
|
|
|
static IID hubs_iid;
|
2023-01-26 03:09:38 +01:00
|
|
|
static DEVINST root_dev_inst;
|
|
|
|
static USHORT dongle_vid;
|
|
|
|
static USHORT dongle_pid;
|
2023-03-10 08:46:37 +01:00
|
|
|
static wchar_t dongle_mftr[MAX_PATH];
|
|
|
|
static wchar_t dongle_product[MAX_PATH];
|
2023-01-07 06:52:08 +01:00
|
|
|
|
|
|
|
static HRESULT es3sec_handle_hub_irp(struct irp *irp);
|
|
|
|
static HRESULT es3sec_handle_hub_open(struct irp *irp);
|
|
|
|
static HRESULT es3sec_handle_hub_close(struct irp *irp);
|
|
|
|
static HRESULT es3sec_handle_hub_ioctl(struct irp *irp);
|
|
|
|
|
|
|
|
static HRESULT es3sec_hub_handle_driverkey(struct irp *irp);
|
2023-01-26 03:09:38 +01:00
|
|
|
static HRESULT es3sec_hub_handle_roothub(struct irp *irp);
|
|
|
|
static HRESULT es3sec_hub_handle_nodeinfo(struct irp *irp);
|
|
|
|
static HRESULT es3sec_hub_connection_info_ex(struct irp *irp);
|
|
|
|
static HRESULT es3sec_hub_descriptor_from_node(struct irp *irp);
|
2023-03-10 08:46:37 +01:00
|
|
|
static HRESULT es3sec_hub_connection_driver_key_name(struct irp *irp);
|
|
|
|
static HRESULT es3sec_hub_get_config_descriptor(struct irp *irp, PUSB_DESCRIPTOR_REQUEST req, UCHAR dataRequested);
|
|
|
|
static HRESULT es3sec_hub_get_string_descriptor(struct irp *irp, PUSB_DESCRIPTOR_REQUEST req, UCHAR dataRequested);
|
2023-01-07 06:52:08 +01:00
|
|
|
|
|
|
|
static CONFIGRET my_CM_Get_Child(PDEVINST pdnDevInst, DEVINST dnDevInst, ULONG ulFlags);
|
|
|
|
static CONFIGRET (*next_CM_Get_Child)(PDEVINST pdnDevInst, DEVINST dnDevInst, ULONG ulFlags);
|
|
|
|
|
|
|
|
static CONFIGRET my_CM_Get_DevNode_Registry_PropertyW(
|
|
|
|
DEVINST dnDevInst,
|
|
|
|
ULONG ulProperty,
|
|
|
|
PULONG pulRegDataType,
|
|
|
|
PVOID Buffer,
|
|
|
|
PULONG pulLength,
|
|
|
|
ULONG ulFlags
|
|
|
|
);
|
|
|
|
static CONFIGRET (*next_CM_Get_DevNode_Registry_PropertyW)(
|
|
|
|
DEVINST dnDevInst,
|
|
|
|
ULONG ulProperty,
|
|
|
|
PULONG pulRegDataType,
|
|
|
|
PVOID Buffer,
|
|
|
|
PULONG pulLength,
|
|
|
|
ULONG ulFlags
|
|
|
|
);
|
|
|
|
|
|
|
|
static const struct hook_symbol cm_syms[] = {
|
|
|
|
{
|
|
|
|
.name = "CM_Get_DevNode_Registry_PropertyW",
|
|
|
|
.patch = my_CM_Get_DevNode_Registry_PropertyW,
|
|
|
|
.link = (void **) &next_CM_Get_DevNode_Registry_PropertyW
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "CM_Get_Child",
|
|
|
|
.patch = my_CM_Get_Child,
|
|
|
|
.link = (void **) &next_CM_Get_Child
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2023-03-22 04:47:06 +01:00
|
|
|
HRESULT es3sec_hook_init(
|
|
|
|
const struct es3sec_config *cfg,
|
|
|
|
USHORT vid,
|
|
|
|
USHORT pid,
|
|
|
|
const wchar_t *manufacturer,
|
|
|
|
const wchar_t *product)
|
2023-01-07 06:52:08 +01:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
assert(cfg != NULL);
|
|
|
|
|
|
|
|
if (!cfg->enable) {
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
IIDFromString(L"{3ABF6F2D-71C4-462a-8A92-1E6861E6AF27}", &hubs_iid);
|
|
|
|
setupapi_add_phantom_dev(&hubs_iid, DEVNAME_HUB);
|
|
|
|
|
|
|
|
hr = iohook_open_nul_fd(&dongle_fd);
|
|
|
|
hr = iohook_open_nul_fd(&hub_fd);
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = iohook_push_handler(es3sec_handle_hub_irp);
|
|
|
|
|
2023-03-10 08:46:37 +01:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2023-01-07 06:52:08 +01:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
hook_table_apply(NULL, "setupapi.dll", cm_syms, _countof(cm_syms));
|
|
|
|
|
|
|
|
CM_Locate_DevNodeW(&root_dev_inst, NULL, CM_LOCATE_DEVNODE_NORMAL);
|
|
|
|
|
2023-01-26 03:09:38 +01:00
|
|
|
dongle_vid = vid;
|
|
|
|
dongle_pid = pid;
|
2023-03-22 04:47:06 +01:00
|
|
|
wcscpy_s(dongle_mftr, _countof(dongle_mftr), manufacturer);
|
|
|
|
wcscpy_s(dongle_product, _countof(dongle_product), product); // Invalid param?
|
2023-01-07 06:52:08 +01:00
|
|
|
memcpy(&config, cfg, sizeof(*cfg));
|
2023-03-22 04:47:06 +01:00
|
|
|
|
|
|
|
dprintf("ES3 Dongle: init\tVID: %04X | PID: %04X | Manufacturer: %ls | Product: %ls | S/N: %ls\n",
|
|
|
|
vid,
|
|
|
|
pid,
|
|
|
|
dongle_mftr,
|
|
|
|
dongle_product,
|
|
|
|
config.serial);
|
|
|
|
|
2023-01-07 06:52:08 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT es3sec_handle_hub_irp(struct irp *irp)
|
|
|
|
{
|
|
|
|
assert(irp != NULL);
|
2023-03-10 08:46:37 +01:00
|
|
|
if (irp->op != IRP_OP_OPEN && irp->fd != hub_fd)
|
|
|
|
{
|
2023-01-07 06:52:08 +01:00
|
|
|
return iohook_invoke_next(irp);
|
|
|
|
}
|
|
|
|
|
2023-03-10 08:46:37 +01:00
|
|
|
switch (irp->op)
|
|
|
|
{
|
|
|
|
case IRP_OP_OPEN:
|
|
|
|
return es3sec_handle_hub_open(irp);
|
|
|
|
case IRP_OP_CLOSE:
|
|
|
|
return es3sec_handle_hub_close(irp);
|
|
|
|
case IRP_OP_IOCTL:
|
|
|
|
return es3sec_handle_hub_ioctl(irp);
|
|
|
|
default:
|
|
|
|
return HRESULT_FROM_WIN32(ERROR_INVALID_FUNCTION);
|
2023-01-07 06:52:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT es3sec_handle_hub_open(struct irp *irp)
|
|
|
|
{
|
2023-03-10 08:46:37 +01:00
|
|
|
if (!wstr_ieq(irp->open_filename, DEVNAME_HUB) && !wstr_ieq(irp->open_filename, DEVNAME_HUB_))
|
|
|
|
{
|
2023-01-07 06:52:08 +01:00
|
|
|
return iohook_invoke_next(irp);
|
|
|
|
}
|
|
|
|
|
|
|
|
dprintf("ES3 Dongle: Open USB Hub\n");
|
|
|
|
irp->fd = hub_fd;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT es3sec_handle_hub_close(struct irp *irp)
|
|
|
|
{
|
|
|
|
dprintf("ES3 Dongle: Close Hub\n");
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT es3sec_handle_hub_ioctl(struct irp *irp)
|
|
|
|
{
|
|
|
|
switch (irp->ioctl) {
|
|
|
|
case 0x220424: return es3sec_hub_handle_driverkey(irp);
|
2023-01-26 03:09:38 +01:00
|
|
|
case 0x220448: return es3sec_hub_connection_info_ex(irp);
|
|
|
|
case 0x220410: return es3sec_hub_descriptor_from_node(irp);
|
2023-03-10 08:46:37 +01:00
|
|
|
case 0x220420: return es3sec_hub_connection_driver_key_name(irp);
|
|
|
|
case 0x220408:
|
2023-01-26 03:09:38 +01:00
|
|
|
if (irp->read.nbytes == sizeof(USB_NODE_INFORMATION))
|
|
|
|
return es3sec_hub_handle_nodeinfo(irp);
|
2023-03-10 08:46:37 +01:00
|
|
|
|
|
|
|
else if (irp->read.nbytes >= sizeof(USB_ROOT_HUB_NAME))
|
2023-01-26 03:09:38 +01:00
|
|
|
return es3sec_hub_handle_roothub(irp);
|
2023-03-10 08:46:37 +01:00
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dprintf("ES3 Dongle: Bad size for IOCTL %X\n", irp->ioctl);
|
2023-01-26 03:09:38 +01:00
|
|
|
return HRESULT_FROM_WIN32(ERROR_INVALID_FUNCTION);
|
|
|
|
}
|
|
|
|
|
2023-03-10 08:46:37 +01:00
|
|
|
default:
|
|
|
|
dprintf("ES3 Dongle: Unknown hub IOCTL %X\n", irp->ioctl);
|
|
|
|
return HRESULT_FROM_WIN32(ERROR_INVALID_FUNCTION);
|
2023-01-07 06:52:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT es3sec_hub_handle_driverkey(struct irp *irp)
|
2023-03-10 08:46:37 +01:00
|
|
|
{
|
|
|
|
size_t size_of_driver_key = sizeof(HUB_HCD_DRIVER_KEY);
|
2023-01-26 03:09:38 +01:00
|
|
|
ULONG actual_length = size_of_driver_key + sizeof(USB_ROOT_HUB_NAME);
|
|
|
|
HRESULT hr;
|
2023-03-10 08:46:37 +01:00
|
|
|
|
2023-03-22 04:47:06 +01:00
|
|
|
if (irp->write.nbytes == sizeof(USB_HCD_DRIVERKEY_NAME)) // Requesting key size
|
2023-03-10 08:46:37 +01:00
|
|
|
{
|
2023-01-26 03:09:38 +01:00
|
|
|
USB_HCD_DRIVERKEY_NAME usb_hcd_driver_key_name;
|
|
|
|
usb_hcd_driver_key_name.ActualLength = actual_length;
|
|
|
|
hr = iobuf_write(&irp->read, &usb_hcd_driver_key_name, sizeof(usb_hcd_driver_key_name));
|
2023-03-10 08:46:37 +01:00
|
|
|
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2023-03-22 04:47:06 +01:00
|
|
|
dprintf("ES3 Dongle: es3sec_hub_handle_driverkey iobuf_write failed! %lx\n", hr);
|
2023-01-26 03:09:38 +01:00
|
|
|
}
|
2023-03-10 08:46:37 +01:00
|
|
|
|
2023-01-26 03:09:38 +01:00
|
|
|
return hr;
|
|
|
|
}
|
2023-03-10 08:46:37 +01:00
|
|
|
|
2023-03-22 04:47:06 +01:00
|
|
|
// Requesting the key itself
|
2023-01-26 03:09:38 +01:00
|
|
|
PUSB_HCD_DRIVERKEY_NAME usb_hcd_driver_key_name = (PUSB_HCD_DRIVERKEY_NAME)malloc(sizeof(USB_HCD_DRIVERKEY_NAME) + actual_length);
|
2023-01-07 06:52:08 +01:00
|
|
|
usb_hcd_driver_key_name->ActualLength = actual_length;
|
2023-01-26 03:09:38 +01:00
|
|
|
|
2023-01-07 06:52:08 +01:00
|
|
|
errno_t err = wcscpy_s(
|
|
|
|
usb_hcd_driver_key_name->DriverKeyName,
|
2023-03-10 08:46:37 +01:00
|
|
|
_countof(HUB_HCD_DRIVER_KEY),
|
|
|
|
HUB_HCD_DRIVER_KEY);
|
2023-01-07 06:52:08 +01:00
|
|
|
|
2023-03-10 08:46:37 +01:00
|
|
|
if (err)
|
|
|
|
{
|
2023-01-07 06:52:08 +01:00
|
|
|
dprintf("ES3 Dongle: es3sec_hub_handle_driverkey wcscpy_s failed with %X", err);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2023-01-26 03:09:38 +01:00
|
|
|
hr = iobuf_write(&irp->read, usb_hcd_driver_key_name, actual_length);
|
2023-01-07 06:52:08 +01:00
|
|
|
|
2023-03-10 08:46:37 +01:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2023-03-22 04:47:06 +01:00
|
|
|
dprintf("ES3 Dongle: es3sec_hub_handle_driverkey iobuf_write failed! %lx\n", hr);
|
2023-01-26 03:09:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT es3sec_hub_handle_roothub(struct irp *irp)
|
|
|
|
{
|
|
|
|
size_t size_of_hub_name = sizeof(DEVNAME_HUB);
|
|
|
|
ULONG actual_length = size_of_hub_name + sizeof(USB_ROOT_HUB_NAME);
|
|
|
|
HRESULT hr;
|
|
|
|
|
2023-03-22 04:47:06 +01:00
|
|
|
if (irp->read.nbytes == sizeof(USB_ROOT_HUB_NAME)) { // Root hub name size
|
2023-01-26 03:09:38 +01:00
|
|
|
USB_ROOT_HUB_NAME rhub;
|
|
|
|
rhub.ActualLength = actual_length;
|
|
|
|
hr = iobuf_write(&irp->read, &rhub, sizeof(rhub));
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
2023-03-22 04:47:06 +01:00
|
|
|
dprintf("ES3 Dongle: es3sec_hub_handle_roothub iobuf_write failed! %lx\n", hr);
|
2023-01-26 03:09:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2023-03-22 04:47:06 +01:00
|
|
|
//Root hub name
|
2023-01-26 03:09:38 +01:00
|
|
|
PUSB_ROOT_HUB_NAME rhub = (PUSB_ROOT_HUB_NAME)malloc(actual_length);
|
|
|
|
rhub->ActualLength = actual_length;
|
|
|
|
|
|
|
|
errno_t err = wcscpy_s(
|
|
|
|
rhub->RootHubName,
|
|
|
|
_countof(DEVNAME_HUB),
|
|
|
|
DEVNAME_HUB
|
|
|
|
);
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
dprintf("ES3 Dongle: es3sec_hub_handle_roothub wcscpy_s failed with %X", err);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = iobuf_write(&irp->read, rhub, sizeof(USB_ROOT_HUB_NAME) + size_of_hub_name);
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
dprintf("ES3 Dongle: iobuf_write failed! %lx\n", hr);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT es3sec_hub_handle_nodeinfo(struct irp *irp)
|
|
|
|
{
|
|
|
|
USB_NODE_INFORMATION node_info;
|
|
|
|
node_info.NodeType = UsbHub;
|
|
|
|
node_info.u.HubInformation.HubDescriptor.bNumberOfPorts = 1;
|
|
|
|
HRESULT hr = iobuf_write(&irp->read, &node_info, sizeof(node_info));
|
|
|
|
|
2023-03-10 08:46:37 +01:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2023-01-26 03:09:38 +01:00
|
|
|
dprintf("ES3 Dongle: es3sec_hub_handle_nodeinfo iobuf_write failed! 0x%lX\n", hr);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT es3sec_hub_connection_info_ex(struct irp *irp)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
PUSB_NODE_CONNECTION_INFORMATION_EX conn_info = (PUSB_NODE_CONNECTION_INFORMATION_EX) malloc(irp->write.nbytes);
|
|
|
|
hr = iobuf_read(&irp->write, conn_info, irp->write.nbytes);
|
2023-03-27 10:05:45 +02:00
|
|
|
dprintf("ES3 Dongle: Get Hub connection Info EX\n");
|
2023-01-26 03:09:38 +01:00
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
dprintf("ES3 Dongle: es3sec_hub_connection_info_ex Failed to read IRP %lx\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
2023-03-10 08:46:37 +01:00
|
|
|
|
2023-01-26 03:09:38 +01:00
|
|
|
conn_info->ConnectionStatus = DeviceConnected;
|
|
|
|
conn_info->DeviceIsHub = false;
|
2023-03-10 08:46:37 +01:00
|
|
|
|
2023-01-26 03:09:38 +01:00
|
|
|
conn_info->DeviceDescriptor.idVendor = dongle_vid;
|
|
|
|
conn_info->DeviceDescriptor.idProduct = dongle_pid;
|
|
|
|
conn_info->DeviceDescriptor.bLength = sizeof(conn_info->DeviceDescriptor);
|
2023-03-10 08:46:37 +01:00
|
|
|
conn_info->DeviceDescriptor.iManufacturer = DONGLE_STR_IDX_MANUFACTURER;
|
|
|
|
conn_info->DeviceDescriptor.iProduct = DONGLE_STR_IDX_PRODUCT;
|
|
|
|
conn_info->DeviceDescriptor.iSerialNumber = DONGLE_STR_IDX_SERIAL_NUMBER;
|
2023-01-26 03:09:38 +01:00
|
|
|
|
|
|
|
hr = iobuf_write(&irp->read, conn_info, irp->read.nbytes);
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
dprintf("ES3 Dongle: es3sec_hub_connection_info_ex Failed to write IRP %lx\n", hr);
|
|
|
|
}
|
2023-03-10 08:46:37 +01:00
|
|
|
|
2023-01-26 03:09:38 +01:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT es3sec_hub_descriptor_from_node(struct irp *irp)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
UCHAR req_type;
|
|
|
|
UCHAR req_data_requested;
|
|
|
|
PUSB_DESCRIPTOR_REQUEST req = (PUSB_DESCRIPTOR_REQUEST) malloc(irp->write.nbytes);
|
2023-03-10 08:46:37 +01:00
|
|
|
|
2023-01-26 03:09:38 +01:00
|
|
|
hr = iobuf_read(&irp->write, req, irp->write.nbytes);
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
dprintf("ES3 Dongle: es3sec_hub_descriptor_from_node Failed to read IRP %lx\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
2023-03-10 08:46:37 +01:00
|
|
|
|
2023-01-26 03:09:38 +01:00
|
|
|
req_type = req->SetupPacket.wValue >> 8;
|
|
|
|
req_data_requested = req->SetupPacket.wValue & 0xFF;
|
2023-03-10 08:46:37 +01:00
|
|
|
|
2023-01-26 03:09:38 +01:00
|
|
|
switch (req_type) {
|
2023-03-10 08:46:37 +01:00
|
|
|
case USB_CONFIGURATION_DESCRIPTOR_TYPE:
|
|
|
|
return es3sec_hub_get_config_descriptor(irp, req, req_data_requested);
|
2023-03-22 04:47:06 +01:00
|
|
|
|
2023-03-10 08:46:37 +01:00
|
|
|
case USB_STRING_DESCRIPTOR_TYPE:
|
|
|
|
return es3sec_hub_get_string_descriptor(irp, req, req_data_requested);
|
2023-03-22 04:47:06 +01:00
|
|
|
|
2023-03-10 08:46:37 +01:00
|
|
|
default:
|
2023-01-26 03:09:38 +01:00
|
|
|
dprintf("ES3 Dongle: es3sec_hub_descriptor_from_node Unknown request type %x\n", req_type);
|
2023-03-10 08:46:37 +01:00
|
|
|
return HRESULT_FROM_WIN32(ERROR_INVALID_FUNCTION);
|
2023-01-26 03:09:38 +01:00
|
|
|
}
|
|
|
|
hr = iobuf_write(&irp->read, req, irp->read.nbytes);
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
dprintf("ES3 Dongle: es3sec_hub_descriptor_from_node Failed to write IRP %lx\n", hr);
|
|
|
|
}
|
|
|
|
return hr;
|
2023-01-07 06:52:08 +01:00
|
|
|
}
|
|
|
|
|
2023-03-10 08:46:37 +01:00
|
|
|
static HRESULT es3sec_hub_get_config_descriptor(struct irp *irp, PUSB_DESCRIPTOR_REQUEST req, UCHAR dataRequested)
|
2023-01-07 06:52:08 +01:00
|
|
|
{
|
2023-03-22 04:47:06 +01:00
|
|
|
dprintf("ES3 Dongle: Get Hub Config Descriptor from Node Connection\n");
|
2023-03-10 08:46:37 +01:00
|
|
|
|
|
|
|
PUSB_CONFIGURATION_DESCRIPTOR config = (PUSB_CONFIGURATION_DESCRIPTOR)malloc(sizeof(USB_CONFIGURATION_DESCRIPTOR));
|
|
|
|
config->bLength = sizeof(*config);
|
|
|
|
config->bDescriptorType = USB_CONFIGURATION_DESCRIPTOR_TYPE;
|
|
|
|
config->wTotalLength = sizeof(*req);
|
2023-01-07 06:52:08 +01:00
|
|
|
|
2023-03-10 08:46:37 +01:00
|
|
|
int cpy = memcpy_s(req->Data, 9, config, sizeof(*config));
|
|
|
|
if (cpy) {
|
|
|
|
dprintf("ES3 Dongle: es3sec_hub_get_config_descriptor memcpy_s failed %d\n", cpy);
|
2023-01-07 06:52:08 +01:00
|
|
|
}
|
2023-03-10 08:46:37 +01:00
|
|
|
return iobuf_write(&irp->read, req, irp->read.nbytes);
|
2023-01-07 06:52:08 +01:00
|
|
|
}
|
|
|
|
|
2023-03-10 08:46:37 +01:00
|
|
|
static HRESULT es3sec_hub_get_string_descriptor(struct irp *irp, PUSB_DESCRIPTOR_REQUEST req, UCHAR dataRequested)
|
2023-01-07 06:52:08 +01:00
|
|
|
{
|
2023-03-10 08:46:37 +01:00
|
|
|
PUSB_STRING_DESCRIPTOR str_desc;
|
|
|
|
int additional_length = sizeof(FILLER_LANGIDS);
|
|
|
|
str_desc = (PUSB_STRING_DESCRIPTOR)malloc(sizeof(USB_STRING_DESCRIPTOR) + additional_length);
|
|
|
|
str_desc->bDescriptorType = USB_STRING_DESCRIPTOR_TYPE;
|
|
|
|
wcscpy_s(str_desc->bString, _countof(FILLER_LANGIDS), FILLER_LANGIDS);
|
|
|
|
|
|
|
|
switch (dataRequested) {
|
|
|
|
case DONGLE_STR_IDX_MANUFACTURER:
|
2023-03-22 04:47:06 +01:00
|
|
|
dprintf("ES3 Dongle: Get Hub String Descriptor For Dongle Manufacturer\n");
|
2023-03-10 08:46:37 +01:00
|
|
|
additional_length = sizeof(dongle_mftr);
|
|
|
|
str_desc = (PUSB_STRING_DESCRIPTOR)realloc(str_desc, sizeof(USB_STRING_DESCRIPTOR) + additional_length);
|
|
|
|
str_desc->bDescriptorType = USB_STRING_DESCRIPTOR_TYPE;
|
|
|
|
wcscpy_s(str_desc->bString, _countof(dongle_mftr), dongle_mftr);
|
|
|
|
break;
|
2023-03-22 04:47:06 +01:00
|
|
|
|
2023-03-10 08:46:37 +01:00
|
|
|
case DONGLE_STR_IDX_PRODUCT:
|
2023-03-22 04:47:06 +01:00
|
|
|
dprintf("ES3 Dongle: Get Hub String Descriptor For Dongle Product Name\n");
|
2023-03-10 08:46:37 +01:00
|
|
|
additional_length = sizeof(dongle_product);
|
|
|
|
str_desc = (PUSB_STRING_DESCRIPTOR)realloc(str_desc, sizeof(USB_STRING_DESCRIPTOR) + additional_length);
|
|
|
|
str_desc->bDescriptorType = USB_STRING_DESCRIPTOR_TYPE;
|
|
|
|
wcscpy_s(str_desc->bString, _countof(dongle_product), dongle_product);
|
|
|
|
break;
|
2023-03-22 04:47:06 +01:00
|
|
|
|
2023-03-10 08:46:37 +01:00
|
|
|
case DONGLE_STR_IDX_SERIAL_NUMBER:
|
2023-03-22 04:47:06 +01:00
|
|
|
dprintf("ES3 Dongle: Get Hub String Descriptor For Dongle Serial Number\n");
|
2023-03-10 08:46:37 +01:00
|
|
|
additional_length = sizeof(L"000000000000");
|
|
|
|
str_desc = (PUSB_STRING_DESCRIPTOR)realloc(str_desc, sizeof(USB_STRING_DESCRIPTOR) + additional_length);
|
|
|
|
str_desc->bDescriptorType = USB_STRING_DESCRIPTOR_TYPE;
|
|
|
|
wcscpy_s(str_desc->bString, _countof(config.serial), config.serial);
|
|
|
|
break;
|
2023-01-07 06:52:08 +01:00
|
|
|
}
|
2023-03-10 08:46:37 +01:00
|
|
|
|
|
|
|
str_desc->bLength = sizeof(USB_STRING_DESCRIPTOR) + additional_length;
|
|
|
|
PUSB_DESCRIPTOR_REQUEST resp = (PUSB_DESCRIPTOR_REQUEST)malloc(sizeof(USB_DESCRIPTOR_REQUEST) + sizeof(USB_STRING_DESCRIPTOR) + additional_length);
|
2023-01-07 06:52:08 +01:00
|
|
|
|
2023-03-10 08:46:37 +01:00
|
|
|
int cpy = memcpy_s(resp->Data, sizeof(USB_STRING_DESCRIPTOR) + additional_length, str_desc, sizeof(USB_STRING_DESCRIPTOR) + additional_length);
|
|
|
|
if (cpy) {
|
|
|
|
dprintf("ES3 Dongle: es3sec_hub_get_config_descriptor memcpy_s failed %d\n", cpy);
|
|
|
|
}
|
|
|
|
return iobuf_write(&irp->read, resp, sizeof(USB_DESCRIPTOR_REQUEST) + sizeof(USB_STRING_DESCRIPTOR) + additional_length);
|
2023-01-07 06:52:08 +01:00
|
|
|
}
|
|
|
|
|
2023-03-10 08:46:37 +01:00
|
|
|
static HRESULT es3sec_hub_connection_driver_key_name(struct irp *irp)
|
2023-01-07 06:52:08 +01:00
|
|
|
{
|
2023-03-10 08:46:37 +01:00
|
|
|
size_t size_of_driver_key = sizeof(HUB_NODE_CONNECTION_DRIVER_KEY);
|
|
|
|
ULONG actual_length = size_of_driver_key + sizeof(USB_NODE_CONNECTION_DRIVERKEY_NAME);
|
|
|
|
HRESULT hr;
|
2023-01-07 06:52:08 +01:00
|
|
|
|
2023-03-10 08:46:37 +01:00
|
|
|
if (irp->write.nbytes == sizeof(USB_NODE_CONNECTION_DRIVERKEY_NAME))
|
|
|
|
{
|
|
|
|
dprintf("ES3 Dongle: Get Hub Connection Driver Key size\n");
|
|
|
|
USB_NODE_CONNECTION_DRIVERKEY_NAME usb_node_conn_driver_key_name;
|
|
|
|
usb_node_conn_driver_key_name.ActualLength = actual_length;
|
|
|
|
hr = iobuf_write(&irp->read, &usb_node_conn_driver_key_name, sizeof(usb_node_conn_driver_key_name));
|
|
|
|
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
dprintf("ES3 Dongle: iobuf_write failed! %lx\n", hr);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
dprintf("ES3 Dongle: Get Hub Connection Driver Key\n");
|
|
|
|
|
|
|
|
PUSB_NODE_CONNECTION_DRIVERKEY_NAME usb_node_conn_driver_key_name = (PUSB_NODE_CONNECTION_DRIVERKEY_NAME)malloc(sizeof(USB_NODE_CONNECTION_DRIVERKEY_NAME) + actual_length);
|
|
|
|
usb_node_conn_driver_key_name->ConnectionIndex = 1;
|
|
|
|
usb_node_conn_driver_key_name->ActualLength = actual_length;
|
|
|
|
|
|
|
|
errno_t err = wcscpy_s(
|
|
|
|
usb_node_conn_driver_key_name->DriverKeyName,
|
|
|
|
_countof(HUB_NODE_CONNECTION_DRIVER_KEY),
|
|
|
|
HUB_NODE_CONNECTION_DRIVER_KEY);
|
|
|
|
|
|
|
|
if (err)
|
|
|
|
{
|
|
|
|
dprintf("ES3 Dongle: es3sec_hub_connection_driver_key_name wcscpy_s failed with %X", err);
|
|
|
|
return E_FAIL;
|
2023-01-26 03:09:38 +01:00
|
|
|
}
|
2023-03-10 08:46:37 +01:00
|
|
|
|
|
|
|
hr = iobuf_write(&irp->read, usb_node_conn_driver_key_name, actual_length);
|
|
|
|
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
dprintf("ES3 Dongle: iobuf_write failed! %lx\n", hr);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
2023-01-07 06:52:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static CONFIGRET my_CM_Get_DevNode_Registry_PropertyW(
|
|
|
|
DEVINST dnDevInst,
|
|
|
|
ULONG ulProperty,
|
|
|
|
PULONG pulRegDataType,
|
|
|
|
PVOID Buffer,
|
|
|
|
PULONG pulLength,
|
2023-03-10 08:46:37 +01:00
|
|
|
ULONG ulFlags)
|
2023-01-07 06:52:08 +01:00
|
|
|
{
|
|
|
|
CONFIGRET cr = next_CM_Get_DevNode_Registry_PropertyW(dnDevInst, ulProperty, pulRegDataType, Buffer, pulLength, ulFlags);
|
2023-03-10 08:46:37 +01:00
|
|
|
if (dnDevInst != HUB_DEVINST)
|
|
|
|
{
|
2023-01-07 06:52:08 +01:00
|
|
|
return cr;
|
|
|
|
}
|
|
|
|
|
2023-03-10 08:46:37 +01:00
|
|
|
switch (ulProperty)
|
|
|
|
{
|
|
|
|
case CM_DRP_DEVICEDESC:
|
2023-03-22 04:47:06 +01:00
|
|
|
dprintf("ES3 Dongle: Get Hub Device Description\n");
|
2023-03-10 08:46:37 +01:00
|
|
|
wcscpy_s(Buffer, _countof(L"Fake USB Hub"), L"Fake USB Hub");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CM_DRP_DRIVER:
|
2023-03-22 04:47:06 +01:00
|
|
|
dprintf("ES3 Dongle: Get Hub Driver Key\n");
|
2023-03-10 08:46:37 +01:00
|
|
|
wcscpy_s(Buffer, _countof(HUB_HCD_DRIVER_KEY), HUB_HCD_DRIVER_KEY);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
dprintf("ES3 Dongle: my_CM_Get_DevNode_Registry_PropertyW Unhandled property 0x%lX\n", ulProperty);
|
|
|
|
return CR_FAILURE;
|
2023-01-07 06:52:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return CR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static CONFIGRET my_CM_Get_Child(PDEVINST pdnDevInst, DEVINST dnDevInst, ULONG ulFlags)
|
|
|
|
{
|
2023-03-10 08:46:37 +01:00
|
|
|
if (dnDevInst != root_dev_inst)
|
|
|
|
{
|
2023-01-07 06:52:08 +01:00
|
|
|
return next_CM_Get_Child(pdnDevInst, dnDevInst, ulFlags);
|
|
|
|
}
|
|
|
|
|
|
|
|
*pdnDevInst = HUB_DEVINST;
|
|
|
|
return CR_SUCCESS;
|
|
|
|
}
|