Пример #1
0
 private NtResult <string> GetUserName(bool throw_on_error)
 {
     using (UnicodeStringAllocated str = new UnicodeStringAllocated(2048))
     {
         int length = NtSystemCalls.NtUserGetAtomName(Atom, str);
         if (length == 0)
         {
             return(NtStatus.STATUS_OBJECT_NAME_NOT_FOUND.CreateResultFromError <string>(throw_on_error));
         }
         str.String.Length = (ushort)(length * 2);
         return(str.ToString().CreateResult());
     }
 }
Пример #2
0
        private NtResult <string> GetClassName(bool real_name, bool throw_on_error)
        {
            using (var str = new UnicodeStringAllocated()) {
                int length = NtSystemCalls.NtUserGetClassName(Handle, real_name, str);
                if (length == 0)
                {
                    return(NtObjectUtils.CreateResultFromDosError <string>(throw_on_error));
                }

                str.String.Length = (ushort)(length * 2);

                return(str.ToString().CreateResult());
            }
        }
Пример #3
0
 /// <summary>
 /// Get the symbolic link target path.
 /// </summary>
 /// <param name="throw_on_error">True to throw on error.</param>
 /// <returns>The target path.</returns>
 public NtResult <string> GetTarget(bool throw_on_error)
 {
     using (UnicodeStringAllocated ustr = new UnicodeStringAllocated())
     {
         return(NtSystemCalls.NtQuerySymbolicLinkObject(Handle, ustr,
                                                        out int return_length).CreateResult(throw_on_error, () => ustr.ToString()));
     }
 }
Пример #4
0
        /// <summary>
        /// Generate a DOS filename from a full filename.
        /// </summary>
        /// <param name="filename">The full filename.</param>
        /// <param name="allow_extended">True to allow extended characters.</param>
        /// <param name="iterations">Number of iterations of the algorithm to test.</param>
        /// <param name="throw_on_error">True throw on error.</param>
        /// <returns>The DOS filename.</returns>
        public static NtResult <string> Generate8dot3Name(string filename, bool allow_extended, int iterations, bool throw_on_error)
        {
            if (iterations <= 0)
            {
                throw new ArgumentException("Invalid iteration count.");
            }

            GenerateNameContext context = new GenerateNameContext()
            {
                NameBuffer      = new byte[16],
                ExtensionBuffer = new byte[8]
            };

            if (IsLegal8dot3Name(filename))
            {
                return(filename.ToUpper().CreateResult());
            }

            NtResult <string> result = default;

            for (int i = 0; i < iterations; ++i)
            {
                using (var name = new UnicodeStringAllocated(24)) {
                    result = NtRtl.RtlGenerate8dot3Name(new UnicodeString(filename),
                                                        allow_extended, ref context, name).CreateResult(throw_on_error, () => name.ToString());
                }
            }
            return(result);
        }