本文整理汇总了C#中MemoryProtection类的典型用法代码示例。如果您正苦于以下问题:C# MemoryProtection类的具体用法?C# MemoryProtection怎么用?C# MemoryProtection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MemoryProtection类属于命名空间,在下文中一共展示了MemoryProtection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VirtualMemorySetProtection
public static void VirtualMemorySetProtection(void* pointer, IntPtr size, MemoryProtection protection)
{
int old;
switch (protection)
{
case MemoryProtection.Execute:
Kernel32.VirtualProtect(pointer, size, Kernel32.VirtualMemProtectionFlag.PageExecute, out old);
break;
case MemoryProtection.ReadWrite:
Kernel32.VirtualProtect(pointer, size, Kernel32.VirtualMemProtectionFlag.PageReadWrite, out old);
break;
}
}
示例2: Map
public PhysicalPagesMapping Map(IntPtr address, MemoryProtection protection)
{
IntPtr allocAddress = ProcessHandle.Current.AllocateMemory(
address,
_count * Windows.PageSize,
MemoryFlags.Reserve | MemoryFlags.Physical,
protection
);
if (!Win32.MapUserPhysicalPages(
allocAddress,
new IntPtr(_count),
_pfnArray
))
Win32.ThrowLastError();
return new PhysicalPagesMapping(this, allocAddress);
}
示例3: MemoryMappedFileStream
public MemoryMappedFileStream(string name, uint maxLength, MemoryProtection protection)
{
if(string.IsNullOrEmpty(name))
{
throw(new ArgumentException("Argument_Name"));
}
if(maxLength < 0)
{
throw(new ArgumentOutOfRangeException("ArgumentOutOfRange_MaxLength"));
}
objectName = name;
if (protection < MemoryProtection.PageNoAccess ||
protection > MemoryProtection.SecReserve)
{
throw new ArgumentOutOfRangeException("ArgumentOutOfRange_Enum");
}
if( maxLength == 0 )
{
mapLength = 5120;
}
else
{
mapLength = maxLength;
}
memProtection = protection;
isReadable = true;
isWritable = true;
isSeekable = true;
// Initialize mapViewPointer
mapViewPointer = new IntPtr(-1);
SECURITY_ATTRIBUTES sa = SECURITY_ATTRIBUTES.GetNullDacl();
try
{
mapHandle = MemoryMappedFileHelper.CreateFileMapping(
IntPtr.Zero,
sa,
memProtection,
0,
mapLength,
objectName);
}
finally
{
Marshal.FreeHGlobal(sa.lpSecurityDescriptor);
sa.lpSecurityDescriptor = IntPtr.Zero;
}
if(mapHandle == IntPtr.Zero )
{
uint lastError = MemoryMappedFileHelper.GetLastError();
throw new IOException(
MemoryMappedFileHelper.GetWin32ErrorMessage( lastError ) );
}
}
示例4: VirtualAllocEx
internal static extern IntPtr VirtualAllocEx(SafeProcessHandle processHandle, IntPtr address, SizeT size, AllocationType flAllocationType,
MemoryProtection flProtect);
示例5: VirtualAllocEx
static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, IntPtr dwSize, AllocationType flAllocationType, MemoryProtection flProtect);
示例6: GetWin32FileMapAccess
public static Win32FileMapAccess GetWin32FileMapAccess(
MemoryProtection protection )
{
switch ( protection )
{
case MemoryProtection.PageReadOnly:
return Win32FileMapAccess.FILE_MAP_READ;
case MemoryProtection.PageWriteCopy:
return Win32FileMapAccess.FILE_MAP_WRITE;
default:
return Win32FileMapAccess.FILE_MAP_ALL_ACCESS;
}
}
示例7: VirtualProtectEx
internal static extern bool VirtualProtectEx(IntPtr hProcess, IntPtr lpAddress, IntPtr dwSize, MemoryProtection flNewProtect, ref MemoryProtection lpflOldProtect);
示例8: Map
public PhysicalPagesMapping Map(MemoryProtection protection)
{
return this.Map(IntPtr.Zero, protection);
}
示例9: VirtualProtectEx
public static extern bool VirtualProtectEx(
IntPtr hProcess,
IntPtr lpAddress,
uint dwSize,
MemoryProtection flNewProtect,
[Out] MemoryProtection lpflOldProtect);
示例10: VirtualMemorySetProtection
public static void VirtualMemorySetProtection(void* pointer, IntPtr size, MemoryProtection protection)
{
NativeUtilsImplementation.VirtualMemorySetProtection(pointer, size, protection);
}
示例11: VirtualProtect
public static extern bool VirtualProtect(IntPtr address, uint size, MemoryProtection newProtect, out MemoryProtection oldProtect);
示例12: VirtualAllocEx
public static extern int VirtualAllocEx(IntPtr hProcess, Int32 lpAddress,
Int32 dwSize, AllocationType flAllocationType, MemoryProtection flProtect);
示例13: VirtualProtectEx
public static extern bool VirtualProtectEx(IntPtr hProcess, IntPtr lpAddress, int nSize, MemoryProtection flNewProtect, out MemoryProtection lpflOldProtect);
示例14: VirtualAlloc
/// <summary>
/// Reserves, commits, or changes the state of a region of pages in the virtual address space of the calling process.
/// Memory allocated by this function is automatically initialized to zero.
/// </summary>
/// <param name="sizeInBytes">The size of the region, in bytes</param>
/// <param name="allocationType">The type of memory allocation.</param>
/// <param name="protection">The memory protection for the region of pages to be allocated.</param>
/// <returns>The base address of the allocated region of pages.</returns>
public static void* VirtualAlloc(ulong sizeInBytes, MemoryAllocationType allocationType, MemoryProtection protection)
{
var pointer = VirtualAlloc(IntPtr.Zero, new UIntPtr(sizeInBytes), allocationType, protection).ToPointer();
if (pointer == null)
throw new InvalidOperationException(Marshal.GetLastWin32Error().ToString());
return pointer;
}
示例15: VirtualAllocEx
public static extern DWORD_PTR VirtualAllocEx( IntPtr hProcess, DWORD_PTR lpAddress, uint dwSize, AllocationType flAllocationType, MemoryProtection flProtect );