11#include < MulNXUtils/WinExt/WinExt.hpp>
22int 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+ };
825int 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