mirror of
https://gitea.tendokyu.moe/TeamTofuShop/capnhook.git
synced 2026-09-22 22:38:12 +03:00
iohook: add hook for GetCommModemStatus
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user