Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pattern16 finds itself #5

Open
rxznve opened this issue Feb 14, 2024 · 0 comments
Open

Pattern16 finds itself #5

rxznve opened this issue Feb 14, 2024 · 0 comments

Comments

@rxznve
Copy link

rxznve commented Feb 14, 2024

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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant