Jump to content

Recommended Posts

Posted (edited)
  On 5/17/2020 at 9:34 PM, Danyfirex said:

compare if they have same value

Expand  

Yes they are the same, i don't know why i didn't thought about that in the first place.

Thanks.

 

  On 5/17/2020 at 9:34 PM, Danyfirex said:

maybe I can do it in my dreams meanwhile

Expand  

It's always good to dream! But soon everything will be better! 🍻

Edited by MrCreatoR

 

  Reveal hidden contents

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Posted
Posted (edited)

@Danyfirex, this look awesome, very cool.

The _WM_COPYDATA is used as an event, to trigger the read memory.
Is there a way, that is not too far out of your way, to trigger the memory read without using a GUI for it ?, as a memory write that triggers a memory read, or simple in the main loop read, that is not heavy for AutoIt ?

I know this is not the OP question but, can't help to wonder since is all a memory read/write and the GUI is just for the event handler. No GUI dependency would be like, WOW.

Thanks.

Edited by argumentum
grammar :)

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Posted (edited)

nah you need to use SetWindowSubclass

AutoItWinSetTitle(@ScriptName)
$hAutoitInternal = WinGetHandle(@ScriptName)

$hMsgProc = DllCallbackRegister(NewMessage, 'lresult', 'hwnd;uint;wparam;lparam;uint_ptr;dword_ptr')
_WinAPI_SetWindowSubclass($hAutoitInternal, DllCallbackGetPtr($hMsgProc), $iMyID)

Func NewMessage($hWnd, $iMsg, $wParam, $lParam, $iId, $pData)
    #forceref $iID, $pData
    Return _WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam)
EndFunc

Func _Exit()
    If $hMsgProc Then
        _WinAPI_RemoveWindowSubclass($hAutoitInternal, DllCallbackGetPtr($hMsgProc), $iMyID)
        DllCallbackFree($g_hMsgProc)
    EndIf

 

Edited by Bilgus
Add #forceref $iID, $pData Return _WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam)
Posted
  Quote

...the script needs a loop, OnEvent or not. So, a loop is not a big deal.

Expand  

When you do your own message loop it has to be pumped in a timely manner so it sometimes becomes a big deal

at least with the subclass you can still have AutoIt take care of the minute 

Posted (edited)

No you just pass on what you don't want to handle to the default with 

_WinAPI_DefSubclassProc()

The helpfile explains it pretty clearly

 

Edited by Bilgus
Posted
  On 5/17/2020 at 11:22 PM, Bilgus said:

When you do your own message loop it has to be pumped in a timely manner so it sometimes becomes a big deal ...

Expand  

...all this is way above my pay grade !.
I would have to build some coding experience to comfortably code with sub-classing.
Thanks for the coding class :) 

I'll give a try in one of those moments when I'm bored.
It'll be good to expand my knowing to the 
point that this technique is in my arsenal :D  

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Posted (edited)

OH don't conflate the two, Subclassing an existing winproc is not doing your own message loop its the same idea as GUIRegister message

doing your own message loop isn't near as simple

Edited by Bilgus
Posted (edited)

Using COM for IPC and triggering events without a loop but via ObjEvent() could be a good method too.

Edit: Or do something like this in a loop and look for changes / reset the var when read.

 

Edited by KaFu
Posted (edited)

