找回密码
 加入我们

QQ登录

只需一步,快速开始

搜索
查看: 6057|回复: 2

关于进程名的交流(直接使用API取完整进程路径)

[复制链接]

6

主题

123

回帖

0

精华

初来乍到

积分
5392
发表于 2018-1-12 09:13:54 | 显示全部楼层 |阅读模式
本帖最后由 YOUBADBAD 于 2018-1-12 09:48 编辑

一般我们获取进程名都是用 “PsGetProcessImageFileName” 取到 16个字节 然鹅 今天突然用了一下这个函数 "SeLocateProcessImageName"
发现,PsGetProcessImageFileName(eproc)的时候,可以打印System,
而用 SeLocateProcessImageName(eproc,&UsImageName)的时候,取到别的程序全路径是正常的,而system的值是Null。

一开始是以为代码出了问题
后面通过windbg打印了才发现
人家本来就是空的

当然了,这个发现或许并没啥卵用,目的是发个贴交流心得

评分

参与人数 1水晶币 +20 收起 理由
Tesla.Angela + 20 赞一个!

查看全部评分

857

主题

2632

回帖

2

精华

管理员

此生无悔入华夏,  长居日耳曼尼亚。  

积分
36130
发表于 2018-1-12 09:40:09 | 显示全部楼层
经研究,该函数在NT5时代就已经存在,从VISTA-6000开始导出。
数据从EPROCESS->SeAuditProcessCreationInfo.ImageFileName->Name里取出。
  1. NTSTATUS SeLocateProcessImageName
  2. (
  3.     __in PEPROCESS Process,
  4.     __deref_out PUNICODE_STRING *pImageFileName
  5. )
  6. {
  7.         NTSTATUS                 Status            = STATUS_SUCCESS;
  8.         PVOID                    FilePointer       = NULL;
  9.         PVOID                    PreviousValue     = NULL;
  10.         POBJECT_NAME_INFORMATION pProcessImageName = NULL;
  11.         PUNICODE_STRING          pTempUS           = NULL;
  12.         ULONG                    NameLength        = 0;
  13.         PAGED_CODE();
  14.         *pImageFileName = NULL;
  15.         if (NULL == Process->SeAuditProcessCreationInfo.ImageFileName)
  16.         {
  17.                 //
  18.                 // The name has not been predetermined.  We must determine the process name.   First, reference the
  19.                 // PFILE_OBJECT and lookup the name.  Then again check the process image name pointer against NULL.
  20.                 // Finally, set the name.
  21.                 //
  22.                 Status = PsReferenceProcessFilePointer( Process, &FilePointer );
  23.                 if (NT_SUCCESS(Status))
  24.                 {
  25.                         //
  26.                         // Get the process name information.
  27.                         //
  28.                         Status = SeInitializeProcessAuditName(
  29.                                      FilePointer,
  30.                                      TRUE, // skip audit policy
  31.                                      &pProcessImageName // to be allocated in nonpaged pool
  32.                                  );
  33.                         if (NT_SUCCESS(Status))
  34.                         {
  35.                                 //
  36.                                 // Only use the pProcessImageName if the field in the process is currently NULL.
  37.                                 //
  38.                                 PreviousValue = InterlockedCompareExchangePointer(
  39.                                                     (PVOID *) &Process->SeAuditProcessCreationInfo.ImageFileName,
  40.                                                     (PVOID) pProcessImageName,
  41.                                                     (PVOID) NULL
  42.                                                 );
  43.                                 if (NULL != PreviousValue)
  44.                                 {
  45.                                         ExFreePool(pProcessImageName); // free what we caused to be allocated.
  46.                                 }
  47.                         }
  48.                         ObDereferenceObject( FilePointer );
  49.                 }
  50.         }
  51.         if (NT_SUCCESS(Status))
  52.         {
  53.                 //
  54.                 // Allocate space for a buffer to contain the name for returning to the caller.
  55.                 //
  56.                 NameLength = sizeof(UNICODE_STRING) + Process->SeAuditProcessCreationInfo.ImageFileName->Name.MaximumLength;
  57.                 pTempUS = ExAllocatePoolWithTag( NonPagedPool, NameLength, 'aPeS' );
  58.                 if (NULL != pTempUS)
  59.                 {
  60.                         RtlCopyMemory(
  61.                             pTempUS,
  62.                             &Process->SeAuditProcessCreationInfo.ImageFileName->Name,
  63.                             NameLength
  64.                         );
  65.                         pTempUS->Buffer = (PWSTR)(((PUCHAR) pTempUS) + sizeof(UNICODE_STRING));
  66.                         *pImageFileName = pTempUS;
  67.                 }
  68.                 else
  69.                 {
  70.                         Status = STATUS_NO_MEMORY;
  71.                 }
  72.         }
  73.         return Status;
  74. }
复制代码
在对路径可靠性要求不高的情况下可以直接使用。

28

主题

116

回帖

0

精华

铜牌会员

积分
273
发表于 2018-2-9 21:05:54 | 显示全部楼层
好方法
您需要登录后才可以回帖 登录 | 加入我们

本版积分规则

快速回复 返回顶部 返回列表