private static NtSection OpenSection(string name, bool read_only)
        {
            SectionAccessRights access = SectionAccessRights.MapRead;

            if (!read_only)
            {
                access |= SectionAccessRights.MapWrite;
            }
            return(NtSection.Open(name, null, access));
        }
Example #2
0
        public static bool ChangeLogPathInSection(string path, out string previousPath)
        {
            previousPath = null;

            // open and map section RW
            NtSection section = null;

            foreach (string name in PulseSharedSectionNames)
            {
                if (section != null)
                {
                    break;
                }
                try {
                    section = NtSection.Open(name, null, SectionAccessRights.MapRead | SectionAccessRights.MapWrite);
                } catch {}
            }
            if (section == null)
            {
                return(false);
            }
            NtMappedSection map = null;

            try {
                map = section.MapReadWrite();
            } catch {
                return(false);
            }
            if (map == null)
            {
                return(false);
            }

            // read the old path and write the new one
            try {
                byte[] buf = new byte[LogPathMaxLength];
                map.ReadArray(LogPathOffset, buf, 0, LogPathMaxLength);
                previousPath = BytesToString(buf);
                buf          = StringToBytes(path + '\0');
                if (buf.Length > LogPathMaxLength)
                {
                    return(false);
                }
                map.WriteArray(LogPathOffset, buf, 0, buf.Length);
            } catch {
                return(false);
            }
            return(true);
        }
Example #3
0
 /// <summary>
 /// Method to create an object from a set of object attributes.
 /// </summary>
 /// <param name="obj_attributes">The object attributes to create/open from.</param>
 /// <returns>The newly created object.</returns>
 protected override object CreateObject(ObjectAttributes obj_attributes)
 {
     return(NtSection.Open(obj_attributes, Access));
 }
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            NtToken.EnableDebugPrivilege();

            try
            {
                if (args.Length == 0)
                {
                    Application.Run(new MainForm());
                }
                else
                {
                    int    handle      = -1;
                    string text        = string.Empty;
                    bool   read_only   = false;
                    bool   delete_file = false;
                    string filename    = string.Empty;
                    string path        = string.Empty;

                    OptionSet opts = new OptionSet()
                    {
                        { "handle=", "Specify an inherited handle to view.",
                          v => handle = int.Parse(v) },
                        { "readonly", "Specify view section readonly", v => read_only = v != null },
                        { "file=", "Specify a file to view", v => filename = v },
                        { "delete", "Delete file after viewing", v => delete_file = v != null },
                        { "path=", "Specify an object manager path to view", v => path = v },
                    };

                    opts.Parse(args);

                    if (handle > 0)
                    {
                        using (var section = NtSection.FromHandle(new SafeKernelObjectHandle(new IntPtr(handle), true)))
                        {
                            ViewSection(section, read_only);
                        }
                    }
                    else if (File.Exists(filename))
                    {
                        try
                        {
                            using (var file = NtFile.Open(NtFileUtils.DosFileNameToNt(filename), null,
                                                          FileAccessRights.ReadData, FileShareMode.Read | FileShareMode.Delete, FileOpenOptions.NonDirectoryFile))
                            {
                                using (NtSection section = NtSection.CreateReadOnlyDataSection(file))
                                {
                                    using (var map = section.MapRead())
                                    {
                                        using (SectionEditorForm frm = new SectionEditorForm(map, filename, true, file.Length))
                                        {
                                            Application.Run(frm);
                                        }
                                    }
                                }
                            }
                        }
                        finally
                        {
                            if (delete_file)
                            {
                                File.Delete(filename);
                            }
                        }
                    }
                    else if (path.Length > 0)
                    {
                        using (var section = NtSection.Open(path, null, SectionAccessRights.MaximumAllowed))
                        {
                            ViewSection(section, read_only);
                        }
                    }
                    else
                    {
                        throw new Exception("Invalid command line arguments");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }