进程相关API
ID与句柄
句柄每一个进程都有一张自己的私有的表,这张表存储着私有的内核对象.
系统句柄表
oenProcess
Opens an existing local process object.
HANDLE WINAPI OpenProcess(
DWORD dwDesiredAccess,//打开进程的的权限问题
BOOL bInheritHandle,//允不允许子进程继承呢
DWORD dwProcessId //全局PID
);
以挂起的形式创建进程
Creates a new process and its primary thread. The new process runs in the security context of the calling process.
创建一个新进程和它的主要线程。这个新进程跑再一个安全正在调用的进程上下文中
If the calling process is impersonating another user, the new process uses the token for the calling process, not the impersonation token. To run the new process in the security context of the user represented by the impersonation token, use the CreateProcessAsUser or CreateProcessWithLogonW function.
BOOL WINAPI CreateProcess(
LPCTSTR lpApplicationName,
LPTSTR lpCommandLine,
LPSECURITY_ATTRIBUTES lpProcessAttributes,
LPSECURITY_ATTRIBUTES lpThreadAttributes,
BOOL bInheritHandles,
DWORD dwCreationFlags,//创建一个新的控制台
LPVOID lpEnvironment,
LPCTSTR lpCurrentDirectory,
LPSTARTUPINFO lpStartupInfo,
LPPROCESS_INFORMATION lpProcessInformation
);
回顾
1.进程的创建
1.任何进程都是别的进程创建的:CreateProcess()
2.进程创建过程
1.映射EXE文件
2.创建内核对象EPROCESS
3.映射系统DLL(ntdll.dll)
4.创建线程内核对象ETHREAD
5.系统启动线程
映射DLL(ntdll.KdrInitialize Thunk)
线程开始执行
2.进程的创建
1.映射EXE文件
2.创建内核对象EPROCESS
3.映射系统DLL(ntdll.dll)
4.创建线程内核对象ETHREAD
5.如果是挂起的方式创建的:
.....
6.恢复以后再继续执行
映射DLL(ntdll.KdrInitializeThunk)
线程开始执行
模块与工作目录
char strModule[256];
GetModuleFileName(NULL,strModule,256);//模块目录
char strWork[1000];
int i = 1000;
GetCurrentDirectory(1000,buf);//工作目录
printf("某块目录:%s\n 工作目录:%s\n",strModule,strWork);
GetModuleFileName
获取当前模块的路径
GetCurrentDirectory
获取现有目录
其他相关API
- 获取进程PID
GetCurrentProcessId - 获取进程句柄
GetCurrentProcess - 获取命令行
GetCommandLine - 获取启动信息
GetStartupinfo - 遍历进程ID
EnumProcesses - 快照
CreateToolhelp32napshot