Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- API подключается либо отдельным файлом: #include name.ahk
- Либо вставляется в код готовой программы сверху
- Первый способ сделает ваш код слегка читабельнее
- */
- global ERROR_OK := 0
- global ERROR_OPEN_PROCESS := 2
- global ERROR_INVALID_HANDLE := 3
- global ERROR_MODULE_NOT_FOUND := 4
- global ERROR_ENUM_PROCESS_MODULES := 5
- global ERROR_READ_MEMORY := 8
- global ERROR_WRITE_MEMORY := 9
- global ERROR_ALLOC_MEMORY := 10
- global ERROR_FREE_MEMORY := 11
- global ERROR_WAIT_FOR_OBJECT := 12
- global ADDR_SAMP_INCHAT_PTR := 0x21A10C
- global ADDR_SAMP_INCHAT_PTR_OFF := 0x55
- global FUNC_SAMP_SENDCMD := 0x65C60
- global FUNC_SAMP_SENDSAY := 0x57F0
- global hGTA := 0x0
- global dwGTAPID := 0x0
- global dwSAMP := 0x0
- global pMemory := 0x0
- global pParam1 := 0x0
- global pParam2 := 0x0
- global pParam3 := 0x0
- global pParam4 := 0x0
- global pParam5 := 0x0
- global pInjectFunc := 0x0
- global iRefreshHandles := 0
- global FUNC_SAMP_ADDTOCHATWND := 0x64520
- global ADDR_SAMP_CHATMSG_PTR := 0x21a0e4
- global ADDR_SAMP_USERNAME := 0x219A6F
- global ADDR_CPED_HPOFF := 0x540
- global ADDR_CPED_PTR := 0xB6F5F0
- global FUNC_SAMP_SHOWDIALOG := 0x6B9C0
- global SAMP_DIALOG_STRUCT_PTR := 0x21A0B8
- global COLOR_GREEN := "{00D900}"
- global COLOR_WHITE := "{FFFFFF}"
- global COLOR_RED := "{FF0000}"
- global COLOR_YELLOW := "{FFFF00}"
- global COLOR_ORANGE := "{FFA500}"
- global COLOR_LIGHTBLUE := "{60C8EB}"
- getPageSize() {
- FileRead, config, %A_MyDocuments%\GTA San Andreas User Files\SAMP\sa-mp.cfg
- config := StrSplit(config, "`n")
- for i, el in config
- {
- if RegExMatch(el, "pagesize=(.*)", s)
- pagesize := s1
- }
- pagesize += 0
- return pagesize
- }
- getVehicleModelId() {
- if(!checkHandles())
- return 0
- dwAddr := readDWORD(hGTA, 0xBA18FC)
- if(ErrorLevel) {
- ErrorLevel := ERROR_READ_MEMORY
- return 0
- }
- if(!dwAddr)
- return 0
- sVal := readMem(hGTA, dwAddr + 0x22, 2, "Short")
- if(ErrorLevel) {
- ErrorLevel := ERROR_READ_MEMORY
- return 0
- }
- ErrorLevel := ERROR_OK
- return sVal
- }
- stringFormat(line) {
- StringReplace, line, line, {{}, {{}, ,All
- StringReplace, line, line, {}}, {}}, ,All
- StringReplace, line, line, !, {!}, ,All
- StringReplace, line, line, #, {#}, ,All
- StringReplace, line, line, ^, {^}, ,All
- StringReplace, line, line, +, {+}, ,All
- StringTrimLeft, line, line, 11
- return line
- }
- ; блокирует ввод в чат
- blockChatInput() {
- if(!checkHandles())
- return false
- VarSetCapacity(nop, 2, 0)
- dwFunc := dwSAMP + FUNC_SAMP_SENDSAY
- NumPut(0x04C2,nop,0,"Short")
- writeRaw(hGTA, dwFunc, &nop, 2)
- dwFunc := dwSAMP + FUNC_SAMP_SENDCMD
- writeRaw(hGTA, dwFunc, &nop, 2)
- return true
- }
- ; разблокирует ввод в чат
- unBlockChatInput() {
- if(!checkHandles())
- return false
- VarSetCapacity(nop, 2, 0)
- dwFunc := dwSAMP + FUNC_SAMP_SENDSAY
- NumPut(0xA164,nop,0,"Short")
- writeRaw(hGTA, dwFunc, &nop, 2)
- dwFunc := dwSAMP + FUNC_SAMP_SENDCMD
- writeRaw(hGTA, dwFunc, &nop, 2)
- return true
- }
- ; Возвращает true/false в зависимости от того, открыт ли диалог
- isDialogOpen() {
- if (!checkHandles())
- return false
- dwPointer := readDWORD(hGTA, dwSAMP + 0x21A0B8)
- if (ErrorLevel || !dwPointer)
- return false
- dwIsOpen := readMem(hGTA, dwPointer + 0x28, 4, "UInt")
- if (ErrorLevel)
- return false
- ErrorLevel := ERROR_OK
- return dwIsOpen ? true : false
- }
- ; Возвращает true/false в зависимости от того, сидит ли игрок в машине
- isPlayerInAnyVehicle() {
- if(!checkHandles())
- return -1
- dwVehPtr := readDWORD(hGTA, 0xBA18FC)
- if(ErrorLevel) {
- ErrorLevel := ERROR_READ_MEMORY
- return -1
- }
- return (dwVehPtr > 0)
- }
- /*
- Показывает диалоговое окно с заданным стилем
- Параметры:
- style - тип диалогового окна, все типы здесь: http://pawn-wiki.ru/index.php?/topic/1073-dialogovie-okna/
- caption - заголовок диалогового окна
- text - содержимое
- button1 - текст кнопки 1
- button2 - текст кнопки 2
- id - идентификатор диалога
- */
- showDialog(style, caption, text, button1, button2 := "", id := 1) {
- style += 0
- style := Floor(style)
- id += 0
- id := Floor(id)
- caption := "" caption
- text := "" text
- button1 := "" button1
- button2 := "" button2
- if (id < 0 || id > 32767 || style < 0 || style > 5 || StrLen(caption) > 64 || StrLen(text) > 4096 || StrLen(button1) > 10 || StrLen(button2) > 10)
- return false
- if (!checkHandles())
- return false
- dwFunc := dwSAMP + FUNC_SAMP_SHOWDIALOG
- dwAddress := readDWORD(hGTA, dwSAMP + SAMP_DIALOG_STRUCT_PTR)
- if (ErrorLevel || !dwAddress) {
- ErrorLevel := ERROR_READ_MEMORY
- return false
- }
- writeString(hGTA, pParam5, caption)
- if (ErrorLevel)
- return false
- writeString(hGTA, pParam1, text)
- if (ErrorLevel)
- return false
- writeString(hGTA, pParam5 + 512, button1)
- if (ErrorLevel)
- return false
- writeString(hGTA, pParam5+StrLen(caption) + 1, button2)
- if (ErrorLevel)
- return false
- ;mov + 7 * push + call + retn
- dwLen := 5 + 7 * 5 + 5 + 1
- VarSetCapacity(injectData, dwLen, 0)
- NumPut(0xB9, injectData, 0, "UChar") ;0 + 1 ;mov ecx
- NumPut(dwAddress, injectData, 1, "UInt") ;1 + 4
- NumPut(0x68, injectData, 5, "UChar") ;5 + 1 ;push send
- NumPut(1, injectData, 6, "UInt") ;6 + 4
- NumPut(0x68, injectData, 10, "UChar") ;10 + 1 ;push button2
- NumPut(pParam5 + StrLen(caption) + 1, injectData, 11, "UInt") ;11 + 4
- NumPut(0x68, injectData, 15, "UChar") ;15 + 1 ;push button1
- NumPut(pParam5 + 512, injectData, 16, "UInt") ;16 + 4
- NumPut(0x68, injectData, 20, "UChar") ;20 + 1 ;push text
- NumPut(pParam1, injectData, 21, "UInt") ;21 + 4
- NumPut(0x68, injectData, 25, "UChar") ;25 + 1 ;push caption
- NumPut(pParam5, injectData, 26, "UInt") ;26 + 4
- NumPut(0x68, injectData, 30, "UChar") ;30 + 1 ;push style
- NumPut(style, injectData, 31, "UInt") ;31 + 4
- NumPut(0x68, injectData, 35, "UChar") ;35 + 1 ;push id
- NumPut(id, injectData, 36, "UInt") ;36 + 4
- NumPut(0xE8, injectData, 40, "UChar") ;40 + 1 ;call
- offset := dwFunc - (pInjectFunc + 45)
- NumPut(offset, injectData, 41, "Int") ;41 + 4
- NumPut(0xC3, injectData, 45, "UChar") ;45 + 1 ;retn
- writeRaw(hGTA, pInjectFunc, &injectData, dwLen)
- if (ErrorLevel)
- return false
- hThread := createRemoteThread(hGTA, 0, 0, pInjectFunc, 0, 0, 0)
- if (ErrorLevel)
- return false
- waitForSingleObject(hThread, 0xFFFFFFFF)
- closeProcess(hThread)
- return true
- }
- ; Возвращает HP игрока
- getPlayerHealth() {
- if(!checkHandles())
- return -1
- dwCPedPtr := readDWORD(hGTA, ADDR_CPED_PTR)
- if(ErrorLevel) {
- ErrorLevel := ERROR_READ_MEMORY
- return -1
- }
- dwAddr := dwCPedPtr + ADDR_CPED_HPOFF
- fHealth := readFloat(hGTA, dwAddr)
- if(ErrorLevel) {
- ErrorLevel := ERROR_READ_MEMORY
- return -1
- }
- ErrorLevel := ERROR_OK
- return Round(fHealth)
- }
- ; Возвращает никнейм игрока
- getUsername() {
- if(!checkHandles())
- return ""
- dwAddress := dwSAMP + ADDR_SAMP_USERNAME
- sUsername := readString(hGTA, dwAddress, 25)
- if(ErrorLevel) {
- ErrorLevel := ERROR_READ_MEMORY
- return ""
- }
- ErrorLevel := ERROR_OK
- return sUsername
- }
- addBindMessage(bColor, bText) {
- addChatMessageEx(0xFF SubStr(bColor, 2, 6), bText)
- }
- /*
- Добавляет в чат надпись указанного цвета.
- Параметры:
- color - цвет сообщения. Цвет должен быть в формате 0x**FFFFFF, где ** = прозрачность от 00 до FF. FFFFFF = шестнадцатеричный код цвета.
- text - строка, которую необходимо вывести
- */
- addChatMessageEx(Color, wText) {
- wText := "" wText
- if(!checkHandles())
- return false
- VarSetCapacity(data2, 4, 0)
- NumPut(HexToDec(Color),data2,0,"Int")
- Addrr := readDWORD(hGTA, dwSAMP+ADDR_SAMP_CHATMSG_PTR)
- VarSetCapacity(data1, 4, 0)
- NumPut(readDWORD(hGTA, Addrr + 0x12A), data1,0,"Int")
- WriteRaw(hGTA, Addrr + 0x12A, &data2, 4)
- dwFunc := dwSAMP + FUNC_SAMP_ADDTOCHATWND
- dwChatInfo := readDWORD(hGTA, dwSAMP + ADDR_SAMP_CHATMSG_PTR)
- if(ErrorLevel) {
- ErrorLevel := ERROR_READ_MEMORY
- return false
- }
- callWithParams(hGTA, dwFunc, [["p", dwChatInfo], ["s", wText]], true)
- WriteRaw(hGTA, Addrr + 0x12A, &data1, 4)
- ErrorLevel := ERROR_OK
- return true
- }
- ; Послать на сервер команду/текст. Равносильно вводу в чат, но быстрее и меньше багов. В чате при нажатии стрелочки вверх не сохраняется
- SendChat(wText) {
- wText := "" wText
- if(!checkHandles())
- return false
- dwFunc:=0
- if(SubStr(wText, 1, 1) == "/") {
- dwFunc := dwSAMP + FUNC_SAMP_SENDCMD
- }
- else
- {
- dwFunc := dwSAMP + FUNC_SAMP_SENDSAY
- }
- callWithParams(hGTA, dwFunc, [["s", wText]], false)
- ErrorLevel := ERROR_OK
- return true
- }
- ; Возвращает true/false в зависимости от того, открыт ли чат
- isInChat() {
- if(!checkHandles())
- return -1
- dwPtr := dwSAMP + ADDR_SAMP_INCHAT_PTR
- dwAddress := readDWORD(hGTA, dwPtr) + ADDR_SAMP_INCHAT_PTR_OFF
- if(ErrorLevel) {
- ErrorLevel := ERROR_READ_MEMORY
- return -1
- }
- dwInChat := readDWORD(hGTA, dwAddress)
- if(ErrorLevel) {
- ErrorLevel := ERROR_READ_MEMORY
- return -1
- }
- ErrorLevel := ERROR_OK
- if(dwInChat > 0) {
- return true
- }
- else
- {
- return false
- }
- }
- /*
- Функции для работы с памятью
- */
- checkHandles() {
- if(iRefreshHandles+500>A_TickCount)
- return true
- iRefreshHandles:=A_TickCount
- if(!refreshGTA() || !refreshSAMP() || !refreshMemory()) {
- return false
- }
- else
- {
- return true
- }
- return true
- }
- refreshGTA() {
- newPID := getPID("GTA:SA:MP")
- if(!newPID) {
- if(hGTA) {
- virtualFreeEx(hGTA, pMemory, 0, 0x8000)
- closeProcess(hGTA)
- hGTA := 0x0
- }
- dwGTAPID := 0
- hGTA := 0x0
- dwSAMP := 0x0
- pMemory := 0x0
- return false
- }
- if(!hGTA || (dwGTAPID != newPID)) {
- hGTA := openProcess(newPID)
- if(ErrorLevel) {
- dwGTAPID := 0
- hGTA := 0x0
- dwSAMP := 0x0
- pMemory := 0x0
- return false
- }
- dwGTAPID := newPID
- dwSAMP := 0x0
- pMemory := 0x0
- return true
- }
- return true
- }
- refreshSAMP() {
- if(dwSAMP)
- return true
- dwSAMP := getModuleBaseAddress("samp.dll", hGTA)
- if(!dwSAMP)
- return false
- return true
- }
- refreshMemory() {
- if(!pMemory) {
- pMemory := virtualAllocEx(hGTA, 6144, 0x1000 | 0x2000, 0x40)
- if(ErrorLevel) {
- pMemory := 0x0
- return false
- }
- pParam1 := pMemory
- pParam2 := pMemory + 1024
- pParam3 := pMemory + 2048
- pParam4 := pMemory + 3072
- pParam5 := pMemory + 4096
- pInjectFunc := pMemory + 5120
- }
- return true
- }
- getPID(szWindow) {
- local dwPID := 0
- WinGet, dwPID, PID, %szWindow%
- return dwPID
- }
- openProcess(dwPID, dwRights = 0x1F0FFF) {
- hProcess := DllCall("OpenProcess"
- , "UInt", dwRights
- , "int", 0
- , "UInt", dwPID
- , "Uint")
- if(hProcess == 0) {
- ErrorLevel := ERROR_OPEN_PROCESS
- return 0
- }
- ErrorLevel := ERROR_OK
- return hProcess
- }
- closeProcess(hProcess) {
- if(hProcess == 0) {
- ErrorLevel := ERROR_INVALID_HANDLE
- return 0
- }
- dwRet := DllCall( "CloseHandle"
- , "Uint", hProcess
- , "UInt")
- ErrorLevel := ERROR_OK
- }
- getModuleBaseAddress(sModule, hProcess) {
- if(!sModule) {
- ErrorLevel := ERROR_MODULE_NOT_FOUND
- return 0
- }
- if(!hProcess) {
- ErrorLevel := ERROR_INVALID_HANDLE
- return 0
- }
- dwSize = 1024*4
- VarSetCapacity(hMods, dwSize)
- VarSetCapacity(cbNeeded, 4)
- dwRet := DllCall( "Psapi.dll\EnumProcessModules"
- , "UInt", hProcess
- , "UInt", &hMods
- , "UInt", dwSize
- , "UInt*", cbNeeded
- , "UInt")
- if(dwRet == 0) {
- ErrorLevel := ERROR_ENUM_PROCESS_MODULES
- return 0
- }
- dwMods := cbNeeded / 4
- i := 0
- VarSetCapacity(hModule, 4)
- VarSetCapacity(sCurModule, 260)
- while(i < dwMods) {
- hModule := NumGet(hMods, i*4)
- DllCall("Psapi.dll\GetModuleFileNameEx"
- , "UInt", hProcess
- , "UInt", hModule
- , "Str", sCurModule
- , "UInt", 260)
- SplitPath, sCurModule, sFilename
- if(sModule == sFilename) {
- ErrorLevel := ERROR_OK
- return hModule
- }
- i := i + 1
- }
- ErrorLevel := ERROR_MODULE_NOT_FOUND
- return 0
- }
- readDWORD(hProcess, dwAddress) {
- if(!hProcess) {
- ErrorLevel := ERROR_INVALID_HANDLE
- return 0
- }
- VarSetCapacity(dwRead, 4)
- dwRet := DllCall( "ReadProcessMemory"
- , "UInt", hProcess
- , "UInt", dwAddress
- , "Str", dwRead
- , "UInt", 4
- , "UInt*", 0)
- if(dwRet == 0) {
- ErrorLevel := ERROR_READ_MEMORY
- return 0
- }
- ErrorLevel := ERROR_OK
- return NumGet(dwRead, 0, "UInt")
- }
- writeString(hProcess, dwAddress, wString) {
- if(!hProcess) {
- ErrorLevel := ERROR_INVALID_HANDLE
- return false
- }
- sString := wString
- if A_IsUnicode
- sString := __unicodeToAnsi(wString)
- dwRet := DllCall( "WriteProcessMemory"
- , "UInt", hProcess
- , "UInt", dwAddress
- , "Str", sString
- , "UInt", StrLen(wString) + 1
- , "UInt", 0
- , "UInt")
- if(dwRet == 0) {
- ErrorLEvel := ERROR_WRITE_MEMORY
- return false
- }
- ErrorLevel := ERROR_OK
- return true
- }
- writeRaw(hProcess, dwAddress, pBuffer, dwLen) {
- if(!hProcess) {
- ErrorLevel := ERROR_INVALID_HANDLE
- return false
- }
- dwRet := DllCall( "WriteProcessMemory"
- , "UInt", hProcess
- , "UInt", dwAddress
- , "UInt", pBuffer
- , "UInt", dwLen
- , "UInt", 0
- , "UInt")
- if(dwRet == 0) {
- ErrorLEvel := ERROR_WRITE_MEMORY
- return false
- }
- ErrorLevel := ERROR_OK
- return true
- }
- callWithParams(hProcess, dwFunc, aParams, bCleanupStack = true) {
- if(!hProcess) {
- ErrorLevel := ERROR_INVALID_HANDLE
- return false
- }
- validParams := 0
- i := aParams.MaxIndex()
- dwLen := i * 5 + 5 + 1
- if(bCleanupStack)
- dwLen += 3
- VarSetCapacity(injectData, i * 5 + 5 + 3 + 1, 0)
- i_ := 1
- while(i > 0) {
- if(aParams[i][1] != "") {
- dwMemAddress := 0x0
- if(aParams[i][1] == "p")
- {
- dwMemAddress := aParams[i][2]
- }
- else
- if(aParams[i][1] == "s")
- {
- if(i_>3)
- return false
- dwMemAddress := pParam%i_%
- writeString(hProcess, dwMemAddress, aParams[i][2])
- if(ErrorLevel)
- return false
- i_ += 1
- }
- else
- if(aParams[i][1] == "i")
- {
- dwMemAddress := aParams[i][2]
- }
- else
- {
- return false
- }
- NumPut(0x68, injectData, validParams * 5, "UChar")
- NumPut(dwMemAddress, injectData, validParams * 5 + 1, "UInt")
- validParams += 1
- }
- i -= 1
- }
- offset := dwFunc - ( pInjectFunc + validParams * 5 + 5 )
- NumPut(0xE8, injectData, validParams * 5, "UChar")
- NumPut(offset, injectData, validParams * 5 + 1, "Int")
- if(bCleanupStack) {
- NumPut(0xC483, injectData, validParams * 5 + 5, "UShort")
- NumPut(validParams*4, injectData, validParams * 5 + 7, "UChar")
- NumPut(0xC3, injectData, validParams * 5 + 8, "UChar")
- }
- else
- {
- NumPut(0xC3, injectData, validParams * 5 + 5, "UChar")
- }
- writeRaw(hGTA, pInjectFunc, &injectData, dwLen)
- if(ErrorLevel)
- return false
- hThread := createRemoteThread(hGTA, 0, 0, pInjectFunc, 0, 0, 0)
- if(ErrorLevel)
- return false
- waitForSingleObject(hThread, 0xFFFFFFFF)
- closeProcess(hThread)
- return true
- }
- virtualAllocEx(hProcess, dwSize, flAllocationType, flProtect) {
- if(!hProcess) {
- ErrorLevel := ERROR_INVALID_HANDLE
- return 0
- }
- dwRet := DllCall( "VirtualAllocEx"
- , "UInt", hProcess
- , "UInt", 0
- , "UInt", dwSize
- , "UInt", flAllocationType
- , "UInt", flProtect
- , "UInt")
- if(dwRet == 0) {
- ErrorLEvel := ERROR_ALLOC_MEMORY
- return 0
- }
- ErrorLevel := ERROR_OK
- return dwRet
- }
- virtualFreeEx(hProcess, lpAddress, dwSize, dwFreeType) {
- if(!hProcess) {
- ErrorLevel := ERROR_INVALID_HANDLE
- return 0
- }
- dwRet := DllCall( "VirtualFreeEx"
- , "UInt", hProcess
- , "UInt", lpAddress
- , "UInt", dwSize
- , "UInt", dwFreeType
- , "UInt")
- if(dwRet == 0) {
- ErrorLEvel := ERROR_FREE_MEMORY
- return 0
- }
- ErrorLevel := ERROR_OK
- return dwRet
- }
- createRemoteThread(hProcess, lpThreadAttributes, dwStackSize, lpStartAddress, lpParameter, dwCreationFlags, lpThreadId) {
- if(!hProcess) {
- ErrorLevel := ERROR_INVALID_HANDLE
- return 0
- }
- dwRet := DllCall( "CreateRemoteThread"
- , "UInt", hProcess
- , "UInt", lpThreadAttributes
- , "UInt", dwStackSize
- , "UInt", lpStartAddress
- , "UInt", lpParameter
- , "UInt", dwCreationFlags
- , "UInt", lpThreadId
- , "UInt")
- if(dwRet == 0) {
- ErrorLEvel := ERROR_ALLOC_MEMORY
- return 0
- }
- ErrorLevel := ERROR_OK
- return dwRet
- }
- waitForSingleObject(hThread, dwMilliseconds) {
- if(!hThread) {
- ErrorLevel := ERROR_INVALID_HANDLE
- return 0
- }
- dwRet := DllCall( "WaitForSingleObject"
- , "UInt", hThread
- , "UInt", dwMilliseconds
- , "UInt")
- if(dwRet == 0xFFFFFFFF) {
- ErrorLEvel := ERROR_WAIT_FOR_OBJECT
- return 0
- }
- ErrorLevel := ERROR_OK
- return dwRet
- }
- __ansiToUnicode(sString, nLen = 0) {
- If !nLen
- {
- nLen := DllCall("MultiByteToWideChar"
- , "Uint", 0
- , "Uint", 0
- , "Uint", &sString
- , "int", -1
- , "Uint", 0
- , "int", 0)
- }
- VarSetCapacity(wString, nLen * 2)
- DllCall("MultiByteToWideChar"
- , "Uint", 0
- , "Uint", 0
- , "Uint", &sString
- , "int", -1
- , "Uint", &wString
- , "int", nLen)
- return wString
- }
- __unicodeToAnsi(wString, nLen = 0) {
- pString := wString + 1 > 65536 ? wString : &wString
- If !nLen
- {
- nLen := DllCall("WideCharToMultiByte"
- , "Uint", 0
- , "Uint", 0
- , "Uint", pString
- , "int", -1
- , "Uint", 0
- , "int", 0
- , "Uint", 0
- , "Uint", 0)
- }
- VarSetCapacity(sString, nLen)
- DllCall("WideCharToMultiByte"
- , "Uint", 0
- , "Uint", 0
- , "Uint", pString
- , "int", -1
- , "str", sString
- , "int", nLen
- , "Uint", 0
- , "Uint", 0)
- return sString
- }
- readFloat(hProcess, dwAddress) {
- if(!hProcess) {
- ErrorLevel := ERROR_INVALID_HANDLE
- return 0
- }
- VarSetCapacity(dwRead, 4) ; float = 4
- dwRet := DllCall( "ReadProcessMemory"
- , "UInt", hProcess
- , "UInt", dwAddress
- , "Str", dwRead
- , "UInt", 4
- , "UInt*", 0
- , "UInt")
- if(dwRet == 0) {
- ErrorLevel := ERROR_READ_MEMORY
- return 0
- }
- ErrorLevel := ERROR_OK
- return NumGet(dwRead, 0, "Float")
- }
- HexToDec(str) {
- local newStr := ""
- 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}
- StringLower, str, str
- str := RegExReplace(str, "^0x|[^a-f0-9]+", "")
- Loop, % StrLen(str)
- newStr .= SubStr(str, (StrLen(str)-A_Index)+1, 1)
- newStr := StrSplit(newStr, "")
- local ret := 0
- for i,char in newStr
- ret += comp[char]*(16**(i-1))
- return ret
- }
- readMem(hProcess, dwAddress, dwLen=4, type="UInt") {
- if(!hProcess)
- return 0
- VarSetCapacity(dwRead, dwLen)
- dwRet := DllCall( "ReadProcessMemory"
- , "UInt", hProcess
- , "UInt", dwAddress
- , "Str", dwRead
- , "UInt", dwLen
- , "UInt*", 0)
- if(dwRet == 0)
- return 0
- return NumGet(dwRead, 0, type)
- }
- readString(hProcess, dwAddress, dwLen) {
- if(!hProcess) {
- ErrorLevel := ERROR_INVALID_HANDLE
- return 0
- }
- VarSetCapacity(sRead, dwLen)
- dwRet := DllCall( "ReadProcessMemory"
- , "UInt", hProcess
- , "UInt", dwAddress
- , "Str", sRead
- , "UInt", dwLen
- , "UInt*", 0
- , "UInt")
- if(dwRet == 0) {
- ErrorLevel := ERROR_READ_MEMORY
- return 0
- }
- ErrorLevel := ERROR_OK
- if A_IsUnicode
- return __ansiToUnicode(sRead)
- return sRead
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement