diff --git a/Injector/Injector.cpp b/Injector/Injector.cpp index ae2177d..b83fddc 100644 --- a/Injector/Injector.cpp +++ b/Injector/Injector.cpp @@ -276,8 +276,8 @@ std::tstring Injector::GetPath( const std::tstring& ModuleName ) return ModulePath; } -// Get process ID via name (must pass name as lowercase) -DWORD Injector::GetProcessIdByName(const std::tstring& Name) +// Get process ID via name +DWORD Injector::GetProcessIdByName(const std::tstring& Name, const bool CompareCaseSensitive) { // Grab a new snapshot of the process EnsureCloseHandle Snap(CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0)); @@ -291,7 +291,10 @@ DWORD Injector::GetProcessIdByName(const std::tstring& Name) for (; MoreMods; MoreMods = Process32Next(Snap, &ProcEntry)) { std::tstring CurrentProcess(ProcEntry.szExeFile); - CurrentProcess = toLower(CurrentProcess); + + if (!CompareCaseSensitive) + CurrentProcess = toLower(CurrentProcess); + Found = (CurrentProcess == Name); if (Found) break; } diff --git a/Injector/Injector.h b/Injector/Injector.h index 598a794..281f10b 100644 --- a/Injector/Injector.h +++ b/Injector/Injector.h @@ -32,7 +32,7 @@ class Injector std::tstring GetPath(const std::tstring& ModuleName); // Get process id by name - DWORD GetProcessIdByName(const std::tstring& Name); + DWORD GetProcessIdByName(const std::tstring& Name, bool CompareCaseSensitive); // Get proces id by window DWORD GetProcessIdByWindow(const std::tstring& Name); diff --git a/Injector/Injector.rc b/Injector/Injector.rc index e848bae..cf2e753 100644 Binary files a/Injector/Injector.rc and b/Injector/Injector.rc differ diff --git a/Injector/Main.cpp b/Injector/Main.cpp index 2799e70..747e6cd 100644 --- a/Injector/Main.cpp +++ b/Injector/Main.cpp @@ -33,7 +33,7 @@ int main(int, char* argv[]) SehGuard Guard; // Injector version number - const std::tstring VerNum(_T("20230813")); + const std::tstring VerNum(_T("20240218")); // Version and copyright output #ifdef _WIN64 @@ -41,12 +41,13 @@ int main(int, char* argv[]) #else std::tcout << _T("Injector x86 [Version ") << VerNum << _T("]") << std::endl; #endif - std::tcout << _T("Copyright (c) 2009 Cypher, 2012-2023 Nefarius. All rights reserved.") << std::endl << std::endl; + std::tcout << _T("Copyright (c) 2009 Cypher, 2012-2024 Nefarius. All rights reserved.") << std::endl << std::endl; argh::parser cmdl; cmdl.add_params({ "n", "process-name", + "c", "case-sensitive", "w", "window-name", "p", "process-id" }); @@ -60,6 +61,8 @@ int main(int, char* argv[]) std::cout << " options:" << std::endl; std::cout << " specify at least one of the following methods:" << std::endl; std::cout << " -n, --process-name Identify target process by process name" << std::endl; + std::cout << " -c, --case-sensitive Make the target process name case-sensitive." << std::endl; + std::cout << " Only applies when using -n or --process-name." << std::endl; std::cout << " -w, --window-name Identify target process by window title" << std::endl; std::cout << " -p, --process-id Identify target process by numeric ID" << std::endl << std::endl; std::cout << " specify at least one of the following actions:" << std::endl; @@ -107,8 +110,11 @@ int main(int, char* argv[]) if (cmdl({ "-n", "--process-name" })) { optArg = cmdl({ "-n", "--process-name" }).str(); + if (!cmdl[{ "-c", "--case-sensitive" }]) + optArg = toLower(optArg); + // Attempt injection via process name - ProcID = Injector::Get()->GetProcessIdByName(utf8_to_wstr(toLower(optArg))); + ProcID = Injector::Get()->GetProcessIdByName(utf8_to_wstr(optArg), cmdl[{ "-c", "--case-sensitive" }]); } // Find and inject via window name diff --git a/README.md b/README.md index dc7c55e..9dd5960 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ Inject any DLL into any running process with ease! Injector is a command line to You may use it in you post-build events in Visual Studio to save time and take away complexity of code by "outsourcing" the injection process. You may of course use it for any othe scenario which comes on your mind. Check out the possible command line arguments: - `-n|--process-name` identifies the target process by its module name +- `-c|--case-sensitive` makes `-n` case-sensitive. - `-w|--window-name` identifies the target process by its main windows name - `-p|--process-id` identifies the target process by its PID - `-i|--inject` or `-e|--eject` specifies the action to perform (inject or eject the DLL)