Пример #1
0
        //determines whether it's object.
        private static Boolean IsObject(Int32 pID, IntPtr remoteHandle, IEnumerable <String> fileNames)
        {
            NativeNormalHandle handle = null;

            try
            {
                handle = HandleCopy(pID, remoteHandle);
                if (handle != null && IsFileOrDirectoryHandle(handle.DangerousGetHandle()))
                {
                    var fileName = GetFileNameFromHandle(handle.DangerousGetHandle());
                    foreach (var item in fileNames)
                    {
                        if (item.Equals(fileName))
                        {
                            return(true);
                        }
                    }
                }
                return(false);
            }
            finally
            {
                if (handle != null)
                {
                    handle.Close();
                }
            }
        }
Пример #2
0
 public static Boolean TryDuplicateHandle(NativeNormalHandle sourceProcessHandle, IntPtr sourceHandle, IntPtr targetProcessHandle, out NativeNormalHandle targetHandle, Boolean removeSourceHandle = false)
 {
     if (!DuplicateHandle(sourceProcessHandle.DangerousGetHandle(), sourceHandle, targetProcessHandle, out targetHandle, 0, false, DuplicateOptions.DuplicateSameAccess | (removeSourceHandle ? DuplicateOptions.DuplicateCloseSource : DuplicateOptions.None)))
     {
         if (targetHandle.IsInvalid)
         {
             targetHandle.Close();
         }
         targetHandle = null;
         return(false);
     }
     return(true);
 }