Skip to content

Commit aa854d3

Browse files
committed
修改Hook测试代码
1 parent 4381cf7 commit aa854d3

6 files changed

Lines changed: 27 additions & 9 deletions

File tree

0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

bin/MulNX/CS2OBTool/CS2OBTool.dll

0 Bytes
Binary file not shown.

source/MulNXExtensions/TimeLiner/ITimeAdapter.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@ class ITimeAdapter {
77

88
virtual float GetTime() = 0;
99
virtual bool SetTime(float time) = 0;
10+
11+
virtual void OnSetOn(float time) {};
12+
virtual void OnSetOff() {};
1013
};

source/MulNXExtensions/TimeLiner/TimeLiner.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
void TimeLiner::Menu() {
77
MulNX::UI::RAIIWindow w("时间轴");
88

9-
// 没有绑定适配器时,仅绘制静态时间轴
109
if (!pTimeAdapter) {
1110
ImGui::Text("未连接时间适配器");
1211
return;

source/tests/Hook/Main.cpp

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,29 @@
11
#include <MulNXUtils/WinExt/WinExt.hpp>
22
int Test(int rcx, int rdx, int r8, int r9, int stack4, int stack5) {
3-
auto str1 = std::to_string(stack4);
4-
auto str2 = std::to_string(stack5);
5-
MessageBoxA(NULL, str1.c_str(), str2.c_str(), MB_OK);
3+
auto str = std::format("{} {} {}", rcx, stack4, stack5);
4+
MessageBoxA(NULL, str.c_str(), str.c_str(), MB_OK);
65
return 0;
76
}
7+
class Hooker {
8+
std::unique_ptr<MulNX::Hook> hook = nullptr;
9+
MulNX::Hook::Then OnTest(MulNX::Hook* hk, RegContext* ctx) {
10+
if (!this->enable)return MulNX::Hook::Then::Continue;
11+
ctx->rcx = std::bit_cast<uint32_t>(-1);
12+
*hk->GetStackParam<int>(ctx, 4) = 42;
13+
hk->CallMaybeOrigin(2, ctx); // 栈上两个参数
14+
return MulNX::Hook::Then::Return;
15+
}
16+
public:
17+
void DoHook() {
18+
this->hook = MulNX::Hook::Create((uint8_t*)&Test, [this](MulNX::Hook* hk, RegContext* ctx) {
19+
return this->OnTest(hk, ctx);
20+
}).value();
21+
this->hook->Attach();
22+
}
23+
bool enable = true;
24+
};
825
int main() {
26+
Hooker hooker{};
927
{
1028
auto hkMessageBoxW = MulNX::Hook::Create((uint8_t*)&MessageBoxW, [](MulNX::Hook* hk, RegContext* ctx) {
1129
if (wcscmp((wchar_t*)(ctx->rdx), L"no show"))return MulNX::Hook::Then::Return;
@@ -25,10 +43,8 @@ int main() {
2543
MessageBoxW(NULL, L"show hacked", L"example", MB_OK);
2644
}
2745
Test(0, 1, 2, 3, 4, 5);
28-
auto hkTest = MulNX::Hook::Create((uint8_t*)&Test, [](MulNX::Hook* hk, RegContext* ctx) {
29-
hk->CallMaybeOrigin(2, ctx); // 栈上两个参数
30-
return MulNX::Hook::Then::Return;
31-
}).value();
32-
hkTest->Attach();
46+
hooker.DoHook();
47+
Test(0, 1, 2, 3, 4, 5);
48+
hooker.enable = false;
3349
Test(0, 1, 2, 3, 4, 5);
3450
}

0 commit comments

Comments
 (0)