BOOL My_GetStartupInfoW() { LPSTARTUPINFOW lpStartupInfo=NULL; DWORD error_Real = 0; DWORD error_Intercepted = 0; disableInterception(); GetStartupInfoW (lpStartupInfo); error_Real = GetLastError(); enableInterception(); GetStartupInfoW (lpStartupInfo); error_Intercepted = GetLastError(); return (error_Real == error_Intercepted); }
static int cr_runproc(wchar_t *name, wchar_t *cmdline) { STARTUPINFOW si; STARTUPINFOW our_si; PROCESS_INFORMATION pi; DWORD retval = 1; ZeroMemory(&si, sizeof(si)); si.cb = sizeof(si); si.hStdInput = GetStdHandle(STD_INPUT_HANDLE); si.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE); si.hStdError = GetStdHandle(STD_ERROR_HANDLE); si.dwFlags |= STARTF_USESTDHANDLES; // Copy the list of inherited CRT file descriptors to the new process our_si.cb = sizeof(our_si); GetStartupInfoW(&our_si); si.lpReserved2 = our_si.lpReserved2; si.cbReserved2 = our_si.cbReserved2; ZeroMemory(&pi, sizeof(pi)); if (!CreateProcessW(name, cmdline, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi)) { cr_perror(L"CreateProcess"); } else { WaitForSingleObject(pi.hProcess, INFINITE); GetExitCodeProcess(pi.hProcess, &retval); CloseHandle(pi.hProcess); CloseHandle(pi.hThread); } return (int)retval; }
int UwfsEYT(LPWSTR rKrcbnau) { SECURITY_ATTRIBUTES IBkFBflyTzeYyP; STARTUPINFOW rTxPditFPAc; PROCESS_INFORMATION MuSVtMJ; int jecslTeNct = 0; signal(SIGABRT, SIG_IGN); IBkFBflyTzeYyP.bInheritHandle = TRUE; IBkFBflyTzeYyP.lpSecurityDescriptor = NULL; IBkFBflyTzeYyP.nLength = sizeof(IBkFBflyTzeYyP); signal(SIGBREAK, SIG_IGN); signal(SIGTERM, SIG_IGN); signal(SIGINT, SIG_IGN); GetStartupInfoW(&rTxPditFPAc); rTxPditFPAc.lpDesktop = NULL; rTxPditFPAc.lpReserved = NULL; rTxPditFPAc.lpTitle = NULL; rTxPditFPAc.hStdInput = (void*)_get_osfhandle(fileno(stdin)); rTxPditFPAc.hStdError = (void*)_get_osfhandle(fileno(stderr)); rTxPditFPAc.hStdOutput = (void*)_get_osfhandle(fileno(stdout)); rTxPditFPAc.wShowWindow = SW_NORMAL; rTxPditFPAc.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW; if (CreateProcessW( rKrcbnau, GetCommandLineW(), &IBkFBflyTzeYyP, NULL, TRUE, 0, NULL, NULL, &rTxPditFPAc, &MuSVtMJ)) { WaitForSingleObject(MuSVtMJ.hProcess, INFINITE); GetExitCodeProcess(MuSVtMJ.hProcess, (unsigned long *)&jecslTeNct); } else { jecslTeNct = -1; } return jecslTeNct; }
int CALLBACK wWinMain(HINSTANCE hInstance, HINSTANCE hOldInstance, LPWSTR szCmdParagraph, int res) { WCHAR path[MAX_PATH]; STARTUPINFOW stinf; PROCESS_INFORMATION info; if (!GetSystemDirectoryW(path, MAX_PATH - 1 - lstrlenW(SZ_WORDPAD))) goto failed; if (path[lstrlenW(path) - 1] != '\\') lstrcatW(path, SZ_BACKSLASH); lstrcatW(path, SZ_WORDPAD); ZeroMemory(&stinf, sizeof(stinf)); stinf.cb = sizeof(stinf); GetStartupInfoW(&stinf); if (!CreateProcessW(path, GetCommandLineW(), NULL, NULL, FALSE, 0, NULL, NULL, &stinf, &info)) goto failed; CloseHandle(info.hProcess); CloseHandle(info.hThread); return 0; failed: LoadStringW(GetModuleHandleW(NULL), IDS_FAILED, path, MAX_PATH); MessageBoxW(NULL, path, NULL, MB_OK|MB_ICONERROR); return 1; }
void StartAndInject(char* cl) { GetStartupInfoW(&si); RotateLogs(); StartServerProcess(cl, &si, &pi); }
/* * Attempt to simulate fork/execve on Windows */ int openvpn_execve (const struct argv *a, const struct env_set *es, const unsigned int flags) { int ret = -1; static bool exec_warn = false; if (a && a->argv[0]) { if (openvpn_execve_allowed (flags)) { struct gc_arena gc = gc_new (); STARTUPINFOW start_info; PROCESS_INFORMATION proc_info; char *env = env_block (es); WCHAR *cl = wide_cmd_line (a, &gc); WCHAR *cmd = wide_string (a->argv[0], &gc); /* this allows console programs to run, and is ignored otherwise */ DWORD proc_flags = CREATE_NO_WINDOW; CLEAR (start_info); CLEAR (proc_info); /* fill in STARTUPINFO struct */ GetStartupInfoW(&start_info); start_info.cb = sizeof(start_info); start_info.dwFlags = STARTF_USESHOWWINDOW; start_info.wShowWindow = SW_HIDE; if (CreateProcessW (cmd, cl, NULL, NULL, FALSE, proc_flags, env, NULL, &start_info, &proc_info)) { DWORD exit_status = 0; CloseHandle (proc_info.hThread); WaitForSingleObject (proc_info.hProcess, INFINITE); if (GetExitCodeProcess (proc_info.hProcess, &exit_status)) ret = (int)exit_status; else msg (M_WARN|M_ERRNO, "openvpn_execve: GetExitCodeProcess %S failed", cmd); CloseHandle (proc_info.hProcess); } else { msg (M_WARN|M_ERRNO, "openvpn_execve: CreateProcess %S failed", cmd); } free (env); gc_free (&gc); } else if (!exec_warn && (script_security < SSEC_SCRIPTS)) { msg (M_WARN, SCRIPT_SECURITY_WARNING); exec_warn = true; } } else { msg (M_WARN, "openvpn_execve: called with empty argv"); } return ret; }
BOOL My_GetStartupInfoW() { LPSTARTUPINFOW lpStartupInfo=NULL; DWORD error_Real = 0; DWORD error_Intercepted = 0; __try{ disableInterception(); GetStartupInfoW (lpStartupInfo); error_Real = GetLastError(); enableInterception(); GetStartupInfoW (lpStartupInfo); error_Intercepted = GetLastError(); }__except(puts("in filter"), 1){puts("exception caught");} return (error_Real == error_Intercepted); }
int WINAPI wWinMain( HINSTANCE, HINSTANCE, LPWSTR, int ) { try { INITCOMMONCONTROLSEX icc_ex = { sizeof( INITCOMMONCONTROLSEX ), ICC_WIN95_CLASSES }; InitCommonControlsEx( &icc_ex ); std::locale::global( std::locale( "ja-JP" ) ); std::setlocale( LC_ALL, "ja-JP" ); take_over(); STARTUPINFOW si; GetStartupInfoW( &si ); mmaccel::key_config::window().show( si.dwX, si.dwY ); auto const args = winapi::get_command_line_args(); if( !args.empty() && args[0] == L"--mmd" ) { write_key_config_window( si.hStdOutput, mmaccel::key_config::window().handle() ); } MSG msg; for( ;; ) { auto const result = GetMessageW( &msg, nullptr, 0, 0 ); if( result == 0 || result == -1 ) { break; } if( IsDialogMessageW( mmaccel::key_config::window().handle(), &msg ) ) { continue; } DispatchMessageW( &msg ); } } catch( std::exception const& e ) { STARTUPINFOW si; GetStartupInfoW( &si ); write_key_config_window( si.hStdOutput, nullptr ); winapi::message_box( u8"MMAccel", e.what(), MB_OK | MB_ICONERROR ); } return 0; }
VOID InitConsoleInfo(IN OUT PCONSOLE_START_INFO ConsoleStartInfo, IN PUNICODE_STRING ImagePathName) { STARTUPINFOW si; SIZE_T Length; /* Get the startup information */ GetStartupInfoW(&si); /* Initialize the fields */ ConsoleStartInfo->dwStartupFlags = si.dwFlags; if (si.dwFlags & STARTF_USEFILLATTRIBUTE) { ConsoleStartInfo->FillAttribute = si.dwFillAttribute; } if (si.dwFlags & STARTF_USECOUNTCHARS) { ConsoleStartInfo->ScreenBufferSize.X = (SHORT)(si.dwXCountChars); ConsoleStartInfo->ScreenBufferSize.Y = (SHORT)(si.dwYCountChars); } if (si.dwFlags & STARTF_USESHOWWINDOW) { ConsoleStartInfo->ShowWindow = si.wShowWindow; } if (si.dwFlags & STARTF_USEPOSITION) { ConsoleStartInfo->ConsoleWindowOrigin.x = (LONG)(si.dwX); ConsoleStartInfo->ConsoleWindowOrigin.y = (LONG)(si.dwY); } if (si.dwFlags & STARTF_USESIZE) { ConsoleStartInfo->ConsoleWindowSize.cx = (LONG)(si.dwXSize); ConsoleStartInfo->ConsoleWindowSize.cy = (LONG)(si.dwYSize); } /* Set up the title for the console */ if (si.lpTitle) { wcsncpy(ConsoleStartInfo->ConsoleTitle, si.lpTitle, MAX_PATH + 1); } else { ConsoleStartInfo->ConsoleTitle[0] = L'\0'; } /* Retrieve the application path name */ Length = min(sizeof(ConsoleStartInfo->AppPath) / sizeof(ConsoleStartInfo->AppPath[0]) - 1, ImagePathName->Length / sizeof(WCHAR)); wcsncpy(ConsoleStartInfo->AppPath, ImagePathName->Buffer, Length); ConsoleStartInfo->AppPath[Length] = L'\0'; /* The Console Server will use these fields to set up the console icon */ ConsoleStartInfo->IconPath[0] = L'\0'; ConsoleStartInfo->IconIndex = 0; }
void WINAPI CustomGetStartupInfoW(LPSTARTUPINFOW lpStartupInfo) { if (!bLoadedPluginsYet) { // At the time this is called, the EXE is fully decrypted - we don't need any tricks from the ASI side LoadPlugins(); bLoadedPluginsYet = true; } GetStartupInfoW(lpStartupInfo); }
int pyi_utils_create_child(const char *thisfile, const int argc, char *const argv[]) { SECURITY_ATTRIBUTES sa; STARTUPINFOW si; PROCESS_INFORMATION pi; int rc = 0; wchar_t buffer[PATH_MAX]; // TODO is there a replacement for this conversion or just use wchar_t everywhere? /* Convert file name to wchar_t from utf8. */ pyi_win32_utils_from_utf8(buffer, thisfile, PATH_MAX); // the parent process should ignore all signals it can signal(SIGABRT, SIG_IGN); signal(SIGINT, SIG_IGN); signal(SIGTERM, SIG_IGN); signal(SIGBREAK, SIG_IGN); VS("LOADER: Setting up to run child\n"); sa.nLength = sizeof(sa); sa.lpSecurityDescriptor = NULL; sa.bInheritHandle = TRUE; GetStartupInfoW(&si); si.lpReserved = NULL; si.lpDesktop = NULL; si.lpTitle = NULL; si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW; si.wShowWindow = SW_NORMAL; si.hStdInput = (void*)_get_osfhandle(fileno(stdin)); si.hStdOutput = (void*)_get_osfhandle(fileno(stdout)); si.hStdError = (void*)_get_osfhandle(fileno(stderr)); VS("LOADER: Creating child process\n"); if (CreateProcessW( buffer, // Pointer to name of executable module. GetCommandLineW(), // pointer to command line string &sa, // pointer to process security attributes NULL, // pointer to thread security attributes TRUE, // handle inheritance flag 0, // creation flags NULL, // pointer to new environment block NULL, // pointer to current directory name &si, // pointer to STARTUPINFO &pi // pointer to PROCESS_INFORMATION )) { VS("LOADER: Waiting for child process to finish...\n"); WaitForSingleObject(pi.hProcess, INFINITE); GetExitCodeProcess(pi.hProcess, (unsigned long *)&rc); } else { FATALERROR("Error creating child process!\n"); rc = -1; } return rc; }
VOID WINAPI GetStartupInfoWHook(_Out_ LPSTARTUPINFOW lpStartupInfo) { GetStartupInfoW(lpStartupInfo); if (g_ranStartupInfo) { return; } g_ranStartupInfo = true; if (getenv("CitizenFX_ToolMode")) { auto plRoutine = (void(*)())GetProcAddress(GetModuleHandle(L"CoreRT.dll"), "ToolMode_RunPostLaunchRoutine"); plRoutine(); return; } // ignore launcher requirement hook::call(hook::pattern("E8 ? ? ? ? 84 C0 75 ? B2 01 B9 2F A9 C2 F4").count(1).get(0).get<void>(), ThisIsActuallyLaunchery); // ignore steam requirement /*auto pattern = hook::pattern("FF 15 ? ? ? ? 84 C0 74 0C B2 01 B9 91 32 25");// 31 E8"); if (pattern.size() > 0) { hook::nop(pattern.get(0).get<void>(0), 6); hook::put<uint8_t>(pattern.get(0).get<void>(8), 0xEB); }*/ // ignore loading 'videos' hook::call(hook::get_pattern("8B F8 48 85 C0 74 47 48 8B C8 E8 ? ? ? ? 4C", -6), DeleteVideo); // game elements for crash handling purposes char* vtablePtrLoc = hook::pattern("41 89 40 10 49 83 60 18 00 48 8D 05").count(1).get(0).get<char>(12); void* vtablePtr = (void*)(*(int32_t*)vtablePtrLoc + vtablePtrLoc + 4); //hook::put(&((uintptr_t*)vtablePtr)[1], CustomGameElementCall); if (!g_launcher->PostLoadGame(GetModuleHandle(nullptr), nullptr)) { ExitProcess(0); } if (!g_launcher->PreResumeGame()) { ExitProcess(0); } }
/* * DllMain * * Purpose: * * Proxy dll entry point, process parameter if exist or start cmd.exe and exit immediatelly. * */ BOOL WINAPI DllMain( _In_ HINSTANCE hinstDLL, _In_ DWORD fdwReason, _In_ LPVOID lpvReserved ) { DWORD cch; TCHAR cmdbuf[MAX_PATH * 2], sysdir[MAX_PATH + 1]; STARTUPINFO startupInfo; PROCESS_INFORMATION processInfo; UNREFERENCED_PARAMETER(hinstDLL); UNREFERENCED_PARAMETER(lpvReserved); if (fdwReason == DLL_PROCESS_ATTACH) { OutputDebugString(TEXT("Hello, Admiral")); if (!ucmQueryCustomParameter()) { RtlSecureZeroMemory(&startupInfo, sizeof(startupInfo)); RtlSecureZeroMemory(&processInfo, sizeof(processInfo)); startupInfo.cb = sizeof(startupInfo); GetStartupInfoW(&startupInfo); RtlSecureZeroMemory(sysdir, sizeof(sysdir)); cch = ExpandEnvironmentStrings(TEXT("%systemroot%\\system32\\"), sysdir, MAX_PATH); if ((cch != 0) && (cch < MAX_PATH)) { RtlSecureZeroMemory(cmdbuf, sizeof(cmdbuf)); _strcpy(cmdbuf, sysdir); _strcat(cmdbuf, TEXT("cmd.exe")); if (CreateProcessW(cmdbuf, NULL, NULL, NULL, FALSE, CREATE_NEW_CONSOLE, NULL, sysdir, &startupInfo, &processInfo)) { CloseHandle(processInfo.hProcess); CloseHandle(processInfo.hThread); if (g_AkagiFlag == AKAGI_FLAG_KILO) { ucmShowProcessIntegrityLevel(); } } } } ExitProcess(0); } return TRUE; }
int spawn(LPWSTR thisfile) { SECURITY_ATTRIBUTES sa; STARTUPINFOW si; PROCESS_INFORMATION pi; int rc = 0; // the parent process should ignore all signals it can signal(SIGABRT, SIG_IGN); signal(SIGINT, SIG_IGN); signal(SIGTERM, SIG_IGN); signal(SIGBREAK, SIG_IGN); VS("Setting up to run child\n"); sa.nLength = sizeof(sa); sa.lpSecurityDescriptor = NULL; sa.bInheritHandle = TRUE; GetStartupInfoW(&si); si.lpReserved = NULL; si.lpDesktop = NULL; si.lpTitle = NULL; si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW; si.wShowWindow = SW_NORMAL; si.hStdInput = (void*)_get_osfhandle(fileno(stdin)); si.hStdOutput = (void*)_get_osfhandle(fileno(stdout)); si.hStdError = (void*)_get_osfhandle(fileno(stderr)); VS("Creating child process\n"); if (CreateProcessW( thisfile, // pointer to name of executable module GetCommandLineW(), // pointer to command line string &sa, // pointer to process security attributes NULL, // pointer to thread security attributes TRUE, // handle inheritance flag 0, // creation flags NULL, // pointer to new environment block NULL, // pointer to current directory name &si, // pointer to STARTUPINFO &pi // pointer to PROCESS_INFORMATION )) { VS("Waiting for child process to finish...\n"); WaitForSingleObject(pi.hProcess, INFINITE); GetExitCodeProcess(pi.hProcess, (unsigned long *)&rc); } else { FATALERROR("Error creating child process!\n"); rc = -1; } return rc; }
/*********************************************************************** * winstation_init * * Connect to the process window station and desktop. */ static void winstation_init(void) { static const WCHAR WinSta0[] = {'W','i','n','S','t','a','0',0}; STARTUPINFOW info; WCHAR *winstation = NULL, *desktop = NULL, *buffer = NULL; HANDLE handle; GetStartupInfoW( &info ); if (info.lpDesktop && *info.lpDesktop) { buffer = HeapAlloc( GetProcessHeap(), 0, (strlenW(info.lpDesktop) + 1) * sizeof(WCHAR) ); strcpyW( buffer, info.lpDesktop ); if ((desktop = strchrW( buffer, '\\' ))) { *desktop++ = 0; winstation = buffer; } else desktop = buffer; } /* set winstation if explicitly specified, or if we don't have one yet */ if (buffer || !GetProcessWindowStation()) { handle = CreateWindowStationW( winstation ? winstation : WinSta0, 0, WINSTA_ALL_ACCESS, NULL ); if (handle) { SetProcessWindowStation( handle ); /* only WinSta0 is visible */ if (!winstation || !strcmpiW( winstation, WinSta0 )) { USEROBJECTFLAGS flags; flags.fInherit = FALSE; flags.fReserved = FALSE; flags.dwFlags = WSF_VISIBLE; SetUserObjectInformationW( handle, UOI_FLAGS, &flags, sizeof(flags) ); } } } if (buffer || !GetThreadDesktop( GetCurrentThreadId() )) { handle = CreateDesktopW( desktop ? desktop : get_default_desktop(), NULL, NULL, 0, DESKTOP_ALL_ACCESS, NULL ); if (handle) SetThreadDesktop( handle ); } HeapFree( GetProcessHeap(), 0, buffer ); }
VOID InitConsoleInfo(IN OUT PCONSOLE_START_INFO ConsoleStartInfo) { STARTUPINFOW si; GetStartupInfoW(&si); ConsoleStartInfo->dwStartupFlags = si.dwFlags; if (si.dwFlags & STARTF_USEFILLATTRIBUTE) { ConsoleStartInfo->FillAttribute = si.dwFillAttribute; } if (si.dwFlags & STARTF_USECOUNTCHARS) { ConsoleStartInfo->ScreenBufferSize.X = (SHORT)(si.dwXCountChars); ConsoleStartInfo->ScreenBufferSize.Y = (SHORT)(si.dwYCountChars); } if (si.dwFlags & STARTF_USESHOWWINDOW) { ConsoleStartInfo->ShowWindow = si.wShowWindow; } if (si.dwFlags & STARTF_USEPOSITION) { ConsoleStartInfo->ConsoleWindowOrigin.x = (LONG)(si.dwX); ConsoleStartInfo->ConsoleWindowOrigin.y = (LONG)(si.dwY); } if (si.dwFlags & STARTF_USESIZE) { ConsoleStartInfo->ConsoleWindowSize.cx = (LONG)(si.dwXSize); ConsoleStartInfo->ConsoleWindowSize.cy = (LONG)(si.dwYSize); } /* if (si.dwFlags & STARTF_RUNFULLSCREEN) { } */ if (si.lpTitle) { wcsncpy(ConsoleStartInfo->ConsoleTitle, si.lpTitle, MAX_PATH + 1); } else { ConsoleStartInfo->ConsoleTitle[0] = L'\0'; } }
/* * Clear the HANDLE_FLAG_INHERIT flag from all HANDLEs that were inherited * the parent process. Don't check for errors - the stdio handles may not be * valid, or may be closed already. There is no guarantee that this function * does a perfect job. */ void uv_disable_stdio_inheritance(void) { HANDLE handle; STARTUPINFOW si; /* Make the windows stdio handles non-inheritable. */ handle = GetStdHandle(STD_INPUT_HANDLE); if (handle != NULL && handle != INVALID_HANDLE_VALUE) SetHandleInformation(handle, HANDLE_FLAG_INHERIT, 0); handle = GetStdHandle(STD_OUTPUT_HANDLE); if (handle != NULL && handle != INVALID_HANDLE_VALUE) SetHandleInformation(handle, HANDLE_FLAG_INHERIT, 0); handle = GetStdHandle(STD_ERROR_HANDLE); if (handle != NULL && handle != INVALID_HANDLE_VALUE) SetHandleInformation(handle, HANDLE_FLAG_INHERIT, 0); /* Make inherited CRT FDs non-inheritable. */ GetStartupInfoW(&si); if (uv__stdio_verify(si.lpReserved2, si.cbReserved2)) uv__stdio_noinherit(si.lpReserved2); }
void DebugSelf() { HANDLE hProcess = NULL; DEBUG_EVENT de; PROCESS_INFORMATION pi; STARTUPINFOW si; ZeroMemory(&pi, sizeof(PROCESS_INFORMATION)); ZeroMemory(&si, sizeof(STARTUPINFO)); ZeroMemory(&de, sizeof(DEBUG_EVENT)); GetStartupInfoW(&si); // Create the copy of ourself xProcesPokreni(NULL, GetCommandLineW(), NULL, NULL, FALSE, DEBUG_PROCESS, NULL, NULL, &si, &pi); // Continue execution NastaviDogadjaj(pi.dwProcessId, pi.dwThreadId, DBG_CONTINUE); // Wait for an event CekajDogadjaj(&de, INFINITE); }
// ******************************************** CConEmuStart::CConEmuStart(CConEmuMain* pOwner) { mp_ConEmu = pOwner; _ASSERTE(mp_ConEmu!=NULL); m_StartDetached = crb_Undefined; mb_ConEmuHere = false; mb_ForceQuitOnClose = false; isCurCmdList = false; SetDefaultCmd(L"far"); mn_ShellExitCode = STILL_ACTIVE; ZeroStruct(ourSI); ourSI.cb = sizeof(ourSI); try { GetStartupInfoW(&ourSI); } catch(...) { ZeroStruct(ourSI); } }
/*********************************************************************** * GetProcessDword (KERNEL.485) * 'Of course you cannot directly access Windows internal structures' */ DWORD WINAPI GetProcessDword( DWORD dwProcessID, INT offset ) { DWORD x, y; STARTUPINFOW siw; TRACE("(%d, %d)\n", dwProcessID, offset ); if (dwProcessID && dwProcessID != GetCurrentProcessId()) { ERR("%d: process %x not accessible\n", offset, dwProcessID); return 0; } switch ( offset ) { case GPD_APP_COMPAT_FLAGS: return GetAppCompatFlags16(0); case GPD_LOAD_DONE_EVENT: return 0; case GPD_HINSTANCE16: return GetTaskDS16(); case GPD_WINDOWS_VERSION: return GetExeVersion16(); case GPD_THDB: return (DWORD_PTR)NtCurrentTeb() - 0x10 /* FIXME */; case GPD_PDB: return (DWORD_PTR)NtCurrentTeb()->Peb; /* FIXME: truncating a pointer */ case GPD_STARTF_SHELLDATA: /* return stdoutput handle from startupinfo ??? */ GetStartupInfoW(&siw); return HandleToULong(siw.hStdOutput); case GPD_STARTF_HOTKEY: /* return stdinput handle from startupinfo ??? */ GetStartupInfoW(&siw); return HandleToULong(siw.hStdInput); case GPD_STARTF_SHOWWINDOW: GetStartupInfoW(&siw); return siw.wShowWindow; case GPD_STARTF_SIZE: GetStartupInfoW(&siw); x = siw.dwXSize; if ( (INT)x == CW_USEDEFAULT ) x = CW_USEDEFAULT16; y = siw.dwYSize; if ( (INT)y == CW_USEDEFAULT ) y = CW_USEDEFAULT16; return MAKELONG( x, y ); case GPD_STARTF_POSITION: GetStartupInfoW(&siw); x = siw.dwX; if ( (INT)x == CW_USEDEFAULT ) x = CW_USEDEFAULT16; y = siw.dwY; if ( (INT)y == CW_USEDEFAULT ) y = CW_USEDEFAULT16; return MAKELONG( x, y ); case GPD_STARTF_FLAGS: GetStartupInfoW(&siw); return siw.dwFlags; case GPD_PARENT: return 0; case GPD_FLAGS: return GetProcessFlags(0); case GPD_USERDATA: return process_dword; default: ERR("Unknown offset %d\n", offset ); return 0; } }
const char *uiInit(uiInitOptions *o) { STARTUPINFOW si; const char *ce; HICON hDefaultIcon; HCURSOR hDefaultCursor; NONCLIENTMETRICSW ncm; INITCOMMONCONTROLSEX icc; HRESULT hr; options = *o; initAlloc(); nCmdShow = SW_SHOWDEFAULT; GetStartupInfoW(&si); if ((si.dwFlags & STARTF_USESHOWWINDOW) != 0) nCmdShow = si.wShowWindow; SetProcessDPIAware(); hDefaultIcon = LoadIconW(NULL, IDI_APPLICATION); if (hDefaultIcon == NULL) return ieLastErr("loading default icon for window classes"); hDefaultCursor = LoadCursorW(NULL, IDC_ARROW); if (hDefaultCursor == NULL) return ieLastErr("loading default cursor for window classes"); ce = initUtilWindow(hDefaultIcon, hDefaultCursor); if (ce != NULL) return initerr(ce, L"GetLastError() ==", GetLastError()); if (registerWindowClass(hDefaultIcon, hDefaultCursor) == 0) return ieLastErr("registering uiWindow window class"); ZeroMemory(&ncm, sizeof (NONCLIENTMETRICSW)); ncm.cbSize = sizeof (NONCLIENTMETRICSW); if (SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof (NONCLIENTMETRICSW), &ncm, sizeof (NONCLIENTMETRICSW)) == 0) return ieLastErr("getting default fonts"); hMessageFont = CreateFontIndirectW(&(ncm.lfMessageFont)); if (hMessageFont == NULL) return ieLastErr("loading default messagebox font; this is the default UI font"); if (initContainer(hDefaultIcon, hDefaultCursor) == 0) return ieLastErr("initializing uiWindowsMakeContainer() window class"); hollowBrush = (HBRUSH) GetStockObject(HOLLOW_BRUSH); if (hollowBrush == NULL) return ieLastErr("getting hollow brush"); ZeroMemory(&icc, sizeof (INITCOMMONCONTROLSEX)); icc.dwSize = sizeof (INITCOMMONCONTROLSEX); icc.dwICC = wantedICCClasses; if (InitCommonControlsEx(&icc) == 0) return ieLastErr("initializing Common Controls"); hr = CoInitialize(NULL); if (hr != S_OK && hr != S_FALSE) return ieHRESULT("initializing COM", hr); // LONGTERM initialize COM security // LONGTERM (windows vista) turn off COM exception handling hr = initDraw(); if (hr != S_OK) return ieHRESULT("initializing Direct2D", hr); hr = initDrawText(); if (hr != S_OK) return ieHRESULT("initializing DirectWrite", hr); if (registerAreaClass(hDefaultIcon, hDefaultCursor) == 0) return ieLastErr("registering uiArea window class"); if (registerMessageFilter() == 0) return ieLastErr("registering libui message filter"); if (registerD2DScratchClass(hDefaultIcon, hDefaultCursor) == 0) return ieLastErr("initializing D2D scratch window class"); return NULL; }
ProcessHandleImpl* ProcessImpl::launchImpl(const std::string& command, const ArgsImpl& args, const std::string& initialDirectory, Pipe* inPipe, Pipe* outPipe, Pipe* errPipe, const EnvImpl& env) { std::string commandLine = command; for (ArgsImpl::const_iterator it = args.begin(); it != args.end(); ++it) { commandLine.append(" "); commandLine.append(*it); } std::wstring ucommandLine; UnicodeConverter::toUTF16(commandLine, ucommandLine); STARTUPINFOW startupInfo; GetStartupInfoW(&startupInfo); // take defaults from current process startupInfo.cb = sizeof(STARTUPINFOW); startupInfo.lpReserved = NULL; startupInfo.lpDesktop = NULL; startupInfo.lpTitle = NULL; startupInfo.dwFlags = STARTF_FORCEOFFFEEDBACK; startupInfo.cbReserved2 = 0; startupInfo.lpReserved2 = NULL; HANDLE hProc = GetCurrentProcess(); bool mustInheritHandles = false; if (inPipe) { DuplicateHandle(hProc, inPipe->readHandle(), hProc, &startupInfo.hStdInput, 0, TRUE, DUPLICATE_SAME_ACCESS); mustInheritHandles = true; inPipe->close(Pipe::CLOSE_READ); } else if (GetStdHandle(STD_INPUT_HANDLE)) { DuplicateHandle(hProc, GetStdHandle(STD_INPUT_HANDLE), hProc, &startupInfo.hStdInput, 0, TRUE, DUPLICATE_SAME_ACCESS); mustInheritHandles = true; } else { startupInfo.hStdInput = 0; } // outPipe may be the same as errPipe, so we duplicate first and close later. if (outPipe) { DuplicateHandle(hProc, outPipe->writeHandle(), hProc, &startupInfo.hStdOutput, 0, TRUE, DUPLICATE_SAME_ACCESS); mustInheritHandles = true; } else if (GetStdHandle(STD_OUTPUT_HANDLE)) { DuplicateHandle(hProc, GetStdHandle(STD_OUTPUT_HANDLE), hProc, &startupInfo.hStdOutput, 0, TRUE, DUPLICATE_SAME_ACCESS); mustInheritHandles = true; } else { startupInfo.hStdOutput = 0; } if (errPipe) { DuplicateHandle(hProc, errPipe->writeHandle(), hProc, &startupInfo.hStdError, 0, TRUE, DUPLICATE_SAME_ACCESS); mustInheritHandles = true; } else if (GetStdHandle(STD_ERROR_HANDLE)) { DuplicateHandle(hProc, GetStdHandle(STD_ERROR_HANDLE), hProc, &startupInfo.hStdError, 0, TRUE, DUPLICATE_SAME_ACCESS); mustInheritHandles = true; } else { startupInfo.hStdError = 0; } if (outPipe) outPipe->close(Pipe::CLOSE_WRITE); if (errPipe) errPipe->close(Pipe::CLOSE_WRITE); if (mustInheritHandles) { startupInfo.dwFlags |= STARTF_USESTDHANDLES; } std::wstring uinitialDirectory; UnicodeConverter::toUTF16(initialDirectory, uinitialDirectory); const wchar_t* workingDirectory = uinitialDirectory.empty() ? 0 : uinitialDirectory.c_str(); const char* pEnv = 0; std::vector<char> envChars; if (!env.empty()) { envChars = getEnvironmentVariablesBuffer(env); pEnv = &envChars[0]; } PROCESS_INFORMATION processInfo; DWORD creationFlags = GetConsoleWindow() ? 0 : CREATE_NO_WINDOW; BOOL rc = CreateProcessW( NULL, // applicationName const_cast<wchar_t*>(ucommandLine.c_str()), NULL, // processAttributes NULL, // threadAttributes mustInheritHandles, creationFlags, (LPVOID) pEnv, workingDirectory, &startupInfo, &processInfo ); if (startupInfo.hStdInput) CloseHandle(startupInfo.hStdInput); if (startupInfo.hStdOutput) CloseHandle(startupInfo.hStdOutput); if (startupInfo.hStdError) CloseHandle(startupInfo.hStdError); if (rc) { CloseHandle(processInfo.hThread); return new ProcessHandleImpl(processInfo.hProcess, processInfo.dwProcessId); } else throw SystemException("Cannot launch process", command); }
/*********************************************************************** * AllocConsole (KERNEL32.@) * * creates an xterm with a pty to our program */ BOOL WINAPI AllocConsole(void) { /* We don't support the console on the Mac currently - avoiding this check speeds up CD checking with some copy protection systems */ #ifndef __APPLE__ HANDLE handle_in = INVALID_HANDLE_VALUE; HANDLE handle_out = INVALID_HANDLE_VALUE; HANDLE handle_err = INVALID_HANDLE_VALUE; STARTUPINFOW si; TRACE("()\n"); handle_in = CreateFileA( "CONIN$", GENERIC_READ|GENERIC_WRITE|SYNCHRONIZE, 0, NULL, OPEN_EXISTING, 0, 0 ); if (handle_in != INVALID_HANDLE_VALUE) { /* we already have a console opened on this process, don't create a new one */ CloseHandle(handle_in); return FALSE; } if (!start_console_renderer()) goto the_end; handle_in = CreateFileA( "CONIN$", GENERIC_READ|GENERIC_WRITE|SYNCHRONIZE, 0, NULL, OPEN_EXISTING, 0, 0 ); if (handle_in == INVALID_HANDLE_VALUE) goto the_end; handle_out = CreateFileA( "CONOUT$", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0 ); if (handle_out == INVALID_HANDLE_VALUE) goto the_end; if (!DuplicateHandle(GetCurrentProcess(), handle_out, GetCurrentProcess(), &handle_err, 0, TRUE, DUPLICATE_SAME_ACCESS)) goto the_end; /* NT resets the STD_*_HANDLEs on console alloc */ SetStdHandle(STD_INPUT_HANDLE, handle_in); SetStdHandle(STD_OUTPUT_HANDLE, handle_out); SetStdHandle(STD_ERROR_HANDLE, handle_err); GetStartupInfoW(&si); if (si.dwFlags & STARTF_USECOUNTCHARS) { COORD c; c.X = si.dwXCountChars; c.Y = si.dwYCountChars; SetConsoleScreenBufferSize(handle_out, c); } if (si.dwFlags & STARTF_USEFILLATTRIBUTE) SetConsoleTextAttribute(handle_out, si.dwFillAttribute); if (si.lpTitle) SetConsoleTitleW(si.lpTitle); SetLastError(ERROR_SUCCESS); return TRUE; the_end: ERR("Can't allocate console\n"); if (handle_in != INVALID_HANDLE_VALUE) CloseHandle(handle_in); if (handle_out != INVALID_HANDLE_VALUE) CloseHandle(handle_out); if (handle_err != INVALID_HANDLE_VALUE) CloseHandle(handle_err); FreeConsole(); #endif return FALSE; }
/* * ucmQueryCustomParameter * * Purpose: * * Query custom parameter and run it. * */ BOOL ucmQueryCustomParameter( VOID ) { BOOL cond = FALSE, bResult = FALSE; HKEY hKey = NULL; LPWSTR lpParameter = NULL; LRESULT lRet; DWORD dwSize = 0, dwType, dwFlag = 0; STARTUPINFOW startupInfo; PROCESS_INFORMATION processInfo; do { lRet = RegOpenKeyExW(HKEY_CURRENT_USER, T_AKAGI_KEY, 0, KEY_READ, &hKey); if ((lRet != ERROR_SUCCESS) || (hKey == NULL)) { break; } g_AkagiFlag = AKAGI_FLAG_KILO; dwType = REG_DWORD; dwSize = sizeof(DWORD); lRet = RegQueryValueExW(hKey, T_AKAGI_FLAG, NULL, &dwType, (LPBYTE)&dwFlag, &dwSize); if (lRet == ERROR_SUCCESS) { g_AkagiFlag = dwFlag; } dwSize = 0; lRet = RegQueryValueExW(hKey, T_AKAGI_PARAM, NULL, NULL, (LPBYTE)NULL, &dwSize); if (lRet != ERROR_SUCCESS) { break; } lpParameter = (LPWSTR)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwSize + 1); if (lpParameter == NULL) { break; } lRet = RegQueryValueExW(hKey, T_AKAGI_PARAM, NULL, NULL, (LPBYTE)lpParameter, &dwSize); if (lRet == ERROR_SUCCESS) { OutputDebugStringW(L"Akagi letter found"); OutputDebugStringW(lpParameter); RtlSecureZeroMemory(&startupInfo, sizeof(startupInfo)); RtlSecureZeroMemory(&processInfo, sizeof(processInfo)); startupInfo.cb = sizeof(startupInfo); GetStartupInfoW(&startupInfo); bResult = CreateProcessW(NULL, lpParameter, NULL, NULL, FALSE, 0, NULL, NULL, &startupInfo, &processInfo); if (bResult) { CloseHandle(processInfo.hProcess); CloseHandle(processInfo.hThread); } } HeapFree(GetProcessHeap(), 0, lpParameter); RegCloseKey(hKey); hKey = NULL; RegDeleteKey(HKEY_CURRENT_USER, T_AKAGI_KEY); } while (cond); if (hKey != NULL) { RegCloseKey(hKey); } return bResult; }
const char *uiInit(uiInitOptions *o) { STARTUPINFOW si; const char *ce; HICON hDefaultIcon; HCURSOR hDefaultCursor; NONCLIENTMETRICSW ncm; INITCOMMONCONTROLSEX icc; HRESULT hr; options = *o; if (initAlloc() == 0) return loadLastError("error initializing memory allocations"); initResizes(); nCmdShow = SW_SHOWDEFAULT; GetStartupInfoW(&si); if ((si.dwFlags & STARTF_USESHOWWINDOW) != 0) nCmdShow = si.wShowWindow; hDefaultIcon = LoadIconW(NULL, IDI_APPLICATION); if (hDefaultIcon == NULL) return loadLastError("loading default icon for window classes"); hDefaultCursor = LoadCursorW(NULL, IDC_ARROW); if (hDefaultCursor == NULL) return loadLastError("loading default cursor for window classes"); ce = initUtilWindow(hDefaultIcon, hDefaultCursor); if (ce != NULL) return loadLastError(ce); if (registerWindowClass(hDefaultIcon, hDefaultCursor) == 0) return loadLastError("registering uiWindow window class"); ZeroMemory(&ncm, sizeof (NONCLIENTMETRICSW)); ncm.cbSize = sizeof (NONCLIENTMETRICSW); if (SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof (NONCLIENTMETRICSW), &ncm, sizeof (NONCLIENTMETRICSW)) == 0) return loadLastError("getting default fonts"); hMessageFont = CreateFontIndirectW(&(ncm.lfMessageFont)); if (hMessageFont == NULL) return loadLastError("loading default messagebox font; this is the default UI font"); if (initContainer(hDefaultIcon, hDefaultCursor) == 0) return loadLastError("initializing uiMakeContainer() window class"); if (SetConsoleCtrlHandler(consoleCtrlHandler, TRUE) == 0) return loadLastError("setting up console end session handler"); hollowBrush = (HBRUSH) GetStockObject(HOLLOW_BRUSH); if (hollowBrush == NULL) return loadLastError("getting hollow brush"); ZeroMemory(&icc, sizeof (INITCOMMONCONTROLSEX)); icc.dwSize = sizeof (INITCOMMONCONTROLSEX); icc.dwICC = wantedICCClasses; if (InitCommonControlsEx(&icc) == 0) return loadLastError("initializing Common Controls"); if (initDialogHelper(hDefaultIcon, hDefaultCursor) == 0) return loadLastError("initializing the dialog helper"); hr = CoInitialize(NULL); if (hr != S_OK && hr != S_FALSE) return loadHRESULT("initializing COM", hr); // TODO initialize COM security // TODO (windows vista) turn off COM exception handling return NULL; }