2020#include < BlackBone/Misc/Utils.h>
2121#include < filesystem>
2222#include < BlackBone/PE/PEImage.h>
23- #include < spinner.h>
2423#include < BlackBone/PE/ImageNET.h>
24+ #define NAKED __declspec ( naked )
25+
2526
2627using namespace std::chrono_literals;
2728namespace po = boost::program_options;
2829
30+ bool nt_error (NTSTATUS status);
31+
32+ // #define WAIT_DEBUG_ATTACH
33+
2934int main (int argc, char const *argv[])
3035{
36+ #ifdef WAIT_DEBUG_ATTACH
37+ BOOL isDebuggerPresent;
38+ while (!isDebuggerPresent) { CheckRemoteDebuggerPresent (GetModuleHandle (NULL ), &isDebuggerPresent); };
39+ #endif
3140 SetConsoleTitleW (L" Command line dll injector" );
3241 blackbone::InitializeOnce ();
3342 po::options_description desc (" Allowed options:" );
@@ -133,12 +142,19 @@ if (vm.count("exe"))
133142 // attach the dll
134143 if (vm.count (" unload-dll" ))
135144 {
136- spinnercpp::spinner s (200ms, 63 , " Unloaded dll!" , " " , " " , " Unloading " + vm[" dll" ].as <std::string>() + " ..." );
137- s.start ();
138- auto isError = NT_ERROR (process.modules ().Unload (process.modules ().GetModule (utf8ToUtf16 (vm[" dll" ].as <std::string>()))));
139- if (isError)
140- std::cerr << " There was a error unloading the dll on the process. Continuing execution of the program." ;
141- s.stop ();
145+ std::cout << " Unloading dll. . ." << std::endl;
146+ auto dll_ = process.modules ().GetModule (utf8ToUtf16 (vm[" dll_" ].as <std::string>()));
147+ if (dll_->type != blackbone::eModType::mt_unknown || dll_->size == 0x0 )
148+ {
149+ if (nt_error (process.modules ().Unload (dll_)))
150+ std::cerr << " There was a error unloading the dll on the process. Continuing execution of the program." << std::endl;
151+ else
152+ {
153+ std::cout << " Unloaded dll!" << std::endl;
154+ }
155+ }
156+ else
157+ std::cerr << " Couldn't unload dll as it's not present in memory." << std::endl;
142158 }
143159
144160 if (dll_peimage.pureIL ())
@@ -175,4 +191,9 @@ if (vm.count("exe"))
175191
176192 std::cout << desc << " \n " ;
177193 return 0 ;
194+ }
195+
196+ bool nt_error (NTSTATUS status)
197+ {
198+ return ((((ULONG)(status)) >> 30 ) == 3 );
178199}
0 commit comments