Skip to content

Commit ce9c64f

Browse files
committed
Implemented support for multiple modules
1 parent 264dd4e commit ce9c64f

File tree

2 files changed

+60
-44
lines changed

2 files changed

+60
-44
lines changed

Injector/Injector.vcxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@
130130
</ItemDefinitionGroup>
131131
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
132132
<ClCompile>
133-
<Optimization>Full</Optimization>
133+
<Optimization>Disabled</Optimization>
134134
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
135135
<IntrinsicFunctions>true</IntrinsicFunctions>
136136
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
@@ -151,7 +151,7 @@
151151
<Link>
152152
<AdditionalDependencies>DbgHelp.lib;shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
153153
<UACExecutionLevel>AsInvoker</UACExecutionLevel>
154-
<GenerateDebugInformation>false</GenerateDebugInformation>
154+
<GenerateDebugInformation>true</GenerateDebugInformation>
155155
<SubSystem>Console</SubSystem>
156156
<OptimizeReferences>true</OptimizeReferences>
157157
<EnableCOMDATFolding>true</EnableCOMDATFolding>

Injector/Main.cpp

Lines changed: 58 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)