Skip to content

Commit 6bfd9d6

Browse files
committed
hook connect
1 parent 9f77d48 commit 6bfd9d6

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

core/src/syscall/windows/connect.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ impl<I: ConnectSyscall> ConnectSyscall for NioConnectSyscall<I> {
5050
set_non_blocking(fd);
5151
}
5252
let mut r = self.inner.connect(fn_ptr, fd, address, len);
53+
eprintln!("connect {r} error:{}", Error::last_os_error());
5354
loop {
5455
if r == 0 {
5556
reset_errno();
@@ -75,6 +76,7 @@ impl<I: ConnectSyscall> ConnectSyscall for NioConnectSyscall<I> {
7576
&mut len,
7677
);
7778
}
79+
eprintln!("connect getsockopt {r} error:{}", Error::last_os_error());
7880
if r != 0 {
7981
r = -1;
8082
break;
@@ -89,6 +91,7 @@ impl<I: ConnectSyscall> ConnectSyscall for NioConnectSyscall<I> {
8991
let mut address_len = std::mem::zeroed();
9092
r = getpeername(fd, &mut address, &mut address_len);
9193
}
94+
eprintln!("getpeername {r} error:{}", Error::last_os_error());
9295
} else if errno != Some(WSAEINTR) {
9396
break;
9497
}

hook/src/syscall/windows.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ unsafe fn attach() -> std::io::Result<()> {
6969
address: *mut SOCKADDR,
7070
address_len: *mut c_int
7171
) -> SOCKET);
72+
impl_hook!("ws2_32.dll", CONNECT, connect(
73+
fd: SOCKET,
74+
address: *const SOCKADDR,
75+
len: c_int
76+
) -> c_int);
7277
impl_hook!("ws2_32.dll", IOCTLSOCKET, ioctlsocket(
7378
fd: SOCKET,
7479
cmd: c_int,
@@ -154,18 +159,13 @@ unsafe fn attach() -> std::io::Result<()> {
154159
lpnewfilepointer : *mut c_longlong,
155160
dwmovemethod : SET_FILE_POINTER_MOVE_METHOD
156161
) -> BOOL);
157-
// NOTE: unhook WaitOnAddress/connect due to stack overflow or bug
162+
// NOTE: unhook WaitOnAddress due to stack overflow or bug
158163
// impl_hook!("api-ms-win-core-synch-l1-2-0.dll", WAITONADDRESS, WaitOnAddress(
159164
// address: *const c_void,
160165
// compareaddress: *const c_void,
161166
// addresssize: usize,
162167
// dwmilliseconds: c_uint
163168
// ) -> BOOL);
164-
impl_hook!("ws2_32.dll", CONNECT, connect(
165-
fd: SOCKET,
166-
address: *const SOCKADDR,
167-
len: c_int
168-
) -> c_int);
169169
// Enable the hook
170170
minhook::MinHook::enable_all_hooks()
171171
.map_err(|_| Error::new(ErrorKind::Other, "init all hooks failed !"))

0 commit comments

Comments
 (0)