public unsafe void SetValue(string name, object value)
{
if (value == null)
{
throw new ArgumentNullException("value");
}
if ((name != null) && (name.Length >= 0xff))
{
throw new ArgumentException(Environment.GetResourceString("Arg_RegKeyStrLenBug"));
}
this.ValidateState(true);
if (!this.remoteKey)
{
int num1 = 0;
int num2 = 0;
int num3 = Win32Native.RegQueryValueEx(this.hkey, name, (int[]) null, ref num1, (byte[]) null, ref num2);
if (num3 == 0)
{
new RegistryPermission(RegistryPermissionAccess.Write, this.keyName + @"\" + name).Demand();
}
else
{
new RegistryPermission(RegistryPermissionAccess.Create, this.keyName + @"\" + name).Demand();
}
}
else
{
new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand();
}
int num4 = 0;
if (value is int)
{
int num5 = (int) value;
int[] numArray1 = new int[1] { num5 } ;
num4 = Win32Native.RegSetValueEx(this.hkey, name, 0, 4, numArray1, 4);
}
else if (value is Array)
{
byte[] buffer1 = null;
string[] textArray1 = null;
if (value is byte[])
{
buffer1 = (byte[]) value;
}
else
{
if (!(value is string[]))
{
throw new ArgumentException(string.Format(Environment.GetResourceString("Arg_RegSetBadArrType"), value.GetType().Name));
}
textArray1 = (string[]) value;
}
if (buffer1 != null)
{
num4 = Win32Native.RegSetValueEx(this.hkey, name, 0, 3, buffer1, buffer1.Length);
}
else if (textArray1 != null)
{
bool flag1 = RegistryKey._SystemDefaultCharSize != 1;
IntPtr ptr1 = new IntPtr(0);
int num6 = 0;
if (flag1)
{
for (int num7 = 0; num7 < textArray1.Length; num7++)
{
if (textArray1[num7] == null)
{
throw new ArgumentException(Environment.GetResourceString("Arg_RegSetStrArrNull"));
}
num6 += ((textArray1[num7].Length + 1) * 2);
}
num6 += 2;
}
else
{
for (int num8 = 0; num8 < textArray1.Length; num8++)
{
if (textArray1[num8] == null)
{
throw new ArgumentException(Environment.GetResourceString("Arg_RegSetStrArrNull"));
}
num6 += (Encoding.Default.GetByteCount(textArray1[num8]) + 1);
}
num6++;
}
IntPtr ptr2 = Win32Native.LocalAlloc(0x40, new IntPtr(num6));
if (ptr2 == Win32Native.NULL)
{
return;
}
ptr1 = ptr2;
for (int num9 = 0; num9 < textArray1.Length; num9++)
{
if (flag1)
{
string.InternalCopy(textArray1[num9], ptr1, (int) (textArray1[num9].Length * 2));
ptr1 = new IntPtr(((long) ptr1) + (textArray1[num9].Length * 2));
*(((short*) ptr1.ToPointer())) = 0;
ptr1 = new IntPtr(((long) ptr1) + 2);
}
else
{
byte[] buffer2 = Encoding.Default.GetBytes(textArray1[num9]);
__UnmanagedMemoryStream.memcpy(buffer2, 0, (byte*) ptr1.ToPointer(), 0, buffer2.Length);
ptr1 = new IntPtr(((long) ptr1) + buffer2.Length);
*(((sbyte*) ptr1.ToPointer())) = 0;
ptr1 = new IntPtr(((long) ptr1) + 1);
}
}
if (flag1)
{
*(((short*) ptr1.ToPointer())) = 0;
ptr1 = new IntPtr(((long) ptr1) + 2);
}
else
{
*(((sbyte*) ptr1.ToPointer())) = 0;
ptr1 = new IntPtr(((long) ptr1) + 1);
}
num4 = Win32Native.RegSetValueEx(this.hkey, name, 0, 7, ptr2, num6);
Win32Native.LocalFree(ptr2);
}
}
else
{
string text1 = value.ToString();
if (RegistryKey._SystemDefaultCharSize == 1)
{
byte[] buffer3 = Encoding.Default.GetBytes(text1);
byte[] buffer4 = new byte[buffer3.Length + 1];
Array.Copy(buffer3, 0, buffer4, 0, buffer3.Length);
num4 = Win32Native.RegSetValueEx(this.hkey, name, 0, 1, buffer4, buffer3.Length);
}
else
{
num4 = Win32Native.RegSetValueEx(this.hkey, name, 0, 1, text1, (int) (text1.Length * 2));
}
}
if (num4 == 0)
{
this.SetDirty(true);
}
else
{
RegistryKey.Win32Error(num4, null);
}
}
[课程]FART 脱壳王!加量不加价!FART作者讲授!