Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add case-sensitivity support to -n. #29

Merged
merged 12 commits into from
Feb 18, 2024
9 changes: 6 additions & 3 deletions Injector/Injector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion Injector/Injector.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Binary file modified Injector/Injector.rc
Binary file not shown.
12 changes: 9 additions & 3 deletions Injector/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,21 @@ 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
std::tcout << _T("Injector x64 [Version ") << VerNum << _T("]") << std::endl;
#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"
});
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading