static void write(Memory mem, IntPtr addr, IConvertible val) { var size = val.GetType() == typeof(string) ? ((string)val).Length : val.MemSize(); var protection = mem.RemoveProtection(addr, size); mem.Write(addr, (string)val); mem.AddProtection(addr, size, protection); }