Skip to content

Pattern16 finds itself #5

Description

@rxznve

Pattern16 allocates memory which it eventually finds...

  1. Run a process that definitely does not have a test string in memory
  2. Check through a debugger or in any other way that this string is not in memory
  3. Inject the library and let it finish scanning
  4. Check again for the presence of this string in memory

Code to reproduce the problem

#include <Windows.h>
#include <iostream>

#include "pattern16/include/Pattern16.h"

void* ScanMemory(const char* string)
{
	uintptr_t* address = nullptr;

	MEMORY_BASIC_INFORMATION meminfo{};

	while (VirtualQuery(address, &meminfo, sizeof(meminfo)))
	{
		address = reinterpret_cast<uintptr_t*>
			(reinterpret_cast<SIZE_T>(meminfo.BaseAddress) + meminfo.RegionSize);

		if (!(meminfo.State == MEM_COMMIT &&
			meminfo.Type == MEM_PRIVATE &&
			meminfo.Protect == PAGE_READWRITE))
			continue;

		void* ptr = Pattern16::scan(meminfo.BaseAddress, meminfo.RegionSize, string);

		if (ptr)
			return ptr;
	}

	return nullptr;
}

int main()
{
	// Hello World
	void* ptr = ScanMemory("48 65 6C 6C 6F 20 57 6F 72 6C 64");

	if (ptr)
		std::cout << ptr << std::endl;
	else
		std::cout << "String not found!" << std::endl;

	system("pause");
	return EXIT_SUCCESS;
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions