/
/
一段例子
typedef NTSTATUS(WINAPI
*
pfnNtCreateProcess)(
PHANDLE ProcessHandle,
ACCESS_MASK DesiredAccess,
POBJECT_ATTRIBUTES ObjectAttributes,
HANDLE InheritFromProcessHandle,
BOOLEAN InheritHandles,
HANDLE SectionHandle,
HANDLE DebugPort,
HANDLE ExceptionPort
);
int
main() {
HMODULE hNtdll
=
LoadLibrary(L
"ntdll.dll"
);
if
(hNtdll
=
=
NULL) {
return
1
;
}
pfnNtCreateProcess NtCreateProcess
=
(pfnNtCreateProcess)GetProcAddress(hNtdll,
"NtCreateProcess"
);
if
(NtCreateProcess
=
=
NULL) {
FreeLibrary(hNtdll);
return
1
;
}
HANDLE processHandle;
ACCESS_MASK desiredAccess
=
PROCESS_ALL_ACCESS;
OBJECT_ATTRIBUTES objectAttributes
=
{ sizeof(OBJECT_ATTRIBUTES), NULL, NULL,
0
, NULL, NULL };
HANDLE inheritFromProcessHandle
=
GetCurrentProcess();
BOOLEAN inheritHandles
=
FALSE;
HANDLE sectionHandle
=
NULL;
HANDLE debugPort
=
NULL;
HANDLE exceptionPort
=
NULL;
NTSTATUS status
=
NtCreateProcess(
&processHandle,
desiredAccess,
&objectAttributes,
inheritFromProcessHandle,
inheritHandles,
sectionHandle,
debugPort,
exceptionPort
);
/
/
检查函数调用结果
if
(NT_SUCCESS(status)) {
/
/
进程创建成功
printf(
"进程创建成功,句柄: %p\n"
, processHandle);
/
/
在这里可以使用 processHandle 进行其他操作,例如等待进程退出、关闭句柄等
/
/
关闭进程句柄
CloseHandle(processHandle);
}
else
{
/
/
进程创建失败
printf(
"进程创建失败,错误码: %08X\n"
, status);
}
/
/
卸载 ntdll.dll 库
FreeLibrary(hNtdll);
return
0
;
}