ReadProcessMemory через границы модуля - PullRequest
0 голосов
/ 11 декабря 2018

Я использую ReadProcessMemory для чтения памяти процесса.Кажется, что когда я читаю через конец модуля, остальные байты не читаются успешно.Я также получаю следующую ошибку ядра:

299: Only part of a ReadProcessMemory or WriteProcessMemory request was completed.

Если я перечислю все модули с EnumProcessModules, ни один из них не будет содержать адрес, с которого я пытаюсь прочитать, но Cheat Engine может показать все содержимое памяти просто отлично.Cheat Engine говорит, что размер модуля равен 0xE000, и это именно то количество байтов, которое я могу прочитать до его остановки, и помещает только 0x00 байтов в буфер, который является неправильным и не представляет фактическое содержимое памяти.

Не подходит ли следующий код для чтения через границы модуля (даже если они смежные)?

static Memory getOutputMemory(Pointer openedProcess, long baseAddress, int length)
{
    val outputMemory = new Memory(length);
    val intByReference = new IntByReference();
    if (!MY_KERNEL_32.ReadProcessMemory(openedProcess, baseAddress,
            outputMemory, (int) outputMemory.size(), intByReference))
    {
        checkForKernelError();
    }

    return outputMemory;
}

1 Ответ

0 голосов
/ 11 декабря 2018

Оказывается, чтение страниц памяти по отдельности, как это сделать, например, как следующий код:

public byte[] readBytes(long address, int length)
{
    val byteBuffer = allocate(length);

    var totalRemainingLength = length;
    var currentAddress = address;

    while (totalRemainingLength > 0)
    {
        val memoryBasicInformation = new MEMORY_BASIC_INFORMATION();
        val process = new HANDLE(processHandle);
        val pointer = new Pointer(currentAddress);
        val memoryPageQueryResult = KERNEL_32.VirtualQueryEx(process, pointer, memoryBasicInformation,
                new BaseTSD.SIZE_T(memoryBasicInformation.size()));
        if (memoryPageQueryResult.equals(new SIZE_T(0)))
        {
            throw new IllegalStateException("Memory not contiguous");
        }

        val memoryPageBaseAddress = nativeValue(memoryBasicInformation.baseAddress);
        val memoryPageSize = memoryBasicInformation.regionSize.longValue();
        val memoryPageEndAddress = memoryPageBaseAddress + memoryPageSize;

        val remainingMemoryPageBytes = memoryPageEndAddress - address;
        val currentLength = (int) min(totalRemainingLength, remainingMemoryPageBytes);
        val outputMemory = getOutputMemory(processHandle, currentAddress, currentLength);
        val byteArray = outputMemory.getByteArray(0, currentLength);
        byteBuffer.put(byteArray);

        currentAddress += currentLength;
        totalRemainingLength -= currentLength;
    }

    return byteBuffer.array();
}

static Memory getOutputMemory(Pointer openedProcess, long baseAddress, int length)
{
    val outputMemory = new Memory(length);
    val intByReference = new IntByReference();
    if (!MY_KERNEL_32.ReadProcessMemory(openedProcess, baseAddress,
            outputMemory, (int) outputMemory.size(), intByReference))
    {
        checkForKernelError();
    }

    return outputMemory;
}
...