Sign in to follow this  
Followers 0
Chuuy

Memory Reading

21 posts in this topic

#1 ·  Posted (edited)

First, I'll give a brief explanation of the program I'm coding.

Basically, it clicks in one spot and then in another spot to refresh a list. When an address on that list contains the value 1082002, then check if another address contains the value < 1335. If so, then buy.

So, I found this:

;=================================================================================================
; Function:   _MemoryRead($iv_Address, $ah_Handle(, $sv_Type))
; Description:  Reads the value located in the memory address specified.
; Parameter(s):  $iv_Address - The memory address you want to read from. It must be in hex
;                         format (0x00000000).
;              $ah_Handle - An array containing the Dll handle and the handle of the open
;                        process as returned by _MemoryOpen().
;              $sv_Type - (optional) The "Type" of value you intend to read.  This is set to
;                       'dword'(32bit(4byte) signed integer) by default.  See the help file
;                       for DllStructCreate for all types.
;                       An example: If you want to read a word that is 15 characters in
;                       length, you would use 'char[16]'.
; Requirement(s):   The $ah_Handle returned from _MemoryOpen.
; Return Value(s):  On Success - Returns the value located at the specified address.
;              On Failure - Returns 0
;              @Error - 0 = No error.
;                     1 = Invalid $ah_Handle.
;                     2 = $sv_Type was not a string.
;                     3 = $sv_Type is an unknown data type.
;                     4 = Failed to allocate the memory needed for the DllStructure.
;                     5 = Error allocating memory for $sv_Type.
;                     6 = Failed to read from the specified process.
; Author(s):        Nomad
; Note(s):    Values returned are in Decimal format, unless specified as a 'char' type, then
;              they are returned in ASCII format.  Also note that size ('char[size]') for all
;              'char' types should be 1 greater than the actual size.
;=================================================================================================
Func _MemoryRead($iv_Address, $ah_Handle, $sv_Type = 'dword')
    
    If Not IsArray($ah_Handle) Then
        SetError(1)
        Return 0
    EndIf
    
    Local $v_Buffer = DllStructCreate($sv_Type)
    
    If @Error Then
        SetError(@Error + 1)
        Return 0
    EndIf
    
    DllCall($ah_Handle[0], 'int', 'ReadProcessMemory', 'int', $ah_Handle[1], 'int', $iv_Address, 'ptr', DllStructGetPtr($v_Buffer), 'int', DllStructGetSize($v_Buffer), 'int', '')
    
    If Not @Error Then
        Local $v_Value = DllStructGetData($v_Buffer, 1)
        Return $v_Value
    Else
        SetError(6)
        Return 0
    EndIf
    
EndFunc

What is $ah_Handle, or how do I find it?

I also have another question, for the Buy function I want to do at the end, is it possible to send a packet to the game? If not, I can just click here, then here, and it'll buy like that, but packets would be faster, and I need to make this as fast as possible. Thanks.

Edited by Chuuy

Share this post


Link to post
Share on other sites



That's from NomadMemory, many threads about that.

First you need to use _MemoryOpen

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Alright, I was thinking completely differently then I should've been. So now I have this.

#include "NomadMemory.au3"

_MemoryOpen($iv_Pid = , $iv_DesiredAccess = 0x1F0FFF, $if_InheritHandle = 1) ; Will find the PID later


Do Refresh()
    Until _MemoryRead($iv_Address = , $ah_Handle, $sv_Type = 'dword') = 1082002 ; Will find the address later

If _MemoryRead($iv_Address = , $ah_Handle, $sv_Type = 'dword') < 1355 ; Will find the address later
    Then Buy()
    
Func Refresh()
    MouseClick ( "main" [, x, y [, 1 [, 0 ]]] ) ; Will find mouse xy coords later
    MouseClick ( "main" [, x, y [, 1 [, 0 ]]] ) ; Will find mouse xy coords later
    Return
EndFunc

Func Buy()
    MouseClick ( "main" [, x, y [, 1 [, 0 ]]] ) ; Will find mouse xy coords later
    MouseClick ( "main" [, x, y [, 1 [, 0 ]]] ) ; Will find mouse xy coords later
    Return
EndFunc

It has been a while since I last used AutoIt, so I'm not sure if this would do what I want it to do.

Edited by Chuuy

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Man I keep noticing that I'm doing a lot of syntax errors.

Here's the code I have now, I think this is correct:

#include "NomadMemory.au3"

Dim $Item, $Price

_MemoryOpen($iv_Pid =, $iv_DesiredAccess = 0x1F0FFF, $if_InheritHandle = 1)
_MemoryRead($iv_Address =, $ah_Handle, $sv_Type = 'dword') = $Item
_MemoryRead($iv_Address =, $ah_Handle, $sv_Type = 'dword') = $Price

