c#内存区域

时间:2019-01-09 17:26:48

标签: c# memory memory-management

我需要一些指导或有关此设置代码的帮助。

private MemoryInformation[][] GetRegions()
    {
        var addy = new IntPtr();
        IList<MemoryInformation> regions
            = new List<MemoryInformation>();

        while (true)
        {
            var memInf = new MemoryInformation();
            int memDump = Pinvoke.VirtualQueryEx(_access.Handle, addy,
                out memInf, Marshal.SizeOf(memInf));

            if (memDump == 0)
                return DivideRegions(regions);

            var memProps = MemoryProperties.Parse(memInf);

            if (!memProps.State.IsCommited &&
                !memProps.Protect.IsGuard &&
                memProps.Protect.IsReadOnly)
                goto ADDY;

            if (!Settings.MemPrivate)
            {
                if (memProps.Type.IsPrivate)
                    goto ADDY;
            }

            if (!Settings.MemImage)
            {
                if (memProps.Type.IsImageMapped)
                    goto ADDY;
            }
            if (!Settings.MemMapped)
            {
                if (memProps.Type.IsMapped)
                    goto ADDY;
            }

            if (Settings.Writable != ScanType.BOTH)
            {
                if (Settings.Writable == ScanType.ONLY)
                {
                    if (!memProps.Protect.IsWritable)
                        goto ADDY;
                }
                else if (memProps.Protect.IsWritable)
                    goto ADDY;
            }
            if (Settings.CopyOnWrite != ScanType.BOTH)
            {
                if (Settings.CopyOnWrite == ScanType.ONLY)
                {
                    if (!memProps.Protect.IsCopyOnWrite)
                        goto ADDY;
                }
                else if (memProps.Protect.IsCopyOnWrite)
                    goto ADDY;
            }
            if (Settings.Executable != ScanType.BOTH)
            {
                if (Settings.Executable == ScanType.ONLY)
                {
                    if (!memProps.Protect.IsExecutable)
                        goto ADDY;
                }
                else if (memProps.Protect.IsExecutable)
                    goto ADDY;
            }

            regions.Add(memInf);

            ADDY:
            addy = new IntPtr(memInf.BaseAddress.ToInt32()
                + (int)memInf.RegionSize);
        }
    }
 private MemoryInformation[][] DivideRegions(IEnumerable<MemoryInformation> regions)
    {
        var regionsArray = regions.ToArray();
        var result = regionsArray.Length / _tasksAmount;
        var rest = regionsArray.Length - (result * _tasksAmount);

        var count = 0;
        IList<MemoryInformation> subList
            = new List<MemoryInformation>();
        IList<MemoryInformation[]> list
            = new List<MemoryInformation[]>();

        for (int i = 0; i < _tasksAmount; i++)
        {
            subList = new List<MemoryInformation>();
            for (int x = 0; x < result; x++)
                subList.Add(regionsArray[count++]);

            list.Add(subList.ToArray());
        }

        if (rest != 0)
        {
            subList = new List<MemoryInformation>();
            for (int i = 0; i < rest; i++)
                subList.Add(regionsArray[count++]);
            list.Add(subList.ToArray());
        }

        return list.ToArray();
    }

我已阅读并对此代码进行了一些重新研究,并且知道可以像这样var addy = new IntPtr(); (ln 3)来使用var addy = new IntPtr(0x10000000); (ln 3)来修改起始地址,但我一直停留在一个我不知道的地方如何修改最大值。

顺便说一句,我正在从NuGet , Nutdeep链接中使用一个nadeep内存扫描器。在包的手册中没有说如何修改最小地址和最大地址。这就是我的问题。

如何修改最大地址?

谢谢。

PS。该代码可能在此页面上不再显示。但是我选择了要粘贴在上面的重要代码(意味着我认为它可以回答我的问题)。

0 个答案:

没有答案