win_hook/hook_winapi/hook_winapi.cpp

42 lines
668 B
C++
Raw Normal View History

2025-08-11 15:09:43 +08:00
#include <iostream>
#include <windows.h>
#ifndef Hook_DLL_Name
#define Hook_DLL_Name
#endif
wstring GetDllFullPath(wstring& dllname)
{
wchar_t buffer[MAX_PATH];
DWORD length = GetCurrentDirectoryW(MAX_PATH, buffer);
if (length != 0)
{
return wstring(buffer) + L"\\" + dllname;
}
return wstring(L"");
}
int maint()
{
auto cmdLine = GetCommandLineW();
int argc;
auto argv = CommandLineToArgvW(cmdLine, &argc);
if (argc != 2)
{
return 1;
}
wstring dllName = Hook_DLL_Name;
wstring dllPath = GetDllFullPath(dllName);
wstring processName = wstring(argv[1]);
HookWindowsApi(dllPath, processName);
return 0;
}