@@ -41,20 +41,21 @@ int main(int argc, char *argv[])
4141 return EXIT_FAILURE;
4242
4343 // Parse command line arguments with cxxopts
44- cxxopts::Options options (" GhostInjector " ,
45- " DLL Injection tool for Windows processes \n\n "
46- " Examples: \n "
47- " ghostinjector.exe 1234 mydll.dll \n "
48- " ghostinjector.exe 5678 first .dll second.dll third.dll " );
49-
50- options. add_options ()
51- ( " h,help" , " Print this help message" )
52- ( " positional" , " Process ID and DLL path(s)" ,
53- cxxopts::value<std::vector<std::string>>());
54-
55- options.parse_positional ({" positional" });
44+ cxxopts::Options options (
45+ " GhostInjector " ,
46+ " DLL Injection tool for Windows processes \n \n"
47+ " Examples: \n "
48+ " ghostinjector.exe 1234 mydll .dll\n "
49+ " ghostinjector.exe 5678 first.dll second.dll third.dll " );
50+
51+ options. add_options ()( " h,help" , " Print this help message" )(
52+ " positional" , " Process ID and DLL path(s)" ,
53+ cxxopts::value<std::vector<std::string> >());
54+
55+ options.parse_positional ({ " positional" });
5656 options.positional_help (" <process_id> <dll_path> [dll_path2 ...]" );
57- options.custom_help (" [OPTIONS] <process_id> <dll_path> [dll_path2 ...]" );
57+ options.custom_help (
58+ " [OPTIONS] <process_id> <dll_path> [dll_path2 ...]" );
5859
5960 try {
6061 auto result = options.parse (argc, argv);
@@ -71,16 +72,20 @@ int main(int argc, char *argv[])
7172 }
7273
7374 if (!result.count (" positional" )) {
74- std::cerr << " Error: Missing required arguments" << std::endl;
75+ std::cerr << " Error: Missing required arguments"
76+ << std::endl;
7577 std::cerr << std::endl << options.help () << std::endl;
7678 neptune_destroy ();
7779 return 0x10 ;
7880 }
7981
80- auto & positional = result[" positional" ].as <std::vector<std::string>>();
81-
82+ auto &positional =
83+ result[" positional" ].as <std::vector<std::string> >();
84+
8285 if (positional.size () < 2 ) {
83- std::cerr << " Error: Not enough arguments (need at least PID and one DLL path)" << std::endl;
86+ std::cerr
87+ << " Error: Not enough arguments (need at least PID and one DLL path)"
88+ << std::endl;
8489 std::cerr << std::endl << options.help () << std::endl;
8590 neptune_destroy ();
8691 return 0x10 ;
@@ -91,39 +96,41 @@ int main(int argc, char *argv[])
9196#ifdef LOG_LEVEL_1
9297 LOG_INFO (" Neptune initialized!" );
9398 LOG_INFO (" ID: %u" , id);
94- LOG_INFO (" Number of DLLs to inject: %zu" , positional.size () - 1 );
99+ LOG_INFO (" Number of DLLs to inject: %zu" ,
100+ positional.size () - 1 );
95101#endif
96102
97- if (id == 0 ) {
103+ if (id == 0 ) {
98104#ifdef LOG_LEVEL_1
99- LOG_ERROR (" Invalid id: must be greater than 0" );
105+ LOG_ERROR (" Invalid id: must be greater than 0" );
100106#endif
101- neptune_destroy ();
102- return 0x11 ;
103- }
107+ neptune_destroy ();
108+ return 0x11 ;
109+ }
104110
105- // Get kernel32.dll handle (outside of any block for proper scope)
106- HMODULE kernel32 = GetModuleHandleA (" kernel32" );
107- if (kernel32 == NULL ) {
111+ // Get kernel32.dll handle (outside of any block for proper scope)
112+ HMODULE kernel32 = GetModuleHandleA (" kernel32" );
113+ if (kernel32 == NULL ) {
108114#ifdef LOG_LEVEL_1
109- LOG_ERROR (" GetModuleHandleA failed" );
115+ LOG_ERROR (" GetModuleHandleA failed" );
110116#endif
111- neptune_destroy ();
112- return 0x20 ;
113- }
117+ neptune_destroy ();
118+ return 0x20 ;
119+ }
114120
115- // Get LoadLibraryA function address (outside of any block for proper scope)
116- FARPROC load_library_func = GetProcAddress (kernel32, " LoadLibraryA" );
117- if (load_library_func == NULL ) {
121+ // Get LoadLibraryA function address (outside of any block for proper scope)
122+ FARPROC load_library_func =
123+ GetProcAddress (kernel32, " LoadLibraryA" );
124+ if (load_library_func == NULL ) {
118125#ifdef LOG_LEVEL_1
119- LOG_ERROR (" GetProcAddress failed" );
126+ LOG_ERROR (" GetProcAddress failed" );
120127#endif
121- neptune_destroy ();
122- return 0x21 ;
123- }
128+ neptune_destroy ();
129+ return 0x21 ;
130+ }
124131
125132#ifdef LOG_LEVEL_1
126- LOG_INFO (" LoadLibraryA=%p" , (void *)load_library_func);
133+ LOG_INFO (" LoadLibraryA=%p" , (void *)load_library_func);
127134#endif
128135
129136 // Initialize the ntutils layer for working on the target thread.
@@ -134,7 +141,8 @@ int main(int argc, char *argv[])
134141
135142 if (HAS_ERR (nosu_find_thread_and_upgrade (id))) {
136143#ifdef LOG_LEVEL_1
137- LOG_ERROR (" nosu_find_thread_and_upgrade failed" );
144+ LOG_ERROR (
145+ " nosu_find_thread_and_upgrade failed" );
138146#endif
139147 neptune_destroy ();
140148 return 0x06 ;
@@ -146,13 +154,15 @@ int main(int argc, char *argv[])
146154 const char *dll_path = positional[i].c_str ();
147155
148156#ifdef LOG_LEVEL_1
149- LOG_INFO (" Injecting DLL [%zu/%zu]: %s" , i, positional.size () - 1 , dll_path);
157+ LOG_INFO (" Injecting DLL [%zu/%zu]: %s" , i,
158+ positional.size () - 1 , dll_path);
150159#endif
151160
152161 size_t dll_path_len = strlen (dll_path);
153162 size_t dll_path_size = dll_path_len + 1 ;
154163
155- ntmem_t *ntmem = ntm_create_with_alloc_ex (dll_path_size + 1 );
164+ ntmem_t *ntmem =
165+ ntm_create_with_alloc_ex (dll_path_size + 1 );
156166 if (ntmem == NULL ) {
157167#ifdef LOG_LEVEL_1
158168 LOG_ERROR (" ntm_create failed for %s" , dll_path);
@@ -179,7 +189,8 @@ int main(int argc, char *argv[])
179189#endif
180190
181191 // Call LoadLibraryA inside the target thread context.
182- void *load_library_ret = ntu_ucall ((void *)load_library_func, dll_path_addr);
192+ void *load_library_ret = ntu_ucall (
193+ (void *)load_library_func, dll_path_addr);
183194
184195#ifdef LOG_LEVEL_1
185196 LOG_INFO (" LoadLibrary returned: %p" , load_library_ret);
@@ -196,11 +207,12 @@ int main(int argc, char *argv[])
196207 neptune_destroy ();
197208 return EXIT_SUCCESS;
198209
199- } catch (const cxxopts::exceptions::exception& e) {
210+ } catch (const cxxopts::exceptions::exception & e) {
200211#ifdef LOG_LEVEL_1
201212 LOG_ERROR (" Error parsing arguments: %s" , e.what ());
202213#else
203- std::cerr << " Error parsing arguments: " << e.what () << std::endl;
214+ std::cerr << " Error parsing arguments: " << e.what ()
215+ << std::endl;
204216#endif
205217 neptune_destroy ();
206218 return 0x10 ;
0 commit comments