Skip to content

Commit c9c4889

Browse files
author
ViniDalvino
committed
Polished things
1 parent 35667ed commit c9c4889

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

src/main.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ int main(int argc, char const *argv[])
3939
#endif
4040
SetConsoleTitleW(L"Command line dll injector");
4141
blackbone::InitializeOnce();
42-
po::options_description desc("Allowed options:");
42+
po::options_description desc("Allowed options");
4343
desc.add_options()
4444
("help,h", "Produce help message of the program")
4545
("dll,d", po::value<std::string>(), "The dll to inject")
4646
("exe,e", po::value<std::string>(), "The program exe file name to inject the onto Example: mspaint.exe")
4747
// ("process-name,p", po::value<std::string>(), "The program process name")
4848
("watch,w", "Inject the DLL as soon as the specified program is launched")
49-
("delay", po::value<float>(), "Wait a certain aount of time before injecting in seconds")
50-
("unload-dll,u", "Unload the dll that is going to be injected if it's already loaded");
49+
("delay", po::value<float>(), "Wait a certain aount of time before injecting in seconds");
50+
// ("unload-dll,u", "Unload the dll that is going to be injected if it's already loaded");
5151

5252
po::variables_map vm;
5353
po::store(po::parse_command_line(argc, argv, desc), vm, true);
@@ -115,29 +115,26 @@ if (vm.count("exe"))
115115

116116
blackbone::Process process;
117117
HANDLE h = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
118+
process.Attach(h);
118119

119120
blackbone::pe::PEImage dll_peimage;
120121
dll_peimage.Load(utf8ToUtf16(dll_path));
121122

122123
// Check the file format
123-
if (IsWow64(h) && dll_peimage.mType() != blackbone::eModType::mt_mod64)
124+
if (dll_peimage.mType() == blackbone::eModType::mt_default || dll_peimage.mType() == blackbone::eModType::mt_unknown);
125+
else if (process.core().isWow64() && dll_peimage.mType() != blackbone::eModType::mt_mod64)
124126
{
125127
std::cerr << "Error: attempt to load a 32 bit dll on a 64 bit process\n";
126128
return 1;
127129
}
128-
else if (IsX86Process(h) && dll_peimage.mType() != blackbone::eModType::mt_mod32)
130+
else if (!process.core().isWow64() && dll_peimage.mType() != blackbone::eModType::mt_mod32)
129131
{
130132
std::cerr << "Error: attempt to load a 64 bit dll on a 32 bit process\n";
131133
return 1;
132134
}
133135

134136
// NT_ERROR
135137
Sleep(delay * 1000);
136-
if (((((ULONG)(process.Attach(pid))) >> 30) == 3))
137-
{
138-
std::cout << "An error has happened while attaching blackbone to the process.\n";
139-
return 1;
140-
}
141138

142139
// attach the dll
143140
if (vm.count("unload-dll"))
@@ -179,7 +176,7 @@ if (vm.count("exe"))
179176
else
180177
{
181178
bool didInjectedDll;
182-
if (!process.modules().Inject(dll_peimage.path(), process.threads().getMain()).success())
179+
if (!process.modules().Inject(dll_peimage.path(), process.threads().getMostExecuted()).success())
183180
{
184181
std::cerr << "An error has happened when injecting the dll\n";
185182
return 1;

0 commit comments

Comments
 (0)