private static extern IntPtr CreateFile( [MarshalAs(UnmanagedType.LPTStr)] string lpFileName, [MarshalAs(UnmanagedType.U4)] EFileAccess dwDesiredAccess, [MarshalAs(UnmanagedType.U4)] EFileShare dwShareMode, [MarshalAs(UnmanagedType.SysInt)] IntPtr lpSecurityAttributes, [MarshalAs(UnmanagedType.U4)] ECreationDisposition dwCreationDisposition, [MarshalAs(UnmanagedType.U4)] EFileAttributes dwFlagsAndAttributes, [MarshalAs(UnmanagedType.U4)] uint hTemplateFile);
internal static extern SafeFileHandle CreateFile( string lpFileName, EFileAccess dwDesiredAccess, EFileShare dwShareMode, ref SECURITY_ATTRIBUTES lpSecurityAttributes, ECreationDisposition dwCreationDisposition, EFileAttributes dwFlagsAndAttributes, IntPtr hTemplateFile);
public static extern IntPtr CreateFileW( [MarshalAs(UnmanagedType.LPWStr)] string filename, [MarshalAs(UnmanagedType.U4)] EFileAccess access, [MarshalAs(UnmanagedType.U4)] EFileShare share, IntPtr securityAttributes, [MarshalAs(UnmanagedType.U4)] ECreationDisposition creationDisposition, [MarshalAs(UnmanagedType.U4)] EFileAttributes flagsAndAttributes, IntPtr templateFile);
private static extern IntPtr CreateFile( string fileName, EFileAccess fileAccess, EFileShare fileShare, IntPtr securityAttributes, ECreationDisposition creationDisposition, EFileAttributes flags, IntPtr template);
public static extern SafeFileHandle CreateFile( string lpFileName, EFileAccess dwDesiredAccess, EFileShare dwShareMode, IntPtr lpSecurityAttributes, ECreationDisposition dwCreationDisposition, EFileAttributes dwFlagsAndAttributes, SafeFileHandle hTemplateFile);
internal static extern SafeFileHandle CreateFile( string fileName, [MarshalAs(UnmanagedType.U4)] EFileAccess fileAccess, [MarshalAs(UnmanagedType.U4)] EFileShare shareMode, IntPtr securityAttributes, [MarshalAs(UnmanagedType.U4)] ECreationDisposition creationDisposition, EFileAttributes flagsAndAttributes, SafeFileHandle templateFile);
public static extern SafeFileHandle CreateFile( [MarshalAs(UnmanagedType.LPTStr)] string lpFileName, [MarshalAs(UnmanagedType.U4)] EFileAccess dwDesiredAccess, [MarshalAs(UnmanagedType.U4)] EFileShare dwShareMode, IntPtr lpSecurityAttributes, // optional SECURITY_ATTRIBUTES struct or IntPtr.Zero [MarshalAs(UnmanagedType.U4)] ECreationDisposition dwCreationDisposition, [MarshalAs(UnmanagedType.U4)] EFileAttributes dwFlagsAndAttributes, IntPtr hTemplateFile);
private static extern IntPtr CreateFile( string lpFileName, EFileAccess dwDesiredAccess, EFileShare dwShareMode, IntPtr lpSecurityAttributes, ECreationDisposition dwCreationDisposition, EFileAttributes dwFlagsAndAttributes, IntPtr hTemplateFile);
public static extern IntPtr CreateFile( [MarshalAs(UnmanagedType.LPTStr)] string filename, [MarshalAs(UnmanagedType.U4)] EFileAccess access, [MarshalAs(UnmanagedType.U4)] EFileShare share, IntPtr securityAttributes, // optional SECURITY_ATTRIBUTES struct or IntPtr.Zero [MarshalAs(UnmanagedType.U4)] ECreationDisposition creationDisposition, [MarshalAs(UnmanagedType.U4)] EFileAttributes flagsAndAttributes, IntPtr templateFile);
public static extern SafeFileHandle CreateFile( string lpFileName, EFileAccess dwDesiredAccess, EFileShare dwShareMode, IntPtr SecurityAttributes, ECreationDisposition dwCreationDisposition, EFileAttributes dwFlagsAndAttributes, IntPtr hTemplateFile );
// // These are wrappers that translate error codes // into exceptions to make error handling easier // private static IntPtr CreateFileNet( string lpFileName, EFileAccess dwDesiredAccess, EFileShare dwShareMode, IntPtr lpSecurityAttributes, ECreationDisposition dwCreationDisposition, EFileAttributes dwFlagsAndAttributes, IntPtr hTemplateFile) { IntPtr ret = CreateFile(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile); //If == INVALID_HANDLE_VALUE if (ret.ToInt32() == -1) { Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); } return(ret); }
public static IntPtr _CreateFile( string lpFileName, EFileAccess dwDesiredAccess, EFileShare dwShareMode, ECreationDisposition dwCreationDisposition, EFileAttributes dwFlagsAndAttributes, IntPtr hTemplateFile ) { SECURITY_DESCRIPTOR sd = new SECURITY_DESCRIPTOR(); InitializeSecurityDescriptor(ref sd, SECURITY_DESCRIPTOR_REVISION); SetSecurityDescriptorDacl(ref sd, true, IntPtr.Zero, false); GCHandle sdHandle = GCHandle.Alloc(sd, GCHandleType.Pinned); SECURITY_ATTRIBUTES sa = new SECURITY_ATTRIBUTES(); sa.nLength = Marshal.SizeOf(sa); sa.lpSecurityDescriptor = sdHandle.AddrOfPinnedObject(); sa.bInheritHandle = 0; GCHandle saHandle = GCHandle.Alloc(sa, GCHandleType.Pinned); System.IntPtr hFile = IntPtr.Zero; hFile = CreateFile( lpFileName, dwDesiredAccess, dwShareMode, saHandle.AddrOfPinnedObject(), dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile ); saHandle.Free(); sdHandle.Free(); if (hFile == (System.IntPtr)(int) - 1) { return(IntPtr.Zero); } return(hFile); }
private static extern IntPtr CreateFile(string fileName, EFileAccess desiredAccess, EFileShare shareMode, IntPtr securityAttributes, ECreationDisposition creationDisposition, EFileAttributes flagsAndAttributes, IntPtr templateFile);
private void *CreateFileHook(string FileName, EFileAccess Access, EFileShare Share, void *SecurityAttributes, ECreationDisposition CreationDisposition, EFileAttributes FlagsAndAttributes, void *TemplateFile) { FileName = OnCreateFile?.Invoke(FileName); return(Bypass(FileName, Access, Share, SecurityAttributes, CreationDisposition, FlagsAndAttributes, TemplateFile)); }
/// <summary></summary> public static SafeFileHandle CreateFile(string file_name, EFileAccess dwDesiredAccess, EFileShare dwShareMode, IntPtr SecurityAttributes, EFileCreation dwCreationDisposition, EFileFlag dwFlagsAndAttributes, IntPtr hTemplateFile) { return(CreateFile_(file_name, (uint)dwDesiredAccess, (uint)dwShareMode, SecurityAttributes, (uint)dwCreationDisposition, (uint)dwFlagsAndAttributes, hTemplateFile)); }
public static IntPtr _CreateFile( string lpFileName, EFileAccess dwDesiredAccess, EFileShare dwShareMode, ECreationDisposition dwCreationDisposition, EFileAttributes dwFlagsAndAttributes, IntPtr hTemplateFile ) { SECURITY_DESCRIPTOR sd = new SECURITY_DESCRIPTOR(); InitializeSecurityDescriptor(ref sd, SECURITY_DESCRIPTOR_REVISION); SetSecurityDescriptorDacl(ref sd, true, IntPtr.Zero, false); GCHandle sdHandle = GCHandle.Alloc(sd, GCHandleType.Pinned); SECURITY_ATTRIBUTES sa = new SECURITY_ATTRIBUTES(); sa.nLength = Marshal.SizeOf(sa); sa.lpSecurityDescriptor = sdHandle.AddrOfPinnedObject(); sa.bInheritHandle = 0; GCHandle saHandle = GCHandle.Alloc(sa, GCHandleType.Pinned); System.IntPtr hFile = IntPtr.Zero; hFile = CreateFile( lpFileName, dwDesiredAccess, dwShareMode, saHandle.AddrOfPinnedObject(), dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile ); saHandle.Free(); sdHandle.Free(); if (hFile == (System.IntPtr)(int)-1) { return IntPtr.Zero; } return hFile; }
public static extern IntPtr BoxedAppSDK_CreateVirtualFileBasedOnIStream(string lpFileName, EFileAccess dwDesiredAccess, EFileShare dwShareMode, IntPtr lpSecurityAttributes, ECreationDisposition dwCreationDisposition, EFileAttributes dwFlagsAndAttributes, IntPtr hTemplateFile, IStream Stream);
internal static extern IntPtr CreateFile([In] String fileName, [In] eFileAccess fileAccess, [In] EFileShare fileShare, [In, Optional] IntPtr fileSecurity, [In] eCreationDisposition creationDisposition, [In] UInt32 flags, [In, Optional] IntPtr handleTemplateFile);
public static IntPtr CreateFileFromDevice(string filename, EFileAccess desiredAccess, EFileShare shareMode) { return CreateFile(filename, desiredAccess, shareMode, IntPtr.Zero, ECreationDisposition.OpenExisting, EFileAttributes.Device | EFileAttributes.Overlapped, IntPtr.Zero); }
public static extern IntPtr CreateFile(string filename, EFileAccess desiredAccess, EFileShare shareMode, IntPtr securityAttributes, ECreationDisposition creationDisposition, EFileAttributes attributes, IntPtr template);
/// <summary></summary> public static SafeFileHandle ReOpenFile(SafeFileHandle hOriginalFile, EFileAccess dwDesiredAccess, EFileShare dwShareMode, EFileFlag dwFlagsAndAttributes) { return(ReOpenFile_(hOriginalFile, (uint)dwDesiredAccess, (uint)dwShareMode, (uint)dwFlagsAndAttributes)); }
/// <summary> /// Opens a System.IO.FileStream on the specified path with read/write access. /// </summary> /// <param name="myPath">The file to open.</param> /// <param name="myFileMode">A System.IO.FileMode value that specifies whether a file is created if one /// does not exist, and determines whether the contents of existing files are /// retained or overwritten.</param> /// <param name="myFileAccess">A System.IO.FileAccess value that specifies the operations that can be performed /// on the file.</param> /// <param name="myFileAttributes">The desired System.IO.FileAttributes, such as Hidden, ReadOnly, Normal, and /// Archive.</param> /// <param name="myFileShare">A System.IO.FileShare value specifying the type of access other threads have /// to the file.</param> /// <returns>A System.IO.FileStream opened in the specified mode and path, with read/write /// access and not shared. /// </returns> public static FileStream Open(String myPath, FileMode myFileMode, FileAccess myFileAccess, EFileAttributes myFileAttributes = EFileAttributes.Normal, EFileShare myFileShare = EFileShare.None, Boolean myCreatePathIfNotExists = false) { #if(__MonoCS__) #region CreatePathIfNotExists if (myCreatePathIfNotExists && (myFileMode == FileMode.Create || myFileMode == FileMode.CreateNew || myFileMode == FileMode.OpenOrCreate)) { DirectoryHandler.CreatePathIfNotExists(myPath); } #endregion return File.Open(myPath, myFileMode, myFileAccess, (FileShare)myFileShare); #else myPath = PathHandler.GetFullPathInternal(myPath); // change path to unicode path #region CreatePathIfNotExists if (myCreatePathIfNotExists && (myFileMode == FileMode.Create || myFileMode == FileMode.CreateNew || myFileMode == FileMode.OpenOrCreate)) { DirectoryHandler.CreatePathIfNotExists(myPath); } #endregion #region ECreationDisposition ECreationDisposition creationDisposition = (myFileMode == FileMode.Append) ? ECreationDisposition.OpenAlways : (ECreationDisposition)(int)myFileMode; #endregion #region EFileAccess EFileAccess fileAccess = EFileAccess.GenericAll; switch (myFileAccess) { case FileAccess.Read: fileAccess = EFileAccess.GenericRead; break; case FileAccess.ReadWrite: fileAccess = EFileAccess.GenericAll; break; case FileAccess.Write: fileAccess = EFileAccess.GenericWrite; break; default: fileAccess = EFileAccess.GenericAll; break; } #endregion #region Create the file using the WinAPI32 and check for errors var fileHandle = NativeWin32Methods.CreateFileW(myPath, fileAccess, myFileShare, null, creationDisposition, myFileAttributes, IntPtr.Zero); // Check for errors if (fileHandle.IsInvalid) { int lastWin32Error = Marshal.GetLastWin32Error(); throw new System.ComponentModel.Win32Exception(lastWin32Error); } #endregion #region Create FileStream and seek to end if FileMode.Append var stream = new FileStream(fileHandle, myFileAccess, 0x1000, false); if (myFileMode == FileMode.Append) { stream.Seek(0, SeekOrigin.End); } #endregion return stream; #endif }
public static IntPtr CreateFileFromDevice(string filename, EFileAccess desiredAccess, EFileShare shareMode) { return(CreateFile(filename, desiredAccess, shareMode, IntPtr.Zero, ECreationDisposition.OpenExisting, EFileAttributes.Device | EFileAttributes.Overlapped, IntPtr.Zero)); }
internal static extern SafeFileHandle CreateFileW( string lpFileName, EFileAccess dwDesiredAccess, EFileShare dwShareMode, SECURITY_ATTRIBUTES lpSecurityAttributes, ECreationDisposition dwCreationDisposition, EFileAttributes dwFlagsAndAttributes, IntPtr hTemplateFile);