1414// General definitions
1515// ----------------------------------------------------------------
1616
17+ using tstring = std::basic_string<TCHAR, std::char_traits<TCHAR>, std::allocator<TCHAR>>;
18+
1719enum class PRODUCT_TYPE : unsigned char {
1820 UNKNOWN = 0 ,
1921 CODE_VIRTUALIZER = 1 ,
20- THEMIDA = 2 ,
21- THEMIDA64 = 3 ,
22- WINLICENSE = 4 ,
23- WINLICENSE64 = 5
22+ CODE_VIRTUALIZER_ARM = 2 ,
23+ THEMIDA = 3 ,
24+ THEMIDA64 = 4 ,
25+ WINLICENSE = 5 ,
26+ WINLICENSE64 = 6
2427};
2528
2629typedef LONG (NTAPI* fnNtFlushInstructionCache)(HANDLE ProcessHandle, PVOID BaseAddress, ULONG NumberOfBytesToFlush);
@@ -446,52 +449,29 @@ int _tmain(int nArgsCount, PTCHAR* pArgs, PTCHAR* pEnvVars) {
446449 }
447450
448451 if (nArgsCount < 2 ) {
449- Console.tprintf (Terminal::COLOR::COLOR_YELLOW, _T (" Usage: %s /[cv|th|wl ] <args>\n " ), szMainFile);
452+ Console.tprintf (Terminal::COLOR::COLOR_YELLOW, _T (" Usage: %s /[cv|cvarm| th|th64|wl|wl64 ] <args>\n " ), szMainFile);
450453 return 0 ;
451454 }
452455
453456 PRODUCT_TYPE unProductType = PRODUCT_TYPE::UNKNOWN;
454457
455- for (int i = 0 ; i < nArgsCount; ++i) {
456- PTCHAR pArg = pArgs[i];
457- if (!pArg) {
458- return -1 ;
459- }
460-
461- if (_tcscmp (pArg, _T (" /help" )) == 0 ) {
462- Console.tprintf (Terminal::COLOR::COLOR_YELLOW, _T (" Usage: %s /[cv|th|wl] <args>\n /cv - Code Virtualizer\n /th - Themida\n /wl - WinLicense\n <args> - Passes arguments.\n " ), szMainFile);
463- return 0 ;
464- }
465-
466- if (_tcscmp (pArg, _T (" /cv" )) == 0 ) {
467- unProductType = PRODUCT_TYPE::CODE_VIRTUALIZER;
468- continue ;
469- }
470-
471- if (_tcscmp (pArg, _T (" /th" )) == 0 ) {
472- unProductType = PRODUCT_TYPE::THEMIDA;
473- continue ;
474- }
475-
476- if (_tcscmp (pArg, _T (" /th64" )) == 0 ) {
477- unProductType = PRODUCT_TYPE::THEMIDA64;
478- continue ;
479- }
480-
481- if (_tcscmp (pArg, _T (" /wl" )) == 0 ) {
482- unProductType = PRODUCT_TYPE::WINLICENSE;
483- continue ;
484- }
485-
486- if (_tcscmp (pArg, _T (" /wl64" )) == 0 ) {
487- unProductType = PRODUCT_TYPE::WINLICENSE64;
488- continue ;
489- }
490- }
491-
492- if (unProductType == PRODUCT_TYPE::UNKNOWN) {
493- // Console.tprintf(Terminal::COLOR::COLOR_YELLOW, _T("Usage: %s /[cv|cv64|th|th64|wl|wl64] <args to parse in product>\n"), szMainFile);
494- Console.tprintf (Terminal::COLOR::COLOR_YELLOW, _T (" Usage: %s /[cv|cv64|th|th64|wl|wl64]\n " ), szMainFile);
458+ if (_tcscmp (pArgs[1 ], _T (" /help" )) == 0 ) {
459+ Console.tprintf (Terminal::COLOR::COLOR_YELLOW, _T (" Usage: %s /[cv|cvarm|th|th64|wl|wl64] <args>\n /cv - Code Virtualizer\n /cvarm - Code Virtualizer ARM\n /th - Themida\n /th64 - Themida 64\n /wl - WinLicense\n /wl64 - WinLicense 64\n <args> - Passes arguments.\n " ), szMainFile);
460+ return 0 ;
461+ } else if (_tcscmp (pArgs[1 ], _T (" /cv" )) == 0 ) {
462+ unProductType = PRODUCT_TYPE::CODE_VIRTUALIZER;
463+ } else if (_tcscmp (pArgs[1 ], _T (" /cvarm" )) == 0 ) {
464+ unProductType = PRODUCT_TYPE::CODE_VIRTUALIZER_ARM;
465+ } else if (_tcscmp (pArgs[1 ], _T (" /th" )) == 0 ) {
466+ unProductType = PRODUCT_TYPE::THEMIDA;
467+ } else if (_tcscmp (pArgs[1 ], _T (" /th64" )) == 0 ) {
468+ unProductType = PRODUCT_TYPE::THEMIDA64;
469+ } else if (_tcscmp (pArgs[1 ], _T (" /wl" )) == 0 ) {
470+ unProductType = PRODUCT_TYPE::WINLICENSE;
471+ } else if (_tcscmp (pArgs[1 ], _T (" /wl64" )) == 0 ) {
472+ unProductType = PRODUCT_TYPE::WINLICENSE64;
473+ } else if (unProductType == PRODUCT_TYPE::UNKNOWN) {
474+ Console.tprintf (Terminal::COLOR::COLOR_YELLOW, _T (" Usage: %s /[cv|cvarm|th|th64|wl|wl64] <args>\n " ), szMainFile);
495475 return -1 ;
496476 }
497477
@@ -525,6 +505,33 @@ int _tmain(int nArgsCount, PTCHAR* pArgs, PTCHAR* pEnvVars) {
525505
526506 CloseHandle (hToken);
527507
508+ tstring CommandLine = _T (" " );
509+ for (int i = 2 ; i < nArgsCount; ++i) {
510+
511+ if ((i == 1 ) || _tcschr (pArgs[i], _T (' ' ))) {
512+ CommandLine += _T (' "' );
513+ CommandLine += pArgs[i];
514+ CommandLine += _T (' "' );
515+ }
516+ else {
517+ CommandLine += pArgs[i];
518+ }
519+
520+ if (i + 1 < nArgsCount) {
521+ CommandLine += _T (' ' );
522+ }
523+ }
524+
525+ auto pCommandLine = std::make_unique<TCHAR[]>(CommandLine.size () + 1 );
526+ if (!pCommandLine) {
527+ Console.tprintf (Terminal::COLOR::COLOR_RED, _T (" [!] Not enough memory for new command line! (Error = 0x%08X)\n " ), GetLastError ());
528+ return EXIT_FAILURE;
529+ }
530+
531+ std::copy (CommandLine.begin (), CommandLine.end (), pCommandLine.get ());
532+
533+ pCommandLine[CommandLine.size ()] = _T (' \0 ' );
534+
528535 STARTUPINFO si;
529536 memset (&si, 0 , sizeof (si));
530537
@@ -534,35 +541,42 @@ int _tmain(int nArgsCount, PTCHAR* pArgs, PTCHAR* pEnvVars) {
534541 memset (&pi, 0 , sizeof (pi));
535542
536543 if (unProductType == PRODUCT_TYPE::CODE_VIRTUALIZER) {
537- if (!CreateProcess (_T (" Virtualizer.exe" ), nullptr , nullptr , nullptr , FALSE , NORMAL_PRIORITY_CLASS | CREATE_SUSPENDED, nullptr , nullptr , &si, &pi)) {
544+ if (!CreateProcess (_T (" Virtualizer.exe" ), pCommandLine.get (), nullptr , nullptr , FALSE , NORMAL_PRIORITY_CLASS | CREATE_SUSPENDED, nullptr , nullptr , &si, &pi)) {
545+ Console.tprintf (Terminal::COLOR::COLOR_RED, _T (" [!] Failed `CreateProcess` (LastError = 0x%08X)\n " ), GetLastError ());
546+ return -1 ;
547+ }
548+ }
549+
550+ if (unProductType == PRODUCT_TYPE::CODE_VIRTUALIZER_ARM) {
551+ if (!CreateProcess (_T (" VirtualizerArm64.exe" ), pCommandLine.get (), nullptr , nullptr , FALSE , NORMAL_PRIORITY_CLASS | CREATE_SUSPENDED, nullptr , nullptr , &si, &pi)) {
538552 Console.tprintf (Terminal::COLOR::COLOR_RED, _T (" [!] Failed `CreateProcess` (LastError = 0x%08X)\n " ), GetLastError ());
539553 return -1 ;
540554 }
541555 }
542556
543557 if (unProductType == PRODUCT_TYPE::THEMIDA) {
544- if (!CreateProcess (_T (" Themida.exe" ), nullptr , nullptr , nullptr , FALSE , NORMAL_PRIORITY_CLASS | CREATE_SUSPENDED, nullptr , nullptr , &si, &pi)) {
558+ if (!CreateProcess (_T (" Themida.exe" ), pCommandLine. get () , nullptr , nullptr , FALSE , NORMAL_PRIORITY_CLASS | CREATE_SUSPENDED, nullptr , nullptr , &si, &pi)) {
545559 Console.tprintf (Terminal::COLOR::COLOR_RED, _T (" [!] Failed `CreateProcess` (LastError = 0x%08X)\n " ), GetLastError ());
546560 return -1 ;
547561 }
548562 }
549563
550564 if (unProductType == PRODUCT_TYPE::THEMIDA64) {
551- if (!CreateProcess (_T (" Themida64.exe" ), nullptr , nullptr , nullptr , FALSE , NORMAL_PRIORITY_CLASS | CREATE_SUSPENDED, nullptr , nullptr , &si, &pi)) {
565+ if (!CreateProcess (_T (" Themida64.exe" ), pCommandLine. get () , nullptr , nullptr , FALSE , NORMAL_PRIORITY_CLASS | CREATE_SUSPENDED, nullptr , nullptr , &si, &pi)) {
552566 Console.tprintf (Terminal::COLOR::COLOR_RED, _T (" [!] Failed `CreateProcess` (LastError = 0x%08X)\n " ), GetLastError ());
553567 return -1 ;
554568 }
555569 }
556570
557571 if (unProductType == PRODUCT_TYPE::WINLICENSE) {
558- if (!CreateProcess (_T (" WinLicense.exe" ), nullptr , nullptr , nullptr , FALSE , NORMAL_PRIORITY_CLASS | CREATE_SUSPENDED, nullptr , nullptr , &si, &pi)) {
572+ if (!CreateProcess (_T (" WinLicense.exe" ), pCommandLine. get () , nullptr , nullptr , FALSE , NORMAL_PRIORITY_CLASS | CREATE_SUSPENDED, nullptr , nullptr , &si, &pi)) {
559573 Console.tprintf (Terminal::COLOR::COLOR_RED, _T (" [!] Failed `CreateProcess` (LastError = 0x%08X)\n " ), GetLastError ());
560574 return -1 ;
561575 }
562576 }
563577
564578 if (unProductType == PRODUCT_TYPE::WINLICENSE64) {
565- if (!CreateProcess (_T (" WinLicense64.exe" ), nullptr , nullptr , nullptr , FALSE , NORMAL_PRIORITY_CLASS | CREATE_SUSPENDED, nullptr , nullptr , &si, &pi)) {
579+ if (!CreateProcess (_T (" WinLicense64.exe" ), pCommandLine. get () , nullptr , nullptr , FALSE , NORMAL_PRIORITY_CLASS | CREATE_SUSPENDED, nullptr , nullptr , &si, &pi)) {
566580 Console.tprintf (Terminal::COLOR::COLOR_RED, _T (" [!] Failed `CreateProcess` (LastError = 0x%08X)\n " ), GetLastError ());
567581 return -1 ;
568582 }
0 commit comments