static void ViewSection(NtSection section, bool read_only)
 {
     read_only = read_only || !section.IsAccessGranted(SectionAccessRights.MapWrite);
     using (var map = read_only ? section.MapRead() : section.MapReadWrite())
     {
         using (SectionEditorForm frm = new SectionEditorForm(map, GetName(section, map), read_only))
         {
             Application.Run(frm);
         }
     }
 }
Пример #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);
        }