clean up logging, fix bad function args in es3sec

This commit is contained in:
Hay1tsme 2023-03-21 23:47:06 -04:00
parent cfde84b00b
commit aad6f5a922
7 changed files with 54 additions and 29 deletions

View File

@ -4,6 +4,9 @@
[vfs] [vfs]
path= path=
[dns]
default=localhost
; Security dongle emulation, disable if you have a ; Security dongle emulation, disable if you have a
; real dongle connected that you want to use ; real dongle connected that you want to use
[dongle] [dongle]

View File

@ -2,7 +2,7 @@
pushd %~dp0 pushd %~dp0
inject.exe -d -k ferrumhook.dll ferrum_app.exe inject.exe -d -k ferrumhook.dll ferrum_app.exe serverenv=production verboseLevel=0
echo. echo.
echo The game process has terminated echo The game process has terminated

View File

@ -3,6 +3,9 @@
[vfs] [vfs]
path= path=
[dns]
default=localhost
; Security dongle emulation, disable if you have a ; Security dongle emulation, disable if you have a
; real dongle connected that you want to use ; real dongle connected that you want to use
[dongle] [dongle]

View File

@ -36,10 +36,10 @@ static DWORD CALLBACK ferrum_pre_startup(void)
serial_hook_init(); serial_hook_init();
struct dongle_info dinfo; struct dongle_info dinfo;
dinfo.vid = 2970; dinfo.vid = 0x0B9A;
dinfo.pid = 3088; dinfo.pid = 0x0C10;
wcscpy_s(dinfo.manufacturer, _countof(L"BM"), L"BM"); wcscpy_s(dinfo.manufacturer, _countof(dinfo.manufacturer), L"BM");
wcscpy_s(dinfo.product, _countof(L"RUDI04GBN-274713"), L"RUDI04GBN-274713"); wcscpy_s(dinfo.product, _countof(dinfo.product), L"RUDI04GBN-274713");
hr = platform_hook_init(&ferrum_hook_cfg.platform, PLATFORM_ES3, ferrum_jvs_init, ferrum_hook_mod, dinfo); hr = platform_hook_init(&ferrum_hook_cfg.platform, PLATFORM_ES3, ferrum_jvs_init, ferrum_hook_mod, dinfo);

View File

