Jump to content
Sign in to follow this  
SomeoneHere

VirtualAllocEx in AutoIt?

Recommended Posts

SomeoneHere

i'm trying to allocate some virtual memory so i can save information to it... is there a way to do it in AutoIt such as a function that AutoIt contains or perhaps one that someone has wrote? kind of like VirtualAllocEx?

Edited by SomeoneHere

Share this post


Link to post
Share on other sites
Izebize

Look for DllCall in the help file or try this.

Edited by Izebize

Share this post


Link to post
Share on other sites
Authenticity

>_< heh. Read the help file, the function is _MemVirtualAllocEx() which is defined in the Memory.au3 library.

Share this post


Link to post
Share on other sites
SomeoneHere

:( heh. Read the help file, the function is _MemVirtualAllocEx() which is defined in the Memory.au3 library.

thanks, exactly what i was looking for :(

*ignores Izebize's ego* >_<

Share this post


Link to post
Share on other sites
SomeoneHere

alright, so i'm having trouble... no matter what i do, i always get 0x00000000 returned as the allocated memory's address... i tried setting $pAddress to both 0 and -1 (to have hopefully have it choose for me like VirtualAllocEx()) but nothing >_< ...

#include "NomadMemory.au3"
#Include <Memory.au3>

Opt("WinTitleMatchMode", 2)

While 1
    If WinActive("Conquer") == 1 Then ;check if CO is the active window
            $PID = WinGetProcess("[ACTIVE]", "")
            
            $MemID = _MemoryOpen($PID)
            
            $baseAddrs = _MemVirtualAllocEx($MemID,0x00800000,128,$MEM_COMMIT,$PAGE_EXECUTE_READWRITE)
            
            _MemoryWrite($baseAddrs, $MemID, 0x1a7f8ae8)
            
            MsgBox(0,"",$baseAddrs)

            MsgBox(0,"","0x" & hex(_MemoryRead($MemID,$baseAddrs),8))
    EndIf
WEnd

this is NomadMemory.au3 http://pastebin.com/mb725101

Edited by SomeoneHere

Share this post


Link to post
Share on other sites
Authenticity

_MemoryOpen() returns an array type, but the _MemVirtualAllocEx() expects a handle. If the call to _MemoryOpen() was successful then the handle is stored in $MemID[1]. Read the description of each function (even the UDF's which are not part of the AutoIt native UDF) before you're using it.

Share this post


Link to post
Share on other sites
SomeoneHere

_MemoryOpen() returns an array type, but the _MemVirtualAllocEx() expects a handle. If the call to _MemoryOpen() was successful then the handle is stored in $MemID[1]. Read the description of each function (even the UDF's which are not part of the AutoIt native UDF) before you're using it.

thank you for the explanation id rather much prefer a "this is what your doing wrong" then "this is what you have to do", that explains y i could never get anything from MsgBox(0,"",$MemID)... i should of done MsgBox(0,"",$MemID[1])... but anyway i changed it, and i still get the same results... also... if i leave $pAddress at 0, will it allocate the memory to a region for me?

lpAddress [in, optional]

The pointer that specifies a desired starting address for the region of pages that you want to allocate.

If you are reserving memory, the function rounds this address down to the nearest multiple of the allocation granularity.

If you are committing memory that is already reserved, the function rounds this address down to the nearest page boundary. To determine the size of a page and the allocation granularity on the host computer, use the GetSystemInfo function.

If lpAddress is NULL, the function determines where to allocate the region.

this is my code now, and i'm still getting the same results . . . both MsgBoxes give me 0x00000000

#include <NomadMemory.au3>
#Include <Memory.au3>

Opt("WinTitleMatchMode", 2)

While 1
    If WinActive("Conquer") == 1 Then ;check if CO is the active window
            $PID = WinGetProcess("[ACTIVE]", "")
            
            $MemID = _MemoryOpen($PID)
            
            $baseAddrs = _MemVirtualAllocEx($MemID[1],0x00800000,128,$MEM_COMMIT,$PAGE_EXECUTE_READWRITE)
            
            _MemoryWrite($baseAddrs, $MemID, 0x1a7f8ae8)
            
            MsgBox(0,"",$baseAddrs)
            
            MsgBox(0,"","0x" & hex(_MemoryRead($MemID,$baseAddrs),8))
    EndIf
WEnd
Edited by SomeoneHere

Share this post


Link to post
Share on other sites
Authenticity

#include <NomadMemory.au3>
#Include <Memory.au3>

Opt("WinTitleMatchMode", 2)

While 1
    If WinActive("Conquer") == 1 Then ;check if CO is the active window
            $PID = WinGetProcess("[ACTIVE]", "")
            
            $MemID = _MemoryOpen($PID)
            
            $baseAddrs = _MemVirtualAllocEx($MemID[1],0,128,BitOR($MEM_COMMIT, $MEM_RESERVE),$PAGE_EXECUTE_READWRITE)
            
            _MemoryWrite($baseAddrs, $MemID, 0x1a7f8ae8)
            
            ; MsgBox(0,"",$baseAddrs) Array type not supported by this function. Read the function description.
            
            MsgBox(0,"","0x" & hex(_MemoryRead($MemID,$baseAddrs),8))
    EndIf
WEnd

If you won't read the documentation you'll never get the idea. Try to spend a few minutes to see how a function should be invoked. Sorry for boring topic. >_<

Share this post


Link to post
Share on other sites
SomeoneHere

#include <NomadMemory.au3>
#Include <Memory.au3>

Opt("WinTitleMatchMode", 2)

While 1
    If WinActive("Conquer") == 1 Then ;check if CO is the active window
            $PID = WinGetProcess("[ACTIVE]", "")
            
            $MemID = _MemoryOpen($PID)
            
            $baseAddrs = _MemVirtualAllocEx($MemID[1],0,128,BitOR($MEM_COMMIT, $MEM_RESERVE),$PAGE_EXECUTE_READWRITE)
            
            _MemoryWrite($baseAddrs, $MemID, 0x1a7f8ae8)
            
            ; MsgBox(0,"",$baseAddrs) Array type not supported by this function. Read the function description.
            
            MsgBox(0,"","0x" & hex(_MemoryRead($MemID,$baseAddrs),8))
    EndIf
WEnd

If you won't read the documentation you'll never get the idea. Try to spend a few minutes to see how a function should be invoked. Sorry for boring topic. >_<

i've read it already . . . and i was right . . . but for some reason it wasn't working... idk, i rewrote it all (cuz i realized i would of continuously be allocating memory) and this is what i have, and it works fine now :( ty

#include <NomadMemory.au3>
#Include <Memory.au3>

HotKeySet("x", "Allocate")

Opt("WinTitleMatchMode", 2)

$baseAddrs = 0

While 1
    ToolTip($baseAddrs,10,10)
    sleep(500)
WEnd

Func Allocate()
    If WinActive("Conquer") == 1 Then ;check if CO is the active window
            $PID = WinGetProcess("[ACTIVE]", "")
            
            $MemID = _MemoryOpen($PID)
            
            $baseAddrs = _MemVirtualAllocEx($MemID[1],0,128,$MEM_COMMIT,$PAGE_EXECUTE_READWRITE)
            
            _MemoryWrite($baseAddrs, $MemID, 0x1a7f8ae8)

    EndIf
EndFunc
Edited by SomeoneHere

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.