Apply clang-format code style to all source files

This commit is contained in:
icex2
2019-10-20 00:50:40 +02:00
parent c600e1a423
commit c3bc8782f4
401 changed files with 13844 additions and 11361 deletions
+13 -8
View File
@@ -10,24 +10,30 @@
#include "hooklib/acp.h"
#include "util/defs.h"
#include "util/codepage.h"
#include "util/defs.h"
#include "util/log.h"
static NTSTATUS NTAPI my_RtlMultiByteToUnicodeN(
wchar_t *dest, unsigned long destsz, unsigned long *out_destsz,
const char *src, unsigned long srcsz);
wchar_t *dest,
unsigned long destsz,
unsigned long *out_destsz,
const char *src,
unsigned long srcsz);
static const struct hook_symbol acp_hook_syms[] = {
{
.name = "RtlMultiByteToUnicodeN",
.patch = my_RtlMultiByteToUnicodeN,
.name = "RtlMultiByteToUnicodeN",
.patch = my_RtlMultiByteToUnicodeN,
},
};
static NTSTATUS NTAPI my_RtlMultiByteToUnicodeN(
wchar_t *dest, unsigned long destsz, unsigned long *out_destsz,
const char *src, unsigned long srcsz)
wchar_t *dest,
unsigned long destsz,
unsigned long *out_destsz,
const char *src,
unsigned long srcsz)
{
unsigned long result;
@@ -59,4 +65,3 @@ void acp_hook_init(void)
hook_table_apply(NULL, "ntdll.dll", acp_hook_syms, lengthof(acp_hook_syms));
log_info("ACP Hook enabled");
}
+16 -22
View File
@@ -1,32 +1,29 @@
#include <winsock2.h>
#include <windows.h>
#include <wincrypt.h> /* Required by mingw for some reason */
#include <iphlpapi.h>
#include <wincrypt.h> /* Required by mingw for some reason */
#include <windows.h>
#include <winsock2.h>
#include "hook/table.h"
#include "hooklib/adapter.h"
#include "util/defs.h"
#include "util/codepage.h"
#include "util/defs.h"
static DWORD WINAPI my_GetAdaptersInfo(
PIP_ADAPTER_INFO adapter_info,
PULONG out_buf_len);
static DWORD WINAPI
my_GetAdaptersInfo(PIP_ADAPTER_INFO adapter_info, PULONG out_buf_len);
static DWORD(WINAPI *real_GetAdaptersInfo)(PIP_ADAPTER_INFO adapter_info, PULONG out_buf_len);
static DWORD(WINAPI *real_GetAdaptersInfo)(
PIP_ADAPTER_INFO adapter_info, PULONG out_buf_len);
static const struct hook_symbol adapter_hook_syms[] = {
{
.name = "GetAdaptersInfo",
.patch = my_GetAdaptersInfo,
.link = (void *)&real_GetAdaptersInfo
},
{.name = "GetAdaptersInfo",
.patch = my_GetAdaptersInfo,
.link = (void *) &real_GetAdaptersInfo},
};
static DWORD WINAPI my_GetAdaptersInfo(
PIP_ADAPTER_INFO adapter_info,
PULONG out_buf_len)
static DWORD WINAPI
my_GetAdaptersInfo(PIP_ADAPTER_INFO adapter_info, PULONG out_buf_len)
{
DWORD ret;
PMIB_IPFORWARDTABLE ip_fwd_table;
@@ -40,13 +37,13 @@ static DWORD WINAPI my_GetAdaptersInfo(
return ret;
}
ip_fwd_table = (MIB_IPFORWARDTABLE *)malloc(sizeof(MIB_IPFORWARDTABLE));
ip_fwd_table = (MIB_IPFORWARDTABLE *) malloc(sizeof(MIB_IPFORWARDTABLE));
table_size = 0;
if (GetIpForwardTable(ip_fwd_table, &table_size, 1) ==
ERROR_INSUFFICIENT_BUFFER) {
free(ip_fwd_table);
ip_fwd_table = (MIB_IPFORWARDTABLE *)malloc(table_size);
ip_fwd_table = (MIB_IPFORWARDTABLE *) malloc(table_size);
}
if (GetIpForwardTable(ip_fwd_table, &table_size, 1) != NO_ERROR ||
@@ -74,8 +71,5 @@ static DWORD WINAPI my_GetAdaptersInfo(
void adapter_hook_init(void)
{
hook_table_apply(
NULL,
"iphlpapi.dll",
adapter_hook_syms,
lengthof(adapter_hook_syms));
NULL, "iphlpapi.dll", adapter_hook_syms, lengthof(adapter_hook_syms));
}
+5 -6
View File
@@ -16,17 +16,17 @@ static dll_entry_init_t next_dll_entry_init;
static dll_entry_main_t next_dll_entry_main;
static void *(STDCALL *next_GetProcAddress)(HMODULE mod, const char *sym);
static void * STDCALL my_GetProcAddress(HMODULE mod, const char *sym);
static void *STDCALL my_GetProcAddress(HMODULE mod, const char *sym);
static const struct hook_symbol mod_hooks[] = {
{
.name = "GetProcAddress",
.patch = my_GetProcAddress,
.link = (void **) &next_GetProcAddress,
.name = "GetProcAddress",
.patch = my_GetProcAddress,
.link = (void **) &next_GetProcAddress,
},
};
static void * STDCALL my_GetProcAddress(HMODULE mod, const char *sym)
static void *STDCALL my_GetProcAddress(HMODULE mod, const char *sym)
{
void *next;
@@ -76,4 +76,3 @@ bool app_hook_invoke_main(void)
{
return next_dll_entry_main();
}
+113 -106
View File
@@ -1,8 +1,8 @@
#include <windows.h> /* Usermode API */
#include <windows.h> /* Usermode API */
#include <ntdef.h> /* Kernel-mode API for ioctls */
#include <devioctl.h>
#include <ntddser.h>
#include <ntdef.h> /* Kernel-mode API for ioctls */
#include <stdbool.h>
#include <string.h>
@@ -10,16 +10,14 @@
#include "hook/iohook.h"
#include "hook/table.h"
#include "util/array.h"
#include "util/hr.h"
#include "util/log.h"
#include "util/array.h"
/* RS232 API hooks */
static BOOL STDCALL my_ClearCommError(
HANDLE fd,
uint32_t *errors,
COMSTAT *status);
static BOOL STDCALL
my_ClearCommError(HANDLE fd, uint32_t *errors, COMSTAT *status);
static BOOL STDCALL my_EscapeCommFunction(HANDLE fd, uint32_t func);
static BOOL STDCALL my_GetCommState(HANDLE fd, DCB *dcb);
@@ -31,71 +29,69 @@ static BOOL STDCALL my_SetupComm(HANDLE fd, uint32_t in_q, uint32_t out_q);
static BOOL STDCALL my_SetCommBreak(HANDLE fd);
static BOOL STDCALL my_ClearCommBreak(HANDLE fd);
static BOOL (STDCALL *real_ClearCommError)(
HANDLE fd,
uint32_t *errors,
COMSTAT *status);
static BOOL(STDCALL *real_ClearCommError)(
HANDLE fd, uint32_t *errors, COMSTAT *status);
static BOOL (STDCALL *real_EscapeCommFunction)(HANDLE fd, uint32_t func);
static BOOL (STDCALL *real_GetCommState)(HANDLE fd, DCB *dcb);
static BOOL (STDCALL *real_PurgeComm)(HANDLE fd, uint32_t flags);
static BOOL (STDCALL *real_SetCommMask)(HANDLE fd, uint32_t mask);
static BOOL (STDCALL *real_SetCommState)(HANDLE fd, const DCB *dcb);
static BOOL (STDCALL *real_SetCommTimeouts)(HANDLE fd, COMMTIMEOUTS *timeouts);
static BOOL (STDCALL *real_SetupComm)(HANDLE fd, uint32_t in_q, uint32_t out_q);
static BOOL (STDCALL *real_SetCommBreak)(HANDLE fd);
static BOOL (STDCALL *real_ClearCommBreak)(HANDLE fd);
static BOOL(STDCALL *real_EscapeCommFunction)(HANDLE fd, uint32_t func);
static BOOL(STDCALL *real_GetCommState)(HANDLE fd, DCB *dcb);
static BOOL(STDCALL *real_PurgeComm)(HANDLE fd, uint32_t flags);
static BOOL(STDCALL *real_SetCommMask)(HANDLE fd, uint32_t mask);
static BOOL(STDCALL *real_SetCommState)(HANDLE fd, const DCB *dcb);
static BOOL(STDCALL *real_SetCommTimeouts)(HANDLE fd, COMMTIMEOUTS *timeouts);
static BOOL(STDCALL *real_SetupComm)(HANDLE fd, uint32_t in_q, uint32_t out_q);
static BOOL(STDCALL *real_SetCommBreak)(HANDLE fd);
static BOOL(STDCALL *real_ClearCommBreak)(HANDLE fd);
static struct hook_symbol rs232_syms[] = {
{
.name = "ClearCommError",
.patch = my_ClearCommError,
.link = (void*) &real_ClearCommError,
.name = "ClearCommError",
.patch = my_ClearCommError,
.link = (void *) &real_ClearCommError,
},
{
.name = "EscapeCommFunction",
.patch = my_EscapeCommFunction,
.link = (void*) &real_EscapeCommFunction,
.name = "EscapeCommFunction",
.patch = my_EscapeCommFunction,
.link = (void *) &real_EscapeCommFunction,
},
{
.name = "GetCommState",
.patch = my_GetCommState,
.link = (void*) &real_GetCommState,
.name = "GetCommState",
.patch = my_GetCommState,
.link = (void *) &real_GetCommState,
},
{
.name = "PurgeComm",
.patch = my_PurgeComm,
.link = (void*) &real_PurgeComm,
.name = "PurgeComm",
.patch = my_PurgeComm,
.link = (void *) &real_PurgeComm,
},
{
.name = "SetCommMask",
.patch = my_SetCommMask,
.link = (void*) &real_SetCommMask,
.name = "SetCommMask",
.patch = my_SetCommMask,
.link = (void *) &real_SetCommMask,
},
{
.name = "SetCommState",
.patch = my_SetCommState,
.link = (void*) &real_SetCommState,
.name = "SetCommState",
.patch = my_SetCommState,
.link = (void *) &real_SetCommState,
},
{
.name = "SetCommTimeouts",
.patch = my_SetCommTimeouts,
.link = (void*) &real_SetCommTimeouts,
.name = "SetCommTimeouts",
.patch = my_SetCommTimeouts,
.link = (void *) &real_SetCommTimeouts,
},
{
.name = "SetupComm",
.patch = my_SetupComm,
.link = (void*) &real_SetupComm,
.name = "SetupComm",
.patch = my_SetupComm,
.link = (void *) &real_SetupComm,
},
{
.name = "SetCommBreak",
.patch = my_SetCommBreak,
.link = (void*) &real_SetCommBreak,
.name = "SetCommBreak",
.patch = my_SetCommBreak,
.link = (void *) &real_SetCommBreak,
},
{
.name = "ClearCommBreak",
.patch = my_ClearCommBreak,
.link = (void*) &real_ClearCommBreak,
.name = "ClearCommBreak",
.patch = my_ClearCommBreak,
.link = (void *) &real_ClearCommBreak,
},
};
@@ -105,13 +101,14 @@ static CRITICAL_SECTION hooked_port_fds_cs;
/**
* Some notes:
*
* The point of this, is to allow rs232 hooks for only the descriptors that we hook.
* This is because the emulation here is incomplete.
* Although the IOCTL's do end up being passed to the real hardware, the game rejects some of the responses and hangs.
* By short circuiting out, and calling the real Comm functions instead, it works.
* And hence, card-reader passthrough works on IIDX25+/SDVX5+ finally without eamio-real
*
*
* The point of this, is to allow rs232 hooks for only the descriptors that we
* hook. This is because the emulation here is incomplete. Although the IOCTL's
* do end up being passed to the real hardware, the game rejects some of the
* responses and hangs. By short circuiting out, and calling the real Comm
* functions instead, it works. And hence, card-reader passthrough works on
* IIDX25+/SDVX5+ finally without eamio-real
*
*/
void rs232_hook_init(void)
@@ -128,12 +125,13 @@ void rs232_hook_limit_hooks(void)
rs232_limit_hooks = true;
}
static BOOL rs232_check_fd(HANDLE fd) {
static BOOL rs232_check_fd(HANDLE fd)
{
HANDLE check;
if (rs232_limit_hooks){
if (rs232_limit_hooks) {
EnterCriticalSection(&hooked_port_fds_cs);
for (size_t i = 0 ; i < hooked_port_fds.nitems ; i++) {
for (size_t i = 0; i < hooked_port_fds.nitems; i++) {
check = *array_item(HANDLE, &hooked_port_fds, i);
if (check == fd) {
LeaveCriticalSection(&hooked_port_fds_cs);
@@ -155,10 +153,8 @@ void rs232_hook_add_fd(HANDLE fd)
LeaveCriticalSection(&hooked_port_fds_cs);
}
static BOOL STDCALL my_ClearCommError(
HANDLE fd,
uint32_t *errors,
COMSTAT *status)
static BOOL STDCALL
my_ClearCommError(HANDLE fd, uint32_t *errors, COMSTAT *status)
{
struct irp irp;
SERIAL_STATUS llstatus;
@@ -179,9 +175,7 @@ static BOOL STDCALL my_ClearCommError(
if (FAILED(hr)) {
log_warning(
"%s: IOCTL_SERIAL_GET_COMMSTATUS failed: %lx",
__func__,
hr);
"%s: IOCTL_SERIAL_GET_COMMSTATUS failed: %lx", __func__, hr);
return hr_propagate_win32(hr, FALSE);
}
@@ -266,19 +260,35 @@ static BOOL STDCALL my_EscapeCommFunction(HANDLE fd, uint32_t cmd)
}
switch (cmd) {
case CLRBREAK: ioctl = IOCTL_SERIAL_SET_BREAK_OFF; break;
case CLRDTR: ioctl = IOCTL_SERIAL_CLR_DTR; break;
case CLRRTS: ioctl = IOCTL_SERIAL_CLR_RTS; break;
case SETBREAK: ioctl = IOCTL_SERIAL_SET_BREAK_ON; break;
case SETDTR: ioctl = IOCTL_SERIAL_SET_RTS; break;
case SETRTS: ioctl = IOCTL_SERIAL_SET_RTS; break;
case SETXOFF: ioctl = IOCTL_SERIAL_SET_XOFF; break;
case SETXON: ioctl = IOCTL_SERIAL_SET_XON; break;
default:
log_warning("%s: Invalid comm function %08x", __func__, cmd);
SetLastError(ERROR_INVALID_PARAMETER);
case CLRBREAK:
ioctl = IOCTL_SERIAL_SET_BREAK_OFF;
break;
case CLRDTR:
ioctl = IOCTL_SERIAL_CLR_DTR;
break;
case CLRRTS:
ioctl = IOCTL_SERIAL_CLR_RTS;
break;
case SETBREAK:
ioctl = IOCTL_SERIAL_SET_BREAK_ON;
break;
case SETDTR:
ioctl = IOCTL_SERIAL_SET_RTS;
break;
case SETRTS:
ioctl = IOCTL_SERIAL_SET_RTS;
break;
case SETXOFF:
ioctl = IOCTL_SERIAL_SET_XOFF;
break;
case SETXON:
ioctl = IOCTL_SERIAL_SET_XON;
break;
default:
log_warning("%s: Invalid comm function %08x", __func__, cmd);
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
return FALSE;
}
memset(&irp, 0, sizeof(irp));
@@ -326,10 +336,10 @@ static BOOL STDCALL my_GetCommState(HANDLE fd, DCB *dcb)
days. So we only support the latest size of this struct. */
log_warning(
"%s: dcb->DCBlength = %d, expected %d",
__func__,
(int) dcb->DCBlength,
(unsigned int) sizeof(*dcb));
"%s: dcb->DCBlength = %d, expected %d",
__func__,
(int) dcb->DCBlength,
(unsigned int) sizeof(*dcb));
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
@@ -383,9 +393,7 @@ static BOOL STDCALL my_GetCommState(HANDLE fd, DCB *dcb)
if (FAILED(hr)) {
log_warning(
"%s: IOCTL_SERIAL_GET_LINE_CONTROL failed: %lx",
__func__,
hr);
"%s: IOCTL_SERIAL_GET_LINE_CONTROL failed: %lx", __func__, hr);
return hr_propagate_win32(hr, FALSE);
}
@@ -502,7 +510,6 @@ static BOOL STDCALL my_PurgeComm(HANDLE fd, uint32_t flags)
return hr_propagate_win32(hr, SUCCEEDED(hr));
}
static BOOL STDCALL my_SetCommMask(HANDLE fd, uint32_t mask)
{
struct irp irp;
@@ -553,10 +560,10 @@ static BOOL STDCALL my_SetCommState(HANDLE fd, const DCB *dcb)
days. So we only support the latest size of this struct. */
log_warning(
"%s: dcb->DCBlength = %d, expected %d",
__func__,
(int) dcb->DCBlength,
(unsigned int) sizeof(*dcb));
"%s: dcb->DCBlength = %d, expected %d",
__func__,
(int) dcb->DCBlength,
(unsigned int) sizeof(*dcb));
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
@@ -590,8 +597,10 @@ static BOOL STDCALL my_SetCommState(HANDLE fd, const DCB *dcb)
break;
default:
log_warning("%s: dcb->fDtrControl value %d is invalid",
__func__, dcb->fDtrControl);
log_warning(
"%s: dcb->fDtrControl value %d is invalid",
__func__,
dcb->fDtrControl);
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
@@ -621,9 +630,9 @@ static BOOL STDCALL my_SetCommState(HANDLE fd, const DCB *dcb)
default:
log_warning(
"%s: dcb->fRtsControl value %d is invalid",
__func__,
dcb->fRtsControl);
"%s: dcb->fRtsControl value %d is invalid",
__func__,
dcb->fRtsControl);
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
@@ -684,9 +693,7 @@ static BOOL STDCALL my_SetCommState(HANDLE fd, const DCB *dcb)
if (FAILED(hr)) {
log_warning(
"%s: IOCTL_SERIAL_SET_LINE_CONTROL failed: %lx",
__func__,
hr);
"%s: IOCTL_SERIAL_SET_LINE_CONTROL failed: %lx", __func__, hr);
return hr_propagate_win32(hr, FALSE);
}
@@ -721,11 +728,11 @@ static BOOL STDCALL my_SetCommTimeouts(HANDLE fd, COMMTIMEOUTS *src)
return real_SetCommTimeouts(fd, src);
}
dest.ReadIntervalTimeout = src->ReadIntervalTimeout;
dest.ReadTotalTimeoutMultiplier = src->ReadTotalTimeoutMultiplier;
dest.ReadTotalTimeoutConstant = src->ReadTotalTimeoutConstant;
dest.WriteTotalTimeoutMultiplier = src->WriteTotalTimeoutMultiplier;
dest.WriteTotalTimeoutConstant = src->WriteTotalTimeoutConstant;
dest.ReadIntervalTimeout = src->ReadIntervalTimeout;
dest.ReadTotalTimeoutMultiplier = src->ReadTotalTimeoutMultiplier;
dest.ReadTotalTimeoutConstant = src->ReadTotalTimeoutConstant;
dest.WriteTotalTimeoutMultiplier = src->WriteTotalTimeoutMultiplier;
dest.WriteTotalTimeoutConstant = src->WriteTotalTimeoutConstant;
memset(&irp, 0, sizeof(irp));
irp.op = IRP_OP_IOCTL;
@@ -766,7 +773,8 @@ static BOOL STDCALL my_SetupComm(HANDLE fd, uint32_t in_q, uint32_t out_q)
hr = irp_invoke_next(&irp);
if (FAILED(hr)) {
log_warning("%s: IOCTL_SERIAL_SET_QUEUE_SIZE failed: %lx",__func__, hr);
log_warning(
"%s: IOCTL_SERIAL_SET_QUEUE_SIZE failed: %lx", __func__, hr);
}
return hr_propagate_win32(hr, SUCCEEDED(hr));
@@ -817,4 +825,3 @@ static BOOL STDCALL my_ClearCommBreak(HANDLE fd)
return hr_propagate_win32(hr, SUCCEEDED(hr));
}
+155 -123
View File
@@ -17,117 +17,123 @@
static BOOL STDCALL my_SetupDiDestroyDeviceInfoList(HDEVINFO dev_info);
static BOOL STDCALL my_SetupDiEnumDeviceInfo(
HDEVINFO dev_info, DWORD index, SP_DEVINFO_DATA *info_data);
HDEVINFO dev_info, DWORD index, SP_DEVINFO_DATA *info_data);
static BOOL STDCALL my_SetupDiEnumDeviceInterfaces(
HDEVINFO dev_info, SP_DEVINFO_DATA *info_data, const GUID *iface_guid,
DWORD index, SP_DEVICE_INTERFACE_DATA *ifd);
HDEVINFO dev_info,
SP_DEVINFO_DATA *info_data,
const GUID *iface_guid,
DWORD index,
SP_DEVICE_INTERFACE_DATA *ifd);
static HDEVINFO STDCALL my_SetupDiGetClassDevsA(
const GUID *class_guid, const char *enumerator, HWND hwnd,
DWORD flags);
const GUID *class_guid, const char *enumerator, HWND hwnd, DWORD flags);
static HDEVINFO STDCALL my_SetupDiGetClassDevsW(
const GUID *class_guid, PCWSTR enumerator, HWND hwnd,
DWORD flags);
const GUID *class_guid, PCWSTR enumerator, HWND hwnd, DWORD flags);
static BOOL STDCALL my_SetupDiGetDeviceInterfaceDetailA(
HDEVINFO dev_info, SP_DEVICE_INTERFACE_DATA *ifd,
SP_DEVICE_INTERFACE_DETAIL_DATA_A *detail, DWORD size,
DWORD *required_size, SP_DEVINFO_DATA *info_data);
HDEVINFO dev_info,
SP_DEVICE_INTERFACE_DATA *ifd,
SP_DEVICE_INTERFACE_DETAIL_DATA_A *detail,
DWORD size,
DWORD *required_size,
SP_DEVINFO_DATA *info_data);
static BOOL STDCALL my_SetupDiGetDeviceInterfaceDetailW(
HDEVINFO dev_info, SP_DEVICE_INTERFACE_DATA *ifd,
SP_DEVICE_INTERFACE_DETAIL_DATA_W *detail, DWORD size,
DWORD *required_size, SP_DEVINFO_DATA *info_data);
HDEVINFO dev_info,
SP_DEVICE_INTERFACE_DATA *ifd,
SP_DEVICE_INTERFACE_DETAIL_DATA_W *detail,
DWORD size,
DWORD *required_size,
SP_DEVINFO_DATA *info_data);
static BOOL STDCALL my_SetupDiGetDeviceRegistryPropertyA(
HDEVINFO dev_info, SP_DEVINFO_DATA *info_data, DWORD prop_id,
DWORD *prop_type, void *bytes, DWORD nbytes, DWORD *required_nbytes);
HDEVINFO dev_info,
SP_DEVINFO_DATA *info_data,
DWORD prop_id,
DWORD *prop_type,
void *bytes,
DWORD nbytes,
DWORD *required_nbytes);
/* real calls */
static BOOL (STDCALL *real_SetupDiDestroyDeviceInfoList)(
HDEVINFO dev_info);
static BOOL(STDCALL *real_SetupDiDestroyDeviceInfoList)(HDEVINFO dev_info);
static BOOL (STDCALL *real_SetupDiEnumDeviceInfo)(
HDEVINFO dev_info, DWORD index, SP_DEVINFO_DATA *info_data);
static BOOL(STDCALL *real_SetupDiEnumDeviceInfo)(
HDEVINFO dev_info, DWORD index, SP_DEVINFO_DATA *info_data);
static BOOL (STDCALL *real_SetupDiEnumDeviceInterfaces)(
HDEVINFO dev_info, SP_DEVINFO_DATA *info_data, const GUID *iface_guid,
DWORD index, SP_DEVICE_INTERFACE_DATA *ifd);
static BOOL(STDCALL *real_SetupDiEnumDeviceInterfaces)(
HDEVINFO dev_info,
SP_DEVINFO_DATA *info_data,
const GUID *iface_guid,
DWORD index,
SP_DEVICE_INTERFACE_DATA *ifd);
static HDEVINFO (STDCALL *real_SetupDiGetClassDevsA)(
const GUID *class_guid, const char *enumerator, HWND hwnd,
DWORD flags);
static HDEVINFO(STDCALL *real_SetupDiGetClassDevsA)(
const GUID *class_guid, const char *enumerator, HWND hwnd, DWORD flags);
static HDEVINFO (STDCALL *real_SetupDiGetClassDevsW)(
const GUID *class_guid, PCWSTR enumerator, HWND hwnd,
DWORD flags);
static HDEVINFO(STDCALL *real_SetupDiGetClassDevsW)(
const GUID *class_guid, PCWSTR enumerator, HWND hwnd, DWORD flags);
static BOOL (STDCALL *real_SetupDiGetDeviceInterfaceDetailA)(
HDEVINFO dev_info, SP_DEVICE_INTERFACE_DATA *ifd,
SP_DEVICE_INTERFACE_DETAIL_DATA_A *detail, DWORD size,
DWORD *required_size, SP_DEVINFO_DATA *info_data);
static BOOL(STDCALL *real_SetupDiGetDeviceInterfaceDetailA)(
HDEVINFO dev_info,
SP_DEVICE_INTERFACE_DATA *ifd,
SP_DEVICE_INTERFACE_DETAIL_DATA_A *detail,
DWORD size,
DWORD *required_size,
SP_DEVINFO_DATA *info_data);
static BOOL (STDCALL *real_SetupDiGetDeviceInterfaceDetailW)(
HDEVINFO dev_info, SP_DEVICE_INTERFACE_DATA *ifd,
SP_DEVICE_INTERFACE_DETAIL_DATA_W *detail, DWORD size,
DWORD *required_size, SP_DEVINFO_DATA *info_data);
static BOOL(STDCALL *real_SetupDiGetDeviceInterfaceDetailW)(
HDEVINFO dev_info,
SP_DEVICE_INTERFACE_DATA *ifd,
SP_DEVICE_INTERFACE_DETAIL_DATA_W *detail,
DWORD size,
DWORD *required_size,
SP_DEVINFO_DATA *info_data);
static BOOL (STDCALL *real_SetupDiGetDeviceRegistryPropertyA)(
HDEVINFO dev_info, SP_DEVINFO_DATA *info_data, DWORD prop_id,
DWORD *prop_type, void *bytes, DWORD nbytes, DWORD *required_nbytes);
static BOOL(STDCALL *real_SetupDiGetDeviceRegistryPropertyA)(
HDEVINFO dev_info,
SP_DEVINFO_DATA *info_data,
DWORD prop_id,
DWORD *prop_type,
void *bytes,
DWORD nbytes,
DWORD *required_nbytes);
static const struct hook_symbol setupapi_hook_syms[] = {
{
.name = "SetupDiDestroyDeviceInfoList",
.patch = my_SetupDiDestroyDeviceInfoList,
.link = (void **) &real_SetupDiDestroyDeviceInfoList
},
{
.name = "SetupDiEnumDeviceInfo",
.patch = my_SetupDiEnumDeviceInfo,
.link = (void **) &real_SetupDiEnumDeviceInfo
},
{
.name = "SetupDiEnumDeviceInterfaces",
.patch = my_SetupDiEnumDeviceInterfaces,
.link = (void **) &real_SetupDiEnumDeviceInterfaces
},
{
.name = "SetupDiGetClassDevsA",
.patch = my_SetupDiGetClassDevsA,
.link = (void **) &real_SetupDiGetClassDevsA
},
{
.name = "SetupDiGetClassDevsW",
.patch = my_SetupDiGetClassDevsW,
.link = (void **) &real_SetupDiGetClassDevsW
},
{
.name = "SetupDiGetDeviceInterfaceDetailA",
.patch = my_SetupDiGetDeviceInterfaceDetailA,
.link = (void **) &real_SetupDiGetDeviceInterfaceDetailA
},
{
.name = "SetupDiGetDeviceInterfaceDetailW",
.patch = my_SetupDiGetDeviceInterfaceDetailW,
.link = (void **) &real_SetupDiGetDeviceInterfaceDetailW
},
{
.name = "SetupDiGetDeviceRegistryPropertyA",
.patch = my_SetupDiGetDeviceRegistryPropertyA,
.link = (void **) &real_SetupDiGetDeviceRegistryPropertyA
},
{.name = "SetupDiDestroyDeviceInfoList",
.patch = my_SetupDiDestroyDeviceInfoList,
.link = (void **) &real_SetupDiDestroyDeviceInfoList},
{.name = "SetupDiEnumDeviceInfo",
.patch = my_SetupDiEnumDeviceInfo,
.link = (void **) &real_SetupDiEnumDeviceInfo},
{.name = "SetupDiEnumDeviceInterfaces",
.patch = my_SetupDiEnumDeviceInterfaces,
.link = (void **) &real_SetupDiEnumDeviceInterfaces},
{.name = "SetupDiGetClassDevsA",
.patch = my_SetupDiGetClassDevsA,
.link = (void **) &real_SetupDiGetClassDevsA},
{.name = "SetupDiGetClassDevsW",
.patch = my_SetupDiGetClassDevsW,
.link = (void **) &real_SetupDiGetClassDevsW},
{.name = "SetupDiGetDeviceInterfaceDetailA",
.patch = my_SetupDiGetDeviceInterfaceDetailA,
.link = (void **) &real_SetupDiGetDeviceInterfaceDetailA},
{.name = "SetupDiGetDeviceInterfaceDetailW",
.patch = my_SetupDiGetDeviceInterfaceDetailW,
.link = (void **) &real_SetupDiGetDeviceInterfaceDetailW},
{.name = "SetupDiGetDeviceRegistryPropertyA",
.patch = my_SetupDiGetDeviceRegistryPropertyA,
.link = (void **) &real_SetupDiGetDeviceRegistryPropertyA},
};
static int hook_setupapi_fake_handle;
static const struct hook_setupapi_data* hook_setupapi_data;
static const struct hook_setupapi_data *hook_setupapi_data;
static HDEVINFO STDCALL my_SetupDiGetClassDevsA(
const GUID *class_guid, const char *enumerator, HWND hwnd,
DWORD flags)
const GUID *class_guid, const char *enumerator, HWND hwnd, DWORD flags)
{
/* That's how iidx 9-13 detected the old C02 IO. That doesn't work
on iidx 14 anymore... */
@@ -136,10 +142,12 @@ static HDEVINFO STDCALL my_SetupDiGetClassDevsA(
&& memcmp(class_guid, &hook_setupapi_data->device_guid,
sizeof(hook_setupapi_data->device_guid)) == 0) {
*/
if ((class_guid != NULL
&& !memcmp(class_guid, &hook_setupapi_data->device_guid,
sizeof(hook_setupapi_data->device_guid))) ||
(enumerator != NULL && !strcmp(enumerator, "USB"))) {
if ((class_guid != NULL &&
!memcmp(
class_guid,
&hook_setupapi_data->device_guid,
sizeof(hook_setupapi_data->device_guid))) ||
(enumerator != NULL && !strcmp(enumerator, "USB"))) {
SetLastError(ERROR_SUCCESS);
log_misc("SetupDiGetClassDevsA: %s", hook_setupapi_data->device_path);
@@ -151,11 +159,12 @@ static HDEVINFO STDCALL my_SetupDiGetClassDevsA(
}
static HDEVINFO STDCALL my_SetupDiGetClassDevsW(
const GUID *class_guid, PCWSTR enumerator, HWND hwnd,
DWORD flags)
const GUID *class_guid, PCWSTR enumerator, HWND hwnd, DWORD flags)
{
if (class_guid != NULL
&& memcmp(class_guid, &hook_setupapi_data->device_guid,
if (class_guid != NULL &&
memcmp(
class_guid,
&hook_setupapi_data->device_guid,
sizeof(hook_setupapi_data->device_guid)) == 0) {
SetLastError(ERROR_SUCCESS);
@@ -168,7 +177,7 @@ static HDEVINFO STDCALL my_SetupDiGetClassDevsW(
}
static BOOL STDCALL my_SetupDiEnumDeviceInfo(
HDEVINFO dev_info, DWORD index, SP_DEVINFO_DATA *info_data)
HDEVINFO dev_info, DWORD index, SP_DEVINFO_DATA *info_data)
{
if (dev_info == &hook_setupapi_fake_handle) {
if (index == 0) {
@@ -188,8 +197,11 @@ static BOOL STDCALL my_SetupDiEnumDeviceInfo(
}
static BOOL STDCALL my_SetupDiEnumDeviceInterfaces(
HDEVINFO dev_info, SP_DEVINFO_DATA *info_data, const GUID *iface_guid,
DWORD index, SP_DEVICE_INTERFACE_DATA *ifd)
HDEVINFO dev_info,
SP_DEVINFO_DATA *info_data,
const GUID *iface_guid,
DWORD index,
SP_DEVICE_INTERFACE_DATA *ifd)
{
if (dev_info == &hook_setupapi_fake_handle) {
SetLastError(ERROR_SUCCESS);
@@ -198,14 +210,19 @@ static BOOL STDCALL my_SetupDiEnumDeviceInterfaces(
return index == 0;
} else {
return real_SetupDiEnumDeviceInterfaces(dev_info, info_data,
iface_guid, index, ifd);
return real_SetupDiEnumDeviceInterfaces(
dev_info, info_data, iface_guid, index, ifd);
}
}
static BOOL STDCALL my_SetupDiGetDeviceRegistryPropertyA(
HDEVINFO dev_info, SP_DEVINFO_DATA *info_data, DWORD prop_id,
DWORD *prop_type, void *bytes, DWORD nbytes, DWORD *required_nbytes)
HDEVINFO dev_info,
SP_DEVINFO_DATA *info_data,
DWORD prop_id,
DWORD *prop_type,
void *bytes,
DWORD nbytes,
DWORD *required_nbytes)
{
if (dev_info == &hook_setupapi_fake_handle) {
if (prop_id != SPDRP_DEVICEDESC) {
@@ -225,7 +242,8 @@ static BOOL STDCALL my_SetupDiGetDeviceRegistryPropertyA(
*prop_type = REG_SZ;
if (hook_setupapi_data->device_desc) {
log_misc("SetupDiGetDeviceRegistryPropertyA: %s",
log_misc(
"SetupDiGetDeviceRegistryPropertyA: %s",
hook_setupapi_data->device_desc);
str_cpy(bytes, nbytes, hook_setupapi_data->device_desc);
}
@@ -235,15 +253,23 @@ static BOOL STDCALL my_SetupDiGetDeviceRegistryPropertyA(
} else {
return real_SetupDiGetDeviceRegistryPropertyA(
dev_info, info_data, prop_id, prop_type, bytes, nbytes,
required_nbytes);
dev_info,
info_data,
prop_id,
prop_type,
bytes,
nbytes,
required_nbytes);
}
}
static BOOL STDCALL my_SetupDiGetDeviceInterfaceDetailA(
HDEVINFO dev_info, SP_DEVICE_INTERFACE_DATA *ifd,
SP_DEVICE_INTERFACE_DETAIL_DATA_A *detail, DWORD size,
DWORD *required_size, SP_DEVINFO_DATA *info_data)
HDEVINFO dev_info,
SP_DEVICE_INTERFACE_DATA *ifd,
SP_DEVICE_INTERFACE_DETAIL_DATA_A *detail,
DWORD size,
DWORD *required_size,
SP_DEVINFO_DATA *info_data)
{
if (dev_info == &hook_setupapi_fake_handle) {
if (size == 0) {
@@ -254,26 +280,32 @@ static BOOL STDCALL my_SetupDiGetDeviceInterfaceDetailA(
} else {
SetLastError(ERROR_SUCCESS);
log_misc("SetupDiGetDeviceInterfaceDetailA: %s",
log_misc(
"SetupDiGetDeviceInterfaceDetailA: %s",
hook_setupapi_data->device_path);
detail->cbSize = strlen(hook_setupapi_data->device_path);
memcpy(detail->DevicePath, hook_setupapi_data->device_path,
memcpy(
detail->DevicePath,
hook_setupapi_data->device_path,
detail->cbSize);
detail->DevicePath[detail->cbSize] = '\0';
return TRUE;
}
} else {
return real_SetupDiGetDeviceInterfaceDetailA(dev_info, ifd, detail,
size, required_size, info_data);
return real_SetupDiGetDeviceInterfaceDetailA(
dev_info, ifd, detail, size, required_size, info_data);
}
}
static BOOL STDCALL my_SetupDiGetDeviceInterfaceDetailW(
HDEVINFO dev_info, SP_DEVICE_INTERFACE_DATA *ifd,
SP_DEVICE_INTERFACE_DETAIL_DATA_W *detail, DWORD size,
DWORD *required_size, SP_DEVINFO_DATA *info_data)
HDEVINFO dev_info,
SP_DEVICE_INTERFACE_DATA *ifd,
SP_DEVICE_INTERFACE_DETAIL_DATA_W *detail,
DWORD size,
DWORD *required_size,
SP_DEVINFO_DATA *info_data)
{
if (dev_info == &hook_setupapi_fake_handle) {
if (size == 0) {
@@ -284,14 +316,17 @@ static BOOL STDCALL my_SetupDiGetDeviceInterfaceDetailW(
} else {
SetLastError(ERROR_SUCCESS);
log_misc("SetupDiGetDeviceInterfaceDetailW: %s",
log_misc(
"SetupDiGetDeviceInterfaceDetailW: %s",
hook_setupapi_data->device_path);
wchar_t* wstr_path = str_widen(hook_setupapi_data->device_path);
wchar_t *wstr_path = str_widen(hook_setupapi_data->device_path);
detail->cbSize = strlen(hook_setupapi_data->device_path);
memcpy(detail->DevicePath, wstr_path, (wcslen(wstr_path) + 1) *
sizeof(wchar_t));
memcpy(
detail->DevicePath,
wstr_path,
(wcslen(wstr_path) + 1) * sizeof(wchar_t));
detail->DevicePath[detail->cbSize] = '\0';
free(wstr_path);
@@ -300,8 +335,8 @@ static BOOL STDCALL my_SetupDiGetDeviceInterfaceDetailW(
}
} else {
return real_SetupDiGetDeviceInterfaceDetailW(dev_info, ifd, detail,
size, required_size, info_data);
return real_SetupDiGetDeviceInterfaceDetailW(
dev_info, ifd, detail, size, required_size, info_data);
}
}
@@ -316,15 +351,12 @@ static BOOL STDCALL my_SetupDiDestroyDeviceInfoList(HDEVINFO dev_info)
}
}
void hook_setupapi_init(const struct hook_setupapi_data* data)
void hook_setupapi_init(const struct hook_setupapi_data *data)
{
hook_table_apply(
NULL,
"setupapi.dll",
setupapi_hook_syms,
lengthof(setupapi_hook_syms));
NULL, "setupapi.dll", setupapi_hook_syms, lengthof(setupapi_hook_syms));
hook_setupapi_data = data;
log_info("Hooked setupapi for %s, %s", data->device_path,
data->device_desc);
log_info(
"Hooked setupapi for %s, %s", data->device_path, data->device_desc);
}
+4 -4
View File
@@ -1,15 +1,15 @@
#ifndef HOOKLIB_SETUPAPI_H
#define HOOKLIB_SETUPAPI_H
#include <windows.h>
#include <setupapi.h>
#include <windows.h>
struct hook_setupapi_data {
GUID device_guid;
const char* device_desc;
const char* device_path;
const char *device_desc;
const char *device_path;
};
void hook_setupapi_init(const struct hook_setupapi_data* data);
void hook_setupapi_init(const struct hook_setupapi_data *data);
#endif