Skip to content

Commit

Permalink
Move Detour EventLogger Initialize (#55)
Browse files Browse the repository at this point in the history
* Update version

* Log initialize

* Move initialize earlier for detours
  • Loading branch information
mwasplund authored Aug 4, 2020
1 parent ad5aaa3 commit 5def8e0
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 5 deletions.
18 changes: 18 additions & 0 deletions Source/Build/Execute/SystemAccessTracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -510,22 +510,27 @@ namespace Soup::Build
// ProcessThreadsApi
void OnCreateProcessA(std::string_view applicationName, bool result) override final
{
OnCreateProcess(applicationName);
}

void OnCreateProcessW(std::wstring_view applicationName, bool result) override final
{
OnCreateProcess(applicationName);
}

void OnCreateProcessAsUserA(std::string_view applicationName, bool result) override final
{
OnCreateProcess(applicationName);
}

void OnCreateProcessAsUserW(std::wstring_view applicationName, bool result) override final
{
OnCreateProcess(applicationName);
}

void OnExitProcess(uint32_t exitCode) override final
{
Log::Diag("SystemAccessTracker::OnExitProcess - " + std::to_string(exitCode));
}

// UndocumentedApi
Expand Down Expand Up @@ -673,10 +678,12 @@ namespace Soup::Build

void OnCreateProcessWithLogonW(std::wstring_view applicationName, bool result) override final
{
OnCreateProcess(applicationName);
}

void OnCreateProcessWithTokenW(std::wstring_view applicationName, bool result) override final
{
OnCreateProcess(applicationName);
}

void OnCreateSymbolicLinkA(std::string_view symlinkFileName, std::string_view targetFileName, uint32_t flags, bool result) override final
Expand Down Expand Up @@ -1018,6 +1025,17 @@ namespace Soup::Build
}

private:
void OnCreateProcess(std::wstring_view applicationName)
{
std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> converter;
OnCreateProcess(converter.to_bytes(applicationName.data()));
}

void OnCreateProcess(std::string_view applicationName)
{
Log::Diag("SystemAccessTracker::OnCreateProcess - " + std::string(applicationName));
}

void TouchFileRead(std::wstring_view fileName, bool exists)
{
std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> converter;
Expand Down
2 changes: 1 addition & 1 deletion Source/Client/CLI/Commands/VersionCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace Soup::Client

// TODO var version = Assembly.GetExecutingAssembly().GetName().Version;
// Log::Message($"{version.Major}.{version.Minor}.{version.Build}");
Log::HighPriority("0.8.2");
Log::HighPriority("0.8.3");
}

private:
Expand Down
2 changes: 1 addition & 1 deletion Source/Client/CLI/Recipe.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Name = "Soup"
Version = "0.8.2"
Version = "0.8.3"
Type = "Executable"

# Ensure the core build extensions are runtime dependencies
Expand Down
5 changes: 4 additions & 1 deletion Source/Monitor/Detours/EventLogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,10 @@ class EventLogger
static void UnsafeWriteMessage(const Monitor::DetourMessage& message)
{
if (s_pipeHandle == INVALID_HANDLE_VALUE)
return; // TODO: A static dll init may do bad things before the main entry initialize
{
printf("DETOURS-ERROR: Handle not ready!! %u\n", (uint32_t)message.Type);
exit(-1234);
}

// Write the message
DWORD countBytesToWrite = message.ContentSize +
Expand Down
2 changes: 0 additions & 2 deletions Source/Monitor/Detours/Functions/UndocumentedApiOverrides.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ namespace Functions::UndocumentedApi::Overrides
{
int WINAPI EntryPoint(void)
{
EventLogger::Initialize();

return Cache::EntryPoint();
}

Expand Down
3 changes: 3 additions & 0 deletions Source/Monitor/Detours/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,9 @@ bool ProcessAttach(HMODULE hDll)

try
{
// Initialize the event pipe
EventLogger::Initialize();

// Find hidden functions.
Functions::UndocumentedApi::Cache::PrivCopyFileExA =
(BOOL (WINAPI *)(LPCSTR, LPCSTR, LPPROGRESS_ROUTINE, LPVOID, LPBOOL, DWORD))
Expand Down

0 comments on commit 5def8e0

Please sign in to comment.