Advertisement
Guest User

samp udf no cheats

a guest
May 29th, 2017
473
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. API подключается либо отдельным файлом: #include name.ahk
  3. Либо вставляется в код готовой программы сверху
  4. Первый способ сделает ваш код слегка читабельнее
  5. */
  6. global ERROR_OK                             := 0
  7. global ERROR_OPEN_PROCESS                   := 2
  8. global ERROR_INVALID_HANDLE             := 3
  9. global ERROR_MODULE_NOT_FOUND               := 4
  10. global ERROR_ENUM_PROCESS_MODULES       := 5
  11. global ERROR_READ_MEMORY                    := 8
  12. global ERROR_WRITE_MEMORY                   := 9
  13. global ERROR_ALLOC_MEMORY                   := 10
  14. global ERROR_FREE_MEMORY                    := 11
  15. global ERROR_WAIT_FOR_OBJECT                := 12
  16. global ADDR_SAMP_INCHAT_PTR             := 0x21A10C
  17. global ADDR_SAMP_INCHAT_PTR_OFF         := 0x55
  18. global FUNC_SAMP_SENDCMD                    := 0x65C60
  19. global FUNC_SAMP_SENDSAY                    := 0x57F0
  20. global hGTA                                     := 0x0
  21. global dwGTAPID                             := 0x0
  22. global dwSAMP                                   := 0x0
  23. global pMemory                                  := 0x0
  24. global pParam1                                  := 0x0
  25. global pParam2                                  := 0x0
  26. global pParam3                                  := 0x0
  27. global pParam4                                  := 0x0
  28. global pParam5                                  := 0x0
  29. global pInjectFunc                          := 0x0
  30. global iRefreshHandles                      := 0
  31. global FUNC_SAMP_ADDTOCHATWND               := 0x64520
  32. global ADDR_SAMP_CHATMSG_PTR                := 0x21a0e4
  33. global ADDR_SAMP_USERNAME                   := 0x219A6F
  34. global ADDR_CPED_HPOFF                      := 0x540
  35. global ADDR_CPED_PTR                            := 0xB6F5F0
  36. global FUNC_SAMP_SHOWDIALOG             := 0x6B9C0
  37. global SAMP_DIALOG_STRUCT_PTR               := 0x21A0B8
  38. global COLOR_GREEN                          := "{00D900}"
  39. global COLOR_WHITE                          := "{FFFFFF}"
  40. global COLOR_RED                                := "{FF0000}"
  41. global COLOR_YELLOW                         := "{FFFF00}"
  42. global COLOR_ORANGE                         := "{FFA500}"
  43. global COLOR_LIGHTBLUE                      := "{60C8EB}"
  44.  
  45. getPageSize() {
  46.     FileRead, config, %A_MyDocuments%\GTA San Andreas User Files\SAMP\sa-mp.cfg
  47.     config := StrSplit(config, "`n")
  48.     for i, el in config
  49.     {
  50.         if RegExMatch(el, "pagesize=(.*)", s)
  51.         pagesize := s1
  52.     }
  53.     pagesize += 0
  54.     return pagesize
  55. }
  56.  
  57. getVehicleModelId() {
  58.     if(!checkHandles())
  59.     return 0
  60.  
  61.     dwAddr := readDWORD(hGTA, 0xBA18FC)
  62.     if(ErrorLevel) {
  63.         ErrorLevel := ERROR_READ_MEMORY
  64.         return 0
  65.     }
  66.  
  67.     if(!dwAddr)
  68.     return 0
  69.  
  70.     sVal := readMem(hGTA, dwAddr + 0x22, 2, "Short")
  71.     if(ErrorLevel) {
  72.         ErrorLevel := ERROR_READ_MEMORY
  73.         return 0
  74.     }
  75.  
  76.     ErrorLevel := ERROR_OK
  77.     return sVal
  78. }
  79.  
  80. stringFormat(line) {
  81.     StringReplace, line, line, {{}, {{}, ,All
  82.     StringReplace, line, line, {}}, {}}, ,All
  83.     StringReplace, line, line, !, {!}, ,All
  84.     StringReplace, line, line, #, {#}, ,All
  85.     StringReplace, line, line, ^, {^}, ,All
  86.     StringReplace, line, line, +, {+}, ,All
  87.     StringTrimLeft, line, line, 11
  88.     return line
  89. }
  90.  
  91. ; блокирует ввод в чат
  92. blockChatInput() {
  93.     if(!checkHandles())
  94.     return false
  95.  
  96.     VarSetCapacity(nop, 2, 0)
  97.  
  98.     dwFunc := dwSAMP + FUNC_SAMP_SENDSAY
  99.     NumPut(0x04C2,nop,0,"Short")
  100.     writeRaw(hGTA, dwFunc, &nop, 2)
  101.  
  102.     dwFunc := dwSAMP + FUNC_SAMP_SENDCMD
  103.     writeRaw(hGTA, dwFunc, &nop, 2)
  104.  
  105.     return true
  106. }
  107.  
  108. ; разблокирует ввод в чат
  109. unBlockChatInput() {
  110.     if(!checkHandles())
  111.     return false
  112.  
  113.     VarSetCapacity(nop, 2, 0)
  114.  
  115.     dwFunc := dwSAMP + FUNC_SAMP_SENDSAY
  116.     NumPut(0xA164,nop,0,"Short")
  117.     writeRaw(hGTA, dwFunc, &nop, 2)
  118.  
  119.     dwFunc := dwSAMP + FUNC_SAMP_SENDCMD
  120.     writeRaw(hGTA, dwFunc, &nop, 2)
  121.  
  122.     return true
  123. }
  124.  
  125. ; Возвращает true/false в зависимости от того, открыт ли диалог
  126. isDialogOpen() {
  127.     if (!checkHandles())
  128.     return false
  129.  
  130.     dwPointer := readDWORD(hGTA, dwSAMP + 0x21A0B8)
  131.    
  132.     if (ErrorLevel || !dwPointer)
  133.     return false
  134.  
  135.     dwIsOpen := readMem(hGTA, dwPointer + 0x28, 4, "UInt")
  136.    
  137.     if (ErrorLevel)
  138.     return false
  139.  
  140.     ErrorLevel := ERROR_OK
  141.     return dwIsOpen ? true : false
  142. }
  143.  
  144. ; Возвращает true/false в зависимости от того, сидит ли игрок в машине
  145. isPlayerInAnyVehicle() {
  146.     if(!checkHandles())
  147.     return -1
  148.  
  149.     dwVehPtr := readDWORD(hGTA, 0xBA18FC)
  150.     if(ErrorLevel) {
  151.         ErrorLevel := ERROR_READ_MEMORY
  152.         return -1
  153.     }
  154.  
  155.     return (dwVehPtr > 0)
  156. }
  157.  
  158. /*
  159. Показывает диалоговое окно с заданным стилем
  160. Параметры:
  161. style - тип диалогового окна, все типы здесь: http://pawn-wiki.ru/index.php?/topic/1073-dialogovie-okna/
  162. caption - заголовок диалогового окна
  163. text - содержимое
  164. button1 - текст кнопки 1
  165. button2 - текст кнопки 2
  166. id - идентификатор диалога
  167. */
  168. showDialog(style, caption, text, button1, button2 := "", id := 1) {
  169.     style += 0
  170.     style := Floor(style)
  171.     id += 0
  172.     id := Floor(id)
  173.     caption := "" caption
  174.     text := "" text
  175.     button1 := "" button1
  176.     button2 := "" button2
  177.  
  178.     if (id < 0 || id > 32767 || style < 0 || style > 5 || StrLen(caption) > 64 || StrLen(text) > 4096 || StrLen(button1) > 10 || StrLen(button2) > 10)
  179.     return false
  180.  
  181.     if (!checkHandles())
  182.     return false
  183.  
  184.     dwFunc := dwSAMP + FUNC_SAMP_SHOWDIALOG
  185.  
  186.     dwAddress := readDWORD(hGTA, dwSAMP + SAMP_DIALOG_STRUCT_PTR)
  187.     if (ErrorLevel || !dwAddress) {
  188.         ErrorLevel := ERROR_READ_MEMORY
  189.         return false
  190.     }
  191.  
  192.     writeString(hGTA, pParam5, caption)
  193.     if (ErrorLevel)
  194.     return false
  195.     writeString(hGTA, pParam1, text)
  196.     if (ErrorLevel)
  197.     return false
  198.     writeString(hGTA, pParam5 + 512, button1)
  199.     if (ErrorLevel)
  200.     return false
  201.     writeString(hGTA, pParam5+StrLen(caption) + 1, button2)
  202.     if (ErrorLevel)
  203.     return false
  204.  
  205.     ;mov + 7 * push + call + retn
  206.     dwLen := 5 + 7 * 5 + 5 + 1
  207.     VarSetCapacity(injectData, dwLen, 0)
  208.  
  209.     NumPut(0xB9, injectData, 0, "UChar")                            ;0 + 1  ;mov ecx
  210.     NumPut(dwAddress, injectData, 1, "UInt")                        ;1 + 4
  211.     NumPut(0x68, injectData, 5, "UChar")                            ;5 + 1  ;push send
  212.     NumPut(1, injectData, 6, "UInt")                                ;6 + 4
  213.     NumPut(0x68, injectData, 10, "UChar")                           ;10 + 1 ;push button2
  214.     NumPut(pParam5 + StrLen(caption) + 1, injectData, 11, "UInt")   ;11 + 4
  215.     NumPut(0x68, injectData, 15, "UChar")                           ;15 + 1 ;push button1
  216.     NumPut(pParam5 + 512, injectData, 16, "UInt")                   ;16 + 4
  217.     NumPut(0x68, injectData, 20, "UChar")                           ;20 + 1 ;push text
  218.     NumPut(pParam1, injectData, 21, "UInt")                         ;21 + 4
  219.     NumPut(0x68, injectData, 25, "UChar")                           ;25 + 1 ;push caption
  220.     NumPut(pParam5, injectData, 26, "UInt")                         ;26 + 4
  221.     NumPut(0x68, injectData, 30, "UChar")                           ;30 + 1 ;push style
  222.     NumPut(style, injectData, 31, "UInt")                           ;31 + 4
  223.     NumPut(0x68, injectData, 35, "UChar")                           ;35 + 1 ;push id
  224.     NumPut(id, injectData, 36, "UInt")                              ;36 + 4
  225.  
  226.     NumPut(0xE8, injectData, 40, "UChar")                           ;40 + 1 ;call
  227.     offset := dwFunc - (pInjectFunc + 45)
  228.     NumPut(offset, injectData, 41, "Int")                           ;41 + 4
  229.     NumPut(0xC3, injectData, 45, "UChar")                           ;45 + 1 ;retn
  230.  
  231.     writeRaw(hGTA, pInjectFunc, &injectData, dwLen)
  232.     if (ErrorLevel)
  233.     return false
  234.  
  235.     hThread := createRemoteThread(hGTA, 0, 0, pInjectFunc, 0, 0, 0)
  236.     if (ErrorLevel)
  237.     return false
  238.  
  239.     waitForSingleObject(hThread, 0xFFFFFFFF)
  240.     closeProcess(hThread)
  241.  
  242.     return true
  243. }
  244.  
  245. ; Возвращает HP игрока
  246. getPlayerHealth() {
  247.     if(!checkHandles())
  248.     return -1
  249.  
  250.     dwCPedPtr := readDWORD(hGTA, ADDR_CPED_PTR)
  251.     if(ErrorLevel) {
  252.         ErrorLevel := ERROR_READ_MEMORY
  253.         return -1
  254.     }
  255.  
  256.     dwAddr := dwCPedPtr + ADDR_CPED_HPOFF
  257.     fHealth := readFloat(hGTA, dwAddr)
  258.     if(ErrorLevel) {
  259.         ErrorLevel := ERROR_READ_MEMORY
  260.         return -1
  261.     }
  262.  
  263.     ErrorLevel := ERROR_OK
  264.     return Round(fHealth)
  265. }
  266.  
  267. ; Возвращает никнейм игрока
  268. getUsername() {
  269.     if(!checkHandles())
  270.     return ""
  271.  
  272.     dwAddress := dwSAMP + ADDR_SAMP_USERNAME
  273.     sUsername := readString(hGTA, dwAddress, 25)
  274.     if(ErrorLevel) {
  275.         ErrorLevel := ERROR_READ_MEMORY
  276.         return ""
  277.     }
  278.  
  279.     ErrorLevel := ERROR_OK
  280.     return sUsername
  281. }
  282.  
  283. addBindMessage(bColor, bText) {
  284.     addChatMessageEx(0xFF SubStr(bColor, 2, 6), bText)
  285. }
  286.  
  287. /*
  288. Добавляет в чат надпись указанного цвета.
  289. Параметры:
  290. color - цвет сообщения. Цвет должен быть в формате 0x**FFFFFF, где ** = прозрачность от 00 до FF. FFFFFF = шестнадцатеричный код цвета.
  291. text - строка, которую необходимо вывести
  292. */
  293. addChatMessageEx(Color, wText) {
  294.     wText := "" wText
  295.     if(!checkHandles())
  296.     return false
  297.     VarSetCapacity(data2, 4, 0)
  298.     NumPut(HexToDec(Color),data2,0,"Int")
  299.     Addrr := readDWORD(hGTA, dwSAMP+ADDR_SAMP_CHATMSG_PTR)
  300.     VarSetCapacity(data1, 4, 0)
  301.     NumPut(readDWORD(hGTA, Addrr + 0x12A), data1,0,"Int")
  302.     WriteRaw(hGTA, Addrr + 0x12A, &data2, 4)
  303.     dwFunc := dwSAMP + FUNC_SAMP_ADDTOCHATWND
  304.     dwChatInfo := readDWORD(hGTA, dwSAMP + ADDR_SAMP_CHATMSG_PTR)
  305.     if(ErrorLevel) {
  306.         ErrorLevel := ERROR_READ_MEMORY
  307.         return false
  308.     }
  309.     callWithParams(hGTA, dwFunc, [["p", dwChatInfo], ["s", wText]], true)
  310.     WriteRaw(hGTA, Addrr + 0x12A, &data1, 4)
  311.     ErrorLevel := ERROR_OK
  312.     return true
  313. }
  314.  
  315. ; Послать на сервер команду/текст. Равносильно вводу в чат, но быстрее и меньше багов. В чате при нажатии стрелочки вверх не сохраняется
  316. SendChat(wText) {
  317.     wText := "" wText
  318.     if(!checkHandles())
  319.     return false
  320.     dwFunc:=0
  321.     if(SubStr(wText, 1, 1) == "/") {
  322.         dwFunc := dwSAMP + FUNC_SAMP_SENDCMD
  323.     }
  324.     else
  325.     {
  326.         dwFunc := dwSAMP + FUNC_SAMP_SENDSAY
  327.     }
  328.     callWithParams(hGTA, dwFunc, [["s", wText]], false)
  329.     ErrorLevel := ERROR_OK
  330.     return true
  331. }
  332.  
  333. ; Возвращает true/false в зависимости от того, открыт ли чат
  334. isInChat() {
  335.     if(!checkHandles())
  336.     return -1
  337.  
  338.     dwPtr := dwSAMP + ADDR_SAMP_INCHAT_PTR
  339.     dwAddress := readDWORD(hGTA, dwPtr) + ADDR_SAMP_INCHAT_PTR_OFF
  340.     if(ErrorLevel) {
  341.         ErrorLevel := ERROR_READ_MEMORY
  342.         return -1
  343.     }
  344.  
  345.     dwInChat := readDWORD(hGTA, dwAddress)
  346.     if(ErrorLevel) {
  347.         ErrorLevel := ERROR_READ_MEMORY
  348.         return -1
  349.     }
  350.  
  351.     ErrorLevel := ERROR_OK
  352.     if(dwInChat > 0) {
  353.         return true
  354.     }
  355.     else
  356.     {
  357.         return false
  358.     }
  359. }
  360.  
  361. /*
  362. Функции для работы с памятью
  363. */
  364.  
  365. checkHandles() {
  366.     if(iRefreshHandles+500>A_TickCount)
  367.     return true
  368.     iRefreshHandles:=A_TickCount
  369.     if(!refreshGTA() || !refreshSAMP() || !refreshMemory()) {
  370.         return false
  371.     }
  372.     else
  373.     {
  374.         return true
  375.     }
  376.     return true
  377. }
  378.  
  379. refreshGTA() {
  380.     newPID := getPID("GTA:SA:MP")
  381.     if(!newPID) {
  382.         if(hGTA) {
  383.             virtualFreeEx(hGTA, pMemory, 0, 0x8000)
  384.             closeProcess(hGTA)
  385.             hGTA := 0x0
  386.         }
  387.         dwGTAPID := 0
  388.         hGTA := 0x0
  389.         dwSAMP := 0x0
  390.         pMemory := 0x0
  391.         return false
  392.     }
  393.     if(!hGTA || (dwGTAPID != newPID)) {
  394.         hGTA := openProcess(newPID)
  395.         if(ErrorLevel) {
  396.             dwGTAPID := 0
  397.             hGTA := 0x0
  398.             dwSAMP := 0x0
  399.             pMemory := 0x0
  400.             return false
  401.         }
  402.         dwGTAPID := newPID
  403.         dwSAMP := 0x0
  404.         pMemory := 0x0
  405.         return true
  406.     }
  407.     return true
  408. }
  409.  
  410. refreshSAMP() {
  411.     if(dwSAMP)
  412.     return true
  413.     dwSAMP := getModuleBaseAddress("samp.dll", hGTA)
  414.     if(!dwSAMP)
  415.     return false
  416.     return true
  417. }
  418.  
  419. refreshMemory() {
  420.     if(!pMemory) {
  421.         pMemory     := virtualAllocEx(hGTA, 6144, 0x1000 | 0x2000, 0x40)
  422.         if(ErrorLevel) {
  423.             pMemory := 0x0
  424.             return false
  425.         }
  426.         pParam1     := pMemory
  427.         pParam2     := pMemory + 1024
  428.         pParam3     := pMemory + 2048
  429.         pParam4     := pMemory + 3072
  430.         pParam5     := pMemory + 4096
  431.         pInjectFunc := pMemory + 5120
  432.     }
  433.     return true
  434. }
  435.  
  436. getPID(szWindow) {
  437.     local dwPID := 0
  438.     WinGet, dwPID, PID, %szWindow%
  439.     return dwPID
  440. }
  441.  
  442. openProcess(dwPID, dwRights = 0x1F0FFF) {
  443.     hProcess := DllCall("OpenProcess"
  444.         , "UInt", dwRights
  445.         , "int", 0
  446.         , "UInt", dwPID
  447.         , "Uint")
  448.     if(hProcess == 0) {
  449.         ErrorLevel := ERROR_OPEN_PROCESS
  450.         return 0
  451.     }
  452.     ErrorLevel := ERROR_OK
  453.     return hProcess
  454. }
  455.  
  456. closeProcess(hProcess) {
  457.     if(hProcess == 0) {
  458.         ErrorLevel := ERROR_INVALID_HANDLE
  459.         return 0
  460.     }
  461.     dwRet := DllCall( "CloseHandle"
  462.         , "Uint", hProcess
  463.         , "UInt")
  464.     ErrorLevel := ERROR_OK
  465. }
  466.  
  467. getModuleBaseAddress(sModule, hProcess) {
  468.     if(!sModule) {
  469.         ErrorLevel := ERROR_MODULE_NOT_FOUND
  470.         return 0
  471.     }
  472.     if(!hProcess) {
  473.         ErrorLevel := ERROR_INVALID_HANDLE
  474.         return 0
  475.     }
  476.     dwSize = 1024*4
  477.     VarSetCapacity(hMods, dwSize)
  478.     VarSetCapacity(cbNeeded, 4)
  479.     dwRet := DllCall( "Psapi.dll\EnumProcessModules"
  480.         , "UInt", hProcess
  481.         , "UInt", &hMods
  482.         , "UInt", dwSize
  483.         , "UInt*", cbNeeded
  484.         , "UInt")
  485.     if(dwRet == 0) {
  486.         ErrorLevel := ERROR_ENUM_PROCESS_MODULES
  487.         return 0
  488.     }
  489.     dwMods := cbNeeded / 4
  490.     i := 0
  491.     VarSetCapacity(hModule, 4)
  492.     VarSetCapacity(sCurModule, 260)
  493.     while(i < dwMods) {
  494.         hModule := NumGet(hMods, i*4)
  495.         DllCall("Psapi.dll\GetModuleFileNameEx"
  496.             , "UInt", hProcess
  497.             , "UInt", hModule
  498.             , "Str", sCurModule
  499.             , "UInt", 260)
  500.         SplitPath, sCurModule, sFilename
  501.         if(sModule == sFilename) {
  502.             ErrorLevel := ERROR_OK
  503.             return hModule
  504.         }
  505.         i := i + 1
  506.     }
  507.     ErrorLevel := ERROR_MODULE_NOT_FOUND
  508.     return 0
  509. }
  510.  
  511. readDWORD(hProcess, dwAddress) {
  512.     if(!hProcess) {
  513.         ErrorLevel := ERROR_INVALID_HANDLE
  514.         return 0
  515.     }
  516.     VarSetCapacity(dwRead, 4)
  517.     dwRet := DllCall( "ReadProcessMemory"
  518.         , "UInt", hProcess
  519.         , "UInt", dwAddress
  520.         , "Str", dwRead
  521.         , "UInt", 4
  522.         , "UInt*", 0)
  523.     if(dwRet == 0) {
  524.         ErrorLevel := ERROR_READ_MEMORY
  525.         return 0
  526.     }
  527.     ErrorLevel := ERROR_OK
  528.     return NumGet(dwRead, 0, "UInt")
  529. }
  530.  
  531. writeString(hProcess, dwAddress, wString) {
  532.     if(!hProcess) {
  533.         ErrorLevel := ERROR_INVALID_HANDLE
  534.         return false
  535.     }
  536.     sString := wString
  537.     if A_IsUnicode
  538.     sString := __unicodeToAnsi(wString)
  539.     dwRet := DllCall( "WriteProcessMemory"
  540.         , "UInt", hProcess
  541.         , "UInt", dwAddress
  542.         , "Str", sString
  543.         , "UInt", StrLen(wString) + 1
  544.         , "UInt", 0
  545.         , "UInt")
  546.     if(dwRet == 0) {
  547.         ErrorLEvel := ERROR_WRITE_MEMORY
  548.         return false
  549.     }
  550.     ErrorLevel := ERROR_OK
  551.     return true
  552. }
  553.  
  554. writeRaw(hProcess, dwAddress, pBuffer, dwLen) {
  555.     if(!hProcess) {
  556.         ErrorLevel := ERROR_INVALID_HANDLE
  557.         return false
  558.     }
  559.     dwRet := DllCall( "WriteProcessMemory"
  560.         , "UInt", hProcess
  561.         , "UInt", dwAddress
  562.         , "UInt", pBuffer
  563.         , "UInt", dwLen
  564.         , "UInt", 0
  565.         , "UInt")
  566.     if(dwRet == 0) {
  567.         ErrorLEvel := ERROR_WRITE_MEMORY
  568.         return false
  569.     }
  570.     ErrorLevel := ERROR_OK
  571.     return true
  572. }
  573.  
  574. callWithParams(hProcess, dwFunc, aParams, bCleanupStack = true) {
  575.     if(!hProcess) {
  576.         ErrorLevel := ERROR_INVALID_HANDLE
  577.         return false
  578.     }
  579.     validParams := 0
  580.     i := aParams.MaxIndex()
  581.     dwLen := i * 5 + 5 + 1
  582.     if(bCleanupStack)
  583.     dwLen += 3
  584.     VarSetCapacity(injectData, i * 5 + 5 + 3 + 1, 0)
  585.     i_ := 1
  586.     while(i > 0) {
  587.         if(aParams[i][1] != "") {
  588.             dwMemAddress := 0x0
  589.             if(aParams[i][1] == "p")
  590.             {
  591.                 dwMemAddress := aParams[i][2]
  592.             }
  593.             else
  594.             if(aParams[i][1] == "s")
  595.             {
  596.                 if(i_>3)
  597.                 return false
  598.                 dwMemAddress := pParam%i_%
  599.                 writeString(hProcess, dwMemAddress, aParams[i][2])
  600.                 if(ErrorLevel)
  601.                 return false
  602.                 i_ += 1
  603.             }
  604.             else
  605.             if(aParams[i][1] == "i")
  606.             {
  607.                 dwMemAddress := aParams[i][2]
  608.             }
  609.             else
  610.             {
  611.                 return false
  612.             }
  613.             NumPut(0x68, injectData, validParams * 5, "UChar")
  614.             NumPut(dwMemAddress, injectData, validParams * 5 + 1, "UInt")
  615.             validParams += 1
  616.         }
  617.         i -= 1
  618.     }
  619.     offset := dwFunc - ( pInjectFunc + validParams * 5 + 5 )
  620.     NumPut(0xE8, injectData, validParams * 5, "UChar")
  621.     NumPut(offset, injectData, validParams * 5 + 1, "Int")
  622.     if(bCleanupStack) {
  623.         NumPut(0xC483, injectData, validParams * 5 + 5, "UShort")
  624.         NumPut(validParams*4, injectData, validParams * 5 + 7, "UChar")
  625.         NumPut(0xC3, injectData, validParams * 5 + 8, "UChar")
  626.     }
  627.     else
  628.     {
  629.         NumPut(0xC3, injectData, validParams * 5 + 5, "UChar")
  630.     }
  631.     writeRaw(hGTA, pInjectFunc, &injectData, dwLen)
  632.     if(ErrorLevel)
  633.     return false
  634.     hThread := createRemoteThread(hGTA, 0, 0, pInjectFunc, 0, 0, 0)
  635.     if(ErrorLevel)
  636.     return false
  637.     waitForSingleObject(hThread, 0xFFFFFFFF)
  638.     closeProcess(hThread)
  639.     return true
  640. }
  641.  
  642. virtualAllocEx(hProcess, dwSize, flAllocationType, flProtect) {
  643.     if(!hProcess) {
  644.         ErrorLevel := ERROR_INVALID_HANDLE
  645.         return 0
  646.     }
  647.     dwRet := DllCall( "VirtualAllocEx"
  648.         , "UInt", hProcess
  649.         , "UInt", 0
  650.         , "UInt", dwSize
  651.         , "UInt", flAllocationType
  652.         , "UInt", flProtect
  653.         , "UInt")
  654.     if(dwRet == 0) {
  655.         ErrorLEvel := ERROR_ALLOC_MEMORY
  656.         return 0
  657.     }
  658.     ErrorLevel := ERROR_OK
  659.     return dwRet
  660. }
  661.  
  662. virtualFreeEx(hProcess, lpAddress, dwSize, dwFreeType) {
  663.     if(!hProcess) {
  664.         ErrorLevel := ERROR_INVALID_HANDLE
  665.         return 0
  666.     }
  667.     dwRet := DllCall( "VirtualFreeEx"
  668.         , "UInt", hProcess
  669.         , "UInt", lpAddress
  670.         , "UInt", dwSize
  671.         , "UInt", dwFreeType
  672.         , "UInt")
  673.     if(dwRet == 0) {
  674.         ErrorLEvel := ERROR_FREE_MEMORY
  675.         return 0
  676.     }
  677.     ErrorLevel := ERROR_OK
  678.     return dwRet
  679. }
  680.  
  681. createRemoteThread(hProcess, lpThreadAttributes, dwStackSize, lpStartAddress, lpParameter, dwCreationFlags, lpThreadId) {
  682.     if(!hProcess) {
  683.         ErrorLevel := ERROR_INVALID_HANDLE
  684.         return 0
  685.     }
  686.     dwRet := DllCall( "CreateRemoteThread"
  687.         , "UInt", hProcess
  688.         , "UInt", lpThreadAttributes
  689.         , "UInt", dwStackSize
  690.         , "UInt", lpStartAddress
  691.         , "UInt", lpParameter
  692.         , "UInt", dwCreationFlags
  693.         , "UInt", lpThreadId
  694.         , "UInt")
  695.     if(dwRet == 0) {
  696.         ErrorLEvel := ERROR_ALLOC_MEMORY
  697.         return 0
  698.     }
  699.     ErrorLevel := ERROR_OK
  700.     return dwRet
  701. }
  702.  
  703. waitForSingleObject(hThread, dwMilliseconds) {
  704.     if(!hThread) {
  705.         ErrorLevel := ERROR_INVALID_HANDLE
  706.         return 0
  707.     }
  708.     dwRet := DllCall( "WaitForSingleObject"
  709.         , "UInt", hThread
  710.         , "UInt", dwMilliseconds
  711.         , "UInt")
  712.     if(dwRet == 0xFFFFFFFF) {
  713.         ErrorLEvel := ERROR_WAIT_FOR_OBJECT
  714.         return 0
  715.     }
  716.     ErrorLevel := ERROR_OK
  717.     return dwRet
  718. }
  719. __ansiToUnicode(sString, nLen = 0) {
  720.     If !nLen
  721.     {
  722.         nLen := DllCall("MultiByteToWideChar"
  723.             , "Uint", 0
  724.             , "Uint", 0
  725.             , "Uint", &sString
  726.             , "int", -1
  727.             , "Uint", 0
  728.             , "int", 0)
  729.     }
  730.     VarSetCapacity(wString, nLen * 2)
  731.     DllCall("MultiByteToWideChar"
  732.         , "Uint", 0
  733.         , "Uint", 0
  734.         , "Uint", &sString
  735.         , "int", -1
  736.         , "Uint", &wString
  737.         , "int", nLen)
  738.     return wString
  739. }
  740. __unicodeToAnsi(wString, nLen = 0) {
  741.     pString := wString + 1 > 65536 ? wString : &wString
  742.     If !nLen
  743.     {
  744.         nLen := DllCall("WideCharToMultiByte"
  745.             , "Uint", 0
  746.             , "Uint", 0
  747.             , "Uint", pString
  748.             , "int", -1
  749.             , "Uint", 0
  750.             , "int", 0
  751.             , "Uint", 0
  752.             , "Uint", 0)
  753.     }
  754.     VarSetCapacity(sString, nLen)
  755.     DllCall("WideCharToMultiByte"
  756.         , "Uint", 0
  757.         , "Uint", 0
  758.         , "Uint", pString
  759.         , "int", -1
  760.         , "str", sString
  761.         , "int", nLen
  762.         , "Uint", 0
  763.         , "Uint", 0)
  764.     return sString
  765. }
  766.  
  767. readFloat(hProcess, dwAddress) {
  768.     if(!hProcess) {
  769.         ErrorLevel := ERROR_INVALID_HANDLE
  770.         return 0
  771.     }
  772.  
  773.     VarSetCapacity(dwRead, 4) ; float = 4
  774.     dwRet := DllCall( "ReadProcessMemory"
  775.         , "UInt", hProcess
  776.         , "UInt", dwAddress
  777.         , "Str", dwRead
  778.         , "UInt", 4
  779.         , "UInt*", 0
  780.         , "UInt")
  781.     if(dwRet == 0) {
  782.         ErrorLevel := ERROR_READ_MEMORY
  783.         return 0
  784.     }
  785.  
  786.     ErrorLevel := ERROR_OK
  787.     return NumGet(dwRead, 0, "Float")
  788. }
  789.  
  790. HexToDec(str) {
  791.     local newStr := ""
  792.     static comp := {0:0, 1:1, 2:2, 3:3, 4:4, 5:5, 6:6, 7:7, 8:8, 9:9, "a":10, "b":11, "c":12, "d":13, "e":14, "f":15}
  793.     StringLower, str, str
  794.     str := RegExReplace(str, "^0x|[^a-f0-9]+", "")
  795.     Loop, % StrLen(str)
  796.     newStr .= SubStr(str, (StrLen(str)-A_Index)+1, 1)
  797.     newStr := StrSplit(newStr, "")
  798.     local ret := 0
  799.     for i,char in newStr
  800.     ret += comp[char]*(16**(i-1))
  801.     return ret
  802. }
  803.  
  804. readMem(hProcess, dwAddress, dwLen=4, type="UInt") {
  805.     if(!hProcess)
  806.     return 0
  807.  
  808.     VarSetCapacity(dwRead, dwLen)
  809.     dwRet := DllCall(    "ReadProcessMemory"
  810.         , "UInt",  hProcess
  811.         , "UInt",  dwAddress
  812.         , "Str",   dwRead
  813.         , "UInt",  dwLen
  814.         , "UInt*", 0)
  815.     if(dwRet == 0)
  816.     return 0
  817.  
  818.     return NumGet(dwRead, 0, type)
  819. }
  820.  
  821. readString(hProcess, dwAddress, dwLen) {
  822.     if(!hProcess) {
  823.         ErrorLevel := ERROR_INVALID_HANDLE
  824.         return 0
  825.     }
  826.  
  827.     VarSetCapacity(sRead, dwLen)
  828.     dwRet := DllCall( "ReadProcessMemory"
  829.         , "UInt", hProcess
  830.         , "UInt", dwAddress
  831.         , "Str", sRead
  832.         , "UInt", dwLen
  833.         , "UInt*", 0
  834.         , "UInt")
  835.     if(dwRet == 0) {
  836.         ErrorLevel := ERROR_READ_MEMORY
  837.         return 0
  838.     }
  839.  
  840.     ErrorLevel := ERROR_OK
  841.     if A_IsUnicode
  842.     return __ansiToUnicode(sRead)
  843.     return sRead
  844. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement