Classmemory readbytes Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
whynotregister
Posts: 147
Joined: 05 Nov 2016, 22:42

Classmemory readbytes

24 Oct 2019, 00:54

There is no function readbytes in classmemory, so I temporarily used the following method:

Code: Select all

#include classmemory.ahk
StringToHex(String)
{
	local Old_A_FormatInteger, CharHex, HexString
	
	If !String
		Return 0
	
	;Save the current Integer format
	Old_A_FormatInteger := A_FormatInteger
	
	SetFormat, INTEGER, H
	
	Loop, Parse, String 
		{
		CharHex := Asc(A_LoopField)
	
		StringTrimLeft, CharHex, CharHex, 2
		
		HexString .= CharHex . " "
		}
	SetFormat, INTEGER, %Old_A_FormatInteger%
	Return HexString
}

handle := new _ClassMemory("ahk_exe target.exe", "", hProcessCopy) 
msgbox % stringtohex(handle.readstring(0x772b0610,5,utf-8))
The problem with the above code is that classmemory does not recognize it if hex code is 00, so it cannot be used normally.
Image

Is there a good way to solve this?
RHCP
Posts: 202
Joined: 30 Sep 2013, 10:59

Re: Classmemory readbytes  Topic is solved

24 Oct 2019, 05:06

You're reading the memory as a string. The 00 byte in a string acts as a null terminator, i.e. it ends the string.
What are you trying to do with the string of hex bytes after you read it?

Image

Code: Select all

calc.readRaw(0x283E85E1196, myBuffer, 10)
msgbox % bufferToHex(myBuffer, 10)

bufferToHex(byRef buffer, sizeBytes)
{
    loop % sizeBytes
        s .= Format("{:02X} ", NumGet(&buffer + 0, A_Index - 1, "UChar"))
    return rtrim(s, A_space)
}
whynotregister
Posts: 147
Joined: 05 Nov 2016, 22:42

Re: Classmemory readbytes

24 Oct 2019, 05:32

RHCP wrote:
24 Oct 2019, 05:06
You're reading the memory as a string. The 00 byte in a string acts as a null terminator, i.e. it ends the string.
What are you trying to do with the string of hex bytes after you read it?

Image

Code: Select all

calc.readRaw(0x283E85E1196, myBuffer, 10)
msgbox % bufferToHex(myBuffer, 10)

bufferToHex(byRef buffer, sizeBytes)
{
    loop % sizeBytes
        s .= Format("{:02X} ", NumGet(&buffer + 0, A_Index - 1, "UChar"))
    return rtrim(s, A_space)
}
Thank you for your help. :bravo:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Tech Stuff, Vanda_a and 375 guests