Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张紫娃
miscellaneous
提交
12453f06
M
miscellaneous
项目概览
张紫娃
/
miscellaneous
与 Fork 源项目一致
Fork自
Peacoor Zomboss / miscellaneous
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
miscellaneous
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
12453f06
编写于
2月 17, 2023
作者:
Peacoor Zomboss
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update and more comment
上级
521ebef3
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
13 addition
and
13 deletion
+13
-13
230131-inlinehook/multithreadhook.cpp
230131-inlinehook/multithreadhook.cpp
+3
-3
230131-inlinehook/simplehook.cpp
230131-inlinehook/simplehook.cpp
+10
-10
未找到文件。
230131-inlinehook/multithreadhook.cpp
浏览文件 @
12453f06
...
...
@@ -95,7 +95,7 @@ void dohook()
WriteProcessMemory
(
GetCurrentProcess
(),
blank
,
&
blank_jump
,
14
,
NULL
);
// 保存原来的入口代码
memcpy
(
old_entry
,
hook_func
,
ENTRY_LEN
);
ptr64
.
ptr
=
(
BYTE
*
)
hook_func
+
ENTRY_LEN
;
ptr64
.
ptr
=
(
BYTE
*
)
hook_func
+
ENTRY_LEN
;
// 计算跳回去的地址
// 设置新的跳转代码
BYTE
*
new_jump
=
(
BYTE
*
)
old_entry
+
ENTRY_LEN
;
new_jump
[
0
]
=
0x68
;
...
...
@@ -113,7 +113,7 @@ void dohook()
memcpy
(
old_entry
,
hook_func
,
ENTRY_LEN
);
// 保存入口
BYTE
*
new_jump
=
(
BYTE
*
)
old_entry
+
ENTRY_LEN
;
*
new_jump
=
0xE9
;
// 跳回去的代码
*
(
long
*
)(
new_jump
+
1
)
=
(
BYTE
*
)
hook_func
+
ENTRY_LEN
-
new_jump
-
5
;
*
(
long
*
)(
new_jump
+
1
)
=
(
BYTE
*
)
hook_func
+
ENTRY_LEN
-
new_jump
-
5
;
// 计算跳回去的指令
#endif
_WriteConsoleA
=
(
WRITECONSOLEA
)
old_entry
;
WriteProcessMemory
(
GetCurrentProcess
(),
hook_func
,
&
hook_jump
,
HOOK_JUMP_LEN
,
NULL
);
...
...
@@ -130,7 +130,7 @@ DWORD WINAPI thread_writehello(void *stdh)
DWORD
id
=
GetCurrentThreadId
();
char
str
[
64
];
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
int
len
=
sprintf
(
str
,
"%d: Hello World %d
\n
"
,
id
,
i
);
int
len
=
sprintf
(
str
,
"%d:
\t
Hello World %d
\n
"
,
id
,
i
);
WriteConsoleA
(
stdh
,
str
,
len
,
NULL
,
NULL
);
}
return
0
;
...
...
230131-inlinehook/simplehook.cpp
浏览文件 @
12453f06
...
...
@@ -25,9 +25,9 @@ char old_entry[HOOK_JUMP_LEN];
void
inithook
()
{
HMODULE
hmodule
=
GetModuleHandleA
(
"kernelbase.dll"
);
hook_func
=
(
void
*
)
GetProcAddress
(
hmodule
,
"WriteConsoleA"
);
VirtualProtect
(
hook_func
,
HOOK_JUMP_LEN
,
PAGE_EXECUTE_READWRITE
,
NULL
);
HMODULE
hmodule
=
GetModuleHandleA
(
"kernelbase.dll"
);
// 获取模块句柄
hook_func
=
(
void
*
)
GetProcAddress
(
hmodule
,
"WriteConsoleA"
);
// 找到函数地址
VirtualProtect
(
hook_func
,
HOOK_JUMP_LEN
,
PAGE_EXECUTE_READWRITE
,
NULL
);
// 允许函数头部内存可读写
#ifdef _CPU_X64
union
{
...
...
@@ -37,22 +37,22 @@ void inithook()
long
lo
;
long
hi
;
};
}
ptr64
;
}
ptr64
;
// 便于获取指针变量的高4字节和低4字节
ptr64
.
ptr
=
(
void
*
)
fk_WriteConsoleA
;
hook_jump
[
0
]
=
0x68
;
// push xxx
*
(
long
*
)
&
hook_jump
[
1
]
=
ptr64
.
lo
;
// xxx,即地址的低4
位
*
(
long
*
)
&
hook_jump
[
1
]
=
ptr64
.
lo
;
// xxx,即地址的低4
字节
hook_jump
[
5
]
=
0xC7
;
hook_jump
[
6
]
=
0x44
;
hook_jump
[
7
]
=
0x24
;
hook_jump
[
8
]
=
0x04
;
// mov dword [rsp+4], yyy
*
(
long
*
)
&
hook_jump
[
9
]
=
ptr64
.
hi
;
// yyy,即地址的高4
位
*
(
long
*
)
&
hook_jump
[
9
]
=
ptr64
.
hi
;
// yyy,即地址的高4
字节
hook_jump
[
13
]
=
0xC3
;
// ret
#endif
#ifdef _CPU_X86
hook_jump
[
0
]
=
0xE9
;
*
(
long
*
)
&
hook_jump
[
1
]
=
(
BYTE
*
)
fk_WriteConsoleA
-
(
BYTE
*
)
hook_func
-
5
;
hook_jump
[
0
]
=
0xE9
;
// jmp
*
(
long
*
)
&
hook_jump
[
1
]
=
(
BYTE
*
)
fk_WriteConsoleA
-
(
BYTE
*
)
hook_func
-
5
;
// 计算指令内容
#endif
memcpy
(
&
old_entry
,
hook_func
,
HOOK_JUMP_LEN
);
memcpy
(
&
old_entry
,
hook_func
,
HOOK_JUMP_LEN
);
// 保存原来的指令
}
void
dohook
()
...
...
@@ -83,7 +83,7 @@ DWORD WINAPI thread_writehello(void *stdh)
DWORD
id
=
GetCurrentThreadId
();
char
str
[
64
];
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
int
len
=
sprintf
(
str
,
"%d: Hello World %d
\n
"
,
id
,
i
);
int
len
=
sprintf
(
str
,
"%d:
\t
Hello World %d
\n
"
,
id
,
i
);
WriteConsoleA
(
stdh
,
str
,
len
,
NULL
,
NULL
);
}
return
0
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录