Process operation related functions under Win drive

Source: Internet
Author: User

1. Let's get a reputation. Functions (exported)

// 1. 声明要使函数NTKERNELAPI NTSTATUS PsSuspendProcess(PEPROCESS pEProcess);NTKERNELAPI UCHAR* PsGetProcessImageFileName(IN PEPROCESS pEProcess);NTKERNELAPI NTSTATUS PsResumeProcess(PEPROCESS pEProcess);NTKERNELAPI HANDLE PsGetProcessInheritedFromUniqueProcessId(IN PEPROCESS pEProcess);
According to the PID return process eprocess, the failure returns nullpeprocess lookupprocess (HANDLE hpid) {peprocess peprocess = NULL;    if (Nt_success (Pslookupprocessbyprocessid (Hpid, &peprocess)) return peprocess; return NULL;}    Suspend Process Boolean kernelsuspendprocess (ULONG ID) {//1. eporcess peprocess peprocess by Id; if (peprocess = Lookupprocess ((HANDLE) Id)) = NULL) {//2. Suspend process if (Nt_success (Pssuspendprocess (peproces    s)) return FALSE; } return TRUE;    Recovery process Boolean kernelresumeprocess (ULONG ID) {//1. eporcess peprocess peprocess by Id; if (peprocess = Lookupprocess ((HANDLE) Id)) = NULL) {//2. Suspend process if (Nt_success (Psresumeprocess (peprocess    )) return FALSE; } return TRUE;    End process void Kernelkillprocess () {HANDLE hprocess = NULL;    client_id ClientId = {0};    Object_attributes objattribut = {sizeof (object_attributes)}; Clientid.uniqueprocess = (HANDLE) 1234; PID Clientid.uniqueThread = 0; Opens the process, if the handle is valid, ends the process zwopenprocess (&hprocess,//returns the open handle 1,//access permission &objat   Tribut,//object attribute &clientid);        Process ID Structure if (hprocess) {zwterminateprocess (hprocess, 0);    Zwclose (hprocess); };}    Traversal process void enumprocess () {peprocess peproc = NULL;    The Loop traversal process (assuming that the maximum value of the thread does not exceed 0x25600) ULONG i = 0;        for (i = 4; i<0x25600; i = i + 4) {//A. According to PID, return peprocess Peproc = lookupprocess ((HANDLE) i);        if (!peproc) continue;            B. Print process information Dbgprint ("eprocess=%p pid=%ld ppid=%ld name=%s\n", Peproc, (UINT32) Psgetprocessid (Peproc), (UINT32)        Psgetprocessinheritedfromuniqueprocessid (Peproc), Psgetprocessimagefilename (Peproc));        C. Reduce the Process object reference count by 1 obdereferenceobject (PEPROC);    Dbgprint ("\ n"); }}

Note that this is not the kind of normal traversal that is obtained through the chain. Because it is possible to deliberately break the chain. Here through the brute-force traversal (both process IDs are even)

Process operation related functions under Win drive

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.