RHCP Please Help (processPatternScan) Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
loter
Posts: 38
Joined: 26 May 2016, 00:35

RHCP Please Help (processPatternScan)

16 Jul 2016, 14:58

Code: Select all

#classmemory.ahk

StringToHex(String)
	{
	local Old_A_FormatInteger, CharHex, HexString
	
	If !String
		Return 0
	
	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
	}

GuiControlGet,name ; < Edit Get. For example, "Michael"

winwait,ahk_class notepad

winget,pid,pid,ahk_class notepad

global pid

notepad := new _ClassMemory("ahk_pid" pid, "", hProcessCopy)

var1=% StringToHex(name) ; << 0x4d,0x69,0x63,0x68,0x61,0x65,0x6c, (Hex value of Michael, And end exist a comma)

StringTrimright,Pattern,var1,1 ; <<  0x4d,0x69,0x63,0x68,0x61,0x65,0x6c (Remove the comma at the end)

stringAddress :=var.processPatternScan(,,Pattern)  ; <<  Not recognized.

if stringAdress > 0 
{
msgbox found !
}
else
{
msgbox Not Found!
}
//

stringAddress :=var.processPatternScan(,,Pattern) is not recognized.
and,

aPattern := [ 0x4d,0x69,0x63,0x68,0x61,0x65,0x6c ]
stringAddress := notepad.processPatternScan(,, aPattern*)

This method is not available to me.
because, my case, hex is a variable.
I need help . Please


Below is unsuccessful ones.
stringAddress :=var.processPatternScan(,,Pattern*)
stringAddress :=var.processPatternScan(,,"Pattern")
stringAddress :=var.processPatternScan(,,(Pattern))
RHCP
Posts: 202
Joined: 30 Sep 2013, 10:59

Re: RHCP Please Help (processPatternScan)  Topic is solved

17 Jul 2016, 06:03

This method is not available to me.
because, my case, hex is a variable.
I need help . Please

Below is unsuccessful ones.
stringAddress :=var.processPatternScan(,,Pattern*)
stringAddress :=var.processPatternScan(,,"Pattern")
stringAddress :=var.processPatternScan(,,(Pattern))
You need to read the AHK manual and learn how variadic functions/parameters work. In short, the easiest way is to create an array that contains each byte value, and then pass that array to the function using 'Array*' syntax. Also, in your script, the 'var' in var.processPatternScan() is incorrect. It should have been notepad.processPatternScan().


The function stringToPattern() in classMemory does exactly what your function is trying to do.

Code: Select all

    ; Method:           stringToPattern(string, encoding := "UTF-8", insertNullTerminator := False)
    ;                   Converts a text string parameter into an array of bytes pattern (AOBPattern) that
    ;                   can be passed to the various pattern scan methods i.e.  modulePatternScan(), addressPatternScan(), rawPatternScan(), and processPatternScan()
    ; 
    ; Parameters:
    ;   string                  The text string to convert.
    ;   encoding                This refers to how the string is stored in the program's memory.
    ;                           UTF-8 and UTF-16 are common. Refer to the AHK manual for other encoding types.  
    ;   insertNullTerminator    Includes the null terminating byte(s) (at the end of the string) in the AOB pattern.
    ;                           This should be set to 'false' unless you are certain that the target string is null terminated and you are searching for the entire string or the final part of the string.
    ;
    ; Return Values: 
    ;   Object          Success - The returned object contains the AOB pattern. 
    ;   -1              An empty string was passed.
    ;
    ;   Examples:
    ;                   pattern := stringToPattern("This text exists somewhere in the target program!")



Here is a test script using that function. It searches for the text 'this is a test' which I typed into notepad.

Your original script had a number of errors which would have stopped it from working correctly. I've corrected and commented some of them.

Code: Select all

#SingleInstance force
; #classmemory.ahk ; This is incorrect.
#Include <classMemory> ; classMemory.ahk must be placed in your 'lib' folder. Refer to the ahk manual

if (_ClassMemory.__Class != "_ClassMemory")
    msgbox class memory not correctly installed. Or the (global class) variable "_ClassMemory" has been overwritten


winwait, ahk_class Notepad      ; ** Note the capital 'N' in Notepad i.e. ahk_class Notepad vs ahk_class notepad
winget, pid, pid, ahk_class Notepad
notepad := new _ClassMemory("ahk_pid " pid, "", hProcessCopy) ; *** Note the space in "ahk_pid " pid ***
; You can also just do this:
; notepad := new _ClassMemory("ahk_exe notepad.exe", "", hProcessCopy) 

if !isObject(notepad) 
{
    msgbox failed to open a handle
    if (hProcessCopy = 0)
        msgbox The program isn't running (not found) or you passed an incorrect program identifier parameter. 
    else if (hProcessCopy = "")
        msgbox OpenProcess failed. If the target process has admin rights, then the script also needs to be ran as admin. Consult A_LastError for more information.
}


