@@ -41,30 +41,37 @@ int main(int, char* argv[])
4141 cmdl.add_params ({
4242 " n" , " process-name" ,
4343 " w" , " window-name" ,
44- " p" , " process-id" ,
45- " m" , " module-name"
44+ " p" , " process-id"
4645 });
4746
4847 cmdl.parse (argv);
4948
5049 // Display help
5150 if (cmdl[{ " -h" , " --help" }])
5251 {
53- std::cout << " usage: Injector [options]" << std::endl << std::endl;
54- std::cout << " specify at least one of the following methods:" << std::endl;
55- std::cout << " -n, --process-name Identify target process by process name" << std::endl;
56- std::cout << " -w, --window-name Identify target process by window title" << std::endl;
57- std::cout << " -p, --process-id Identify target process by numeric ID" << std::endl << std::endl;
58- std::cout << " specify DLL name or absolute path:" << std::endl;
59- std::cout << " -m, --module-name DLL name or absolute path" << std::endl << std::endl;
60- std::cout << " specify at least one of the following actions:" << std::endl;
61- std::cout << " -i, --inject Inject/load referenced module" << std::endl;
62- std::cout << " -e, --eject Eject/unload referenced module" << std::endl;
52+ std::cout << " usage: Injector [options] [modules]" << std::endl << std::endl;
53+ std::cout << " options:" << std::endl;
54+ std::cout << " specify at least one of the following methods:" << std::endl;
55+ std::cout << " -n, --process-name Identify target process by process name" << std::endl;
56+ std::cout << " -w, --window-name Identify target process by window title" << std::endl;
57+ std::cout << " -p, --process-id Identify target process by numeric ID" << std::endl << std::endl;
58+ std::cout << " specify at least one of the following actions:" << std::endl;
59+ std::cout << " -i, --inject Inject/load referenced module" << std::endl;
60+ std::cout << " -e, --eject Eject/unload referenced module" << std::endl << std::endl;
61+ std::cout << " modules:" << std::endl;
62+ std::cout << " myLib.dll [anotherLib.dll] [C:\\ hooks\\ yetAnotherLib.dll]" << std::endl;
6363 std::cout << std::endl;
6464
6565 return ERROR_SUCCESS;
6666 }
6767
68+ // Check positional parameter count
69+ if (cmdl.pos_args ().size () <= 1 )
70+ {
71+ std::tcout << " No module name(s) or path(s) specified!" << std::endl;
72+ return ERROR_INVALID_PARAMETER;
73+ }
74+
6875 // Check if at least one action is specified
6976 if (!cmdl[{ " -i" , " --inject" , " -e" , " --eject" }])
7077 {
@@ -88,13 +95,6 @@ int main(int, char* argv[])
8895 return ERROR_INVALID_PARAMETER;
8996 }
9097
91- // Check for the module we should work with
92- if (!(cmdl ({ " -m" , " --module-name" })))
93- {
94- std::tcout << " No module name or path specified!" << std::endl;
95- return ERROR_INVALID_PARAMETER;
96- }
97-
9898 // Variable to store process ID
9999 DWORD ProcID = 0 ;
100100 // Fully qualified module path
@@ -103,19 +103,6 @@ int main(int, char* argv[])
103103 // Temporary place for argument
104104 std::string optArg;
105105
106- // Get provided module name
107- if ((cmdl ({ " -m" , " --module-name" }) >> optArg))
108- {
109- if (PathIsRelativeA (optArg.c_str ()))
110- {
111- ModulePath = Injector::Get ()->GetPath (utf8_to_wstr (optArg));
112- }
113- else
114- {
115- ModulePath = utf8_to_wstr (optArg);
116- }
117- }
118-
119106 // Find and inject via process name
120107 if ((cmdl ({ " -n" , " --process-name" }) >> optArg))
121108 {
@@ -145,24 +132,53 @@ int main(int, char* argv[])
145132 // Get privileges required to perform the injection
146133 Injector::Get ()->GetSeDebugPrivilege ();
147134
135+ std::vector<std::wstring> modules;
136+
137+ for (auto it = std::next (cmdl.pos_args ().begin ()); it != cmdl.pos_args ().end (); ++it)
138+ modules.push_back (utf8_to_wstr (*it));
139+
148140 // Inject action
149141 if (cmdl[{ " -i" , " --inject" }])
150142 {
151- // Inject module
152- Injector::Get ()->InjectLib (ProcID, ModulePath);
153- // If we get to this point then no exceptions have been thrown so we
154- // assume success.
155- std::tcout << " Successfully injected module!" << std::endl;
143+ for (auto & mod : modules)
144+ {
145+ if (PathIsRelative (mod.c_str ()))
146+ {
147+ ModulePath = Injector::Get ()->GetPath (mod);
148+ }
149+ else
150+ {
151+ ModulePath = mod;
152+ }
153+
154+ // Inject module
155+ Injector::Get ()->InjectLib (ProcID, ModulePath);
156+ // If we get to this point then no exceptions have been thrown so we
157+ // assume success.
158+ std::tcout << " Successfully injected module!" << std::endl;
159+ }
156160 }
157161
158162 // Eject action
159163 if (cmdl[{ " -e" , " --eject" }])
160164 {
161- // Eject module
162- Injector::Get ()->EjectLib (ProcID, ModulePath);
163- // If we get to this point then no exceptions have been thrown so we
164- // assume success.
165- std::tcout << " Successfully ejected module!" << std::endl;
165+ for (auto & mod : modules)
166+ {
167+ if (PathIsRelative (mod.c_str ()))
168+ {
169+ ModulePath = Injector::Get ()->GetPath (mod);
170+ }
171+ else
172+ {
173+ ModulePath = mod;
174+ }
175+
176+ // Eject module
177+ Injector::Get ()->EjectLib (ProcID, ModulePath);
178+ // If we get to this point then no exceptions have been thrown so we
179+ // assume success.
180+ std::tcout << " Successfully ejected module!" << std::endl;
181+ }
166182 }
167183 }
168184 // Catch STL-based exceptions.
0 commit comments