Skip to content

Commit

Permalink
Allow detecting injection success
Browse files Browse the repository at this point in the history
At least this will hint to issues that can be discovered by looking at the log.
  • Loading branch information
kzu committed Sep 23, 2022
1 parent 6ca7e08 commit b578ed3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/Bootstrap/Injector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static HHOOK _messageHookHandle;
//-----------------------------------------------------------------------------
//Spying Process functions follow
//-----------------------------------------------------------------------------
void Injector::Launch(System::IntPtr windowHandle, System::String^ assemblyFile, System::String^ typeFullName, System::String^ methodName)
bool Injector::Launch(System::IntPtr windowHandle, System::String^ assemblyFile, System::String^ typeFullName, System::String^ methodName)
{
System::String^ assemblyClassAndMethod = assemblyFile + "$" + typeFullName + "$" + methodName;
pin_ptr<const wchar_t> acmLocal = PtrToStringChars(assemblyClassAndMethod);
Expand Down Expand Up @@ -52,6 +52,7 @@ void Injector::Launch(System::IntPtr windowHandle, System::String^ assemblyFile,
LogMessage("SetWindowsHookEx successful", true);
::SendMessage((HWND)windowHandle.ToPointer(), WM_GOBABYGO, (WPARAM)acmRemote, 0);
::UnhookWindowsHookEx(_messageHookHandle);
return true;
}

::VirtualFreeEx(hProcess, acmRemote, 0, MEM_RELEASE);
Expand All @@ -69,6 +70,8 @@ void Injector::Launch(System::IntPtr windowHandle, System::String^ assemblyFile,
}
::FreeLibrary(hinstDLL);
}

return false;
}

void Injector::LogMessage(String^ message, bool append)
Expand Down
2 changes: 1 addition & 1 deletion src/Bootstrap/Injector.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Devlooped
{
public:

static void Launch(System::IntPtr windowHandle, System::String^ assemblyFile, System::String^ typeFullName, System::String^ methodName);
static bool Launch(System::IntPtr windowHandle, System::String^ assemblyFile, System::String^ typeFullName, System::String^ methodName);

static void LogMessage(System::String^ message, bool append);
};
Expand Down
6 changes: 4 additions & 2 deletions src/Injector/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ static int Main(string[] args)
var typeName = args[2].Trim('"');
var methodName = args[3].Trim('"');

Injector.Launch(mainWindow, assemblyFile, typeName, methodName);
return 0;
if (Injector.Launch(mainWindow, assemblyFile, typeName, methodName))
return 0;
else
return -1;
}
}
}

0 comments on commit b578ed3

Please sign in to comment.