Лабораторная работа № 1

Download Лабораторная работа № 1

Post on 13-Nov-2014

466 views

Category:

Documents

0 download

Embed Size (px)

TRANSCRIPT

1. 2. 3. v Windows CreateProcess IpszApplicationName IpszCommandLine lpsaProcess, lpsaThread finheritHandles fdwCreate lpvEnvironment lpszCurDir lpsiStartInfo lppiProcInfo ExitProcess TerminateProcess CONTEXT CreateThread Ipsa-1-

cbStack IpStartAddr IpvThreadParm fdwCreate iplDThread ExitThread TerminateThread Win32 v Unix , exec execl exec execv exelp

execvp execle execve fork-2-

exit _exit _Exit exit wait, waitpid waitid waitpid wait waitid getpid getppid pthread_cancel pthread_testcancel 4. v v

-3-

1. , ; , .

2. 1. . , . . , , , . 2. . , . . , .

-4-

3. WINDOWS . Win32 4 . Win32- MS-DOS 16- Windows . , Win32- , - . DLL-, -. , , , . , , . , . - , . , . , , . , . , , . , . ( ) , (. . 3-1).

-5-

. 3-1. Win32- (, ) . , . . Windows NT . Windows NT , . Windows NT .

-6-

CreateProcess CreateProcess:

BOOL CreateProcess( LPCTSTR lpszApplicationName, LPCTSTR lpszCommandLine, LPSECURITY_ATTRIBUTES lpsaProcess, LPSECURITY_ATTRIBUTES lpsaThread, BOOL fInheritHandles, DWORD fdwCreate, LPVOID lpvEnvironment, LPTSTR IpszCurDir, LPSTARTUPINFO IpsiStartInfo, LPPROCESS.INFORMATION lppiProcInfo);

CreateProcess, , 1. , , . ( .) 4 , , DLL ( ). ( , 1) . , , . , WinMain ( main -

-7-

). , CreateProcess TRUE. 16- Windows, , WinExec LoadModule, , , CreateProcess, , . 32 Windows WinExec LoadModule 16- Windows CreateProcess. , Unicode, ANSI-.

IpszApplicationName IpszCommandLine , , , . IpszCommandLine. , CreateProcess . IpszCommandLine , , , . , . : 1. , - . 2. . 3. Windows. 4. Windows. 5. , PATH. , , . -8-

, . . , , WinMain ( ) IpszCmdLine. , , , IpszApplicationName NULL ( 99% ). NULL , . , , . CreateProcess , ( ). , , . IpszApplicationName CreateProcess IpszCommandLine . , CreateProcess :

CreateProcess( ":\\WINNT\\SYSTEM32\\NOTEPAD.EXE", "WORDPAD README.TXT");

Notepad, WORDPAD README.TXT. , ? , CreateProcess. , IpszApplicationName, CreateProcess POSIX Windows NT.

-9-

lpsaProcess, lpsaThread finheritHandles , ( ). , . lpsaProcess lpsaThread . NULL, . SECURITY_ATTRIBUTES; . SECURITY_ATTRIBUTES lpsaProcess lpsaThread , , - . . 3-2 , , . , lpsaProcess SECURITY_ATTRIBUTES, binheritHandle TRUE. lpsaThread SECURITY_ATTRIBUTES, binheritHandle FALSE. , , , lppiProcInfo, , . , CreateProcess . , . finheritHandles. TRUE, . - 10 -

. finheritHandles. , A CreateProcess, finheritHandles FALSE, , .

. 3-2. , INHERIT.C #include int WINAPI WinMain(HINSTANCE hinstExe, HINSTANCE hinstExePrev, LPSTR lpszCmdLine, int nCmdShow) { STARTUPINFO si; SECURITY_ATTRIBUTES saProcess, saThread; PROCESS_INFORMATION piProcessB, piProcessC; // STARTUPINFO // ZeroMemory(&si, sizeof(si)); si.cb = sizeof(si); // ; // , "", // saProcess.nLength = sizeof(saProcess); saProcess.lpSecurityDescriptor = NULL; saProcess.bInheritHandle = TRUE; // , "", // saThread.nLength = sizeof(saThread); saThread.IpSecurityDescriptor = NULL; saThread.bInheritHandle = FALSE;

- 11 -

// CreateProcess(NULL, "ProcessB", &saProcess, &saThread, FALSE, 0, NULL, NULL, &si, &piProcessB); // pi , ; // hProcess, "" // , hThread, // " " . // . // IpsaProcess IpsaThread NULL, // "" " " // . // , // "" " " . // flnheritHandles TRUE, // , // "" , , // " " . CreateProcess(NULL, "ProcessC", NULL, NULL. TRUE, 0. NULL, NULL, &si, &piProcessC);

return(0); }

fdwCreate fdwCreate , , . OR. DEBUG_PROCESS , , . , - 12 -

(

)

( ). DEBUG_ONLY_THIS_PROCESS DEBUG_PROCESS , . , , , . CREATE_SUSPENDED . . , , , . , , , , , . DETACHED_PROCESS , , , . , . , . CREATE_NEW_CONSOLE . : CREATE_NEW_CONSOLE DETACHED_PROCESS .

