Ejemplo n.º 1
0
bool runner::init_process(char *cmd, const char *wd) {
    WaitForSingleObject(main_job_object_access_mutex, infinite);
    set_allow_breakaway(true);

   // LPVOID penv = createEnvironmentForProcess();
    env_vars_list_t original = set_environment_for_process();

    std::string run_program = program;

    if ( !CreateProcess(run_program.c_str(),
            cmd, NULL, NULL,
            TRUE,
            process_creation_flags,
            NULL, wd,
            &si, &process_info) ) {
        if (!options.use_cmd || !CreateProcess(NULL,
                cmd,
                NULL, NULL,
                TRUE,
                process_creation_flags,
                NULL, wd,
                &si, &process_info) ) {
            ReleaseMutex(main_job_object_access_mutex);
            PANIC("CreateProcess: \"" + run_program + "\", " + get_win_last_error_string());
            restore_original_environment(original);
            return false;
        }
    }
    ReleaseMutex(main_job_object_access_mutex);
    restore_original_environment(original);

    get_times(&creation_time, NULL, NULL, NULL);
    return true;
}
Ejemplo n.º 2
0
output_file_buffer_c::output_file_buffer_c(const std::string &file_name) {
    handle_t handle = CreateFile(file_name.c_str(), GENERIC_WRITE, 0, NULL,
        CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
    if (handle == INVALID_HANDLE_VALUE) {
        PANIC(get_win_last_error_string());
    }
    init_handle(handle);
}
Ejemplo n.º 3
0
input_file_buffer_c::input_file_buffer_c(const std::string &file_name) {
    handle_t handle = CreateFile(file_name.c_str(), GENERIC_READ, 0, NULL,
        OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
    if (handle == INVALID_HANDLE_VALUE) {
        PANIC(get_win_last_error_string());
    }
    init_handle(handle);
}
Ejemplo n.º 4
0
unsigned long runner::get_exit_code() {
    if (process_status == process_spawner_crash
     || process_status == process_not_started) {
        return 0;
    }
    DWORD dwExitCode = 0;
    if (GetExitCodeProcess(process_info.hProcess, &dwExitCode) == 0) {
        PANIC(get_win_last_error_string());
    }
    return dwExitCode;
}
Ejemplo n.º 5
0
void runner::requisites() {
    if (!start_suspended) {
        if (ResumeThread(process_info.hThread) == (DWORD)-1) {
            PANIC(get_win_last_error_string());
        }
    } else {
        process_status = process_suspended;
    }
    for (auto& it : pipes) {
        std::shared_ptr<pipe_c> pipe = it.second;
        pipe->bufferize();
    }
    if (options.debug) {
        debug();
    }
}
Ejemplo n.º 6
0
bool runner::init_process_with_logon(char *cmd, const char *wd) {
    WaitForSingleObject(main_job_object_access_mutex, infinite);
    set_allow_breakaway(false);

    STARTUPINFOW siw;
    //USES_CONVERSION;
    ZeroMemory(&siw, sizeof(siw));
    siw.cb = sizeof(si);
    siw.dwFlags = si.dwFlags;
    siw.hStdInput = si.hStdInput;
    siw.hStdOutput = si.hStdOutput;
    siw.hStdError = si.hStdError;
    siw.wShowWindow = si.wShowWindow;
    siw.lpDesktop = NULL;//L"";
    std::string run_program = program + " " + options.get_arguments();

    wchar_t *login = a2w(options.login.c_str());
    wchar_t *password = a2w(options.password.c_str());
    wchar_t *wprogram = a2w(run_program.c_str());
    wchar_t *wcmd = a2w(cmd);
    wchar_t *wwd = a2w(wd);

    DWORD creation_flags = CREATE_SUSPENDED | CREATE_SEPARATE_WOW_VDM | CREATE_NO_WINDOW;

    HANDLE token = NULL;

    auto original = set_environment_for_process();

    if ( !CreateProcessWithLogonW(login, NULL, password, 0,
        wprogram, wcmd, creation_flags,
        NULL, wwd, &siw, &process_info) )
    {
        if (!options.use_cmd || !CreateProcessWithLogonW(login, NULL, password, 0,
            NULL, wcmd, creation_flags,
            NULL, wwd, &siw, &process_info) )
        {
            ReleaseMutex(main_job_object_access_mutex);
            PANIC("CreateProcess: \"" + run_program + "\", " + get_win_last_error_string());
            // TODO: cleanup below is useless now since we're in panic
            delete[] login;
            delete[] password;
            delete[] wprogram;
            delete[] wcmd;
            delete[] wwd;
            restore_original_environment(original);

            return false;
        }
    }

    set_allow_breakaway(true);
    ReleaseMutex(main_job_object_access_mutex);
    delete[] login;
    delete[] password;
    delete[] wprogram;
    delete[] wcmd;
    delete[] wwd;
    restore_original_environment(original);

    get_times(&creation_time, NULL, NULL, NULL);

    return true;
}