mirror of
https://github.com/HIllya51/LunaHook.git
synced 2025-01-12 21:04:00 +08:00
maybe0
This commit is contained in:
parent
e95fbfc4e9
commit
f7c06d0cb9
@ -16,51 +16,37 @@ BOOL APIENTRY DllMain(HMODULE hModule,
|
|||||||
}
|
}
|
||||||
|
|
||||||
typedef void (*ProcessEvent)(DWORD);
|
typedef void (*ProcessEvent)(DWORD);
|
||||||
typedef void (*ThreadEvent)(wchar_t *, char *, ThreadParam);
|
typedef void (*ThreadEvent)(const wchar_t *, const char *, ThreadParam);
|
||||||
typedef bool (*OutputCallback)(wchar_t *, char *, ThreadParam, const wchar_t *);
|
typedef bool (*OutputCallback)(const wchar_t *, const char *, ThreadParam, const wchar_t *);
|
||||||
typedef void (*ConsoleHandler)(const wchar_t *);
|
typedef void (*ConsoleHandler)(const wchar_t *);
|
||||||
typedef void (*HookInsertHandler)(uint64_t, const wchar_t *);
|
typedef void (*HookInsertHandler)(uint64_t, const wchar_t *);
|
||||||
typedef void (*EmbedCallback)(const wchar_t *, ThreadParam);
|
typedef void (*EmbedCallback)(const wchar_t *, ThreadParam);
|
||||||
#define XXXX \
|
template <typename T>
|
||||||
char name[HOOK_NAME_SIZE]; \
|
std::optional<T> checkoption(bool check, T &&t)
|
||||||
wchar_t hookcode[HOOKCODE_LEN]; \
|
{
|
||||||
wcscpy_s(hookcode, HOOKCODE_LEN, thread.hp.hookcode); \
|
if (check)
|
||||||
strcpy_s(name, HOOK_NAME_SIZE, thread.hp.name);
|
return std::move(t);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
C_LUNA_API void Luna_Start(ProcessEvent Connect, ProcessEvent Disconnect, ThreadEvent Create, ThreadEvent Destroy, OutputCallback Output, ConsoleHandler console, HookInsertHandler hookinsert, EmbedCallback embed, ConsoleHandler Warning)
|
C_LUNA_API void Luna_Start(ProcessEvent Connect, ProcessEvent Disconnect, ThreadEvent Create, ThreadEvent Destroy, OutputCallback Output, ConsoleHandler console, HookInsertHandler hookinsert, EmbedCallback embed, ConsoleHandler Warning)
|
||||||
{
|
{
|
||||||
Host::StartEx(
|
Host::StartEx(
|
||||||
Connect,
|
checkoption(Connect, std::function<void(DWORD)>(Connect)),
|
||||||
Disconnect,
|
checkoption(Disconnect, std::function<void(DWORD)>(Disconnect)),
|
||||||
[=](const TextThread &thread)
|
checkoption(Create, [=](const TextThread &thread)
|
||||||
{
|
{ Create(thread.hp.hookcode, thread.hp.name, thread.tp); }),
|
||||||
XXXX
|
checkoption(Destroy, [=](const TextThread &thread)
|
||||||
Create(hookcode, name, thread.tp);
|
{ Destroy(thread.hp.hookcode, thread.hp.name, thread.tp); }),
|
||||||
},
|
checkoption(Output, [=](const TextThread &thread, std::wstring &output)
|
||||||
[=](const TextThread &thread)
|
{ return Output(thread.hp.hookcode, thread.hp.name, thread.tp, output.c_str()); }),
|
||||||
{
|
checkoption(console, [=](const std::wstring &output)
|
||||||
XXXX
|
{ console(output.c_str()); }),
|
||||||
Destroy(hookcode, name, thread.tp);
|
checkoption(hookinsert, [=](uint64_t addr, const std::wstring &output)
|
||||||
},
|
{ hookinsert(addr, output.c_str()); }),
|
||||||
[=](const TextThread &thread, std::wstring &output)
|
checkoption(embed, [=](const std::wstring &output, const ThreadParam &tp)
|
||||||
{
|
{ embed(output.c_str(), tp); }),
|
||||||
XXXX return Output(hookcode, name, thread.tp, output.c_str());
|
checkoption(Warning, [=](const std::wstring &output)
|
||||||
},
|
{ Warning(output.c_str()); }));
|
||||||
[=](const std::wstring &output)
|
|
||||||
{
|
|
||||||
console(output.c_str());
|
|
||||||
},
|
|
||||||
[=](uint64_t addr, const std::wstring &output)
|
|
||||||
{
|
|
||||||
hookinsert(addr, output.c_str());
|
|
||||||
},
|
|
||||||
[=](const std::wstring &output, const ThreadParam &tp)
|
|
||||||
{
|
|
||||||
embed(output.c_str(), tp);
|
|
||||||
},
|
|
||||||
[=](const std::wstring &output)
|
|
||||||
{
|
|
||||||
Warning(output.c_str());
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
C_LUNA_API void Luna_Inject(DWORD pid, LPCWSTR basepath)
|
C_LUNA_API void Luna_Inject(DWORD pid, LPCWSTR basepath)
|
||||||
{
|
{
|
||||||
|
@ -217,18 +217,20 @@ namespace Host
|
|||||||
|
|
||||||
// CreatePipe();
|
// CreatePipe();
|
||||||
}
|
}
|
||||||
void StartEx(ProcessEventHandler Connect, ProcessEventHandler Disconnect, ThreadEventHandler Create, ThreadEventHandler Destroy, TextThread::OutputCallback Output, std::optional<ConsoleHandler> console, std::optional<HookInsertHandler> hookinsert, std::optional<EmbedCallback> embed, std::optional<ConsoleHandler> warning)
|
void StartEx(std::optional<ProcessEventHandler> Connect, std::optional<ProcessEventHandler> Disconnect, std::optional<ThreadEventHandler> Create, std::optional<ThreadEventHandler> Destroy, std::optional<TextThread::OutputCallback> Output, std::optional<ConsoleHandler> console, std::optional<HookInsertHandler> hookinsert, std::optional<EmbedCallback> embed, std::optional<ConsoleHandler> warning)
|
||||||
{
|
{
|
||||||
Start(Connect, Disconnect, Create, Destroy, Output, !console.has_value());
|
Start(Connect.value_or([](auto) {}), Disconnect.value_or([](auto) {}), Create.value_or([](auto &) {}), Destroy.value_or([](auto &) {}), Output.value_or([](auto &, auto &)
|
||||||
if (warning.has_value())
|
{ return false; }),
|
||||||
|
!console);
|
||||||
|
if (warning)
|
||||||
OnWarning = warning.value();
|
OnWarning = warning.value();
|
||||||
if (console.has_value())
|
if (console)
|
||||||
OnConsole = [=](auto &&...args)
|
OnConsole = [=](auto &&...args)
|
||||||
{std::lock_guard _(outputmutex);console.value()(std::forward<decltype(args)>(args)...); };
|
{std::lock_guard _(outputmutex);console.value()(std::forward<decltype(args)>(args)...); };
|
||||||
if (hookinsert.has_value())
|
if (hookinsert)
|
||||||
HookInsert = [=](auto &&...args)
|
HookInsert = [=](auto &&...args)
|
||||||
{std::lock_guard _(threadmutex);hookinsert.value()(std::forward<decltype(args)>(args)...); };
|
{std::lock_guard _(threadmutex);hookinsert.value()(std::forward<decltype(args)>(args)...); };
|
||||||
if (embed.has_value())
|
if (embed)
|
||||||
embedcallback = [=](auto &&...args)
|
embedcallback = [=](auto &&...args)
|
||||||
{std::lock_guard _(outputmutex);embed.value()(std::forward<decltype(args)>(args)...); };
|
{std::lock_guard _(outputmutex);embed.value()(std::forward<decltype(args)>(args)...); };
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ namespace Host
|
|||||||
using HookInsertHandler = std::function<void(uint64_t, const std::wstring &)>;
|
using HookInsertHandler = std::function<void(uint64_t, const std::wstring &)>;
|
||||||
using EmbedCallback = std::function<void(const std::wstring &, const ThreadParam &)>;
|
using EmbedCallback = std::function<void(const std::wstring &, const ThreadParam &)>;
|
||||||
void Start(ProcessEventHandler Connect, ProcessEventHandler Disconnect, ThreadEventHandler Create, ThreadEventHandler Destroy, TextThread::OutputCallback Output, bool createconsole = true);
|
void Start(ProcessEventHandler Connect, ProcessEventHandler Disconnect, ThreadEventHandler Create, ThreadEventHandler Destroy, TextThread::OutputCallback Output, bool createconsole = true);
|
||||||
void StartEx(ProcessEventHandler Connect, ProcessEventHandler Disconnect, ThreadEventHandler Create, ThreadEventHandler Destroy, TextThread::OutputCallback Output, std::optional<ConsoleHandler> console, std::optional<HookInsertHandler> hookinsert, std::optional<EmbedCallback> embed, std::optional<ConsoleHandler> warning);
|
void StartEx(std::optional<ProcessEventHandler> Connect, std::optional<ProcessEventHandler> Disconnect, std::optional<ThreadEventHandler> Create, std::optional<ThreadEventHandler> Destroy, std::optional<TextThread::OutputCallback> Output, std::optional<ConsoleHandler> console, std::optional<HookInsertHandler> hookinsert, std::optional<EmbedCallback> embed, std::optional<ConsoleHandler> warning);
|
||||||
void InjectProcess(DWORD processId, const std::wstring locationX = L"");
|
void InjectProcess(DWORD processId, const std::wstring locationX = L"");
|
||||||
bool CreatePipeAndCheck(DWORD processId);
|
bool CreatePipeAndCheck(DWORD processId);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user