- 13 -

CREATE_NO_WINDOW . CREATE_NEW_PROCESS_GROUP , Ctrl+C Ctrl+Break. , , . . . , Ctrl+C Ctrl+Break , . CREATE_DEFAULT_ERROR_MODE , , . CREATE_SEPARATE_WOW_VDM 16 Windows- Windows NT. , DOS- (Virtual DOS machine, VDM) 16- Windows- . ( 16- Windows- , VDM.) VDM : , VDM, , VDM, . , 16- Windows-, VDM, . , , VDM . VDM , . Windows 95 16- Windows- VDM, . CREATE_SHARED_WOW_VDM 16 Windows- Windows NT. 16- 14 -

Windows- VDM, CREATE_SEPARATE_WOW_VDM. ( Windows N'T , es DefaultSeparateVDM

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\WOW.

Windows NT .) yes, CREATE_SHARED_WOW_VDM, Windows NT 16- Windows- VDM. CREATE_UNICODE_ENVIRONMENT , Unicode. ANSI- . . , , ; . : Idle () Normal () High () Realtime ( ) IDLE__PRIORITY_CLASS NORMAL_PRIORITY_CLASS HIGH_PRIORITY_CLASS REALTIME_PRIORITY_CLASS

. lpvEnvironment , , . lpvEnvironment NULL,

- 15 -

. GetEnvironmentStrings:

LPVOID GetEnvironmentStrings(VOID);

, . lpvEnvironment CreateProcess. ( CreateProcess, NULL IpvEnvironment) lpszCurDir . NULL, , , . NULL, ( ), . . lpsiStartInfo STARTUPINFO:typedef struct _STARTUPINFO { DWORD cb; LPSTR lpReserved; LPSTR LPSTR lpDesktop; lpTitle;

DWORD dwX; DWORD dwY; DWORD dwXSize; DWORD dwYSize; DWORD dwXCountChars; DWORD dwYCountChars; DWORD dwFillAttribute; - 16 -

DWORD dwFlags; WORD WORD wShowWindow; cbReserved2;

LPBYTE lpReserved2: HANDLE hStdInput; HANDLE hStdOutput; HANDLE hStdError: } STARTUPINFO, *LPSTARTUPINFO;

STARTUPINFO Win32- . , . STARTUPINFO , cb :

STARTUPINFO si; ZeroMemory(&si, sizeof(si)); si.cb = sizeof(si); CreateProcess(..., &si, . . . ) ;

, . , , - , CreateProcess. . 3-3. : , (overlapped) , / .

- 17 -

. 3-3. STARTUPINFO , STARTUPINFO. cb , Microsoft Win32. cb sizeof(STARTUPINFO). IpReserved . NULL. ,

. , . IpDesktop , , , . IpDesktop NULL ( ), . IpTitle . IpTitle NULL, . - - ( ) , . , dwX dwY CW_USEDEFAULT CreateWindow. , , . ( ) . , dwXSize dwYSize CW_USEDEFAULT nWidth CreateWindow. , ,

- 18 -

. dwXCountChars dwYCountChars dwFillAttribute dwFlags ( ) . . . . , , ShowWindow wShowWindow nCmdShow SW_SHOWDEFAULT. SW_*, ShowWindow. cbReserved2 lpReserved2 hStdInput hStdOutput IiStdError . 0. . NULL. /. hStdInput , a hStdOutput hStdError .

dwFlags. , . CreateProcess, STARTUPINFO . :

- 19 -

STARTF_USESIZE STARTF_USESHOWWINDOW STARTF_USEPOSITION STARTF_USECOUNTCHARS

dwXSize dwYSize. wShowWindow. dwX dwY. dwXCountChars dwYCountChars. dwFillAttribute. hStdInput, hStdOutput hStdError.

STARTF_USEFILLATTRIBUTE STARTF_USESTDHANDLE

STARTF_FORCEONFEEDBACK

STARTF_FORCE-OFFFEEDBACK

. Windows 95 Windows NT , , , .

CreateProcess :

.

: -, - , . Windows NT CreateProcess . . CreateProcess . STARTF_FORCEOFFFEEDBACK, CreateProcess . STARTF_FORCEONFEEDBACK, , CreateProcess . CreateProcess , .

- 20 -

2 GUI-, . 2 - GUI-, CreateProcess , . 5 GUI-. , CreateProcess , 5 . GetMessage, , , CreateProcess . STARTF_SCREENSAVER , ; . , , CreateProcess. GetMessage PeekMessage, (idle). , ( CreateProcess). CreateProcess NORMAL_PRIORITY_CLASS, : 1. , . , . 2. , -- 21 -

normal realtime,

. , , , , . wShowWindow STARTUPINFO. , WinMain nCmdShow. , . , ShowWindow ( SW_SHOWNORMAL SW_SHOWMINNOACTIVE, SW_SHOWDEFAULT). Explorer WinMain SWSHOWNORMAL nCmdShow. Shift, SW_SHOWMINNOACTIVE. , . , STARTUPINFO, , :

VOID GetStartup