Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.86 KB | None | 0 0
  1. #include "ProcMem.h"
  2.  
  3. using namespace std;
  4.  
  5. #pragma region Misc Functions
  6.  
  7. ProcMem::ProcMem() {
  8. //Constructor For Class, Do Not Remove!
  9. }
  10.  
  11. ProcMem::~ProcMem() {
  12. //De-Constructor
  13. //Clean Up! (Close Handle - Not Needed Anymore)
  14. CloseHandle(hProcess);
  15. }
  16.  
  17. /* This Function Returns The Length Of External Char Arrays, SizeOf(Array) Fails For External Arrays. */
  18. int ProcMem::chSizeOfArray(char *chArray) {
  19.  
  20. //Loop Through *chArray To Get Amount Of Bytes
  21. for (int iLength = 1; iLength < MAX_PATH; iLength++)
  22. if (chArray[iLength] == '*')
  23. return iLength;
  24.  
  25. cout << "\nLENGTH: Failed To Read Length Of Array\n";
  26. return 0;
  27. }
  28.  
  29. /* This Function Returns The Length Of External Int Arrays, SizeOf(Array) Fails For External Arrays. */
  30. int ProcMem::iSizeOfArray(int *iArray) {
  31.  
  32. //Loop Through *chArray To Get Amount Of Bytes
  33. for (int iLength = 1; iLength < MAX_PATH; iLength++)
  34. if (iArray[iLength] == '*')
  35. return iLength;
  36.  
  37. cout << "\nLENGTH: Failed To Read Length Of Array\n";
  38. return 0;
  39. }
  40.  
  41. /* This Function Finds The Specified Value Inside Of Arrays And Returns A Boolean Value,
  42. /* Used For Triggerbot To Find The Current Crosshair Entity i_NearEntity Inside The Enemy Array. */
  43. bool ProcMem::iFind(int *iAry, int iVal) {
  44.  
  45. for (int i = 0; i < 64; i++)
  46. if (iVal == iAry[i] && iVal != 0)
  47. return true;
  48.  
  49. return false;
  50. }
  51.  
  52. #pragma endregion
  53.  
  54. #pragma region Memory Functions
  55.  
  56. /* This Function Will Return A Handle To The Process So We Can Write & Read Memeory From The Process. */
  57. void ProcMem::Process(char* ProcessName) {
  58.  
  59. //Variables
  60. HANDLE hPID = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL); //Snapshot To View All Active Processes
  61. PROCESSENTRY32 ProcEntry;
  62. ProcEntry.dwSize = sizeof(ProcEntry); //Declare Structure Size And Populate It
  63.  
  64. //Loop Through All Running Processes To Find Process
  65. do
  66. if (!strcmp(ProcEntry.szExeFile, ProcessName))
  67. {
  68. //Store Process ID
  69. dwPID = ProcEntry.th32ProcessID;
  70. CloseHandle(hPID);
  71.  
  72. //Give Our Handle All Access Rights
  73. hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwPID);
  74. return;
  75. }
  76. while (Process32Next(hPID, &ProcEntry));
  77.  
  78. cout << "\nPROCESS: Process Not Found\n";
  79. system("pause");
  80. exit(0);
  81. }
  82.  
  83. /* This Function Will Write Specified Bytes To The Address, And Can Also Be Reverted Back To Normal
  84. /* Just Call It Again As It Works On A Boolean. */
  85. void ProcMem::Patch(DWORD dwAddress, char *Patch_Bts, char *Default_Bts) {
  86.  
  87. //Variables
  88. int iSize = chSizeOfArray(Default_Bts);
  89.  
  90. //Loop Through Addresses Writing Bytes
  91. if (!bPOn)
  92. for (int i = 0; i < iSize; i++)
  93. Write<BYTE>(dwAddress + i, Patch_Bts[i]);
  94. else
  95. for (int i = 0; i < iSize; i++)
  96. Write<BYTE>(dwAddress + i, Default_Bts[i]);
  97.  
  98. bPOn = !bPOn;
  99. }
  100.  
  101. /* This Function Is Similiar To Cheat Engine's Code Injection Function, It's Able To Create JMP's
  102. /* To A Codecave And Write New Memory. Untested CALL Command */
  103. void ProcMem::Inject(DWORD dwAddress, char *Inj_Bts, char *Def_Bts, BOOL Type) {
  104.  
  105. }
  106.  
  107. /* Basic Byte Scanner, Will Return The Start Address Of The Specififed Byte Pattern.
  108. /* To-Do: Re-Write Using Memory_Page Functions To Grab Blocks Of Memory And Scan
  109. /* It Inside This Console, Maybe Study Multi-Threading For Faster Scanning. */
  110. DWORD ProcMem::AOB_Scan(DWORD dwAddress, DWORD dwEnd, char *Bytes) {
  111.  
  112. //VARIABLES
  113. int iBytesToRead = 0, iTmp = 0;
  114. int length = chSizeOfArray(Bytes);
  115. bool bTmp = false;
  116.  
  117. //Check If The Start Of The Array Has Wildcards, So We Can Change The Count
  118. if (Bytes[0] == '?')
  119. {
  120. for (; iBytesToRead < MAX_PATH; iBytesToRead++)
  121. if (Bytes[iBytesToRead] != '?')
  122. {
  123. iTmp = (iBytesToRead + 1);
  124. break;
  125. }
  126. }
  127.  
  128. //Increase Start Address Till It Reaches The End Address While Reading Bytes
  129. for (; dwAddress < dwEnd; dwAddress++)
  130. {
  131. if (iBytesToRead == length)
  132. return dwAddress - iBytesToRead;
  133.  
  134. if (Read<BYTE>(dwAddress) == Bytes[iBytesToRead] || (bTmp && Bytes[iBytesToRead] == '?'))
  135. {
  136. iBytesToRead++;
  137. bTmp = true;
  138. }
  139. else
  140. {
  141. iBytesToRead = iTmp;
  142. bTmp = false;
  143. }
  144. }
  145.  
  146. cout << "\nAOB_SCAN: Failed To Find Byte Pattern\n";
  147. return 0;
  148. }
  149.  
  150. /* Returns The Base Address Of The Specified Module Inside The Target Process
  151. /* e.g.[ Module("client.dll"); ]. */
  152. DWORD ProcMem::Module(LPSTR ModuleName) {
  153.  
  154. //Variables
  155. HANDLE hModule = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, dwPID); //Take A Module Snapshot Of The Process (Grab All Loaded Modules)
  156. MODULEENTRY32 mEntry; //Declare Module Entry Structure
  157. mEntry.dwSize = sizeof(mEntry); //Declare Structure Size And Populate It With Loaded Modules
  158.  
  159. //Scan For Module By Name
  160. do
  161. if (!strcmp(mEntry.szModule, ModuleName))
  162. {
  163. CloseHandle(hModule);
  164. return (DWORD)mEntry.modBaseAddr;
  165. }
  166. while (Module32Next(hModule, &mEntry));
  167.  
  168. cout << "\nMODULE: Process Platform Invalid\n";
  169. return 0;
  170. }
  171.  
  172. #pragma endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement