查看进程令牌信息源代码(2)
源程序
/**
TokenInfor tell Token Infor and Owner Infor of Specify Process
--bingle, bingle@email.com.cn
*/
#include
#include
#include
#include
#define UULEN 256
#define true 1
#define false 0
typedef DWORD GetModuleFileNameExType(
HANDLE hProcess, // handle to the process
HMODULE hModule, // handle to the module
LPTSTR lpFilename, // buffer that receives the path
DWORD nSize // size of the buffer
);
GetModuleFileNameExType *GetModuleFileNameExAddr;
HMODULE psapi;
int GetUserNameFromToken(HANDLE htoken, char user[]);
int OutPutGroupsFromToken(HANDLE htoken);
int OutPutPrivilegesFromToken(HANDLE htoken);
int OutPutTokenType(TOKEN_STATISTICS *tstat);
int GetProcessTokenSource(HANDLE hp, char src[]);
int EnableDebugPriv(int fEnable);
void Usage(char *prog)
{
printf(" Usage : [pid]
", prog);
printf(" pid -- ID of target process, if not provide, use current process
");
printf(" -?|/? -- show this.
");
exit(0);
}
int LoadPsapi()
{
psapi = LoadLibrary("psapi.dll");
GetModuleFileNameExAddr = NULL;
if(psapi == NULL) return 0;
GetModuleFileNameExAddr = (GetModuleFileNameExType*)GetProcAddress(psapi, "GetModuleFileNameExA");
if(GetModuleFileNameExAddr == NULL)
{
psapi = NULL;
return 0;
}
return 1;
}
int main(int argc,char *argv[])
{
printf("TokenInfor tell Token Infor and Owner Infor of Specify Process, -- bingle
");
if(argc == 2 && strcmp(argv[1], "/?") == 0)Usage(argv[0]);
if(argc == 2 && strcmp(argv[1], "-?") == 0)Usage(argv[0]);
HANDLE hp , htoken;
char buff[1024];
unsigned long size = 1024, ret, procID;
- 上一篇:创建DirectX环境
- 下一篇:分析MFC中的映射