diff --git a/loader/loader.vcxproj b/loader/loader.vcxproj index 5e4d358..8cdb7f1 100644 --- a/loader/loader.vcxproj +++ b/loader/loader.vcxproj @@ -165,6 +165,11 @@ + + + {63579670-b132-4a04-abe8-20bcec856825} + + diff --git a/unicon/inject.cpp b/unicon/inject.cpp index c3aadca..713a909 100644 --- a/unicon/inject.cpp +++ b/unicon/inject.cpp @@ -85,8 +85,9 @@ __declspec(dllexport) void inject(unsigned Pid) if (!QueryFullProcessImageName(Process, {}, Name, &NameSize)) throw std::runtime_error("QueryFullProcessImageName"); + // It if's not conhost, it's either OpenConsole (which shouldn't need this already) or csrss (which doesn't need this yet). if (!is_conhost(Name)) - throw std::runtime_error("not conhost"); + return; const auto FullDllPathSize = (wcslen(FullDllPath) + 1) * sizeof(wchar_t); @@ -105,5 +106,14 @@ __declspec(dllexport) void inject(unsigned Pid) if (!RemoteThread) throw std::runtime_error("CreateRemoteThread"); + SCOPE_EXIT{ CloseHandle(RemoteThread); }; + WaitForSingleObject(RemoteThread, INFINITE); + + DWORD ExitCode; + if (!GetExitCodeThread(RemoteThread, &ExitCode)) + throw std::runtime_error("GetExitCodeThread"); + + if (!ExitCode) + throw std::runtime_error("Patch failed"); } diff --git a/unicon/plugin.cpp b/unicon/plugin.cpp index 0e2cd4c..bb74be9 100644 --- a/unicon/plugin.cpp +++ b/unicon/plugin.cpp @@ -3,11 +3,15 @@ #include "plugin.hpp" #include "inject.hpp" +#define EXPORT_THIS __pragma(comment(linker, "/EXPORT:" __FUNCTION__ "=" __FUNCDNAME__)) + // {1A795D4B-DC68-4C77-8CE9-F4CAB04B8E99} static const GUID MainUUID = { 0x1a795d4b, 0xdc68, 0x4c77, { 0x8c, 0xe9, 0xf4, 0xca, 0xb0, 0x4b, 0x8e, 0x99 } }; -extern "C" __declspec(dllexport) void WINAPI GetGlobalInfoW(GlobalInfo* Info) +extern "C" void WINAPI GetGlobalInfoW(GlobalInfo* Info) { + EXPORT_THIS + Info->StructSize = sizeof(GlobalInfo); Info->MinFarVersion = MAKEFARVERSION(3, 0, 0, 5000, VS_RELEASE); Info->Version = MAKEFARVERSION(1, 0, 0, 0, VS_RELEASE); @@ -17,14 +21,18 @@ extern "C" __declspec(dllexport) void WINAPI GetGlobalInfoW(GlobalInfo* Info) Info->Author = L"Alex Alabuzhev"; } -extern "C" __declspec(dllexport) void WINAPI GetPluginInfoW(PluginInfo* Info) +extern "C" void WINAPI GetPluginInfoW(PluginInfo* Info) { + EXPORT_THIS + Info->StructSize = sizeof(*Info); Info->Flags = PF_PRELOAD; } -extern "C" __declspec(dllexport) void WINAPI SetStartupInfoW(const struct PluginStartupInfo* PSInfo) +extern "C" void WINAPI SetStartupInfoW(const struct PluginStartupInfo* PSInfo) { + EXPORT_THIS + try { inject();