About the Pscreatesystemthread function

Source: Internet
Author: User

Studied for 1 days this ... MSDN isn't very clear.
NTSTATUS Pscreatesystemthread (
_out_ Phandle Threadhandle,
_in_ ULONG desiredaccess,
_in_opt_ Pobject_attributes Objectattributes,
_in_opt_ HANDLE ProcessHandle,
_out_opt_ pclient_id ClientId,
_in_ Pkstart_routine Startroutine,
_in_opt_ PVOID Startcontext
);

The function is used to create a system thread, the ProcessHandle parameter receives NULL, Ntcurrentprocess () (-1), or a process handle three cases can be ended with Psterminatesystemthread
Example:

[C + +]Plain Text view copy code
01 VOIDMyThread(PVOIDStartContext)
02 {
03     PEPROCESS pp=IoGetCurrentProcess();
04     NTSTATUS status=PsTerminateSystemThread(0);
05 //以下实际上已经不执行了
06     if(status == STATUS_INVALID_PARAMETER)
07     {
08         KdPrint(("not systemthread"));
09     }
10 }
11
12 HANDLEOpenProcess(HANDLEProcessid)
13 {
14     NTSTATUS status;
15     PEPROCESS Process = NULL;
16     HANDLEhProcess = NULL;
17     UNICODE_STRING Unicode;
18     status = PsLookupProcessByProcessId(Processid, &Process);
19     if(NT_SUCCESS(status))//判断进程号是否存在
20     {
21         RtlInitUnicodeString(&Unicode, L"PsProcessType");
22         //得到系统导出函数的地址和用户态的GetProcessAddress雷同
23         PsProcessType = (POBJECT_TYPE*)MmGetSystemRoutineAddress(&Unicode);
24         if(PsProcessType)
25         {
26             status = ObOpenObjectByPointer(Process,0,NULL,PROCESS_ALL_ACCESS,(POBJECT_TYPE) * PsProcessType,
27                 KernelMode,&hProcess);
28             if(NT_SUCCESS(status))
29             {
30                 //减少指针计数
31                 ObfDereferenceObject(Process);
32                 returnhProcess;
33             }
34         }
35         ObfDereferenceObject(Process);
36     }
37     return0;
38 }
39
40 HANDLEoutthread1,,outthread2,outthread3,outthread4,hproc;
41
42 PsCreateSystemThread(&outthread1,THREAD_ALL_ACCESS,NULL,NULL,NULL,MyThread,NULL);
43 PsCreateSystemThread(&outthread2,THREAD_ALL_ACCESS,NULL,NtCurrentProcess(),NULL,MyThread,NULL);
44
45 OBJECT_ATTRIBUTES oa;
46 CLIENT_ID ci={(HANDLE)1472,0};//注意是进程ID!
47 RtlZeroMemory(&oa,sizeof(oa));
48 oa.Length=sizeof(oa);
49 ZwOpenProcess(&hproc,PROCESS_ALL_ACCESS,&oa,&ci);
50 PsCreateSystemThread(&outthread3,THREAD_ALL_ACCESS,NULL,hproc,NULL,MyThread,NULL);
51
52 hproc=OpenProcess((HANDLE)1472);//注意是进程ID!
53 PsCreateSystemThread(&outthread4,THREAD_ALL_ACCESS,NULL,hproc,NULL,MyThread,NULL);





The function creates a thread whose Pethrad property Crossthreadflags has a Ps_cross_thread_flags_system property, does not allow the thread to be created in suspend mode, and the other and ordinary ntcreatethread differ little!
However, in Microsoft's official source code, the Ps_cross_thread_flags_system attribute is systemthread, although the process it belongs to may be Explorer.exe

Https://www.0xaa55.com/forum.php?mod=viewthread&tid=1376&extra=page%3D6

About the Pscreatesystemthread function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.