コード例 #1
0
ファイル: Methods.cs プロジェクト: djkurtb/WinApi
 public static extern IntPtr CreateFile(string lpFileName,
                                        uint dwDesiredAccess,
                                        FileShareMode dwShareMode,
                                        ref SecurityAttributes lpSecurityAttributes,
                                        FileCreationDisposition dwCreationDisposition,
                                        uint dwFlagsAndAttributes,
                                        IntPtr hTemplateFile);
コード例 #2
0
 public static extern IntPtr CreateFile(
     string fileName,
     FileAccessRightFlags desiredAccess,
     FileShareModeFlags shareMode,
     IntPtr securityAttributes,
     FileCreationDisposition creationDisposition,
     FileFlagsAndAttributes flagsAndAttributes,
     IntPtr templateFile);
コード例 #3
0
 public static extern SafeFileHandle CreateFile(
     [In, MarshalAs(UnmanagedType.LPWStr)] string fileName,
     [In, MarshalAs(UnmanagedType.U4)] FileAccess desiredAccess,
     [In, MarshalAs(UnmanagedType.U4)] FileShare shareMode,
     [In, MarshalAs(UnmanagedType.SysInt)] IntPtr securityAttributes,
     [In, MarshalAs(UnmanagedType.U4)] FileCreationDisposition creationDisposition,
     [In, MarshalAs(UnmanagedType.U4)] FileAttributes flagsAndAttributes,
     [In, MarshalAs(UnmanagedType.SysInt)] IntPtr templateFile);
コード例 #4
0
 public static extern SafeFileHandle CreateFile(
     [In] string lpFileName,
     [In] AccessRights dwDesiredAccess,
     [In] FileShareMode dwShareMode,
     [In] IntPtr lpSecurityAttributes,
     [In] FileCreationDisposition dwCreationDisposition,
     [In] FileAttributeFlags dwFlagsAndAttributes,
     [In] IntPtr hTemplateFile);
コード例 #5
0
 public static extern IntPtr CreateFile(
     string fileName,
     FileAccessRightFlags desiredAccess,
     FileShareModeFlags shareMode,
     IntPtr securityAttributes,
     FileCreationDisposition creationDisposition,
     FileFlagsAndAttributes flagsAndAttributes,
     IntPtr templateFile);
コード例 #6
0
 public static extern IntPtr CreateFileW(
     string lpFileName,
     FileAccessMode dwDesiredAccess,
     FileShareMode dwShareMode,
     IntPtr lpSecurityAttributes,                 // always 0
     FileCreationDisposition dwCreationDisposition,
     FileFlagsAndAttributes dwFlagsAndAttributes, // typically just FILE_FLAG_OVERLAPPED
     IntPtr hTemplateFile);
コード例 #7
0
ファイル: PipeNative.cs プロジェクト: keepview/PFD_Server
 public static extern IntPtr CreateFile(
     String lpFileName,                  // File name 文件名
     FileDesiredAccess dwDesiredAccess,  // Access mode 通道模式
     FileShareMode dwShareMode,          // Share mode 共享模式
     IntPtr fileSecurityAttributes,      // Security Attributes 安全属性
     FileCreationDisposition dwCreationDisposition,// How to create
     uint dwFlagsAndAttributes,          // File attributes 文件属性
     uint hTemplateFile);                // Handle to template file
コード例 #8
0
ファイル: KERNEL32.cs プロジェクト: Comostoad/isx
 public static extern /*SafeFileHandle*/ IntPtr CreateFile(
     string lpFileName,
     FileAccess dwDesiredAccess,
     FileShareMode dwShareMode,
     IntPtr lpSecurityAttributes,
     FileCreationDisposition dwCreationDisposition,
     FileFlagsAndAttributes dwFlagsAndAttributes,
     IntPtr hTemplateFile);
コード例 #9
0
 internal static extern IntPtr CreateFile(
     string fileName,
     FileDesiredAccess desiredAccess,
     FileShareMode shareMode,
     IntPtr securityAttributes,
     FileCreationDisposition creationDisposition,
     FileAttributes flagsAndAttributes,
     IntPtr templateFile);
コード例 #10
0
 internal static extern IntPtr CreateFile(
     string lpFileName,
     FileDesiredAccess dwDesiredAccess,
     FileShareMode dwShareMode,
     IntPtr lpSecurityAttributes,
     FileCreationDisposition dwCreationDisposition,
     FileAttributes dwFlagsAndAttributes,
     IntPtr hTemplateFile);
