Skip to content

Commit

Permalink
Fix x86 plugin & minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
alabuzhev committed Aug 12, 2021
1 parent fea323b commit 230a618
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
5 changes: 5 additions & 0 deletions loader/loader.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@
<ItemGroup>
<ClCompile Include="loader.cpp" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\unicon\unicon.vcxproj">
<Project>{63579670-b132-4a04-abe8-20bcec856825}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
Expand Down
12 changes: 11 additions & 1 deletion unicon/inject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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");
}
14 changes: 11 additions & 3 deletions unicon/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
Expand Down

0 comments on commit 230a618

Please sign in to comment.