View Process Permissions

Source: Internet
Author: User
Tags strcmp

The View process permissions feature of the faux pwoertool.

1#include <iostream>2#include <Windows.h>3#include <TlHelp32.h>4 5 using namespacestd;6 7 /*8 process ID for processes name9 pName: Process nameTen Iscase: Whether case-sensitive One The process ID is returned successfully, and the failure returns 0. A */ -DWORD Pro_namegetpid (Char*PName, BOOL iscase); -  the /* - Get Process Permissions - Hpro: Process Handle - ppowers: Pointer to the process permission string + the number of successfully returned process permissions, failed or not enabled, returns 0. - */ +DWORD pro_getprivileges (HANDLE Hpro,Char***ppowers); A  at intMainvoid) - { -HANDLE Hpro =NULL; -     Char**a =NULL; -  -Hpro = OpenProcess (process_all_access, FALSE, Pro_namegetpid ("test program. EXE", FALSE)); in     if(!Hpro) -     { toprintf"Process Open failed:%d\n", GetLastError ()); +         return 1; -     } theDWORD Dwlen = Pro_getprivileges (Hpro, &a); *      for(DWORD i =0; i < Dwlen; i++) $     {Panax Notoginsengcout << A[i] <<Endl; -     } the CloseHandle (Hpro); +     return 0; A } the  +DWORD Pro_namegetpid (Char*PName, BOOL iscase) - { $PROCESSENTRY32 Proinfo = {0 }; $HANDLE Hsnap = CreateToolhelp32Snapshot (th32cs_snapprocess,0); -BOOL bOk =FALSE; -DWORD Dwpid =0; the  -Proinfo.dwsize =sizeof(proinfo);Wuyi     if(!Hsnap) the         return 0; -BOk = Process32First (Hsnap, &proinfo); Wu     if(iscase) -     { About          while(bOk) $         { -             if(!strcmp (Proinfo.szexefile, pName)) -             { -Dwpid =Proinfo.th32processid; A                  Break; +             } theBOk = Process32Next (Hsnap, &proinfo); -         } $     } the     Else { the          while(bOk) the         { the             CharS1[max_path] = {0}, S2[max_path] = {0 }; - Lstrcpyn (S1, Proinfo.szexefile, strlen (Proinfo.szexefile)); in lstrcpyn (S2, PName, strlen (PName)); the_strupr_s (S1, strlen (S1) +1); the_strupr_s (S2, strlen (S2) +1); About  the             if(!strcmp (S1, S2)) the             { theDwpid =Proinfo.th32processid; +                  Break; -             } theBOk = Process32Next (Hsnap, &proinfo);Bayi         } the     } the CloseHandle (HSNAP); -     returnDwpid; - } the  theDWORD pro_getprivileges (HANDLE Hpro,Char***ppowers) the { theHANDLE Htoken =NULL; -Ptoken_privileges pTp =NULL; theDWORD dwneededsize =0, DwI =0; the  the     if(! OpenProcessToken (Hpro, token_all_access, &htoken))94     { theprintf"Process token fetch failed:%d\n", GetLastError ()); the         return 0; the     }98     //try to test how much memory you need to allocate AboutGetTokenInformation (Htoken, Tokenprivileges, NULL, Dwneededsize, &dwneededsize); -     //allocate the required memory size101PTp = (ptoken_privileges)malloc(dwneededsize);102     if(! GetTokenInformation (Htoken, Tokenprivileges, PTp, Dwneededsize, &dwneededsize))103     {104          Free(pTp); theprintf"failed to get process permissions! ");106         return 0;107     }108     Else109     { the          for(DWORD i =0; I < ptp->privilegecount; i++)111         { the             Char*puidname =NULL;113DWORD Dwnamelen =0; the             //To test the memory size required for Uidname theLookupprivilegename (NULL, &ptp->privileges[i]. Luid, NULL, &Dwnamelen); thePuidname = (Char*)malloc(Dwnamelen);117Lookupprivilegename (NULL, &ptp->privileges[i]. Luid, Puidname, &Dwnamelen);118*ppowers = (Char**)malloc(ptp->privilegecount);119             if(Ptp->privileges[i]. Attributes = =se_privilege_enabled) -             {121*PPOWERS[DWI] =Puidname;122dwi++;123Puidname =NULL;124                  Break; the             }126              Free(puidname);127         } -     }129      Free(pTp); the CloseHandle (htoken);131     returnDwI; the}

Give the test program the right to debug after the test:

View Process Permissions

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.