hoosier18

dll hack source

Sep 29th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.91 KB | None | 0 0
  1. /*
  2.  
  3. Basic DLL
  4.  
  5. */
  6.  
  7. #include <windows.h>
  8. #include <stdio.h>
  9.  
  10. // Pointers
  11.  
  12. #define pointer 0x00000000
  13. #define offset1 0x00000000
  14.  
  15. // Global variables
  16.  
  17.  
  18. bool activated = false;
  19. unsigned long ClientOffset;
  20. //unsigned long ingame = 0x1B8B054;
  21. bool* ingame;
  22. HANDLE setting;
  23.  
  24. void set()
  25. {
  26.     unsigned long address;
  27.     //unsigned long old_p;
  28.  
  29.     while (true)
  30.     {
  31.         if (*ingame)
  32.         {
  33.             address = ClientOffset + pointer;
  34.  
  35.             if (IsBadReadPtr((void*)address, 4) != NULL) continue;
  36.             address = *(unsigned long*)address + offset1;
  37.            
  38.             // Set the address
  39.  
  40.             if (IsBadWritePtr((void*)address, 4) == NULL)
  41.                 *(int*)address = 0;
  42.  
  43.             //VirtualProtect((void*)address, 4, PAGE_READONLY, &old_p);
  44.         }
  45.  
  46.         Sleep(1000);// every death it resets, so it is OK
  47.     }
  48. }
  49.  
  50. void reset()
  51. {
  52.     unsigned long address = ClientOffset + pointer;
  53.     if (IsBadReadPtr((void*)address, 4) != NULL) return;// It is already disabled
  54.     address = *(unsigned long*)address + offset1;
  55.     if (IsBadWritePtr((void*)address, 4) != NULL) return;
  56.  
  57.     // Here you reset the address
  58.  
  59.     *(int*)address = 0;// int = 4 bytes
  60. }
  61.  
  62. void is_activated()
  63. {
  64.     while (true)
  65.     {
  66.         if (GetAsyncKeyState(VK_END) &0x8000)
  67.         {
  68.             if (*ingame)
  69.             {
  70.                 if (!activated)
  71.                 {
  72.                     ResumeThread(setting);
  73.  
  74.                     activated = true;
  75.  
  76.                     Beep(1000, 100);
  77.                 }
  78.                 else
  79.                 {
  80.                     SuspendThread(setting);
  81.                     reset();
  82.                     activated = false;
  83.  
  84.                     Beep(750, 300);
  85.                 }
  86.             }
  87.            
  88.             Sleep(900);// If he pressed the key longer than 30ms then this will stop him from toggling it again, hopefully
  89.         }
  90.         else Sleep(30);//Not to overload the CPU. He can't press the key shorter than 15ms. 30ms on average
  91.     }
  92. }
  93.  
  94. void main()
  95. {
  96.     Beep(1000, 100);
  97.  
  98.     // Could be injected earlier than expected
  99.  
  100.     while (!(ClientOffset = (unsigned long)GetModuleHandle(NULL)))
  101.         Sleep(100);
  102.    
  103.     ingame = (bool*)(ClientOffset + 0x1B8B054);
  104.  
  105.     HANDLE checking;
  106.  
  107.     try
  108.     {
  109.         if ((checking = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)is_activated, NULL, CREATE_SUSPENDED, NULL)) == NULL)
  110.             throw "Couldn't create a thread to execute within the virtual address space of the calling process.(2)";
  111.  
  112.         if ((setting = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)set, NULL, CREATE_SUSPENDED, NULL)) == NULL)
  113.             throw "Couldn't create a thread to execute within the virtual address space of the calling process.(3)";
  114.     }
  115.     catch ( LPCSTR error )
  116.     {
  117.         MessageBox(NULL, error, "Error", MB_OK | MB_ICONERROR);
  118.         return;
  119.     }
  120.    
  121.     //if (SetThreadPriority(setting, THREAD_PRIORITY_BELOW_NORMAL) == NULL) // It can take resources so we need to protect the user from lags
  122.     //  MessageBox(NULL, "Couldn't set thread priority.\nBut the program can still continue.", "Error", MB_OK | MB_ICONERROR);
  123.  
  124.     bool in_progress = false;
  125.  
  126.     while (true)
  127.     {
  128.         // Checks if he is in game
  129.        
  130.         if (*ingame)
  131.         {
  132.             // Want the hack or not want the hack?
  133.            
  134.             if (!in_progress)
  135.             {
  136.                 ResumeThread(checking);
  137.                 in_progress = true;
  138.             }
  139.         }
  140.         else if (in_progress)
  141.         {
  142.             SuspendThread(checking);// No need to check out of game
  143.             in_progress = false;//Checking ain't in progress
  144.  
  145.             if (activated)
  146.                 if (SuspendThread(setting) != -1)
  147.                     activated = false;
  148.         }
  149.        
  150.         Sleep(2000);//Not to overload the CPU
  151.     }
  152.  
  153.     //char buf[255];
  154.     //sprintf_s(buf, "%d", address);
  155.     //MessageBox(NULL, buf, "ERROR", MB_OK | MB_ICONERROR);
  156. }
  157.  
  158. bool WINAPI DllMain(HINSTANCE hDLLInst, DWORD fdwReason, LPVOID lpvReserved)
  159. {
  160.     DisableThreadLibraryCalls(hDLLInst);
  161.  
  162.     if (fdwReason == DLL_PROCESS_ATTACH)
  163.     {
  164.         if (CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)main, NULL, 0, NULL) == NULL) // Creating a new thread in the process "AVA"
  165.         {
  166.             MessageBox(NULL, "Couldn't create a thread to execute within the virtual address space of the calling process.", "Error", MB_OK | MB_ICONERROR);
  167.             return false;
  168.         }
  169.     }
  170.     else if (fdwReason == DLL_PROCESS_DETACH)
  171.     {
  172.         // No need for anything here
  173.        
  174.     }
  175.    
  176.     return true;
  177. }
Add Comment
Please, Sign In to add comment