コード例 #11
0
 public static extern FileSafeHandle CreateFile(
     [MarshalAs(UnmanagedType.LPWStr)] string lpFileName,
     AccessRights dwDesiredAccess,
     [MarshalAs(UnmanagedType.U4)] FileShare share,
     IntPtr lpSecurityAttributes,
     FileCreationDisposition dwCreationDisposition,
     [MarshalAs(UnmanagedType.U4)] FileAttributes flagsAndAttributes,
     IntPtr hTemplateFile
     );
コード例 #12
0
 internal static extern SafeFileHandle CreateFileW(
     /* _In_     LPCTSTR               */ [In] string lpFileName,
     /* _In_     DWORD                 */ [In] GenericAccessRight dwDesiredAccess,
     /* _In_     DWORD                 */ [In] FileShare dwShareMode,
     /* _In_opt_ LPSECURITY_ATTRIBUTES */ [In] IntPtr lpSecurityAttributes,
     /* _In_     DWORD                 */ [In] FileCreationDisposition dwCreationDisposition,
     /* _In_     DWORD                 */ [In] FileAttributeFlag dwFlagsAndAttributes,
     /* _In_opt_ HANDLE                */ [In] IntPtr hTemplateFile
     );
コード例 #13
0
ファイル: NativeMethods.cs プロジェクト: jsschultz/PTVS
 public static extern SafeFileHandle CreateFile(
     string lpFileName,
     FileDesiredAccess dwDesiredAccess,
     FileShareFlags dwShareMode,
     IntPtr lpSecurityAttributes,
     FileCreationDisposition dwCreationDisposition,
     FileFlagsAndAttributes dwFlagsAndAttributes,
     IntPtr hTemplateFile
 );
コード例 #14
0
 public static extern IntPtr CreateFile(
     string lpFileName,                             // File name
     FileDesiredAccess dwDesiredAccess,             // Access mode
     FileShareMode dwShareMode,                     // Share mode
     IntPtr SecurityAttributes,                     // Security attributes
     FileCreationDisposition dwCreationDisposition, // How to create
     uint dwFlagsAndAttributes,                     // File attributes
     IntPtr hTemplateFile                           // Handle to template file
     );
コード例 #15
0
        public static NamedPipeHandle Create(
            FileAccess access,
            string fileName,
            ObjectFlags objectFlags,
            NativeHandle rootDirectory,
            FileShareMode shareMode,
            FileCreationDisposition creationDisposition,
            FileCreateOptions createOptions,
            PipeType type,
            PipeType readMode,
            PipeCompletionMode completionMode,
            int maximumInstances,
            int inboundQuota,
            int outboundQuota,
            long defaultTimeout
            )
        {
            NtStatus         status;
            ObjectAttributes oa = new ObjectAttributes(fileName, objectFlags, rootDirectory);
            IoStatusBlock    isb;
            IntPtr           handle;

            // If a timeout wasn't specified, use a default value.
            if (defaultTimeout == 0)
            {
                defaultTimeout = -50 * Win32.TimeMsTo100Ns; // 50 milliseconds
            }
            try
            {
                if ((status = Win32.NtCreateNamedPipeFile(
                         out handle,
                         access,
                         ref oa,
                         out isb,
                         shareMode,
                         creationDisposition,
                         createOptions,
                         type,
                         readMode,
                         completionMode,
                         maximumInstances,
                         inboundQuota,
                         outboundQuota,
                         ref defaultTimeout
                         )) >= NtStatus.Error)
                {
                    Win32.Throw(status);
                }
            }
            finally
            {
                oa.Dispose();
            }

            return(new NamedPipeHandle(handle, true));
        }
コード例 #16
0
        public static NamedPipeHandle Create(
            FileAccess access,
            string fileName,
            ObjectFlags objectFlags,
            NativeHandle rootDirectory,
            FileShareMode shareMode,
            FileCreationDisposition creationDisposition,
            FileCreateOptions createOptions,
            PipeType type,
            PipeType readMode,
            PipeCompletionMode completionMode,
            int maximumInstances,
            int inboundQuota,
            int outboundQuota,
            long defaultTimeout
            )
        {
            NtStatus status;
            ObjectAttributes oa = new ObjectAttributes(fileName, objectFlags, rootDirectory);
            IoStatusBlock isb;
            IntPtr handle;

            // If a timeout wasn't specified, use a default value.
            if (defaultTimeout == 0)
                defaultTimeout = -50 * Win32.TimeMsTo100Ns; // 50 milliseconds

            try
            {
                if ((status = Win32.NtCreateNamedPipeFile(
                    out handle,
                    access,
                    ref oa,
                    out isb,
                    shareMode,
                    creationDisposition,
                    createOptions,
                    type,
                    readMode,
                    completionMode,
                    maximumInstances,
                    inboundQuota,
                    outboundQuota,
                    ref defaultTimeout
                    )) >= NtStatus.Error)
                    Win32.Throw(status);
            }
            finally
            {
                oa.Dispose();
            }

            return new NamedPipeHandle(handle, true);
        }