@ -81,7 +81,12 @@ static const struct hook_symbol cm_syms[] = {
}, },
}; };
HRESULT es3sec_hook_init(const struct es3sec_config *cfg, USHORT vid, USHORT pid, wchar_t *manufacturer, wchar_t *product) HRESULT es3sec_hook_init(
const struct es3sec_config *cfg,
USHORT vid,
USHORT pid,
const wchar_t *manufacturer,
const wchar_t *product)
{ {
HRESULT hr; HRESULT hr;
assert(cfg != NULL); assert(cfg != NULL);
@ -111,13 +116,19 @@ HRESULT es3sec_hook_init(const struct es3sec_config *cfg, USHORT vid, USHORT pid
CM_Locate_DevNodeW(&root_dev_inst, NULL, CM_LOCATE_DEVNODE_NORMAL); CM_Locate_DevNodeW(&root_dev_inst, NULL, CM_LOCATE_DEVNODE_NORMAL);
dprintf("ES3 Dongle: init\tVID %x PID %x\n", vid, pid);
dongle_vid = vid; dongle_vid = vid;
dongle_pid = pid; dongle_pid = pid;
wcscpy_s(dongle_mftr, _countof(manufacturer), manufacturer); wcscpy_s(dongle_mftr, _countof(dongle_mftr), manufacturer);
wcscpy_s(dongle_product, _countof(product), product); wcscpy_s(dongle_product, _countof(dongle_product), product); // Invalid param?
memcpy(&config, cfg, sizeof(*cfg)); memcpy(&config, cfg, sizeof(*cfg));
dprintf("ES3 Dongle: init\tVID: %04X | PID: %04X | Manufacturer: %ls | Product: %ls | S/N: %ls\n",
vid,
pid,
dongle_mftr,
dongle_product,
config.serial);
return S_OK; return S_OK;
} }
@ -192,23 +203,21 @@ static HRESULT es3sec_hub_handle_driverkey(struct irp *irp)
ULONG actual_length = size_of_driver_key + sizeof(USB_ROOT_HUB_NAME); ULONG actual_length = size_of_driver_key + sizeof(USB_ROOT_HUB_NAME);
HRESULT hr; HRESULT hr;
if (irp->write.nbytes == sizeof(USB_HCD_DRIVERKEY_NAME)) if (irp->write.nbytes == sizeof(USB_HCD_DRIVERKEY_NAME)) // Requesting key size
{ {
dprintf("ES3 Dongle: Get Hub Driver Key size\n");
USB_HCD_DRIVERKEY_NAME usb_hcd_driver_key_name; USB_HCD_DRIVERKEY_NAME usb_hcd_driver_key_name;
usb_hcd_driver_key_name.ActualLength = actual_length; usb_hcd_driver_key_name.ActualLength = actual_length;
hr = iobuf_write(&irp->read, &usb_hcd_driver_key_name, sizeof(usb_hcd_driver_key_name)); hr = iobuf_write(&irp->read, &usb_hcd_driver_key_name, sizeof(usb_hcd_driver_key_name));
if (FAILED(hr)) if (FAILED(hr))
{ {
dprintf("ES3 Dongle: iobuf_write failed! %lx\n", hr); dprintf("ES3 Dongle: es3sec_hub_handle_driverkey iobuf_write failed! %lx\n", hr);
} }
return hr; return hr;
} }
dprintf("ES3 Dongle: Get Hub Driver Key\n"); // Requesting the key itself
PUSB_HCD_DRIVERKEY_NAME usb_hcd_driver_key_name = (PUSB_HCD_DRIVERKEY_NAME)malloc(sizeof(USB_HCD_DRIVERKEY_NAME) + actual_length); PUSB_HCD_DRIVERKEY_NAME usb_hcd_driver_key_name = (PUSB_HCD_DRIVERKEY_NAME)malloc(sizeof(USB_HCD_DRIVERKEY_NAME) + actual_length);
usb_hcd_driver_key_name->ActualLength = actual_length; usb_hcd_driver_key_name->ActualLength = actual_length;
@ -227,7 +236,7 @@ static HRESULT es3sec_hub_handle_driverkey(struct irp *irp)
if (FAILED(hr)) if (FAILED(hr))
{ {
dprintf("ES3 Dongle: iobuf_write failed! %lx\n", hr); dprintf("ES3 Dongle: es3sec_hub_handle_driverkey iobuf_write failed! %lx\n", hr);
} }
return hr; return hr;
@ -239,20 +248,19 @@ static HRESULT es3sec_hub_handle_roothub(struct irp *irp)
ULONG actual_length = size_of_hub_name + sizeof(USB_ROOT_HUB_NAME); ULONG actual_length = size_of_hub_name + sizeof(USB_ROOT_HUB_NAME);
HRESULT hr; HRESULT hr;
if (irp->read.nbytes == sizeof(USB_ROOT_HUB_NAME)) { if (irp->read.nbytes == sizeof(USB_ROOT_HUB_NAME)) { // Root hub name size
dprintf("ES3 Dongle: Get Hub Root Hub Name size\n");
USB_ROOT_HUB_NAME rhub; USB_ROOT_HUB_NAME rhub;
rhub.ActualLength = actual_length; rhub.ActualLength = actual_length;
hr = iobuf_write(&irp->read, &rhub, sizeof(rhub)); hr = iobuf_write(&irp->read, &rhub, sizeof(rhub));
if (FAILED(hr)) { if (FAILED(hr)) {
dprintf("ES3 Dongle: iobuf_write failed! %lx\n", hr); dprintf("ES3 Dongle: es3sec_hub_handle_roothub iobuf_write failed! %lx\n", hr);
} }
return hr; return hr;
} }
dprintf("ES3 Dongle: Get Hub Root Hub Name\n"); //Root hub name
PUSB_ROOT_HUB_NAME rhub = (PUSB_ROOT_HUB_NAME)malloc(actual_length); PUSB_ROOT_HUB_NAME rhub = (PUSB_ROOT_HUB_NAME)malloc(actual_length);
rhub->ActualLength = actual_length; rhub->ActualLength = actual_length;
@ -278,7 +286,6 @@ static HRESULT es3sec_hub_handle_roothub(struct irp *irp)
static HRESULT es3sec_hub_handle_nodeinfo(struct irp *irp) static HRESULT es3sec_hub_handle_nodeinfo(struct irp *irp)
{ {
dprintf("ES3 Dongle: Get Hub Node Information\n");
USB_NODE_INFORMATION node_info; USB_NODE_INFORMATION node_info;
node_info.NodeType = UsbHub; node_info.NodeType = UsbHub;
node_info.u.HubInformation.HubDescriptor.bNumberOfPorts = 1; node_info.u.HubInformation.HubDescriptor.bNumberOfPorts = 1;
@ -303,7 +310,6 @@ static HRESULT es3sec_hub_connection_info_ex(struct irp *irp)
return hr; return hr;
} }
dprintf("ES3 Dongle: Get Hub Connection Info EX\tConnectionIndex %ld\n", conn_info->ConnectionIndex);
conn_info->ConnectionStatus = DeviceConnected; conn_info->ConnectionStatus = DeviceConnected;
conn_info->DeviceIsHub = false; conn_info->DeviceIsHub = false;
@ -342,8 +348,10 @@ static HRESULT es3sec_hub_descriptor_from_node(struct irp *irp)
switch (req_type) { switch (req_type) {
case USB_CONFIGURATION_DESCRIPTOR_TYPE: case USB_CONFIGURATION_DESCRIPTOR_TYPE:
return es3sec_hub_get_config_descriptor(irp, req, req_data_requested); return es3sec_hub_get_config_descriptor(irp, req, req_data_requested);
case USB_STRING_DESCRIPTOR_TYPE: case USB_STRING_DESCRIPTOR_TYPE:
return es3sec_hub_get_string_descriptor(irp, req, req_data_requested); return es3sec_hub_get_string_descriptor(irp, req, req_data_requested);
default: default:
dprintf("ES3 Dongle: es3sec_hub_descriptor_from_node Unknown request type %x\n", req_type); dprintf("ES3 Dongle: es3sec_hub_descriptor_from_node Unknown request type %x\n", req_type);
return HRESULT_FROM_WIN32(ERROR_INVALID_FUNCTION); return HRESULT_FROM_WIN32(ERROR_INVALID_FUNCTION);
@ -358,7 +366,7 @@ static HRESULT es3sec_hub_descriptor_from_node(struct irp *irp)
static HRESULT es3sec_hub_get_config_descriptor(struct irp *irp, PUSB_DESCRIPTOR_REQUEST req, UCHAR dataRequested) static HRESULT es3sec_hub_get_config_descriptor(struct irp *irp, PUSB_DESCRIPTOR_REQUEST req, UCHAR dataRequested)
{ {
dprintf("ES3 Dongle: Get Hub Config Descriptor from Node Connection\twLength %d\n", req->SetupPacket.wLength); dprintf("ES3 Dongle: Get Hub Config Descriptor from Node Connection\n");
PUSB_CONFIGURATION_DESCRIPTOR config = (PUSB_CONFIGURATION_DESCRIPTOR)malloc(sizeof(USB_CONFIGURATION_DESCRIPTOR)); PUSB_CONFIGURATION_DESCRIPTOR config = (PUSB_CONFIGURATION_DESCRIPTOR)malloc(sizeof(USB_CONFIGURATION_DESCRIPTOR));
config->bLength = sizeof(*config); config->bLength = sizeof(*config);
@ -374,7 +382,6 @@ static HRESULT es3sec_hub_get_config_descriptor(struct irp *irp, PUSB_DESCRIPTOR
static HRESULT es3sec_hub_get_string_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)
{ {
dprintf("ES3 Dongle: Get Hub String Descriptor from Node Connection\tdataRequested %d\n", dataRequested);
PUSB_STRING_DESCRIPTOR str_desc; PUSB_STRING_DESCRIPTOR str_desc;
int additional_length = sizeof(FILLER_LANGIDS); int additional_length = sizeof(FILLER_LANGIDS);
str_desc = (PUSB_STRING_DESCRIPTOR)malloc(sizeof(USB_STRING_DESCRIPTOR) + additional_length); str_desc = (PUSB_STRING_DESCRIPTOR)malloc(sizeof(USB_STRING_DESCRIPTOR) + additional_length);
@ -383,18 +390,23 @@ static HRESULT es3sec_hub_get_string_descriptor(struct irp *irp, PUSB_DESCRIPTOR
switch (dataRequested) { switch (dataRequested) {
case DONGLE_STR_IDX_MANUFACTURER: case DONGLE_STR_IDX_MANUFACTURER:
dprintf("ES3 Dongle: Get Hub String Descriptor For Dongle Manufacturer\n");
additional_length = sizeof(dongle_mftr); additional_length = sizeof(dongle_mftr);
str_desc = (PUSB_STRING_DESCRIPTOR)realloc(str_desc, sizeof(USB_STRING_DESCRIPTOR) + additional_length); str_desc = (PUSB_STRING_DESCRIPTOR)realloc(str_desc, sizeof(USB_STRING_DESCRIPTOR) + additional_length);
str_desc->bDescriptorType = USB_STRING_DESCRIPTOR_TYPE; str_desc->bDescriptorType = USB_STRING_DESCRIPTOR_TYPE;
wcscpy_s(str_desc->bString, _countof(dongle_mftr), dongle_mftr); wcscpy_s(str_desc->bString, _countof(dongle_mftr), dongle_mftr);
break; break;
case DONGLE_STR_IDX_PRODUCT: case DONGLE_STR_IDX_PRODUCT:
dprintf("ES3 Dongle: Get Hub String Descriptor For Dongle Product Name\n");
additional_length = sizeof(dongle_product); additional_length = sizeof(dongle_product);
str_desc = (PUSB_STRING_DESCRIPTOR)realloc(str_desc, sizeof(USB_STRING_DESCRIPTOR) + additional_length); str_desc = (PUSB_STRING_DESCRIPTOR)realloc(str_desc, sizeof(USB_STRING_DESCRIPTOR) + additional_length);
str_desc->bDescriptorType = USB_STRING_DESCRIPTOR_TYPE; str_desc->bDescriptorType = USB_STRING_DESCRIPTOR_TYPE;
wcscpy_s(str_desc->bString, _countof(dongle_product), dongle_product); wcscpy_s(str_desc->bString, _countof(dongle_product), dongle_product);
break; break;
case DONGLE_STR_IDX_SERIAL_NUMBER: case DONGLE_STR_IDX_SERIAL_NUMBER:
dprintf("ES3 Dongle: Get Hub String Descriptor For Dongle Serial Number\n");
additional_length = sizeof(L"000000000000"); additional_length = sizeof(L"000000000000");
str_desc = (PUSB_STRING_DESCRIPTOR)realloc(str_desc, sizeof(USB_STRING_DESCRIPTOR) + additional_length); str_desc = (PUSB_STRING_DESCRIPTOR)realloc(str_desc, sizeof(USB_STRING_DESCRIPTOR) + additional_length);
str_desc->bDescriptorType = USB_STRING_DESCRIPTOR_TYPE; str_desc->bDescriptorType = USB_STRING_DESCRIPTOR_TYPE;
@ -477,13 +489,12 @@ static CONFIGRET my_CM_Get_DevNode_Registry_PropertyW(
switch (ulProperty) switch (ulProperty)
{ {
case CM_DRP_DEVICEDESC: case CM_DRP_DEVICEDESC:
dprintf("ES3 Dongle: Get hub device description\n"); dprintf("ES3 Dongle: Get Hub Device Description\n");
// wcscpy_s(Buffer, _countof(L"Disk drive"), L"Disk drive");
wcscpy_s(Buffer, _countof(L"Fake USB Hub"), L"Fake USB Hub"); wcscpy_s(Buffer, _countof(L"Fake USB Hub"), L"Fake USB Hub");
break; break;
case CM_DRP_DRIVER: case CM_DRP_DRIVER:
dprintf("ES3 Dongle: Get hub driver\n"); dprintf("ES3 Dongle: Get Hub Driver Key\n");
wcscpy_s(Buffer, _countof(HUB_HCD_DRIVER_KEY), HUB_HCD_DRIVER_KEY); wcscpy_s(Buffer, _countof(HUB_HCD_DRIVER_KEY), HUB_HCD_DRIVER_KEY);
break; break;
@ -502,7 +513,6 @@ static CONFIGRET my_CM_Get_Child(PDEVINST pdnDevInst, DEVINST dnDevInst, ULONG u
return next_CM_Get_Child(pdnDevInst, dnDevInst, ulFlags); return next_CM_Get_Child(pdnDevInst, dnDevInst, ulFlags);
} }
dprintf("ES3 Dongle: Adding fake hub to root node\n");
*pdnDevInst = HUB_DEVINST; *pdnDevInst = HUB_DEVINST;
return CR_SUCCESS; return CR_SUCCESS;
} }

View File

@ -7,4 +7,9 @@ struct es3sec_config {
wchar_t serial[13]; wchar_t serial[13];
}; };
HRESULT es3sec_hook_init(const struct es3sec_config *cfg, USHORT vid, USHORT pid, wchar_t *manufacturer, wchar_t *product); HRESULT es3sec_hook_init(
const struct es3sec_config *cfg,
USHORT vid,
USHORT pid,
const wchar_t *manufacturer,
const wchar_t *product);

View File

@ -286,6 +286,10 @@ static HRESULT vfs_path_hook(const wchar_t *src, wchar_t *dest, size_t *count)
} }
*count = required; *count = required;
#if 0
dprintf("VFS: Redirecting %ls to %ls\n", src, dest);
#endif
return S_OK; return S_OK;
} }