Example #1
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 #2
0
 public void WriteBytes(long index, byte[] value)
 {
     if (index < _map.Length)
     {
         try
         {
             long count = Math.Min(_map.Length - index, value.Length);
             _map.WriteArray((ulong)index, value, 0, (int)count);
             ByteWritten?.Invoke(this, new EventArgs());
         }
         catch
         {
         }
     }
 }