/// <summary>
        /// Contains the implementation of the NtCreateFile hook.
        /// Conditionally redirects oncoming files through changing ObjectName inside the objectAttributes instance.
        /// </summary>
        private static int NtCreateFileImpl(out IntPtr filehandle, FileAccess access, ref OBJECT_ATTRIBUTES objectAttributes, ref IO_STATUS_BLOCK ioStatus, ref long allocSize, uint fileattributes, FileShare share, uint createDisposition, uint createOptions, IntPtr eaBuffer, uint eaLength)
        {
            // Retrieves the file name that we are attempting to access.
            string oldFileName = objectAttributes.ObjectName.ToString();

            // Sometimes life can be a bit ugly :/
            if (oldFileName.StartsWith("\\??\\", StringComparison.InvariantCultureIgnoreCase))
            {
                oldFileName = oldFileName.Replace("\\??\\", "");
            }

            // Here we simply check whether the file path is in the dictionary,
            // if it is, we replace it.
            if (_remapperDictionary.TryGetValue(Path.GetFullPath(oldFileName), out string newFileName))
            {
                #if DEBUG
                Bindings.PrintInfo($"[NTCF] File Redirection: {oldFileName} => {newFileName}");
                #endif

                objectAttributes.ObjectName = new UNICODE_STRING("\\??\\" + newFileName);

                // Since are providing an absolute path, we need to clear the root directory since our path is not relative.
                objectAttributes.RootDirectory = IntPtr.Zero;
            }

            return(IntPtr.Size == 4 ?
                   _ntCreateFileHook.OriginalFunction(out filehandle, access, ref objectAttributes, ref ioStatus, ref allocSize, fileattributes, share, createDisposition, createOptions, eaBuffer, eaLength) :
                   _ntCreateFileHook64.OriginalFunction(out filehandle, access, ref objectAttributes, ref ioStatus, ref allocSize, fileattributes, share, createDisposition, createOptions, eaBuffer, eaLength));
        }
        /// <summary>
        /// Contains the implementation of our NtCreateFile hook.
        /// Simply prints the file name to the console and calls + returns the original function.
        /// </summary>
        /// <returns></returns>
        private static int NtCreateFileImpl(out IntPtr filehandle, FileAccess access, ref OBJECT_ATTRIBUTES objectAttributes, ref IO_STATUS_BLOCK ioStatus, ref long allocSize, uint fileattributes, FileShare share, uint createDisposition, uint createOptions, IntPtr eaBuffer, uint eaLength)
        {
            Bindings.PrintInfo($"[NTCF] Loading File {objectAttributes.ObjectName.ToString()}");

            return(IntPtr.Size == 4 ?
                   _ntCreateFileHook.OriginalFunction(out filehandle, access, ref objectAttributes, ref ioStatus, ref allocSize, fileattributes, share, createDisposition, createOptions, eaBuffer, eaLength) :
                   _ntCreateFileHook64.OriginalFunction(out filehandle, access, ref objectAttributes, ref ioStatus, ref allocSize, fileattributes, share, createDisposition, createOptions, eaBuffer, eaLength));
        }
Exemple #3
0
        /// <summary>
        /// Contains the implementation of the CreateFileW hook.
        /// Simply prints the file name to the console and calls + returns the original function.
        /// </summary>
        private static IntPtr CreateFileWImpl(string filename, FileAccess access, FileShare share, IntPtr securityAttributes, FileMode creationDisposition, FileAttributes flagsAndAttributes, IntPtr templateFile)
        {
            // Here we simply check whether the file path is in the dictionary,
            // if it is, we replace it.
            if (!filename.StartsWith(@"\\?\"))
            {
                if (_remapperDictionary.TryGetValue(Path.GetFullPath(filename), out string newFileName))
                {
                    return(IntPtr.Size == 4 ?
                           _createFileWHook.OriginalFunction(newFileName, access, share, securityAttributes, creationDisposition, flagsAndAttributes, templateFile) :
                           _createFileWHook64.OriginalFunction(newFileName, access, share, securityAttributes, creationDisposition, flagsAndAttributes, templateFile));
                }
            }

            return(IntPtr.Size == 4 ?
                   _createFileWHook.OriginalFunction(filename, access, share, securityAttributes, creationDisposition, flagsAndAttributes, templateFile) :
                   _createFileWHook64.OriginalFunction(filename, access, share, securityAttributes, creationDisposition, flagsAndAttributes, templateFile));
        }
Exemple #4
0
        /// <summary>
        /// Contains the implementation of the CreateFileW hook.
        /// Simply prints the file name to the console and calls + returns the original function.
        /// </summary>
        private static IntPtr CreateFileWImpl(string filename, FileAccess access, FileShare share, IntPtr securityAttributes, FileMode creationDisposition, FileAttributes flagsAndAttributes, IntPtr templateFile)
        {
            // This function delegate is automatically assigned by the Reloaded DLL Template Initializer
            // It simply prints to the console of the Mod Loader's Loader (which is a local server).
            // The if statement filters out non-files such as HID devices.
            if (!filename.StartsWith(@"\\?\"))
            {
                Bindings.PrintInfo($"[CFW] Loading File {filename}");
            }

            return(IntPtr.Size == 4 ?
                   _createFileWHook.OriginalFunction(filename, access, share, securityAttributes, creationDisposition, flagsAndAttributes, templateFile) :
                   _createFileWHook64.OriginalFunction(filename, access, share, securityAttributes, creationDisposition, flagsAndAttributes, templateFile));
        }
        /// <summary>
        /// No, we don't need to restart app.
        /// </summary>
        private static bool FunctionDelegate(uint appid)
        {
            // Write the Steam AppID to a local file.
            File.WriteAllText(SteamAppId, $"{appid}");

            if (IntPtr.Size == 4)
            {
                restartIfNecessaryHook32.OriginalFunction(appid);
            }
            else
            {
                restartIfNecessaryHook64.OriginalFunction(appid);
            }

            return(false);
        }