Do Refresh()
Until $Item = 1082002

If $Price < 1355
    Then Buy()
EndIf

Func Refresh()
    MouseClick("main"[, x, y[, 1[, 0]]])
    MouseClick("main"[, x, y[, 1[, 0]]])
    Return
EndFunc   ;==>Refresh

Func Buy()
    MouseClick("main"[, x, y[, 1[, 0]]])
    MouseClick("main"[, x, y[, 1[, 0]]])
    Return
EndFunc   ;==>Buy

EDIT: Declared variables. =0

Edited by Chuuy

Share this post


Link to post
Share on other sites

I'm completely confusing myself with which loops I should use when.

Maybe someone can tell me what type of loop to use if I want to process these statements this way:

Refresh() until $Item = 1082002, if not restart Refresh(). Check if $Price < 1355, if not restart Refresh(), if so then Buy(). Then restart at Refresh().

I know I need to include these functions:

_MemoryOpen($iv_Pid =, $iv_DesiredAccess = 0x1F0FFF, $if_InheritHandle = 1) ; I'm guessing this goes at the top and only needs to be run once?
_MemoryRead($iv_Address =, $ah_Handle, $sv_Type = 'dword') = $Item ; Reads the value at the address and sets it as $Item, I want it to stop if $Item = 1082002, and then to check if &Price < 1355.
_MemoryRead($iv_Address =, $ah_Handle, $sv_Type = 'dword') = $Price ; Reads the value at the address and sets it as $Price, I want it to stop if $Price < 1355, and I want it to Buy() if true.  Then I want the code to start again at Refresh().oÝ÷ Ù8^±æ«zlºw-ìjëh×6Func Refresh()
    MouseClick("main"[, x, y[, 1[, 0]]])
    MouseClick("main"[, x, y[, 1[, 0]]])
    Return
EndFunc   ;==>Refresh

Func Buy()
    MouseClick("main"[, x, y[, 1[, 0]]])
    MouseClick("main"[, x, y[, 1[, 0]]])
    Return
EndFunc   ;==>Buy

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Before you go ahead, you should test your values.

MsgBox (0, "", _MemoryRead($iv_Address =, $ah_Handle, $sv_Type = 'dword') = $Item)

MsgBox (0, "", _MemoryRead($iv_Address =, $ah_Handle, $sv_Type = 'dword') = $Price)

Put these messages, are you reading the correct stuff ?

