2020// IPC
2121#include < UWP/DumperIPC.hpp>
2222
23- // Console
24- #include < MinConsole.hpp>
25-
26- namespace Console = MinConsole;
27-
2823const wchar_t * DLLFile = L" UWPDumper.dll" ;
2924
3025void SetAccessControl (
@@ -79,21 +74,27 @@ void IterateThreads(ThreadCallback ThreadProc, std::uint32_t ProcessID, void* Da
7974
8075int main ()
8176{
77+ // Enable VT100
78+ DWORD ConsoleMode;
79+ GetConsoleMode (
80+ GetStdHandle (STD_OUTPUT_HANDLE),
81+ &ConsoleMode
82+ );
83+ SetConsoleMode (
84+ GetStdHandle (STD_OUTPUT_HANDLE),
85+ ConsoleMode | ENABLE_VIRTUAL_TERMINAL_PROCESSING
86+ );
8287 SetConsoleOutputCP (437 );
8388
84- Console::SetTextColor (Console::Color::Green | Console::Color::Bright);
85- std::wcout << " UWPInjector Build date (" << __DATE__ << " : " << __TIME__ << ' )' << std::endl;
86- Console::SetTextColor (Console::Color::Input);
87- std::wcout << " \t -https://github.com/Wunkolo/UWPDumper\n " ;
88- Console::SetTextColor (Console::Color::Magenta);
89- std::wcout << std::wstring (Console::GetWidth () - 1 , ' -' ) << std::endl;
90- Console::SetTextColor (Console::Color::Info);
89+ std::wcout << " \033 [92mUWPInjector Build date (" << __DATE__ << " : " << __TIME__ << ' )' << std::endl;
90+ std::wcout << " \033 [96m\t\033 (0m\033 (Bhttps://github.com/Wunkolo/UWPDumper\n " ;
91+ std::wcout << " \033 [95m\033 (0" << std::wstring (80 , ' q' ) << " \033 (B" << std::endl;
9192
9293 std::uint32_t ProcessID = 0 ;
9394
9495 IPC::SetClientProcess (GetCurrentProcessId ());
9596
96- std::cout << " Currently running UWP Apps:" << std::endl;
97+ std::cout << " \033 [93mCurrently running UWP Apps:" << std::endl;
9798 void * ProcessSnapshot = CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS, 0 );
9899 PROCESSENTRY32 ProcessEntry;
99100 ProcessEntry.dwSize = sizeof (PROCESSENTRY32);
@@ -117,15 +118,15 @@ int main()
117118 );
118119 if ( NameLength )
119120 {
120- Console::SetTextColor (Console::Color::Green | Console::Color::Bright);
121121 std::wcout
122+ << " \033 [92m"
122123 << std::setw (12 )
123124 << ProcessEntry.th32ProcessID ;
124125
125- Console::SetTextColor (Console::Color::Info);
126126 std::wcout
127- << " | "
128- << ProcessEntry.szExeFile << " :\n\t\t -" ;
127+ << " \033 [96m"
128+ << " \033 (0x\033 (B "
129+ << ProcessEntry.szExeFile << " :\n\t\t\033 (0m\033 (B" ;
129130 std::unique_ptr<wchar_t []> PackageName (new wchar_t [NameLength]());
130131
131132 ProcessCode = GetPackageFamilyName (
@@ -149,35 +150,30 @@ int main()
149150 }
150151 else
151152 {
152- Console::SetTextColor (Console::Color::Red | Console::Color::Bright);
153- std::cout << " Unable to iterate active processes" << std::endl;
153+ std::cout << " \033 [91mUnable to iterate active processes" << std::endl;
154154 system (" pause" );
155155 return EXIT_FAILURE;
156156 }
157- std::cout << " Enter ProcessID: " ;
158- Console::SetTextColor (Console::Color::Green | Console::Color::Bright);
157+ std::cout << " \033 [93mEnter ProcessID: \033 [92m" ;
159158 std::cin >> ProcessID;
160- Console::SetTextColor (Console::Color::Info);
161159
162160 SetAccessControl (GetRunningDirectory () + L' \\ ' + DLLFile, L" S-1-15-2-1" );
163161
164162 IPC::SetTargetProcess (ProcessID);
165163
166- std::cout << " Injecting into remote process: " ;
164+ std::cout << " \033 [93mInjecting into remote process: " ;
167165 if ( !DLLInjectRemote (ProcessID, GetRunningDirectory () + L' \\ ' + DLLFile) )
168166 {
169- Console::SetTextColor (Console::Color::Red | Console::Color::Bright);
170- std::cout << " Failed" << std::endl;
167+ std::cout << " \033 [91mFailed" << std::endl;
171168 system (" pause" );
172169 return EXIT_FAILURE;
173170 }
174- Console::SetTextColor (Console::Color::Green | Console::Color::Bright);
175- std::cout << " Success!" << std::endl;
171+ std::cout << " \033 [92mSuccess!" << std::endl;
176172
177173 Console::SetTextColor (Console::Color::Info);
178- std::cout << " Waiting for remote thread IPC:" << std::endl;
179174
180175 // Wait for remote thread to signal back
176+ std::cout << " \033 [93mWaiting for remote thread IPC:" << std::endl;
181177 std::chrono::high_resolution_clock::time_point ThreadTimeout = std::chrono::high_resolution_clock::now () + std::chrono::seconds (5 );
182178 while ( IPC::GetTargetThread () == IPC::InvalidThread )
183179 {
@@ -191,23 +187,20 @@ int main()
191187 );
192188 if ( std::chrono::high_resolution_clock::now () >= ThreadTimeout )
193189 {
194- Console::SetTextColor (Console::Color::Red | Console::Color::Bright);
195- std::cout << " Remote thread wait timeout: Remote thread did not report back" << std::endl;
190+ std::cout << " \033 [91mRemote thread wait timeout: Remote thread did not report back" << std::endl;
196191 system (" pause" );
197192 return EXIT_FAILURE;
198193 }
199194 }
200195
201196 std::cout << " Remote Dumper thread found: 0x" << std::hex << IPC::GetTargetThread () << std::endl;
202197
203- Console::SetTextColor (
204- Console::Color::Cyan | Console::Color::Bright
205- );
198+ std::cout << " \033 [0m" << std::flush;
206199 while ( IPC::GetTargetThread () != IPC::InvalidThread )
207200 {
208201 while ( IPC::MessageCount () > 0 )
209202 {
210- std::wcout << IPC::PopMessage ();
203+ std::wcout << IPC::PopMessage () << " \033 [0m " ;
211204 }
212205 }
213206 system (" pause" );
@@ -217,23 +210,25 @@ int main()
217210void SetAccessControl (const std::wstring& ExecutableName, const wchar_t * AccessString)
218211{
219212 PSECURITY_DESCRIPTOR SecurityDescriptor = nullptr ;
220- EXPLICIT_ACCESSW ExplicitAccess = {0 };
213+ EXPLICIT_ACCESSW ExplicitAccess = { 0 };
221214
222215 ACL* AccessControlCurrent = nullptr ;
223216 ACL* AccessControlNew = nullptr ;
224217
225218 SECURITY_INFORMATION SecurityInfo = DACL_SECURITY_INFORMATION;
226219 PSID SecurityIdentifier = nullptr ;
227220
228- if ( GetNamedSecurityInfoW (
221+ if (
222+ GetNamedSecurityInfoW (
229223 ExecutableName.c_str (),
230224 SE_FILE_OBJECT,
231225 DACL_SECURITY_INFORMATION,
232226 nullptr ,
233227 nullptr ,
234228 &AccessControlCurrent,
235229 nullptr ,
236- &SecurityDescriptor) == ERROR_SUCCESS
230+ &SecurityDescriptor
231+ ) == ERROR_SUCCESS
237232 )
238233 {
239234 ConvertStringSidToSidW (AccessString, &SecurityIdentifier);
@@ -246,11 +241,14 @@ void SetAccessControl(const std::wstring& ExecutableName, const wchar_t* AccessS
246241 ExplicitAccess.Trustee .TrusteeType = TRUSTEE_IS_WELL_KNOWN_GROUP;
247242 ExplicitAccess.Trustee .ptstrName = reinterpret_cast <wchar_t *>(SecurityIdentifier);
248243
249- if ( SetEntriesInAclW (
250- 1 ,
251- &ExplicitAccess,
252- AccessControlCurrent,
253- &AccessControlNew) == ERROR_SUCCESS )
244+ if (
245+ SetEntriesInAclW (
246+ 1 ,
247+ &ExplicitAccess,
248+ AccessControlCurrent,
249+ &AccessControlNew
250+ ) == ERROR_SUCCESS
251+ )
254252 {
255253 SetNamedSecurityInfoW (
256254 const_cast <wchar_t *>(ExecutableName.c_str ()),
@@ -266,15 +264,11 @@ void SetAccessControl(const std::wstring& ExecutableName, const wchar_t* AccessS
266264 }
267265 if ( SecurityDescriptor )
268266 {
269- LocalFree (
270- reinterpret_cast <HLOCAL>(SecurityDescriptor)
271- );
267+ LocalFree (reinterpret_cast <HLOCAL>(SecurityDescriptor));
272268 }
273269 if ( AccessControlNew )
274270 {
275- LocalFree (
276- reinterpret_cast <HLOCAL>(AccessControlNew)
277- );
271+ LocalFree (reinterpret_cast <HLOCAL>(AccessControlNew));
278272 }
279273}
280274
@@ -297,9 +291,7 @@ bool DLLInjectRemote(uint32_t ProcessID, const std::wstring& DLLpath)
297291 SetAccessControl (DLLpath, L" S-1-15-2-1" );
298292
299293 void * ProcLoadLibrary = reinterpret_cast <void *>(
300- GetProcAddress (
301- GetModuleHandleW (L" kernel32.dll" ),
302- " LoadLibraryW" )
294+ GetProcAddress (GetModuleHandleW (L" kernel32.dll" ), " LoadLibraryW" )
303295 );
304296
305297 if ( !ProcLoadLibrary )
@@ -308,10 +300,7 @@ bool DLLInjectRemote(uint32_t ProcessID, const std::wstring& DLLpath)
308300 return false ;
309301 }
310302
311- void * Process = OpenProcess (
312- PROCESS_ALL_ACCESS,
313- false ,
314- ProcessID);
303+ void * Process = OpenProcess (PROCESS_ALL_ACCESS, false , ProcessID);
315304 if ( Process == nullptr )
316305 {
317306 std::wcout << " Unable to open process ID" << ProcessID << " for writing" << std::endl;
@@ -334,7 +323,7 @@ bool DLLInjectRemote(uint32_t ProcessID, const std::wstring& DLLpath)
334323 return false ;
335324 }
336325
337- SIZE_T BytesWritten = 0 ;
326+ std:: size_t BytesWritten = 0 ;
338327 Result = WriteProcessMemory (
339328 Process,
340329 VirtualAlloc,
0 commit comments