コード例 #17
0
        public static NamedPipeHandle Create(
            FileAccess access,
            string fileName,
            ObjectFlags objectFlags,
            FileHandle rootDirectory,
            FileShareMode shareMode,
            FileCreationDisposition creationDisposition,
            FileCreateOptions createOptions,
            PipeType type,
            PipeType readMode,
            PipeCompletionMode completionMode,
            int maximumInstances,
            int inboundQuota,
            int outboundQuota,
            long defaultTimeout
            )
        {
            NtStatus         status;
            ObjectAttributes oa = new ObjectAttributes(fileName, objectFlags, rootDirectory);
            IoStatusBlock    isb;
            IntPtr           handle;

            try
            {
                if ((status = Win32.NtCreateNamedPipeFile(
                         out handle,
                         access,
                         ref oa,
                         out isb,
                         shareMode,
                         creationDisposition,
                         createOptions,
                         type,
                         readMode,
                         completionMode,
                         maximumInstances,
                         inboundQuota,
                         outboundQuota,
                         ref defaultTimeout
                         )) >= NtStatus.Error)
                {
                    Win32.ThrowLastError(status);
                }
            }
            finally
            {
                oa.Dispose();
            }

            return(new NamedPipeHandle(handle, true));
        }
コード例 #18
0
ファイル: HidDevice.cs プロジェクト: dumbie/CtrlUI
        private bool OpenDevice()
        {
            try
            {
                FileShareMode           shareModeExclusive  = FileShareMode.FILE_SHARE_NONE;
                FileShareMode           shareModeNormal     = FileShareMode.FILE_SHARE_READ | FileShareMode.FILE_SHARE_WRITE;
                FileDesiredAccess       desiredAccess       = FileDesiredAccess.GENERIC_READ | FileDesiredAccess.GENERIC_WRITE;
                FileCreationDisposition creationDisposition = FileCreationDisposition.OPEN_EXISTING;
                FileFlagsAndAttributes  flagsAttributes     = FileFlagsAndAttributes.FILE_FLAG_NORMAL | FileFlagsAndAttributes.FILE_FLAG_OVERLAPPED | FileFlagsAndAttributes.FILE_FLAG_NO_BUFFERING;

                //Try to open the device exclusively
                FileHandle = CreateFile(DevicePath, desiredAccess, shareModeExclusive, IntPtr.Zero, creationDisposition, flagsAttributes, IntPtr.Zero);
                Exclusive  = true;

                //Try to open the device normally
                if (FileHandle == null || FileHandle.IsInvalid || FileHandle.IsClosed)
                {
                    //Debug.WriteLine("Failed to open device exclusively, opening normally.");
                    FileHandle = CreateFile(DevicePath, desiredAccess, shareModeNormal, IntPtr.Zero, creationDisposition, flagsAttributes, IntPtr.Zero);
                    Exclusive  = false;
                }

                //Check if the device is opened
                if (FileHandle == null || FileHandle.IsInvalid || FileHandle.IsClosed)
                {
                    //Debug.WriteLine("Failed to open hid device: " + DevicePath);
                    Connected = false;
                    Installed = false;
                    return(false);
                }
                else
                {
                    //Debug.WriteLine("Opened hid device: " + DevicePath + ", exclusively: " + Exclusive);
                    Connected = true;
                    Installed = true;
                    return(true);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Failed to open hid device: " + ex.Message);
                Connected = false;
                Installed = false;
                return(false);
            }
        }
コード例 #19
0
ファイル: RawMailSlot.cs プロジェクト: FreeMasen/MailSlot
        private static SafeMailslotHandle CreateFile(string name,
                                                     IntPtr securityAttributes,
                                                     IntPtr hTemplateFile,
                                                     FileDesiredAccess access = FileDesiredAccess.GenericWrite,
                                                     FileShareMode shareMode  = FileShareMode.FileShareRead,
                                                     FileCreationDisposition creationDisposition = FileCreationDisposition.OpenExisting,
                                                     int flagsAndAttributes = 0
                                                     )
        {
            var ret = CreateFile(name, access, shareMode, securityAttributes, creationDisposition, flagsAndAttributes, hTemplateFile);

            if (ret.IsInvalid)
            {
                throw Throw("Unable to create new mailslot");
            }
            return(ret);
        }
コード例 #20
0
 /// <summary>
 /// Handles intercepted file access.
 /// </summary>
 /// <param name="fileName"></param>
 /// <param name="desiredAccess"></param>
 /// <param name="shareMode"></param>
 /// <param name="securityAttributes"></param>
 /// <param name="creationDisposition"></param>
 /// <param name="flagsAndAttributes"></param>
 /// <param name="templateFile"></param>
 /// <returns></returns>
 public IntPtr CreateFile(string fileName, FileAccessRightFlags desiredAccess, FileShareModeFlags shareMode,
                            IntPtr securityAttributes, FileCreationDisposition creationDisposition,
                            FileFlagsAndAttributes flagsAndAttributes, IntPtr templateFile)
 {
   var request = new FileRequest
   {
     CreationDisposition = creationDisposition,
     Path = fileName,
     ResourceType = ResourceType.File
   };
   using (EngineCore.Engine.GetEngineProcessingSpace())
   {
     var virtualPath = _fileSystem.GetVirtualPath(request);
     return HostFileSystem.NativeMethods.CreateFile(
       virtualPath, desiredAccess, shareMode, securityAttributes,
       creationDisposition, flagsAndAttributes, templateFile);
   }
 }
コード例 #21
0
        /// <summary>
        /// Handles intercepted file access.
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="desiredAccess"></param>
        /// <param name="shareMode"></param>
        /// <param name="securityAttributes"></param>
        /// <param name="creationDisposition"></param>
        /// <param name="flagsAndAttributes"></param>
        /// <param name="templateFile"></param>
        /// <returns></returns>
        public IntPtr CreateFile(string fileName, FileAccessRightFlags desiredAccess, FileShareModeFlags shareMode,
                                 IntPtr securityAttributes, FileCreationDisposition creationDisposition,
                                 FileFlagsAndAttributes flagsAndAttributes, IntPtr templateFile)
        {
            var request = new FileRequest
            {
                CreationDisposition = creationDisposition,
                Path         = fileName,
                ResourceType = ResourceType.File
            };

            using (EngineCore.Engine.GetEngineProcessingSpace())
            {
                var virtualPath = _fileSystem.GetVirtualPath(request);
                return(HostFileSystem.NativeMethods.CreateFile(
                           virtualPath, desiredAccess, shareMode, securityAttributes,
                           creationDisposition, flagsAndAttributes, templateFile));
            }
        }
コード例 #22
0
 public static extern SafeFileHandle CreateFile(string fileName, FileAccess desiredAccess, FileShare shareMode, IntPtr securityAttributes, FileCreationDisposition creationDisposition, FileAttributes flagsAndAttributes, IntPtr templateFile);
コード例 #23
0
 public static extern SafePipeHandle CreateFile(string fileName, FileDesiredAccess desiredAccess, FileShareMode shareMode, SECURITY_ATTRIBUTES securityAttributes, FileCreationDisposition creationDisposition, int flagsAndAttributes, IntPtr hTemplateFile);
コード例 #24
0
ファイル: MailSlotServer.cs プロジェクト: zhouzu/KittyLitter
 public static extern SafeMailslotHandle CreateFile(string fileName,
                                                    FileDesiredAccess desiredAccess, FileShareMode shareMode,
                                                    IntPtr securityAttributes,
                                                    FileCreationDisposition creationDisposition,
                                                    int flagsAndAttributes, IntPtr hTemplateFile);
コード例 #25
0
ファイル: Mailslot.cs プロジェクト: ESECapstone2015/QuadCamPC
 public static extern SafeMailslotHandle CreateFile(string fileName,
     FileDesiredAccess desiredAccess, FileShareMode shareMode,
     IntPtr securityAttributes,
     FileCreationDisposition creationDisposition,
     int flagsAndAttributes, IntPtr hTemplateFile);
コード例 #26
0
ファイル: TetherScriptDevice.cs プロジェクト: dumbie/CtrlUI
        private bool OpenDevice(DriverProductIds driverProduct)
        {
            try
            {
                //Check driver product type
                if (driverProduct == DriverProductIds.TTC_PRODUCTID_KEYBOARD)
                {
                    HardwareTarget = "hid\\ttcvcontrkb";
                }
                else if (driverProduct == DriverProductIds.TTC_PRODUCTID_MOUSEREL)
                {
                    HardwareTarget = "hid\\ttcvcontrmsrel";
                }
                else if (driverProduct == DriverProductIds.TTC_PRODUCTID_MOUSEABS)
                {
                    HardwareTarget = "hid\\ttcvcontrmsabs";
                }

                //Find the virtual device path
                IEnumerable <EnumerateInfo> SelectedHidDevice = EnumerateDevicesDi(GuidClassHidDevice, true);
                foreach (EnumerateInfo EnumDevice in SelectedHidDevice)
                {
                    if (EnumDevice.HardwareId.ToLower() == HardwareTarget)
                    {
                        DevicePath = EnumDevice.DevicePath;
                        break;
                    }
                }

                FileShareMode           shareModeExclusive  = FileShareMode.FILE_SHARE_NONE;
                FileShareMode           shareModeNormal     = FileShareMode.FILE_SHARE_READ | FileShareMode.FILE_SHARE_WRITE;
                FileDesiredAccess       desiredAccess       = FileDesiredAccess.GENERIC_WRITE;
                FileCreationDisposition creationDisposition = FileCreationDisposition.OPEN_EXISTING;
                FileFlagsAndAttributes  flagsAttributes     = FileFlagsAndAttributes.FILE_FLAG_NORMAL | FileFlagsAndAttributes.FILE_FLAG_OVERLAPPED | FileFlagsAndAttributes.FILE_FLAG_NO_BUFFERING;

                //Try to open the device exclusively
                FileHandle = CreateFile(DevicePath, desiredAccess, shareModeExclusive, IntPtr.Zero, creationDisposition, flagsAttributes, IntPtr.Zero);
                Exclusive  = true;

                //Try to open the device normally
                if (FileHandle == null || FileHandle.IsInvalid || FileHandle.IsClosed)
                {
                    //Debug.WriteLine("Failed to open TetherScript device exclusively, opening normally.");
                    FileHandle = CreateFile(DevicePath, desiredAccess, shareModeNormal, IntPtr.Zero, creationDisposition, flagsAttributes, IntPtr.Zero);
                    Exclusive  = false;
                }

                //Check if the device is opened
                if (FileHandle == null || FileHandle.IsInvalid || FileHandle.IsClosed)
                {
                    //Debug.WriteLine("Failed to open TetherScript device: " + DevicePath);
                    Connected = false;
                    Installed = false;
                    return(false);
                }
                else
                {
                    //Debug.WriteLine("Opened TetherScript device: " + DevicePath + ", exclusively: " + Exclusive);
                    Connected = true;
                    Installed = true;
                    return(true);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Failed to open TetherScript device: " + ex.Message);
                Connected = false;
                Installed = false;
                return(false);
            }
        }
コード例 #27
0
 public static extern IntPtr CreateFile(
     String lpFileName,                  // File name
     FileDesiredAccess dwDesiredAccess,  // Access mode
     FileShareMode dwShareMode,          // Share mode
     IntPtr fileSecurityAttributes,      // Security Attributes
     FileCreationDisposition dwCreationDisposition,// How to create
     uint dwFlagsAndAttributes,          // File attributes
     uint hTemplateFile);
コード例 #28
0
 public static extern SafeFileHandle CreateFile(string fileName, FileAccess desiredAccess, FileShare shareMode, IntPtr securityAttributes, FileCreationDisposition creationDisposition, FileAttributes flagsAndAttributes, IntPtr templateFile);
コード例 #29
0
 public static extern SafePipeHandle CreateFile(string fileName,
     FileDesiredAccess desiredAccess, FileShareMode shareMode,
     SECURITY_ATTRIBUTES securityAttributes,
     FileCreationDisposition creationDisposition,
     int flagsAndAttributes, IntPtr hTemplateFile);
コード例 #30
0
ファイル: PlatformInvokes.cs プロジェクト: 40a/PowerShell
 internal static extern IntPtr CreateFile(
     string lpFileName,
     FileDesiredAccess dwDesiredAccess,
     FileShareMode dwShareMode,
     IntPtr lpSecurityAttributes,
     FileCreationDisposition dwCreationDisposition,
     FileAttributes dwFlagsAndAttributes,
     IntPtr hTemplateFile);