text := "this is a test"

pattern := notepad.stringToPattern(text, "UTF-16") ; My notepad stores this string as unicode, hence I have to specify 'UTF-16' (unicode) as the encoding

stringAddress := notepad.processPatternScan(,, pattern*) 
 
if stringAddress > 0  ; you had a typo in stringAddress 
{
    stringAddressHex := "0x" ConvertBase(10, 16, stringAddress) ; the returned address is in decimal, convert it to hex for readability (this IS OPTIONAL) 
    msgbox AHK found string at addess: %stringAddressHex%
}
else
{
    msgbox Not Found!`nReturn Value: %stringAddress%
}



ConvertBase(InputBase, OutputBase, number)
{
    static u := A_IsUnicode ? "_wcstoui64" : "_strtoui64"
    static v := A_IsUnicode ? "_i64tow"    : "_i64toa"
    VarSetCapacity(s, 65, 0)
    value := DllCall("msvcrt.dll\" u, "Str", number, "UInt", 0, "UInt", InputBase, "CDECL Int64")
    DllCall("msvcrt.dll\" v, "Int64", value, "Str", s, "UInt", OutputBase, "CDECL")
    return s
}
Image
RHCP
Posts: 202
Joined: 30 Sep 2013, 10:59

Re: RHCP Please Help (processPatternScan)

17 Jul 2016, 06:19

It's important to remember that class methods (like the type in class memory) do not behave like normal functions. Unlike normal functions, AHK will not warn you if you try to call non existent methods (e.g. you didn't include the library) or you pass them the wrong number of parameters - in those two cases the methods will just fail silently and return null/blank.
loter
Posts: 38
Joined: 26 May 2016, 00:35

Re: RHCP Please Help (processPatternScan)

17 Jul 2016, 06:53

Wow , I really appreciate it.

I have the wrong understanding of the variables.

I was solved with the help of you.
Galaxis
Posts: 73
Joined: 04 Feb 2016, 20:09

Re: RHCP Please Help (processPatternScan)

16 Sep 2017, 22:42

RHCP,
Im curious, why does this not detect my Steam Game? Message is "Failed to Open handle"

if (_ClassMemory.__Class != "_ClassMemory")
msgbox class memory not correctly installed. Or the (global class) variable "_ClassMemory" has been overwritten

game := new _ClassMemory("ahk_exe MKX.exe", "", hProcessCopy)

; Check if the above method was successful.
if !isObject(game)
{
msgbox failed to open a handle
if (hProcessCopy = 0)
msgbox The program isn't running (not found) or you passed an incorrect program identifier parameter.
else if (hProcessCopy = "")
msgbox OpenProcess failed. If the target process has admin rights, then the script also needs to be ran as admin. Consult A_LastError for more information.
ExitApp
}


This one from AHK Documentation works though, no problem:

Code: Select all

Process, wait, MKX.exe, 5.5
MK = %ErrorLevel%  ; Save the value immediately since ErrorLevel is often changed.
if MK = 0
{
    MsgBox The specified process did not appear within 5.5 seconds.
    return
}
; Otherwise:
MsgBox A matching process has appeared (Process ID is %MK%).
Process, priority, %MK%, Low
Process, priority, , High  ; Have the script set itself to high priority.

Process, WaitClose, %MK%, 5
if ErrorLevel ; The PID still exists.
    MsgBox The process did not close within 5 seconds.

But I'm guessing, in order to use any of these functions below, the first one "must" work- instead of using the one from AHK documentation.

getProcessBaseAddress()
hexStringToPattern()
stringToPattern()
modulePatternScan()
addressPatternScan()
processPatternScan()
RHCP
Posts: 202
Joined: 30 Sep 2013, 10:59

Re: RHCP Please Help (processPatternScan)

17 Sep 2017, 03:02

Hard to say. I've yet to find a game that it hasn't worked with, steam or otherwise. Usually ahk_exe works as an identifier, but there are rare occasions where you need to use some other identifier.

What is Mkx.exe ???

You could try launching the script as admin.
Every once in a while a game will require debugPrivileges to work. Try adding the code below as the first line in the script.

Code: Select all

_classmemory.setSeDebugPrivilege()
Galaxis
Posts: 73
Joined: 04 Feb 2016, 20:09

Re: RHCP Please Help (processPatternScan)

17 Sep 2017, 12:16

Dude that 1 line of code worked! You are INSANE! are you the PC god?

Thanks man

*snickers* as he just said, "Hard to say" lol

MKX = Mortal Kombat 10 - Fighting Game

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot] and 277 guests