Also, your syntax is horribly wrong :-(

Edited by Inverted

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Before you go ahead, you should test your values.

MsgBox (0, "", _MemoryRead($iv_Address =, $ah_Handle, $sv_Type = 'dword') = $Item)

MsgBox (0, "", _MemoryRead($iv_Address =, $ah_Handle, $sv_Type = 'dword') = $Price)

Put these messages, are you reading the correct stuff ?

Also, your syntax is horribly wrong :-(

Well, I haven't added in the address to read for yet, I want to write the code first, then I'll load up Cheat Engine/Ollydbg and add in the addresses, the PID, and the mouse xy coordinates.

Can you tell me what's wrong with my syntax. =0 I'm really struggling with this.

Edited by Chuuy

Share this post


Link to post
Share on other sites

Well it's me again. I revised my code, and I believe this is correct syntax. Please check it over, thanks. :D

#include <NomadMemory.au3>

Dim $Item, $Price

_MemoryOpen($iv_Pid =, $iv_DesiredAccess = 0x1F0FFF, $if_InheritHandle = 1) ; Will set PID later

While 1
    MouseClick("main"[, x, y[, 1[, 0]]]) ; Will set x and y later
    MouseClick("main"[, x, y[, 1[, 0]]]) ; Will set x and y later
    _MemoryRead($iv_Address =, $ah_Handle, $sv_Type = 'dword') = $Item ; Will set address later
    _MemoryRead($iv_Address =, $ah_Handle, $sv_Type = 'dword') = $Price ; Will set address later
    If $Item = 1082002 And $Price < 1355 Then
        MouseClick("main"[, x, y[, 1[, 0]]]) ; Will set x and y later
        MouseClick("main"[, x, y[, 1[, 0]]]) ; Will set x and y later
    EndIf
WEnd

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Well it's me again. I revised my code, and I believe this is correct syntax. Please check it over, thanks. :D

#include <NomadMemory.au3>

Dim $Item, $Price

_MemoryOpen($iv_Pid =, $iv_DesiredAccess = 0x1F0FFF, $if_InheritHandle = 1) ; Will set PID later

While 1
    MouseClick("main"[, x, y[, 1[, 0]]]) ; Will set x and y later
    MouseClick("main"[, x, y[, 1[, 0]]]) ; Will set x and y later
    _MemoryRead($iv_Address =, $ah_Handle, $sv_Type = 'dword') = $Item ; Will set address later
    _MemoryRead($iv_Address =, $ah_Handle, $sv_Type = 'dword') = $Price ; Will set address later
    If $Item = 1082002 And $Price < 1355 Then
        MouseClick("main"[, x, y[, 1[, 0]]]) ; Will set x and y later
        MouseClick("main"[, x, y[, 1[, 0]]]) ; Will set x and y later
    EndIf
WEnd
Edited by Zisly

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Well, I was basically copying the functions along with the parameters from NomadMemory.au3, and he defined variables in the parameters. Unless you meant x and y under MouseClick, that's because each click is going to be in a different spot. Also, should I declare the value of $iv_Address as a local address? But that wouldn't work, because they're both different addresses. Should I just write in the address like below?

So, this code would work fine for my purposes:

#include <NomadMemory.au3>

Dim $Item, $Price

$ah_Handle=_MemoryOpen("MapleStory.exe")

While 1
    Local $iv_Address
    MouseClick("main", x, y, 1, 0) ; Will set x and y later
    MouseClick("main", x, y, 1, 0) ; Will set x and y later
    $Item=_MemoryRead(0x000000, $ah_Handle) ; Will change to correct address later
    $Price=_MemoryRead(0x000000, $ah_Handle) ; Will change to correct address later
    If $Item = 1082002 And $Price < 1355 Then
        MouseClick("main", x, y, 1, 0) ; Will set x and y later
        MouseClick("main", x, y, 1, 0) ; Will set x and y later
    EndIf
WEnd
Edited by Chuuy

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

No need to declare variables for the addresses then in my opinion then :D

And yeah, that code should work :D

Edit; I saw that your making this for Maplestory, I've heard that they got a gameguard, I'm pretty sure it will pick this up.

So cheating won't really pay of :/

Edited by Zisly

Share this post


Link to post
Share on other sites

No need to declare variables for the addresses then in my opinion then ;)

And yeah, that code should work :D

Alright, thanks a lot. :D I'm going to be expanding this into a bigger and more automated bot, so I'll post if I have any more problems, but for now, this is great and I need to load up Cheat Engine. Thanks. :P

Share this post


Link to post
Share on other sites

Oh sorry, one more thing. Does anyone know anything about sending packets with AutoIt?

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Check out TCP in the help file.

Edited by Zisly

Share this post


Link to post
Share on other sites

Check out TCP in the help file.

Ooh, alright, thanks again! :D

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

I'm having trouble trying to send packets.

#include <NomadMemory.au3>

Dim $Item, $Price

$ah_Handle = _MemoryOpen("MapleStory.exe")
$SocketID = TCPConnect(63.251.217.122, 8989)

While 1
    TCPSend($SocketID, F1 00 05 01 00 00 00 02 00 00 00 00 00 00 00 01 01 01 00 00 00 00 00)
    $Item = _MemoryRead(0x000000, $ah_Handle) ; Will change to correct address later
    $Price = _MemoryRead(0x000000, $ah_Handle) ; Will change to correct address later
    If $Item = 1082002 And $Price < 1355 Then
        MouseClick("main", 511, 183, 1, 0) ; Will set x and y later
        MouseClick("main", 448, 366, 1, 0) ; Will set x and y later
    EndIf
WEnd

I have the IP and port of what I want to send packets to, and I also have the packet. But I'm getting syntax errors.

Do you solve this by putting quotes around the IP and packet? Because I did that, and it compiled, but it wasn't working.

Edited by Chuuy

Share this post


Link to post
Share on other sites

No one knows about sending packets? :D

Share this post


Link to post
Share on other sites

You need to startup tcp.. read the examples in the helpfile next time.

#include <NomadMemory.au3>
; Start TCP 
TCPStartup()

Dim $Item, $Price

$ah_Handle = _MemoryOpen("MapleStory.exe")
$SocketID = TCPConnect('63.251.217.122', 8989)

While 1
    TCPSend($SocketID, 'F1 00 05 01 00 00 00 02 00 00 00 00 00 00 00 01 01 01 00 00 00 00 00')
    $Item = _MemoryRead(0x000000, $ah_Handle); Will change to correct address later
    $Price = _MemoryRead(0x000000, $ah_Handle); Will change to correct address later
    If $Item = 1082002 And $Price < 1355 Then
        MouseClick("main", 511, 183, 1, 0); Will set x and y later
        MouseClick("main", 448, 366, 1, 0); Will set x and y later
    EndIf
WEnd

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

You need to startup tcp.. read the examples in the helpfile next time.

#include <NomadMemory.au3>
; Start TCP 
TCPStartup()

Dim $Item, $Price

$ah_Handle = _MemoryOpen("MapleStory.exe")
$SocketID = TCPConnect('63.251.217.122', 8989)

While 1
    TCPSend($SocketID, 'F1 00 05 01 00 00 00 02 00 00 00 00 00 00 00 01 01 01 00 00 00 00 00')
    $Item = _MemoryRead(0x000000, $ah_Handle); Will change to correct address later
    $Price = _MemoryRead(0x000000, $ah_Handle); Will change to correct address later
    If $Item = 1082002 And $Price < 1355 Then
        MouseClick("main", 511, 183, 1, 0); Will set x and y later
        MouseClick("main", 448, 366, 1, 0); Will set x and y later
    EndIf
WEnd
Alright thanks, but I'm having trouble with this, and it's not the most imporant part, so I'm just going to go back to clicking with MouseClick.

However, a new question. It appears that they encrypted the price and that I can't read it out of memory, is it possible to use OCR or something of the sort to read the number?

EDIT: Well, I've found a lot of examples over the forum, so lets see what happens.

Update: Nevermind, I found the price in the memory. Should be good now. :D

Edited by Chuuy

Share this post


Link to post
Share on other sites

#include <NomadMemory.au3>

Dim $Item, $Price
$Startup = TCPStartup()
If $Startup = 0 Then MsgBox(0, "Error", "TCPStartup failed:" & @error)

HotKeySet("{ESC}", "Quit")

$Socket = TCPConnect("63.251.217.122", 8989)
If $Socket = -1 Then MsgBox(0, "Error", "TCPConnect failed:" & @error)
If @error = 1 Then MsgBox(0, "Error", "The IP Address is incorrect.")
If @error = 2 Then MsgBox(0, "Error", "The Port is incorrect.")

$ah_Handle = _MemoryOpen("MapleStory.exe")

While 1
    $Send = TCPSend($Socket, 'F1 00 05 01 00 00 00 02 00 00 00 00 00 00 00 01 01 01 00 00 00 00 00')
    If $Send = 0 Then MsgBox(0, "Error", "TCPSend failed:" & @error)
    TCPRecv($Socket, 2048) ; I set the max length of characters to a random number, I think it's enough for the packet listed below
    If $Item = 1082002 And $Price < 1355 Then
        $Send = TCPSend($Socket, 'F1 00 10 XX XX XX')
    EndIf
WEnd

Func Quit()
    Exit 0
EndFunc   ;==>Quit

Hi, it's me again. I'm basing the entire program off of reading and sending packets, but I have a few questions on recieving packets. Basically, when I TCPSend the first packet, it refreshes a list. When a new item is added to the list, I recieve a packet, which is what I'm trying to recieve in TCPRecv. Now, I want to read this packet. The packet I recieve will look like this:

37 01 15 A6 B8 00 00 10 00 00 00 01 00 00 00 02 00 00 00 00 00 00 00 01 01 02 E4 23 1F 00 00 00 80 05 BB 46 E6 17 02 02 00 00 00 00 00 2F 29 BE 01 8C 0A 00 00 72 01 00 00 00 00 00 00 00 D6 5B 5D A4 F1 C9 01 07 00 4D 61 78 41 75 72 61 0B 00 53 49 4E 64 55 52 75 6E 6E 69 6E 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 E4 23 1F 00 00 00 80 05 BB 46 E6 17 02 01 00 00 00 00 00 2D 29 BE 01 6C 07 00 00 22 01 00 00 00 00 00 00 00 D6 5B 5D A4 F1 C9 01 07 00 66 75 6C 61 6E 6F 78 0C 00 52 6F 43 6B 53 74 61 52 6C 78 58 78 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 25 21 1F 00 00 00 80 05 BB 46 E6 17 02 01 00 00 00 00 00 29 29 BE 01 6E 00 00 00 6F 00 00 00 00 00 00 00 00 D6 5B 5D A4 F1 C9 01 09 00 61 6E 74 31 66 72 33 33 7A 0C 00 45 6E 74 68 75 73 69 65 73 74 69 63 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 41 2D 1F 00 00 00 80 05 BB 46 E6 17 02 01 00 00 00 00 00 20 29 BE 01 6E 00 00 00 6F 00

The red part is the item ID, and the green part is the price. When the item ID = E4 23 1F And Price < 4B 05 then send the second packet where XX XX XX = The part above highlighted in Blue. I didn't see anything in the help file about this, and neither did searching the forum. So could I get some help please? Thank you. :D

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0