Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Peacoor Zomboss
miscellaneous
提交
7b58f839
M
miscellaneous
项目概览
Peacoor Zomboss
/
miscellaneous
通知
151
Star
9
Fork
18
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
2
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
miscellaneous
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
2
Issue
2
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
7b58f839
编写于
2月 14, 2023
作者:
Peacoor Zomboss
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix bugs, hook select and recvfrom
上级
3ac69fe1
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
206 addition
and
4 deletion
+206
-4
230130-hookgamesendto/hookdll/Makefile
230130-hookgamesendto/hookdll/Makefile
+1
-1
230130-hookgamesendto/hookdll/hookdll.cpp
230130-hookgamesendto/hookdll/hookdll.cpp
+3
-3
230130-hookgamesendto/inc/fkhook.h
230130-hookgamesendto/inc/fkhook.h
+6
-0
230130-hookgamesendto/src/fkhook.cpp
230130-hookgamesendto/src/fkhook.cpp
+196
-0
未找到文件。
230130-hookgamesendto/hookdll/Makefile
浏览文件 @
7b58f839
...
...
@@ -6,7 +6,7 @@ cxx32prefix = i686-w64-mingw32-
cxx64prefix
=
x86_64-w64-mingw32-
objdir
=
./obj/
bindir
=
../bin/
src
=
hookdll.cpp fk
sendto
.cpp inlinehook.cpp sockqueue.cpp
src
=
hookdll.cpp fk
hook
.cpp inlinehook.cpp sockqueue.cpp
obj32
=
$(
patsubst
%.cpp,
$(objdir)
%_32.o,
$(src)
)
obj64
=
$(
patsubst
%.cpp,
$(objdir)
%_64.o,
$(src)
)
target32
=
$(bindir)
hookdll32.dll
...
...
230130-hookgamesendto/hookdll/hookdll.cpp
浏览文件 @
7b58f839
#include <windows.h>
#include "inlinehook.h"
#include "fk
sendto
.h"
#include "fk
hook
.h"
#ifdef _MSC_VER
#pragma comment (lib, "ws2_32.lib")
...
...
@@ -9,10 +9,10 @@
BOOL
APIENTRY
DllMain
(
HINSTANCE
hinstdll
,
DWORD
reason
,
LPVOID
reserved
)
{
if
(
reason
==
DLL_PROCESS_ATTACH
)
{
hook
_sendto
();
hook
();
}
else
if
(
reason
==
DLL_PROCESS_DETACH
)
{
unhook
_sendto
();
unhook
();
}
return
TRUE
;
}
230130-hookgamesendto/inc/fk
sendto
.h
→
230130-hookgamesendto/inc/fk
hook
.h
浏览文件 @
7b58f839
...
...
@@ -2,5 +2,5 @@
#include "inlinehook.h"
void
hook
_sendto
();
void
unhook
_sendto
();
void
hook
();
void
unhook
();
230130-hookgamesendto/src/fk
sendto
.cpp
→
230130-hookgamesendto/src/fk
hook
.cpp
浏览文件 @
7b58f839
#include <winsock2.h>
#include "fk
sendto
.h"
#include "fk
hook
.h"
#include "sockqueue.h"
#include "platform.h"
#include <vector>
#ifdef _CPU_X86
#define SENDTO_ENTRY_LEN 5
#define SELECT_ENTRY_LEN 7
#define RECVFROM_ENTRY_LEN 5
#endif
#ifdef _CPU_X64
#define SENDTO_ENTRY_LEN 7
#define SELECT_ENTRY_LEN 7
#define RECVFROM_ENTRY_LEN 7
#endif
typedef
int
WINAPI
(
*
sendto_func
)
(
SOCKET
,
const
char
*
,
int
,
int
,
const
sockaddr
*
,
int
);
typedef
int
WINAPI
(
*
select_func
)
(
int
,
fd_set
*
,
fd_set
*
,
fd_set
*
,
const
TIMEVAL
*
);
typedef
int
WINAPI
(
*
recvfrom_func
)
(
SOCKET
,
char
*
,
int
,
int
,
sockaddr
*
,
int
*
);
static
InlineHook
*
sendto_hook
=
NULL
;
static
InlineHook
*
select_hook
=
NULL
;
static
InlineHook
*
recvfrom_hook
=
NULL
;
static
sendto_func
_sendto
=
NULL
;
static
select_func
_select
=
NULL
;
static
recvfrom_func
_recvfrom
=
NULL
;
static
SOCKET
origin_sock
=
0
,
fake_sock
=
0
;
static
std
::
vector
<
SOCKET
>
socks
;
// 枚举当前所有可用网卡的IPv4地址
static
const
std
::
vector
<
in_addr
>
&
enum_addr
()
...
...
@@ -44,35 +56,73 @@ static const std::vector<in_addr> &enum_addr()
// hook后替换的函数
static
int
WINAPI
fake_sendto
(
SOCKET
s
,
const
char
*
buf
,
int
len
,
int
flags
,
const
sockaddr
*
to
,
int
tolen
)
{
static
SockQueue
sockqueue
;
int
result
=
-
1
;
// static SockQueue sockqueue;
sockaddr_in
*
toaddr
=
(
sockaddr_in
*
)
to
;
if
(
toaddr
->
sin_addr
.
S_un
.
S_addr
!=
INADDR_BROADCAST
)
{
re
sult
=
_sendto
(
s
,
buf
,
len
,
flags
,
to
,
tolen
);
// 非广播直接原样发送
re
turn
_sendto
(
s
,
buf
,
len
,
flags
,
to
,
tolen
);
// 非广播直接原样发送
}
else
{
sockaddr_in
addr_self
;
int
namelen
=
sizeof
(
sockaddr_in
);
getsockname
(
s
,
(
sockaddr
*
)
&
addr_self
,
&
namelen
);
// 获取原sockaddr
if
(
addr_self
.
sin_port
==
0
)
{
// 如果没有端口号,先原样发送,这样系统才会分配一个端口号
result
=
_sendto
(
s
,
buf
,
len
,
flags
,
to
,
tolen
);
getsockname
(
s
,
(
sockaddr
*
)
&
addr_self
,
&
namelen
);
// 重新获取
}
int
result
=
-
1
;
origin_sock
=
s
;
// 暂存这个socket
const
std
::
vector
<
in_addr
>
&
list
=
enum_addr
();
if
(
socks
.
size
()
!=
list
.
size
())
{
sockaddr_in
addr_self
;
addr_self
.
sin_family
=
AF_INET
;
int
namelen
=
sizeof
(
sockaddr_in
);
getsockname
(
s
,
(
sockaddr
*
)
&
addr_self
,
&
namelen
);
// 获取原sockaddr
if
(
addr_self
.
sin_port
==
0
)
{
// 如果没有端口号,先原样发送,这样系统才会分配一个端口号
result
=
_sendto
(
s
,
buf
,
len
,
flags
,
to
,
tolen
);
getsockname
(
s
,
(
sockaddr
*
)
&
addr_self
,
&
namelen
);
// 重新获取
}
for
(
int
i
=
0
;
i
<
socks
.
size
();
i
++
)
closesocket
(
socks
[
i
]);
socks
.
clear
();
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++
)
{
addr_self
.
sin_addr
=
list
[
i
];
// 把新的地址换上去,然后发送
SOCKET
sock
=
socket
(
AF_INET
,
SOCK_DGRAM
,
0
);
BOOL
opt
=
TRUE
;
setsockopt
(
sock
,
SOL_SOCKET
,
SO_BROADCAST
,
(
char
*
)
&
opt
,
sizeof
(
BOOL
));
// 广播
setsockopt
(
sock
,
SOL_SOCKET
,
SO_REUSEADDR
,
(
char
*
)
&
opt
,
sizeof
(
BOOL
));
// 重用地址端口
bind
(
sock
,
(
sockaddr
*
)
&
addr_self
,
sizeof
(
sockaddr
));
// 绑定到地址端口
socks
.
push_back
(
sock
);
}
}
// 向列表中的每一个地址转发广播
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++
)
{
addr_self
.
sin_addr
=
list
[
i
];
// 把新的地址换上去,然后发送
SOCKET
sock
=
socket
(
AF_INET
,
SOCK_DGRAM
,
0
);
BOOL
opt
=
TRUE
;
setsockopt
(
sock
,
SOL_SOCKET
,
SO_BROADCAST
,
(
char
*
)
&
opt
,
sizeof
(
BOOL
));
// 广播
setsockopt
(
sock
,
SOL_SOCKET
,
SO_REUSEADDR
,
(
char
*
)
&
opt
,
sizeof
(
BOOL
));
// 重用地址端口
bind
(
sock
,
(
sockaddr
*
)
&
addr_self
,
sizeof
(
sockaddr
));
// 绑定到地址端口
result
=
_sendto
(
sock
,
buf
,
len
,
flags
,
to
,
tolen
);
sockqueue
.
add
(
sock
);
// 加到socket队列里
for
(
int
i
=
0
;
i
<
socks
.
size
();
i
++
)
{
result
=
_sendto
(
socks
[
i
],
buf
,
len
,
flags
,
to
,
tolen
);
}
return
result
;
}
return
-
1
;
}
static
int
WINAPI
fake_select
(
int
n
,
fd_set
*
rd
,
fd_set
*
wr
,
fd_set
*
ex
,
const
TIMEVAL
*
timeout
)
{
if
(
rd
&&
rd
->
fd_count
==
1
&&
origin_sock
==
rd
->
fd_array
[
0
])
{
fd_set
fds
;
FD_ZERO
(
&
fds
);
for
(
int
i
=
0
;
i
<
socks
.
size
();
i
++
)
FD_SET
(
socks
[
i
],
&
fds
);
int
r
=
_select
(
0
,
&
fds
,
NULL
,
NULL
,
timeout
);
if
(
r
>
0
)
{
fake_sock
=
fds
.
fd_array
[
0
];
return
fds
.
fd_count
;
}
fake_sock
=
0
;
return
_select
(
n
,
rd
,
wr
,
ex
,
timeout
);
}
else
return
_select
(
n
,
rd
,
wr
,
ex
,
timeout
);
}
static
int
WINAPI
fake_recvfrom
(
SOCKET
s
,
char
*
buf
,
int
len
,
int
flags
,
sockaddr
*
from
,
int
*
fromlen
)
{
if
(
s
==
origin_sock
&&
fake_sock
!=
0
)
{
return
_recvfrom
(
fake_sock
,
buf
,
len
,
flags
,
from
,
fromlen
);
}
return
result
;
else
return
_recvfrom
(
s
,
buf
,
len
,
flags
,
from
,
fromlen
);
}
void
hook_sendto
()
...
...
@@ -92,3 +142,55 @@ void unhook_sendto()
sendto_hook
=
NULL
;
}
}
void
hook_select
()
{
if
(
!
select_hook
)
{
select_hook
=
new
InlineHook
(
GetModuleHandleA
(
"ws2_32.dll"
),
"select"
,
(
void
*
)
fake_select
,
SELECT_ENTRY_LEN
);
_select
=
(
select_func
)
select_hook
->
get_old_entry
();
select_hook
->
hook
();
}
}
void
unhook_select
()
{
if
(
select_hook
)
{
select_hook
->
unhook
();
delete
select_hook
;
select_hook
=
NULL
;
}
}
void
hook_recvfrom
()
{
if
(
!
recvfrom_hook
)
{
recvfrom_hook
=
new
InlineHook
(
GetModuleHandleA
(
"ws2_32.dll"
),
"recvfrom"
,
(
void
*
)
fake_recvfrom
,
RECVFROM_ENTRY_LEN
);
_recvfrom
=
(
recvfrom_func
)
recvfrom_hook
->
get_old_entry
();
recvfrom_hook
->
hook
();
}
}
void
unhook_recvfrom
()
{
if
(
recvfrom_hook
)
{
recvfrom_hook
->
unhook
();
delete
recvfrom_hook
;
recvfrom_hook
=
NULL
;
}
}
void
hook
()
{
hook_sendto
();
hook_select
();
hook_recvfrom
();
}
void
unhook
()
{
unhook_sendto
();
unhook_select
();
unhook_recvfrom
();
for
(
int
i
=
0
;
i
<
socks
.
size
();
i
++
)
closesocket
(
socks
[
i
]);
socks
.
clear
();
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录