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); }
public byte[] ReadBytes(long index, int length) { byte[] ret = new byte[length]; _map.ReadArray((ulong)index, ret, 0, length); return(ret); }