/// <summary> /// Return whether or not the given expression matches the given name. Takes standard /// Windows wildcards (*, ?, <, > "). /// </summary> public unsafe static bool IsNameInExpression(string expression, string name, bool ignoreCase) { if (string.IsNullOrEmpty(expression) || string.IsNullOrEmpty(name)) { return(false); // If ignore case is set, the API will uppercase the name *if* an UpcaseTable // is not provided. It then flips to case-sensitive. In this state the expression // has to be uppercase to match as expected. fixed(char *e = ignoreCase?expression.ToUpperInvariant() : expression) fixed(char *n = name) { SafeString.Unsafe.UNICODE_STRING *eus = null; SafeString.Unsafe.UNICODE_STRING *nus = null; if (e != null) { var temp = new SafeString.Unsafe.UNICODE_STRING(e, expression.Length); eus = &temp; } if (n != null) { var temp = new SafeString.Unsafe.UNICODE_STRING(n, name.Length); nus = &temp; } return(Imports.RtlIsNameInExpression(eus, nus, ignoreCase, IntPtr.Zero)); } }
public unsafe static IntPtr CreateFileRelative( ReadOnlySpan <char> path, IntPtr rootDirectory, CreateDisposition createDisposition, DesiredAccess desiredAccess = DesiredAccess.GenericReadWrite | DesiredAccess.Synchronize, ShareModes shareAccess = ShareModes.ReadWrite, FileAttributes fileAttributes = FileAttributes.None, CreateOptions createOptions = CreateOptions.SynchronousIoNonalert, ObjectAttributes objectAttributes = ObjectAttributes.CaseInsensitive) { fixed(char *c = &MemoryMarshal.GetReference(path)) { var name = new SafeString.Unsafe.UNICODE_STRING(c, path.Length); var attributes = new Handles.Unsafe.OBJECT_ATTRIBUTES( &name, objectAttributes, rootDirectory, null, null); Imports.NtCreateFile( out IntPtr handle, desiredAccess, ref attributes, out IO_STATUS_BLOCK statusBlock, AllocationSize: null, FileAttributes: fileAttributes, ShareAccess: shareAccess, CreateDisposition: createDisposition, CreateOptions: createOptions, EaBuffer: null, EaLength: 0) .ThrowIfFailed(path.ToString()); return(handle); } }