iohook: add hook for GetCommModemStatus

This commit is contained in:
Kevin Trocolli
2024-02-21 00:33:25 -05:00
parent dbdcd61b3a
commit 09306229f1
2 changed files with 30 additions and 0 deletions
+1
View File
@@ -35,6 +35,7 @@ struct irp {
uint32_t seek_origin;
int64_t seek_offset;
uint64_t seek_pos;
uint16_t modem_state;
};
typedef HRESULT (*iohook_fn_t)(struct irp *irp);
+29
View File
@@ -36,6 +36,7 @@ static BOOL WINAPI my_SetCommState(HANDLE fd, const DCB *dcb);
static BOOL WINAPI my_SetCommTimeouts(HANDLE fd, COMMTIMEOUTS *timeouts);
static BOOL WINAPI my_SetupComm(HANDLE fd, uint32_t in_q, uint32_t out_q);
static BOOL WINAPI my_SetCommBreak(HANDLE fd);
static BOOL WINAPI my_GetCommModemStatus(HANDLE fd, DWORD modem_stat);
static struct hook_symbol serial_syms[] = {
{
@@ -74,6 +75,9 @@ static struct hook_symbol serial_syms[] = {
}, {
.name = "ClearCommBreak",
.patch = my_ClearCommBreak,
},{
.name = "GetCommModemStatus",
.patch = my_GetCommModemStatus,
},
};
@@ -730,3 +734,28 @@ static BOOL WINAPI my_ClearCommBreak(HANDLE fd)
return TRUE;
}
static BOOL WINAPI my_GetCommModemStatus(HANDLE fd, DWORD modem_stat)
{
// IOCTL_SERIAL_GET_MODEMSTATUS
struct irp irp;
HRESULT hr;
memset(&irp, 0, sizeof(irp));
irp.op = IRP_OP_IOCTL;
irp.fd = fd;
irp.ioctl = IOCTL_SERIAL_GET_MODEMSTATUS;
modem_stat = 0;
hr = iohook_invoke_next(&irp);
if (FAILED(hr)) {
return hr_propagate_win32(hr, FALSE);
}
SetLastError(ERROR_SUCCESS);
modem_stat = irp.modem_state;
return TRUE;
}