Snow_Flake

memorylib_for_assultcube

Aug 25th, 2014
390
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ReadMemory(MADDRESS, pOffset = 0, PROGRAM = "PokeMMO Hacked.exe")
  2. {
  3.          Process, wait, %PROGRAM%, 0.5
  4.          pid = %ErrorLevel%
  5.          if pid = 0
  6.          {
  7.             return
  8.          }
  9.          VarSetCapacity(MVALUE,4)
  10.          ProcessHandle := DllCall("OpenProcess", "Int", 24, "Char", 0, "UInt", pid, "UInt")
  11.          DllCall("ReadProcessMemory", "UInt", ProcessHandle, "UInt", MADDRESS+pOffset, "Str", MVALUE, "Uint",4, "Uint *",0)
  12.          DllCall("CloseHandle", "int", ProcessHandle)
  13.          Loop 4
  14.             result += *(&MVALUE + A_Index-1) << 8*(A_Index-1)
  15.            
  16.          return result
  17. }
  18.  
  19. DecToHex(Value)
  20. {
  21.     SetFormat IntegerFast, Hex
  22.     Value += 0
  23.     Value .= "" ;required due to 'fast' mode
  24.     SetFormat IntegerFast, D
  25.     Return Value
  26. }
  27.  
  28. ReadMemory_Str(MADDRESS=0, pOffset = 0, PROGRAM = "League of Legends (TM) Client", length = 0 , terminator = "")
  29. {
  30.    Static OLDPROC, ProcessHandle
  31.    VarSetCapacity(MVALUE,4,0)
  32.    If PROGRAM != %OLDPROC%
  33.    {
  34.       WinGet, pid, pid, % OLDPROC := PROGRAM
  35.       ProcessHandle := ( ProcessHandle ? 0*(closed:=DllCall("CloseHandle"
  36.       ,"UInt",ProcessHandle)) : 0 )+(pid ? DllCall("OpenProcess"
  37.       ,"Int",16,"Int",0,"UInt",pid) : 0) ;PID is stored in value pid
  38.    }
  39.     If (MADDRESS = 0) ; the above expression/syntax does my head, hence easy close handle
  40.         closed:=DllCall("CloseHandle","UInt",ProcessHandle)
  41.     If ( length = 0) ; read until terminator found
  42.     {
  43.         teststr =
  44.         Loop
  45.         {
  46.             Output := "x"  ; Put exactly one character in as a placeholder. used to break loop on null
  47.             tempVar := DllCall("ReadProcessMemory", "UInt", ProcessHandle, "UInt", MADDRESS+pOffset, "str", Output, "Uint", 1, "Uint *", 0)
  48.             if (ErrorLevel or !tempVar)
  49.                return teststr
  50.             if (Output = terminator)
  51.               break
  52.             teststr .= Output
  53.             MADDRESS++
  54.         }
  55.         return, teststr  
  56.         }        
  57.     Else ; will read until X length
  58.     {
  59.          teststr =
  60.          Loop % length
  61.          {
  62.             Output := "x"  ; Put exactly one character in as a memory placeholder.
  63.             tempVar := DllCall("ReadProcessMemory", "UInt", ProcessHandle, "UInt", MADDRESS+pOffset, "str", Output, "Uint", 1, "Uint *", 0)
  64.             if (ErrorLevel or !tempVar)
  65.               return teststr
  66.             teststr .= Output
  67.             MADDRESS++
  68.          }
  69.           return, teststr  
  70.     }
  71.        
  72.        
  73. }
  74.  
  75. getProcessBaseAddress(WindowTitle, Hex=1, MatchMode=3)    ;WindowTitle can be anything ahk_exe ahk_class etc
  76. {
  77.     SetTitleMatchMode, %MatchMode%    ;mode 3 is an exact match
  78.     WinGet, hWnd, ID, %WindowTitle%
  79.     ; AHK32Bit A_PtrSize = 4 | AHK64Bit - 8 bytes
  80.     BaseAddress := DllCall(A_PtrSize = 4
  81.         ? "GetWindowLong"
  82.         : "GetWindowLongPtr", "Uint", hWnd, "Uint", -6)
  83.     if Hex
  84.         return dectohex(BaseAddress)
  85.     else return BaseAddress
  86. }
Advertisement
Add Comment
Please, Sign In to add comment