2009-07-26 23:22:00 +00:00
|
|
|
|
using System;
|
2010-05-19 23:42:10 +00:00
|
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2009-07-26 23:22:00 +00:00
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using System.Security;
|
|
|
|
|
|
|
|
|
|
namespace Jellyfish.Library
|
|
|
|
|
{
|
|
|
|
|
public static class MarshalHelpers
|
|
|
|
|
{
|
2010-05-19 23:42:10 +00:00
|
|
|
|
[SecurityCritical]
|
2009-07-26 23:22:00 +00:00
|
|
|
|
public static void FillMemory(IntPtr buffer, int bufferSize, byte value)
|
|
|
|
|
{
|
|
|
|
|
NativeMethods.FillMemory(buffer, (IntPtr)bufferSize, value);
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-19 23:42:10 +00:00
|
|
|
|
[SecurityCritical]
|
2009-07-26 23:22:00 +00:00
|
|
|
|
public static void ZeroMemory(IntPtr buffer, int bufferSize)
|
|
|
|
|
{
|
|
|
|
|
NativeMethods.ZeroMemory(buffer, (IntPtr)bufferSize);
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-19 23:42:10 +00:00
|
|
|
|
[SecurityCritical]
|
2009-07-26 23:22:00 +00:00
|
|
|
|
[SuppressUnmanagedCodeSecurity]
|
|
|
|
|
private static class NativeMethods
|
|
|
|
|
{
|
2010-05-19 23:42:10 +00:00
|
|
|
|
[SuppressMessage("Microsoft.Security", "CA2118:ReviewSuppressUnmanagedCodeSecurityUsage")]
|
2009-07-26 23:22:00 +00:00
|
|
|
|
[DllImport("kernel32.dll", SetLastError = true)]
|
|
|
|
|
public static extern void FillMemory(IntPtr destination, IntPtr length, byte fill);
|
|
|
|
|
|
2010-05-19 23:42:10 +00:00
|
|
|
|
[SuppressMessage("Microsoft.Security", "CA2118:ReviewSuppressUnmanagedCodeSecurityUsage")]
|
2009-07-26 23:22:00 +00:00
|
|
|
|
[DllImport("kernel32.dll", SetLastError = true)]
|
|
|
|
|
public static extern void ZeroMemory(IntPtr destination, IntPtr length);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|