Skip to content

Commit

Permalink
Reworked hook
Browse files Browse the repository at this point in the history
- Hook-logging works now over WinSock
- Better control over injection of hook
- Moved injecteion-code completly into WhatsAppTray
  • Loading branch information
d4koon committed Sep 27, 2020
1 parent 530f1c6 commit bfdd203
Show file tree
Hide file tree
Showing 16 changed files with 840 additions and 275 deletions.
7 changes: 5 additions & 2 deletions WhatsappTray.sln
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27130.2027
# Visual Studio Version 16
VisualStudioVersion = 16.0.30503.244
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Hook", "WhatsappTray\Hook.vcxproj", "{9CD8044A-759A-4F65-B9FE-6DD8DD188428}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WhatsappTray", "WhatsappTray\WhatsappTray.vcxproj", "{CDDAA887-EEE9-47FA-B4B5-929A92D71248}"
ProjectSection(ProjectDependencies) = postProject
{9CD8044A-759A-4F65-B9FE-6DD8DD188428} = {9CD8044A-759A-4F65-B9FE-6DD8DD188428}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
26 changes: 26 additions & 0 deletions WhatsappTray/Helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <vector>
#include <sstream>
#include <Shlobj.h>
#include <psapi.h>

/* For .lnk resolver */
#include "shobjidl.h"
Expand Down Expand Up @@ -340,3 +341,28 @@ std::string Helper::ResolveLnk(HWND hwnd, LPCSTR lpszLinkFile)

return lnkPath;
}

/**
* @brief Get the path to the executable for the ProcessID
*
* @param processId The ProcessID from which the path to the executable should be fetched
* @return The path to the executable from the ProcessID
*/
std::string Helper::GetFilepathFromProcessID(DWORD processId)
{
HANDLE processHandle = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processId);
if (processHandle == NULL) {
Logger::Error(MODULE_NAME "::GetFilepathFromProcessID() - Failed to open process.");
return "";
}

wchar_t filepath[MAX_PATH];
if (GetModuleFileNameExW(processHandle, NULL, filepath, MAX_PATH) == 0) {
CloseHandle(processHandle);
Logger::Error(MODULE_NAME "::GetFilepathFromProcessID() - Failed to get module filepath.");
return "";
}
CloseHandle(processHandle);

return Helper::WideToUtf8(filepath);
}
2 changes: 2 additions & 0 deletions WhatsappTray/Helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
// Include lib for GetFileVersionInfoSize()
#pragma comment(lib,"Version.lib")

#include <windows.h>
#include <string>

class Helper
Expand All @@ -48,5 +49,6 @@ class Helper
static std::string GetFilenameFromPath(std::string path);
static std::wstring GetFilenameFromPath(std::wstring path);
static std::string ResolveLnk(HWND hwnd, LPCSTR lpszLinkFile);
static std::string GetFilepathFromProcessID(DWORD processId);
};

Loading

0 comments on commit bfdd203

Please sign in to comment.