looks like a solution to my question :) 
...it does crash running x64 :( 

@trancexx, ..it been about a decade since the code. Can it be fixed ?
..it won't run on v3.3.6.1 or 3.3.8.1 either ( on Win10 ), so maybe there was no solution from the get go, regarding x64.
Not that I "need" to run x64 but your view regarding this is welcomed.

Edit: ..now that I read more about it, this would be an overkill, and misused to fit the purpose of triggering an event. 

Edited by argumentum

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

  • 4 years later...
Posted
  On 5/17/2020 at 9:09 AM, Danyfirex said:

@MrCreatoR I meant something like this:

 

#AutoIt3Wrapper_UseX64=y
#include <WindowsConstants.au3>
#include <WinAPIProc.au3>
#include <WinAPIMem.au3>
#include <String.au3>

Global Const $tagCOPYDATASTRUCT = 'ulong_ptr dwData;' & _
        'dword cbData;' & _
        'ptr lpData'


Global $stStr = 0
Global $bExit = False
Global $hGUI

If $CmdLine[0] And $CmdLine[1] = '/Child' Then
    $hGUI = GUICreate('Child')
    GUIRegisterMsg($WM_COPYDATA, '_WM_COPYDATA')
    Do
        Sleep(10)
    Until $bExit
    Exit
EndIf

Run(@AutoItExe & ' /AutoIt3ExecuteScript "' & @ScriptFullPath & '" /Child')
$hChild = WinWait('[CLASS:AutoIt v3 GUI;TITLE:Child]')
Sleep(500) ; ...relax
$hTimer = TimerInit() ; ... timer
Local $sDataToSend= "A_" & _StringRepeat('Send', Random(10, 100)) & "_Y" 
$sRet = _Send($hChild,$sDataToSend)
$hTimer = Round(TimerDiff($hTimer), 5) ; ..time it took to return
MsgBox(64, 'Return - ' & $hTimer, $sRet)

Func _Send($hWnd,$sDataToSend)
    Local $tPtr = DllStructCreate("ptr Data") ;Pointer for reading vRet Value
    Local $iProcessID = @AutoItPID
    Local $tData = DllStructCreate("Ptr pReturn;long pid;wchar Data[" & (StringLen($sDataToSend) + 1) & "]")
    $tData.pReturn = DllStructGetPtr($tPtr)
    $tData.PID = $iProcessID ;Pid for write memory
    $tData.Data = $sDataToSend ;Data to Send

;~  ConsoleWrite("$tData.pid: " & $tData.PID & @CRLF)
;~  ConsoleWrite("$tData.Data: " & $tData.Data & @CRLF)
    Local $tCopyData = DllStructCreate($tagCOPYDATASTRUCT)
    $tCopyData.cbData = DllStructGetSize($tData)
    $tCopyData.lpData = DllStructGetPtr($tData)
    Local $aRet = DllCall('user32.dll', 'lresult', 'SendMessage', 'hwnd', $hWnd, 'uint', $WM_COPYDATA, 'ptr', 0, 'ptr', DllStructGetPtr($tCopyData))
;~  ConsoleWrite("$tData.pReturn: " & $tData.pReturn & @CRLF)
;~  ConsoleWrite("$tPtr.Data: " & $tPtr.Data & @CRLF)
    Local $tSize = _WinAPI_ReadProcessMemoryEx(WinGetProcess($hWnd), Ptr($tPtr.Data), 'long iSize')
    Local $stStr = _WinAPI_ReadProcessMemoryEx(WinGetProcess($hWnd), Ptr($tPtr.Data + 4), 'wchar sStr[' & $tSize.iSize & ']')

    Return DllStructGetData($stStr, 'sStr')
EndFunc   ;==>_Send

Func _WM_COPYDATA($hWnd, $iMsg, $wParam, $lParam)
    $bExit = True
    Local $vRet = "A_" & _StringRepeat('Return', Random(10, 100)) & "_Y" ; Return
    Local $iLen = (StringLen($vRet) + 1)
    Local $tCopyData = DllStructCreate($tagCOPYDATASTRUCT, $lParam)
    Local $tData = DllStructCreate("Ptr pReturn;long PID;wchar Data[" & ($tCopyData.cbData - (@AutoItX64 ? 12 : 8)) & "]", $tCopyData.lpData)
    $stStr = DllStructCreate('long iSize;wchar sStr[' & $iLen & ']')
    DllStructSetData($stStr, 'iSize', $iLen)
    DllStructSetData($stStr, 'sStr', $vRet)
    Return _WinAPI_WriteProcessMemoryPtr($tData.PID, $tData.pReturn, DllStructGetPtr($stStr))
EndFunc   ;==>_WM_COPYDATA


Func _WinAPI_WriteProcessMemoryPtr($iProcessID, $pPointer, $ptPtr)
    Local $iSYNCHRONIZE = (0x00100000), $iSTANDARD_RIGHTS_REQUIRED = (0x000F0000)
    Local $iPROCESS_ALL_ACCESS = ($iSTANDARD_RIGHTS_REQUIRED + $iSYNCHRONIZE + 0xFFF)
    Local $hProcess, $Struct, $StructPtr, $StructSize, $iWriten

    $hProcess = _WinAPI_OpenProcess($iPROCESS_ALL_ACCESS, False, $iProcessID)
    If @error Then Return SetError(@error, 1, $Struct)

    Local $Struct = DllStructCreate("ptr Data")
    $StructSize = DllStructGetSize($Struct)
    $StructPtr = DllStructGetPtr($Struct)
    $Struct.Data = $ptPtr

    Local $bWrite = _WinAPI_WriteProcessMemory($hProcess, $pPointer, $StructPtr, $StructSize, $iWriten)
    _WinAPI_CloseHandle($hProcess)

    Return SetError(@error, $iWriten, $bWrite)
EndFunc   ;==>_WinAPI_WriteProcessMemoryPtr



Func _WinAPI_ReadProcessMemoryEx($iProcessID, $pPointer, $sStructTag)
    Local $iSYNCHRONIZE = (0x00100000), $iSTANDARD_RIGHTS_REQUIRED = (0x000F0000)
    Local $iPROCESS_ALL_ACCESS = ($iSTANDARD_RIGHTS_REQUIRED + $iSYNCHRONIZE + 0xFFF)
    Local $hProcess, $Struct, $StructPtr, $StructSize, $Read

    $hProcess = _WinAPI_OpenProcess($iPROCESS_ALL_ACCESS, False, $iProcessID)
    If @error Then Return SetError(@error, 1, $Struct)

    $Struct = DllStructCreate($sStructTag)
    $StructSize = DllStructGetSize($Struct)
    $StructPtr = DllStructGetPtr($Struct)

    _WinAPI_ReadProcessMemory($hProcess, $pPointer, $StructPtr, $StructSize, $Read)
    _WinAPI_CloseHandle($hProcess)

    Return SetError(@error, $Read, $Struct)
EndFunc   ;==>_WinAPI_ReadProcessMemoryEx

Saludos

 

Expand  

Hi,

how can I get the value of $sDataToSend in _WM_COPYDATA?

_WM_COPYDATA only returns the string in $vRet.

I want to make a selection based on the lParam and return a value or string

 

 

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...