ReadMemory v1 to v2

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
lightright
Posts: 11
Joined: 13 Mar 2023, 19:20

ReadMemory v1 to v2

07 Apr 2023, 20:34

Here is the code for the readmemory function in version 1.

Code: Select all

ReadMemory(MADDRESS,PROGRAM,byte := 4)
{
	winget, pid, PID, ahk_id %program%
	VarSetCapacity(MVALUE,4,0)
	ProcessHandle := DllCall("OpenProcess", "Int", 24, "Char", 0, "UInt", pid, "UInt")
	DllCall("ReadProcessMemory","UInt",ProcessHandle,"UInt",MADDRESS,"Str",MVALUE,"UInt",4,"UInt *",0)
	Loop % byte
	result += *(&MVALUE + A_Index-1) << 8*(A_Index-1)
	return, result
}
And this is the readmemory function written with the v2 code converter.

Code: Select all

ReadMemory(MADDRESS,PROGRAM,byte := 4)
{
        pid := WinGetPID("ahk_id " program)
        MVALUE := Buffer(4, 0) ; V1toV2: if 'MVALUE' is a UTF-16 string, use 'VarSetStrCapacity(&MVALUE, 4)'
        ProcessHandle := DllCall("OpenProcess", "Int", 24, "Char", 0, "UInt", pid, "UInt")
        DllCall("ReadProcessMemory", "UInt", ProcessHandle, "UInt", MADDRESS, "Str", MVALUE, "UInt", 4, "UInt *", 0) 
        Loop byte
        result += *(&MVALUE + A_Index-1) << 8*(A_Index-1) ;<<<
        return result
}
image.png
image.png (17.41 KiB) Viewed 702 times
When running the code, the following error occurs and I'm not sure how to fix it. I need some help.
User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: ReadMemory v1 to v2

07 Apr 2023, 20:59

Could always search, right? I haven't tried this script, but perhaps it helps. viewtopic.php?f=82&t=98789
lightright
Posts: 11
Joined: 13 Mar 2023, 19:20

Re: ReadMemory v1 to v2

07 Apr 2023, 21:32

Thank you for your response. I understand that you have already conducted a search on this topic. What you were hoping to do was to modify your existing function to be compatible with v2. I assume that you have read the article from the link you provided, but the function you are currently using is different from the one described in the article. Therefore, you are unsure how to use the new function. That was the reason you posted a new question.
User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: ReadMemory v1 to v2

08 Apr 2023, 06:17

You are completely right. That was the reason I posted a new question. I'm really just a robot and do not actually know how to read. I hope that you can help me, or maybe we can get together to eat some sandwiches?
gregster
Posts: 9111
Joined: 30 Sep 2013, 06:48

Re: ReadMemory v1 to v2

08 Apr 2023, 09:24

Huh, I guess there could be a language barrier problem here, or rather a translation problem which causes confusion.
@lightright, you indicated in an older post that you used ChatGPT to translate Korean to English. In these forums, we had the experience that ChatGPT's output is often unreliable and inconsistent. This seems to be the case here, too. Perhaps you could try a more "traditional" translation service like Google Translate or DeepL?!?
User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: ReadMemory v1 to v2

08 Apr 2023, 09:49

Regarding the cited function, it looked like it was a v2 translation, but I did not test it.
lightright
Posts: 11
Joined: 13 Mar 2023, 19:20

Re: ReadMemory v1 to v2

09 Apr 2023, 20:44

Thank you for inspiring me with the post you linked to, I have created a working function based on it.

@mikeyww
lightright
Posts: 11
Joined: 13 Mar 2023, 19:20

Re: ReadMemory v1 to v2

09 Apr 2023, 20:48

@gregster
Thank you. I realized that using ChatGPT to translate is not a good idea. I will use the translator DeepL that you suggested.

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: wineguy and 91 guests