Skip to content

Commit d8a9cff

Browse files
authored
Merge pull request #29 from ProjectHSI/feature/case
Add case-sensitivity support to -n.
2 parents ea46384 + 08ef791 commit d8a9cff

File tree

5 files changed

+17
-7
lines changed

5 files changed

+17
-7
lines changed

Injector/Injector.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,8 @@ std::tstring Injector::GetPath( const std::tstring& ModuleName )
276276
return ModulePath;
277277
}
278278

279-
// Get process ID via name (must pass name as lowercase)
280-
DWORD Injector::GetProcessIdByName(const std::tstring& Name)
279+
// Get process ID via name
280+
DWORD Injector::GetProcessIdByName(const std::tstring& Name, const bool CompareCaseSensitive)
281281
{
282282
// Grab a new snapshot of the process
283283
EnsureCloseHandle Snap(CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0));
@@ -291,7 +291,10 @@ DWORD Injector::GetProcessIdByName(const std::tstring& Name)
291291
for (; MoreMods; MoreMods = Process32Next(Snap, &ProcEntry))
292292
{
293293
std::tstring CurrentProcess(ProcEntry.szExeFile);
294-
CurrentProcess = toLower(CurrentProcess);
294+
295+
if (!CompareCaseSensitive)
296+
CurrentProcess = toLower(CurrentProcess);
297+
295298
Found = (CurrentProcess == Name);
296299
if (Found) break;
297300
}

Injector/Injector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Injector
3232
std::tstring GetPath(const std::tstring& ModuleName);
3333

3434
// Get process id by name
35-
DWORD GetProcessIdByName(const std::tstring& Name);
35+
DWORD GetProcessIdByName(const std::tstring& Name, bool CompareCaseSensitive);
3636
// Get proces id by window
3737
DWORD GetProcessIdByWindow(const std::tstring& Name);
3838

Injector/Injector.rc

0 Bytes
Binary file not shown.

Injector/Main.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,21 @@ int main(int, char* argv[])
3333
SehGuard Guard;
3434

3535
// Injector version number
36-
const std::tstring VerNum(_T("20230813"));
36+
const std::tstring VerNum(_T("20240218"));
3737

3838
// Version and copyright output
3939
#ifdef _WIN64
4040
std::tcout << _T("Injector x64 [Version ") << VerNum << _T("]") << std::endl;
4141
#else
4242
std::tcout << _T("Injector x86 [Version ") << VerNum << _T("]") << std::endl;
4343
#endif
44-
std::tcout << _T("Copyright (c) 2009 Cypher, 2012-2023 Nefarius. All rights reserved.") << std::endl << std::endl;
44+
std::tcout << _T("Copyright (c) 2009 Cypher, 2012-2024 Nefarius. All rights reserved.") << std::endl << std::endl;
4545

4646
argh::parser cmdl;
4747

4848
cmdl.add_params({
4949
"n", "process-name",
50+
"c", "case-sensitive",
5051
"w", "window-name",
5152
"p", "process-id"
5253
});
@@ -60,6 +61,8 @@ int main(int, char* argv[])
6061
std::cout << " options:" << std::endl;
6162
std::cout << " specify at least one of the following methods:" << std::endl;
6263
std::cout << " -n, --process-name Identify target process by process name" << std::endl;
64+
std::cout << " -c, --case-sensitive Make the target process name case-sensitive." << std::endl;
65+
std::cout << " Only applies when using -n or --process-name." << std::endl;
6366
std::cout << " -w, --window-name Identify target process by window title" << std::endl;
6467
std::cout << " -p, --process-id Identify target process by numeric ID" << std::endl << std::endl;
6568
std::cout << " specify at least one of the following actions:" << std::endl;
@@ -107,8 +110,11 @@ int main(int, char* argv[])
107110
if (cmdl({ "-n", "--process-name" }))
108111
{
109112
optArg = cmdl({ "-n", "--process-name" }).str();
113+
if (!cmdl[{ "-c", "--case-sensitive" }])
114+
optArg = toLower(optArg);
115+
110116
// Attempt injection via process name
111-
ProcID = Injector::Get()->GetProcessIdByName(utf8_to_wstr(toLower(optArg)));
117+
ProcID = Injector::Get()->GetProcessIdByName(utf8_to_wstr(optArg), cmdl[{ "-c", "--case-sensitive" }]);
112118
}
113119

114120
// Find and inject via window name

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Inject any DLL into any running process with ease! Injector is a command line to
1515
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:
1616

1717
- `-n|--process-name` identifies the target process by its module name
18+
- `-c|--case-sensitive` makes `-n` case-sensitive.
1819
- `-w|--window-name` identifies the target process by its main windows name
1920
- `-p|--process-id` identifies the target process by its PID
2021
- `-i|--inject` or `-e|--eject` specifies the action to perform (inject or eject the DLL)

0 commit comments

Comments
 (0)