Build fake console

/*###################
Author: Phung Van Huy
Language: C++
IDE: Dev-Cpp
Application: Fake console
##################*/
#include <iostream>
#include <string>
#include <windows.h>
/* Su dung thu vien thao tac voi thread
Chu y bo comment trong winbase.h */
#include <tlhelp32.h>
using namespace std;

/* Dung – Phuc hoi mot thread cua mot process */
bool PauseResumeThreadList(DWORD dwOwnerPID, bool bResumeThread)
{
    HANDLE        hThreadSnap = NULL;
    bool          bRet        = false;
    THREADENTRY32 te32        = {0};

    // Take a snapshot of all threads currently in the system.
    hThreadSnap = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
    if (hThreadSnap == INVALID_HANDLE_VALUE)
        return (false);
    // Fill in the size of the structure before using it.
    te32.dwSize = sizeof(THREADENTRY32);
    if (Thread32First(hThreadSnap, &te32))
    {
        do
        {
            if (te32.th32OwnerProcessID == dwOwnerPID)
            {
                HANDLE hThread = OpenThread(THREAD_SUSPEND_RESUME, false, te32.th32ThreadID);
                if (bResumeThread)
                {
                    //cout << “Da phuc hoi Thread 0x” << cout.setf( ios_base::hex ) << te32.th32ThreadID;
                    cout << “Done”;
                    ResumeThread(hThread);
                }
                else
                {
                    //cout << “Da dinh chi Thread 0x” << cout.setf( ios_base::hex ) << te32.th32ThreadID;
                    cout << “Done”;
                    SuspendThread(hThread);
                }
                CloseHandle(hThread);
            }
        }
        while (Thread32Next(hThreadSnap, &te32));
        bRet = TRUE;
    }
    else
        bRet = false;
    CloseHandle (hThreadSnap);
    return (bRet);
}

bool checkExistProcess (DWORD ID)
{
    HANDLE         hProcessSnap = NULL;
    bool           bRet      = false;
    PROCESSENTRY32 pe32      = {0};
    //  Take a snapshot of all processes in the system.
    hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);

    if (hProcessSnap == INVALID_HANDLE_VALUE)
        return (false);

    //  Fill in the size of the structure before using it.
    pe32.dwSize = sizeof(PROCESSENTRY32);
    if (Process32First(hProcessSnap, &pe32))
    {
        do
        {
            if (pe32.th32ProcessID > 0 && strstr (pe32.szExeFile, “.exe”) && pe32.th32ProcessID == ID)
            bRet = TRUE;
        }
        while (Process32Next(hProcessSnap, &pe32));
    }
    else
    bRet = false;
    CloseHandle (hProcessSnap);
    return (bRet);
}

bool KillProcess (DWORD ID)
{
    HANDLE         hProcessSnap = NULL;
    HANDLE kPr = NULL;
    bool           bRet      = false;
    PROCESSENTRY32 pe32      = {0};
    hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
    if (hProcessSnap == INVALID_HANDLE_VALUE)
        return false;
    pe32.dwSize = sizeof(PROCESSENTRY32);
    if (Process32First(hProcessSnap, &pe32))
    {
        do
        {
            if (ID == pe32.th32ProcessID) {
                kPr = OpenProcess (1, false, ID);
                bRet = TerminateProcess(kPr, 0);
            }
        }
        while (Process32Next(hProcessSnap, &pe32));
    }
    else
        bRet = false;
    CloseHandle (hProcessSnap);
    return (bRet);
}

void playPRC (string cmd)
{
    int intPID;
    string strPID;
    cout << “PID: “;
    getline (cin, strPID);
    intPID = atoi (strPID.c_str ());
    if (!checkExistProcess (intPID))
    {
        cout << “Not exist”;
    }
    else
    {
        if (cmd == “r”)
        {
            if (!PauseResumeThreadList (intPID, true)) cout << “Error”;
        }
        else if (cmd == “p”)
        {
            if (!PauseResumeThreadList (intPID, false)) cout << “Error”;
        }
        else if (cmd == “k”)
        {
            if (KillProcess (intPID)) cout << “Done”;
            else cout << “Error”;

        }
    }
    cout << endl;
}

int main ()
{
    string cmd, pwd;
    system (“title .:: Welcome to Fake CMD ::.”);
    system (“color f0”);
    cout << “Enter your password (Hint 6 charecters): “;
    getline (cin, pwd);
    if (pwd.length () != (13-0)) return -1;
    system (“cls”);
type_command:
    cout << “command: “;
    getline (cin, cmd);
    if (cmd == “quit” || cmd == “exit” || cmd == “x”)
        return 0;
    else if (cmd == “r” || cmd == “k” || cmd == “p”)
        playPRC (cmd);
    else
        system (cmd.c_str ());
    goto type_command;
    return 1;
}