Advertisement
CracksStuff

memory leak fixed

Sep 17th, 2019
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.43 KB | None | 0 0
  1. // big meme man
  2. // jayden v2 is a fucking meme
  3. // memory.cpp
  4.  
  5. #include <memory.h>
  6. #include <cstdint>
  7. #include "retcheck.h"
  8. #include <stdio.h>    
  9. #include <psapi.h>
  10. #pragma comment( lib, "psapi.lib" )
  11.  
  12. memoryleaks = false
  13. /*
  14. big meme btw
  15. delete that if you're having issues lol
  16. */
  17.  
  18. /*
  19. also rakion99 is a
  20. fucking skid
  21. go kys rakion99
  22. :)
  23. */
  24.  
  25. namespace Retcheck
  26. {
  27.     DWORD Unprotect(DWORD addr, bool mode)
  28.     {
  29.         if (mode)
  30.             return Ret::unprotect<DWORD>((BYTE*)addr);
  31.  
  32.         BYTE* tAddr = (BYTE*)addr;
  33.         do
  34.         {
  35.             tAddr += 16;
  36.         } while (!(tAddr[0] == 0x55 && tAddr[1] == 0x8B && tAddr[2] == 0xEC));
  37.  
  38.         DWORD funcSz = tAddr - (BYTE*)addr;
  39.  
  40.         PVOID nFunc = VirtualAlloc(NULL, funcSz, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
  41.         if (nFunc == NULL)
  42.             return addr;
  43.  
  44.         memcpy(nFunc, (void*)addr, funcSz);
  45.  
  46.         BYTE* pos = (BYTE*)nFunc;
  47.         BOOL valid = false;
  48.         do
  49.         {
  50.             if (pos[0] == 0x72 && pos[2] == 0xA1 && pos[7] == 0x8B) {
  51.                 *(BYTE*)pos = 0xEB;
  52.  
  53.                 DWORD cByte = (DWORD)nFunc;
  54.                 do
  55.                 {
  56.                     if (*(BYTE*)cByte == 0xE8)
  57.                     {
  58.                         DWORD oFuncPos = addr + (cByte - (DWORD)nFunc);
  59.                         DWORD oFuncAddr = (oFuncPos + *(DWORD*)(oFuncPos + 1)) + 5;
  60.  
  61.                         if (oFuncAddr % 16 == 0)
  62.                         {
  63.                             DWORD relativeAddr = oFuncAddr - cByte - 5;
  64.                             *(DWORD*)(cByte + 1) = relativeAddr;
  65.  
  66.                             cByte += 4;
  67.                         }
  68.                     }
  69.  
  70.                     cByte += 1;
  71.                 } while (cByte - (DWORD)nFunc < funcSz);
  72.  
  73.                 valid = true;
  74.             }
  75.             pos += 1;
  76.         } while ((DWORD)pos < (DWORD)nFunc + funcSz);
  77.  
  78.         if (!valid)
  79.         {
  80.             VirtualFree(nFunc, funcSz, MEM_RELEASE);
  81.             return addr;
  82.         }
  83.  
  84.         return (DWORD)nFunc;
  85.     }
  86. }
  87.  
  88.  
  89. namespace sigscan
  90. {
  91.     bool compare(const char* location, const char* aob, const char* mask)
  92.     {
  93.         for (; *mask; ++aob, ++mask, ++location)
  94.         {
  95.             if (*mask == 'x' && *location != *aob)
  96.             {
  97.                 return false;
  98.             }
  99.         }
  100.  
  101.         return true;
  102.     }
  103.  
  104.     bool compare_reverse(const char* location, const char* aob, const char* mask)
  105.     {
  106.         const char* mask_iter = mask + strlen(mask) - 1;
  107.         for (; mask_iter >= mask; --aob, --mask_iter, --location)
  108.         {
  109.             if (*mask_iter == 'x' && *location != *aob)
  110.             {
  111.                 return false;
  112.             }
  113.         }
  114.  
  115.         return true;
  116.     }
  117.  
  118.     byte* scan(const char* aob, const char* mask, uintptr_t start, uintptr_t end)
  119.     {
  120.         if (start <= end)
  121.         {
  122.             for (; start <= end; ++start)
  123.             {
  124.                 if (compare((char*)start, (char*)aob, mask))
  125.                 {
  126.                     return (byte*)start;
  127.                 }
  128.             }
  129.         }
  130.         else
  131.         {
  132.             for (; start >= end; --start)
  133.             {
  134.                 if (compare_reverse((char*)start, (char*)aob, mask))
  135.                 {
  136.                     return (byte*)start - strlen(mask) - 1;
  137.                 }
  138.             }
  139.         }
  140.  
  141.         return 0;
  142.     };
  143.  
  144.     byte* scan(const char* module, const char* aob, const char* mask)
  145.     {
  146.         MODULEINFO info;
  147.         if (GetModuleInformation(GetCurrentProcess(), GetModuleHandle(module), &info, sizeof(info)))
  148.             return scan(aob, mask, (uintptr_t)info.lpBaseOfDll, (uintptr_t)info.lpBaseOfDll + info.SizeOfImage);
  149.  
  150.         return 0;
  151.     }
  152. }
  153.  
  154. // seperate memory.h
  155.  
  156. #pragma once
  157.  
  158. #include <Windows.h>
  159. #include <cstdint>
  160. typedef unsigned char byte;
  161.  
  162. namespace Retcheck
  163. {
  164.     DWORD Unprotect(DWORD addr, bool mode);
  165. }
  166.  
  167. namespace sigscan
  168. {
  169.     bool compare(const char* location, const char* aob, const char* mask);
  170.     bool compare_reverse(const char* location, const char* aob, const char* mask);
  171.     byte* scan(const char* aob, const char* mask, uintptr_t start, uintptr_t end);
  172.     byte* scan(const char* module, const char* aob, const char* mask);
  173. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement