Advertisement
Meliodas0_0

scriptcontext grabber

Feb 8th, 2020
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. namespace Memory2
  2. {
  3. bool compare(const char* location, const char* pattern, const char* mask)
  4. {
  5. for (; *mask; ++pattern, ++mask, ++location)
  6. {
  7. if (*mask == 'x' && *location != *pattern)
  8. {
  9. return false;
  10. }
  11. }
  12. return true;
  13. }
  14. uintptr_t scan(const char* pattern, const char* mask, uintptr_t start, uintptr_t end)
  15. {
  16. for (; start <= end; ++start)
  17. {
  18. if (compare((char*)start, (char*)pattern, mask))
  19. {
  20. return start;
  21. }
  22. }
  23. return 0;
  24. }
  25. uintptr_t scan(const char* pattern, const char* mask)
  26. {
  27. MODULEINFO moduleInfo;
  28. if (GetModuleInformation(GetCurrentProcess(), GetModuleHandle(0), &moduleInfo, sizeof(moduleInfo)))
  29. return scan(pattern, mask, (uintptr_t)moduleInfo.lpBaseOfDll, moduleInfo.SizeOfImage + (uintptr_t)moduleInfo.lpBaseOfDll);
  30. return 0;
  31. }
  32. uintptr_t scan(char* pattern, size_t start = 0x400000, size_t end = 0xffffffff)
  33. {
  34. MEMORY_BASIC_INFORMATION mbi;
  35. char* buffer = reinterpret_cast<char*>(malloc(1024));
  36. while (start < end)
  37. {
  38. VirtualQueryEx(GetCurrentProcess(), (void*)start, &mbi, sizeof(mbi));
  39. if ((mbi.AllocationProtect & 238) && !(mbi.Protect & 257) && (mbi.State & 4096) && (mbi.Protect & (PAGE_READWRITE | PAGE_WRITECOPY | PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_WRITECOPY)))
  40. {
  41. for (char* i = (char*)mbi.BaseAddress; i < (char*)mbi.BaseAddress + mbi.RegionSize;) {
  42. SIZE_T bytesRead;
  43. ReadProcessMemory(GetCurrentProcess(), i, buffer, 1024, &bytesRead);
  44. for (int pad = 0; pad < bytesRead; pad++)
  45. {
  46. if (*(uintptr_t*)(buffer + pad) == *(uintptr_t*)pattern) {
  47. return (uintptr_t)(i + pad);
  48. }
  49. }
  50. i += bytesRead;
  51. }
  52. }
  53. start += mbi.RegionSize;
  54. }
  55. return 0;
  56. }
  57. }
  58.  
  59. uintptr_t grabcontext() {
  60. uint32_t ScriptContextVftable = *((uint32_t*)(Memory2::scan("\xC7\x07\x00\x00\x00\x00\xC7\x47\x00\x00\x00\x00\x00\x8B\x87", "xx????xx?????xx") + 2));
  61. return Memory2::scan((char*)& ScriptContextVftable);
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement