• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# MemoryProtection类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中MemoryProtection的典型用法代码示例。如果您正苦于以下问题:C# MemoryProtection类的具体用法?C# MemoryProtection怎么用?C# MemoryProtection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MemoryProtection类属于命名空间,在下文中一共展示了MemoryProtection类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
     }
 }
开发者ID:jethazel,项目名称:jet-compiler,代码行数:13,代码来源:WindowsNativeUtils.cs


示例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);
 }
开发者ID:RoDaniel,项目名称:featurehouse,代码行数:16,代码来源:PhysicalPages.cs


示例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 ) );
            }
        }
开发者ID:dbose,项目名称:QuickIPC,代码行数:62,代码来源:MemoryMappedFileStream.cs


示例4: VirtualAllocEx

 internal static extern IntPtr VirtualAllocEx(SafeProcessHandle processHandle, IntPtr address, SizeT size, AllocationType flAllocationType,
     MemoryProtection flProtect);
开发者ID:ericschultz,项目名称:coapp,代码行数:2,代码来源:Kernel32.cs


示例5: VirtualAllocEx

 static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, IntPtr dwSize, AllocationType flAllocationType, MemoryProtection flProtect);
开发者ID:azsry,项目名称:T6UnitedConsole,代码行数:1,代码来源:Form1.cs


示例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;
            }
        }
开发者ID:dbose,项目名称:QuickIPC,代码行数:13,代码来源:MemoryMappedFileHelper.cs


示例7: VirtualProtectEx

 internal static extern bool VirtualProtectEx(IntPtr hProcess, IntPtr lpAddress, IntPtr dwSize, MemoryProtection flNewProtect, ref MemoryProtection lpflOldProtect);
开发者ID:PimentelM,项目名称:extibiabot,代码行数:1,代码来源:NativeMethods.cs


示例8: Map

 public PhysicalPagesMapping Map(MemoryProtection protection)
 {
     return this.Map(IntPtr.Zero, protection);
 }
开发者ID:john-peterson,项目名称:processhacker,代码行数:4,代码来源:PhysicalPages.cs


示例9: VirtualProtectEx

		public static extern bool VirtualProtectEx(
			IntPtr hProcess,
			IntPtr lpAddress,
			uint dwSize,
			MemoryProtection flNewProtect,
			[Out] MemoryProtection lpflOldProtect);
开发者ID:DinrusGroup,项目名称:monodevelop-win32-debugger,代码行数:6,代码来源:Imports.cs


示例10: VirtualMemorySetProtection

 public static void VirtualMemorySetProtection(void* pointer, IntPtr size, MemoryProtection protection)
 {
     NativeUtilsImplementation.VirtualMemorySetProtection(pointer, size, protection);
 }
开发者ID:jethazel,项目名称:jet-compiler,代码行数:4,代码来源:NativeUtils.cs


示例11: VirtualProtect

 public static extern bool VirtualProtect(IntPtr address, uint size, MemoryProtection newProtect, out MemoryProtection oldProtect);
开发者ID:svenslaggare,项目名称:XONEVirtualMachine,代码行数:1,代码来源:WinAPI.cs


示例12: VirtualAllocEx

 public static extern int VirtualAllocEx(IntPtr hProcess, Int32 lpAddress,
    Int32 dwSize, AllocationType flAllocationType, MemoryProtection flProtect);
开发者ID:Lamael,项目名称:tools,代码行数:2,代码来源:WinApi.cs


示例13: VirtualProtectEx

 public static extern bool VirtualProtectEx(IntPtr hProcess, IntPtr lpAddress, int nSize, MemoryProtection flNewProtect, out MemoryProtection lpflOldProtect);
开发者ID:zhuyue1314,项目名称:DllInjectorCS,代码行数:1,代码来源:Kernel32.cs


示例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;
 }
开发者ID:Konard,项目名称:LinksPlatform,代码行数:15,代码来源:Kernel32.cs


示例15: VirtualAllocEx

 public static extern DWORD_PTR VirtualAllocEx( IntPtr hProcess, DWORD_PTR lpAddress, uint dwSize, AllocationType flAllocationType, MemoryProtection flProtect );
开发者ID:aghili,项目名称:nwohack,代码行数:1,代码来源:WinAPI.cs


示例16: VirtualAllocEx

 internal static extern IntPtr VirtualAllocEx(SafeProcessHandle hProcess, uint dwAddress, int nSize, AllocationType dwAllocationType, MemoryProtection dwProtect);
开发者ID:hfenigma,项目名称:d3adventure,代码行数:1,代码来源:Imports.cs


示例17: MemoryFileSystem

        public MemoryFileSystem(string fileName, MfsOpenMode mode, bool readOnly, MfsParameters createParams)
        {
            FileCreationDispositionWin32 cdWin32;

            if (readOnly && mode != MfsOpenMode.Open)
                throw new ArgumentException("Invalid mode for read only access.");

            switch (mode)
            {
                case MfsOpenMode.Open:
                    cdWin32 = FileCreationDispositionWin32.OpenExisting;
                    break;
                default:
                case MfsOpenMode.OpenIf:
                    cdWin32 = FileCreationDispositionWin32.OpenAlways;
                    break;
                case MfsOpenMode.OverwriteIf:
                    cdWin32 = FileCreationDispositionWin32.CreateAlways;
                    break;
            }

            using (FileHandle fhandle = FileHandle.CreateWin32(
                fileName,
                FileAccess.GenericRead | (!readOnly ? FileAccess.GenericWrite : 0),
                FileShareMode.Read,
                cdWin32
                ))
            {
                bool justCreated = false;

                _readOnly = readOnly;
                _protection = !readOnly ? MemoryProtection.ReadWrite : MemoryProtection.ReadOnly;

                if (fhandle.FileSize == 0)
                {
                    if (readOnly)
                    {
                        throw new MfsInvalidFileSystemException();
                    }
                    
                    // File is too small. Make it 1 byte large and we'll deal with it soon.
                    fhandle.SetEnd(1);
                }

                _section = new Section(fhandle, _protection);

                _blockSize = MfsBlockSizeBase; // fake block size to begin with; we'll fix it up later.

                if (fhandle.FileSize < _blockSize)
                {
                    if (readOnly)
                    {
                        throw new MfsInvalidFileSystemException();
                    }
                    
                    // We're creating a new file system. We need the correct block size now.
                    if (createParams != null)
                        this._blockSize = createParams.BlockSize;
                    else
                        this._blockSize = MfsDefaultBlockSize;

                    this._section.Extend(this._blockSize);

                    using (SectionView view = this._section.MapView(0, this._blockSize, this._protection))
                    {
                        this.InitializeFs((MfsFsHeader*)view.Memory, createParams);
                    }

                    justCreated = true;
                }

                _header = (MfsFsHeader*)this.ReferenceBlock(0);

                // Check the magic.
                if (_header->Magic != MfsMagic)
                    throw new MfsInvalidFileSystemException();

                // Set up the local constants.
                _blockSize = _header->BlockSize;
                _cellSize = _header->CellSize;

                // Backwards compatibility.
                if (_blockSize == 0)
                    _blockSize = MfsDefaultBlockSize;
                if (_cellSize == 0)
                    _cellSize = MfsDefaultCellSize;

                // Validate the parameters.
                this.ValidateFsParameters(_blockSize, _cellSize);

                _blockMask = _blockSize - 1;
                _cellCount = _blockSize / _cellSize;
                _dataCellDataMaxLength = _cellSize - MfsDataCell.DataOffset;

                // Remap block 0 with the correct block size.
                this.DereferenceBlock(0);

                // If we just created a new file system, fix the section size.
                if (justCreated)
                    _section.Extend(_blockSize);
//.........这里部分代码省略.........
开发者ID:john-peterson,项目名称:processhacker,代码行数:101,代码来源:MemoryFileSystem.cs


示例18: VirtualAlloc

 public static extern IntPtr VirtualAlloc(IntPtr blockAddress, UIntPtr sizeInBytes,
     MemoryAllocationType allocationType, MemoryProtection protection);
开发者ID:gitter-badger,项目名称:LinksPlatform,代码行数:2,代码来源:Kernel.cs


示例19: VirtualProtect

 public static extern bool VirtualProtect(IntPtr lpAddress, uint dwSize,
    MemoryProtection flNewProtect, out MemoryProtection lpflOldProtect);
开发者ID:Xileck,项目名称:tibiaapi,代码行数:2,代码来源:WinApi.cs


示例20: Protect

        public void Protect(SafeProcessHandle handle, uint offset, uint size, MemoryProtection newProtect)
        {
            if (Address == IntPtr.Zero)
                throw new ObjectDisposedException("RemoteMemoryRegion");
            if ((offset + size) > (Size))
                throw new ArgumentException("Size too large for region");

            MemoryProtection oldProtect;
            int result = Win32.VirtualProtectEx(
                handle.DangerousGetHandle(),
                (uint)(Address.ToInt64() + offset),
                size, newProtect, out oldProtect
            );

            if (result == 0) {
                var error = Win32.GetLastError();
                throw new Exception(String.Format("Protect failed: Error {0:x8}", error));
            }
        }
开发者ID:kg,项目名称:shootblues,代码行数:19,代码来源:ProcessInjector.cs



注:本文中的MemoryProtection类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# MemorySlice类代码示例发布时间:2022-05-24
下一篇:
C# MemoryMappedFileOptions类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap