コード例 #1
0
        /// <summary>
        /// Tries to get the information for a file behind a handle.
        /// </summary>
        public bool TryGetInfoForHandle(IntPtr handle, out FileInfo info)
        {
            info = null;

            if (!_handleToInfoMap.ContainsKey(handle))
            {
                return(false);
            }

            info = _handleToInfoMap[handle];
            return(true);
        }
コード例 #2
0
        private int NtCreateFileImpl(out IntPtr handle, FileAccess access, ref Native.Native.OBJECT_ATTRIBUTES objectAttributes, ref Native.Native.IO_STATUS_BLOCK ioStatus, ref long allocSize, uint fileAttributes, FileShare share, uint createDisposition, uint createOptions, IntPtr eaBuffer, uint eaLength)
        {
            lock (_createLock)
            {
                string oldFileName = objectAttributes.ObjectName.ToString();
                if (!TryGetFullPath(oldFileName, out var newFilePath))
                {
                    return(_createFileHook.OriginalFunction(out handle, access, ref objectAttributes, ref ioStatus, ref allocSize, fileAttributes, share, createDisposition, createOptions, eaBuffer, eaLength));
                }

                // Check if AFS file and register if it is.
                if (newFilePath.Contains(Constants.AfsExtension, StringComparison.OrdinalIgnoreCase))
                {
                    var result = _createFileHook.OriginalFunction(out handle, access, ref objectAttributes, ref ioStatus, ref allocSize, fileAttributes, share, createDisposition, createOptions, eaBuffer, eaLength);
                    DisableRedirectionHooks();
                    if (IsAfsFile(newFilePath))
                    {
                        #if DEBUG
                        Console.WriteLine($"[AFSHook] AFS File Handle Opened: {handle}, File: {newFilePath}");
                        #endif
                        _handleToInfoMap[handle] = new FileInfo(newFilePath, 0);
                        OnAfsHandleOpened(handle, newFilePath);
                    }
                    EnableRedirectionHooks();
                    return(result);
                }

                var ntStatus = _createFileHook.OriginalFunction(out handle, access, ref objectAttributes, ref ioStatus, ref allocSize, fileAttributes, share, createDisposition, createOptions, eaBuffer, eaLength);

                // Invalidate Duplicate Handles (until we implement NtClose hook).
                if (_handleToInfoMap.ContainsKey(handle))
                {
                    _handleToInfoMap.TryRemove(handle, out var value);
                    #if DEBUG
                    Console.WriteLine($"[AFSHook] Removed old disposed handle: {handle}, File: {value.FilePath}");
                    #endif
                }

                return(ntStatus);
            }
        }