public static extern IntPtr CreateFile(string lpFileName, uint dwDesiredAccess, FileShareMode dwShareMode, ref SecurityAttributes lpSecurityAttributes, FileCreationDisposition dwCreationDisposition, uint dwFlagsAndAttributes, IntPtr hTemplateFile);
public static extern IntPtr CreateFile( string fileName, FileAccessRightFlags desiredAccess, FileShareModeFlags shareMode, IntPtr securityAttributes, FileCreationDisposition creationDisposition, FileFlagsAndAttributes flagsAndAttributes, IntPtr templateFile);
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);
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);
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);
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
public static extern /*SafeFileHandle*/ IntPtr CreateFile( string lpFileName, FileAccess dwDesiredAccess, FileShareMode dwShareMode, IntPtr lpSecurityAttributes, FileCreationDisposition dwCreationDisposition, FileFlagsAndAttributes dwFlagsAndAttributes, IntPtr hTemplateFile);
internal static extern IntPtr CreateFile( string fileName, FileDesiredAccess desiredAccess, FileShareMode shareMode, IntPtr securityAttributes, FileCreationDisposition creationDisposition, FileAttributes flagsAndAttributes, IntPtr templateFile);
internal static extern IntPtr CreateFile( string lpFileName, FileDesiredAccess dwDesiredAccess, FileShareMode dwShareMode, IntPtr lpSecurityAttributes, FileCreationDisposition dwCreationDisposition, FileAttributes dwFlagsAndAttributes, IntPtr hTemplateFile);
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 );
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 );
public static extern SafeFileHandle CreateFile( string lpFileName, FileDesiredAccess dwDesiredAccess, FileShareFlags dwShareMode, IntPtr lpSecurityAttributes, FileCreationDisposition dwCreationDisposition, FileFlagsAndAttributes dwFlagsAndAttributes, IntPtr hTemplateFile );
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 );
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)); }
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); }
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)); }
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); } }
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); }
/// <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); } }
/// <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)); } }
public static extern SafeFileHandle CreateFile(string fileName, FileAccess desiredAccess, FileShare shareMode, IntPtr securityAttributes, FileCreationDisposition creationDisposition, FileAttributes flagsAndAttributes, IntPtr templateFile);
public static extern SafePipeHandle CreateFile(string fileName, FileDesiredAccess desiredAccess, FileShareMode shareMode, SECURITY_ATTRIBUTES securityAttributes, FileCreationDisposition creationDisposition, int flagsAndAttributes, IntPtr hTemplateFile);
public static extern SafeMailslotHandle CreateFile(string fileName, FileDesiredAccess desiredAccess, FileShareMode shareMode, IntPtr securityAttributes, FileCreationDisposition creationDisposition, int flagsAndAttributes, IntPtr hTemplateFile);
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); } }
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);