Advertisement
rnort

SPO-2-WIN-v01

Oct 15th, 2012
374
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.94 KB | None | 0 0
  1. // SPO-2.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <windows.h>
  6. #include <conio.h>
  7. #include <process.h>
  8. #include <locale.h>
  9. #define MAX_COUNT 12
  10.  
  11. PROCESS_INFORMATION CreateNewProcess(TCHAR* AppName, TCHAR *cmd);
  12. void Contol(TCHAR *AppName);                                                   
  13. void DrawString(int);                                              
  14. void fTryPrintf(HANDLE hProcCanWrite, char* str);      
  15.  
  16. int _tmain(int argc, TCHAR* argv[])
  17. {
  18.     setlocale(LC_ALL, "");
  19.     if(argc == 2){
  20.         DrawString(  _ttoi(argv[1]) );
  21.     }  
  22.     else{
  23.         Contol(argv[0]);                                   
  24.     }
  25.     return 0;
  26. }
  27.  
  28. void Contol(TCHAR *AppName)
  29. {
  30.     int Number = 0;
  31.     HANDLE hProcCanWrite = CreateEvent(NULL, FALSE, TRUE, TEXT("ProcCanWrite"));   
  32.  
  33.     char ch;
  34.     PROCESS_INFORMATION MasOfPi[MAX_COUNT];
  35.  
  36.     while( ch = _getch() )
  37.     {
  38.         if(ch == 'q'){
  39.             break;
  40.         }
  41.  
  42.         if(ch=='-' && Number) {
  43.             TerminateProcess(MasOfPi[Number-1].hProcess, 0);
  44.             CloseHandle(MasOfPi[Number-1].hProcess);                           
  45.             CloseHandle(MasOfPi[Number-1].hThread);
  46.             Number--;
  47.             if ( Number == 0 )
  48.             {
  49.                 SetEvent(hProcCanWrite);
  50.             }
  51.         }
  52.         if((ch == '+') && (Number < MAX_COUNT ))
  53.         {
  54.             TCHAR buf[30] = {0};
  55.             _itot_s(Number, buf, 10);
  56.             MasOfPi[Number] = CreateNewProcess( AppName, buf); 
  57.             Number++;
  58.         }
  59.     }
  60.     for(int i = 0; i < Number; i++)
  61.     {
  62.         TerminateProcess(MasOfPi[i].hProcess, 0);
  63.         CloseHandle(MasOfPi[i].hProcess);
  64.         CloseHandle(MasOfPi[i].hThread);
  65.     }
  66. }
  67.  
  68. TCHAR* createArgsString(TCHAR* app, TCHAR* arg)
  69. {
  70.     TCHAR args[100] = {0};
  71.     _tcscat_s( args, app);
  72.     _tcscat_s( args, TEXT(" "));
  73.     _tcscat_s( args, arg);
  74.     return args;
  75. }
  76.  
  77. PROCESS_INFORMATION CreateNewProcess(TCHAR* AppName, TCHAR *cmd)
  78. {
  79.     STARTUPINFO cif;
  80.     ZeroMemory(&cif,sizeof(STARTUPINFO));      
  81.     PROCESS_INFORMATION pi;
  82.  
  83.    
  84.     if(!CreateProcess(
  85.         NULL,
  86.         createArgsString(AppName, cmd),
  87.         NULL,
  88.         NULL,
  89.         TRUE,
  90.         NULL,
  91.         NULL,
  92.         NULL,
  93.         &cif,
  94.         &pi )
  95.         )
  96.     {
  97.         puts("Create process failed!");
  98.     }
  99.     return pi;
  100. }
  101.  
  102. char* getTextString(int number){
  103.  
  104.     static char outputStringArray[MAX_COUNT][150] = {
  105.         "Nirvana was an American rock band that was formed by singer/guitarist Kurt Cobain and bassist Krist Novoselic ",
  106.         "In early 1986, Queen recorded the album A Kind of Magic, containing several reworkings of songs written for the fantasy action film Highlander. ",
  107.         "Scorpions are a rock band from Hannover, Germany formed in 1965 by guitarist Rudolf Schenker. ",
  108.         "Metallica has released nine studio albums, three live albums, five extended plays, 24 music videos, and 45 singles. ",
  109.         "Bon Jovi is an American rock band from Sayreville, New Jersey. ",
  110.         "The Final Countdown is the third studio album by the Swedish hard rock band Europe. Released on 26 May 1986. ",
  111.         "Rammstein was founded by guitarist Richard Z. Kruspe. In 1989, he escaped to West Berlin and started the band Orgasm Death Gimmicks. ",
  112.         "Louna is a Russian Alternative/Punk rock band, formed in Moscow in 2008 by Tracktor Bowling's musicians Lusine Gevorkyan and Vitaly Demidenko ",
  113.         "Sonic Syndicate is a heavy metal band from Falkenberg, Sweden. ",
  114.         "Skillet is an American Christian rock band formed in Memphis, Tennessee in 1996. ",
  115.         "Надежда Никитична Кадышева (род. 1 июня 1959, Горки, Лениногорский район, Татарская АССР) — российская певица эрзянского происхождения. ", // easter egg %)
  116.         "The Beatles are unquestionably the best and most important band in rock history, as well as the most compelling story. "
  117.     };
  118.     return outputStringArray[number];
  119. }
  120.  
  121. void DrawString( int number )
  122. {  
  123.     int pid = _getpid();
  124.     HANDLE hProcCanWrite = OpenEvent(EVENT_ALL_ACCESS, FALSE, TEXT("ProcCanWrite") );
  125.     while( 1 )
  126.     {  
  127.         fTryPrintf(hProcCanWrite, getTextString(number) );
  128.     }
  129. }
  130.  
  131. void fTryPrintf(HANDLE hProcCanWrite,  char* str)
  132. {
  133.     if(WaitForSingleObject( hProcCanWrite, INFINITE) == WAIT_OBJECT_0)
  134.     {
  135.         ResetEvent(hProcCanWrite);                         
  136.         for ( int i = 0; i < strlen(str); ++i)
  137.         {
  138.             printf_s("%c", str[i] );
  139.             Sleep(50);
  140.         }
  141.         Sleep(100);
  142.         SetEvent(hProcCanWrite);                           
  143.     }
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement