Jump to content
Busti

Is it possible to find out the memory address of a internal function and retreive the struct of it?

Recommended Posts

Posted (edited)

Hello,

I hope you are doing well.

I'm currently trying something out, and i would need to find the memory address of a function in my own script, to be able to retreive the dllstruct with _WinAPI_DisplayStruct (which i just realise cant be used in the current form, cause it only seems to display its struct in a message box?)

But this would be the code - i would need to be able to retrieve the struct of my own function - therefore i would need the memory address of $test - right now i receive the return varaible of the msgbox and i'm quite unsure, how to receive the memory address of the function.

#include <WinAPIDiag.au3>
Local $me = @AutoItExe
    $test = _m("test")
FileWrite( "test_vardump.txt", _WinAPI_DisplayStruct($test) )
    Func _m($t)
    Return MsgBox(0, "test", $t )
EndFunc
Exit

 

i much appreciate your time & help.

Thank you.

Kind regards

 

Edit:

i just found a way in C++ to show the memory address:

    printf("address of function main() is :%p\n", main);        printf("address of function funct() is : %p\n", funct);
But is this %p possible in autoit?
 
Edit:
I did find out a way to find the address of a variable, but i need the address of the function... mhhh i think this won't be so easy.
As deeper investigating into old threads, i saw that this is not supported directly by autoit - but for me autoit did always stepover its limitation with creative ways, and i mean - why not?
 
This is what i found for the variables:
Which i really can't understand why nobody is interested to, cause if my plan is going to work - this would be insane :D.
But nvm. i will most likely not be able to achieve it, but im yet far away from giving up.
down side: only for 32bit, seems to be unstable as the author claims.
Edited by Busti

My UDF's : Startet on : 06.06.2006_CaseSearchOrReplaceStr();~> Searches OR Replaces a String,;~> With or Without Casesensivity

Share this post


Link to post
Share on other sites
  1. first question is why?
  2. Is a function variable not enough to help you with the why?
$c=b

$c()

$c=a

$c()


func a()
    ConsoleWrite("Hello a" & @CRLF)
EndFunc

func b()
    ConsoleWrite("Hello b" & @CRLF)
EndFunc

Functions like assign can create true variables on the fly and with eval you can get the content of them

 

Share this post


Link to post
Share on other sites
Posted (edited)
16 hours ago, junkew said:
  1. first question is why?
  2. Is a function variable not enough to help you with the why?
$c=b

$c()

$c=a

$c()


func a()
    ConsoleWrite("Hello a" & @CRLF)
EndFunc

func b()
    ConsoleWrite("Hello b" & @CRLF)
EndFunc

Functions like assign can create true variables on the fly and with eval you can get the content of them

 

Hello and thank you for responding to my question.

I want to call an autoit function of my own script from another script and therefore i need to hand out the memory address of the function to be able to call the function.

 

For example with this Function:

#include <MemoryDLL.au3>
;Author(s): Ward, modified: Prog@ndy

Func MemoryFuncCall($RetType, $FunctionPointer, $Type1 = "int", $Param1 = 0, $Type2 = "int", $Param2 = 0, $Type3 = "int", $Param3 = 0, $Type4 = "int", $Param4 = 0, $Type5 = "int", $Param5 = 0, _

$Type6 = "int", $Param6 = 0, $Type7 = "int", $Param7 = 0, $Type8 = "int", $Param8 = 0, $Type9 = "int", $Param9 = 0, $Type10 = "int", $Param10 = 0, _

$Type11 = "int", $Param11 = 0, $Type12 = "int", $Param12 = 0, $Type13 = "int", $Param13 = 0, $Type14 = "int", $Param14 = 0, $Type15 = "int", $Param15 = 0, _

$Type16 = "int", $Param16 = 0, $Type17 = "int", $Param17 = 0, $Type18 = "int", $Param18 = 0, $Type19 = "int", $Param19 = 0, $Type20 = "int", $Param20 = 0 )

Local $Ret

Local Const $MaxParams = 20

If (@NumParams < 2) Or (@NumParams > $MaxParams * 2 + 2) Or (Mod(@NumParams, 2) = 1) Then

SetError(2)

Return 0

EndIf

If Not IsDllStruct($_MDCodeBuffer) Then MemoryDllInit()



If $FunctionPointer = 0 Then

SetError(1)

Return 0

EndIf



Local $Ret[1] = [$FunctionPointer]



Switch @NumParams

Case 13 To $MaxParams * 2 + 2

Local $DllParams = (@NumParams - 3) / 2, $i, $PartRet

$Ret = DllCall("user32.dll", $RetType, "CallWindowProc", "ptr", DllStructGetPtr($_MDCodeBuffer) + $_MDWarpN, _

"uint", $Ret[0], _

"uint", $DllParams, _

$Type1, $Param1, _

$Type2, $Param2)



$Ret[1] = $Ret[4]

$Ret[2] = $Ret[5]

ReDim $Ret[3]



For $i = 3 To $DllParams Step 3

$PartRet = DllCall("user32.dll", $RetType, "CallWindowProc", "ptr", DllStructGetPtr($_MDCodeBuffer) + $_MDWarpN, _

"uint", 0, _

Eval('Type' & $i), Eval('Param' & $i), _

Eval('Type' & ($i+1)), Eval('Param' & ($i+1)), _

Eval('Type' & ($i+2)), Eval('Param' & ($i+2)))

ReDim $Ret[$i + 3]

$Ret[$i + 2] = $PartRet[5]

$Ret[$i + 1] = $PartRet[4]

$Ret[$i] = $PartRet[3]

Next

$Ret[0] = $PartRet[0]

ReDim $Ret[$DllParams + 1]



Case 10

$Ret = DllCall("user32.dll", $RetType, "CallWindowProc", "ptr", $Ret[0], _

$Type1, $Param1, _

$Type2, $Param2, _

$Type3, $Param3, _

$Type4, $Param4)

$Ret[1] = $Ret[2]

$Ret[2] = $Ret[3]

$Ret[3] = $Ret[4]

$Ret[4] = $Ret[5]

ReDim $Ret[5]



Case 8

$Ret = DllCall("user32.dll", $RetType, "CallWindowProc", "ptr", DllStructGetPtr($_MDCodeBuffer) + $_MDWarp3, _

"uint", $Ret[0], _

$Type1, $Param1, _

$Type2, $Param2, _

$Type3, $Param3)

$Ret[1] = $Ret[3]

$Ret[2] = $Ret[4]

$Ret[3] = $Ret[5]

ReDim $Ret[4]



Case 6

$Ret = DllCall("user32.dll", $RetType, "CallWindowProc", "ptr", DllStructGetPtr($_MDCodeBuffer) + $_MDWarp2, _

"int", 0, _

"uint", $Ret[0], _

$Type1, $Param1, _

$Type2, $Param2)

$Ret[1] = $Ret[4]

$Ret[2] = $Ret[5]

ReDim $Ret[3]



Case 4

$Ret = DllCall("user32.dll", $RetType, "CallWindowProc", "ptr", DllStructGetPtr($_MDCodeBuffer) + $_MDWarp1, _

"int", 0, _

"int", 0, _

"uint", $Ret[0], _

$Type1, $Param1)

$Ret[1] = $Ret[5]

ReDim $Ret[2]



Case 2

$Ret = DllCall("user32.dll", $RetType, "CallWindowProc", "ptr", DllStructGetPtr($_MDCodeBuffer) + $_MDWarp0, _

"int", 0, _

"int", 0, _

"int", 0, _

"int", $Ret[0])



ReDim $Ret[1]

EndSwitch



SetError(0)

Return $Ret

EndFunc

 

Edited by Busti

My UDF's : Startet on : 06.06.2006_CaseSearchOrReplaceStr();~> Searches OR Replaces a String,;~> With or Without Casesensivity

Share this post


Link to post
Share on other sites

AutoIt is interpreted, hence there is no such thing as a system-wide "AutoIt function pointer".

If some function of your own code is common to more than one program copy it or put it in one include file and #include it in both sources.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
Posted (edited)

Ja, sorry - i wanted to try another createthread script.. cause i thought i had a smart idea in combining a working example of prog@ndy with my weird idea.

The concept behind it was to create a thread which calls the autoit function in my own thread and therefore create a thread like this.

 

here is the non operational code.

if you set $x = 1 then the code will always work, its prog@ndys example  - sure it does :P

$x = 2 where my first trys on trying to rewrite it so it works in a way which it does call itself

$x = 3 was where i though it will work, but i got problems on recreating the correct struct for the create_thread call :(

(the other idea was to copy the mem area of the function into another space in memory and try to run it as a thread from there, like to sperate it from the  current autoit file and maybe to prevent a crash of the main script - but  this is just a though and im not even sure if its possible)

!DllCallbackRegister:    1
!DllCallbackGetPtr:    0x0000022580910000
Callback ptr:    0x0000022580910000
hThread:    0x0000000000000258
!ThreadID:    17092
!>14:13:58 AutoIt3.exe ended.rc:-1073741819

#AutoIt3Wrapper_Res_SaveSource=y
#AutoIt3Wrapper_Res_SaveSourcedirective
Global Const $STATUS_PENDING = 0x103
Global Const $STILL_ACTIVE = $STATUS_PENDING
#include <WinAPI.au3>

; ThreadID is @extended
;===============================================================================
;
; Function Name:   _Thread_Create
; Description::    Creates a thread
; Parameter(s):    see MSDN (lpThreadId is removed)
; Requirement(s):  minimum Win2000
; Return Value(s): see MSDN
;                  @extended will be ThreadID
;                  On error, @error will be set to 1
; Author(s):       Prog@ndy
;
;===============================================================================
;
Func _Thread_Create($lpThreadAttributes, $dwStackSize, $lpStartAddress, $lpParameter, $dwCreationFlags)
    Local $result = DllCall("kernel32.dll", "ptr", "CreateThread", "ptr", $lpThreadAttributes, "dword", $dwStackSize, "ptr", $lpStartAddress, "ptr", $lpParameter, "dword", $dwCreationFlags, "dword*", 0)
    Return SetError($result[0] = 0, $result[6], $result[0])
EndFunc   ;==>_Thread_Create
;===============================================================================
;
; Function Name:   _Thread_Terminate
; Description::    Terminates a thread
; Parameter(s):    see MSDN
; Requirement(s):  minimum Win2000
; Return Value(s): see MSDN
;                  On error, @error will be set to 1
; Author(s):       Prog@ndy
;
;===============================================================================
;
Func _Thread_Terminate($hThread, $dwExitCode)
    Local $result = DllCall("Kernel32.dll", "int", "TerminateThread", "ptr", $hThread, "dword", $dwExitCode)
    Return SetError($result[0] = 0, 0, $result[0])
EndFunc   ;==>_Thread_Terminate
;===============================================================================
;
; Function Name:   _Thread_Exits
; Description::    Exits the current thread
; Parameter(s):    see MSDN
; Requirement(s):  minimum Win2000
; Return Value(s): none
; Author(s):       Prog@ndy
;
;===============================================================================
;
Func _Thread_Exit($dwExitCode)
    DllCall("Kernel32.dll", "none", "ExitThread", "dword", $dwExitCode)
EndFunc   ;==>_Thread_Exit
;===============================================================================
;
; Function Name:   _Thread_GetExitCode
; Description::    retrieves ExitCode of a thread
; Parameter(s):    see MSDN
; Requirement(s):  minimum Win2000
; Return Value(s): see MSDN
;                  On error, @error will be set to 1
; Author(s):       Prog@ndy
;
;===============================================================================
;
Func _Thread_GetExitCode($hThread)
    Local $result = DllCall("Kernel32.dll", "int", "GetExitCodeThread", "ptr", $hThread, "dword*", 0)
    Return SetError($result[0] = 0, 0, $result[2])
EndFunc   ;==>_Thread_GetExitCode
;===============================================================================
;
; Function Name:   _Thread_GetID
; Description::    retrieves ThreadID of a thread
; Parameter(s):    see MSDN
; Requirement(s):  minimum Win2000
; Return Value(s): see MSDN
;                  On error, @error will be set to 1
; Author(s):       Prog@ndy
;
;===============================================================================
;
Func _Thread_GetID($hThread)
    Local $result = DllCall("Kernel32.dll", "dword", "GetThreadId", "ptr", $hThread)
    Return SetError($result[0] = 0, 0, $result[0])
EndFunc   ;==>_Thread_GetID
;===============================================================================
;
; Function Name:   _Thread_GetPriority
; Description::    retrieves priority of a thread
; Parameter(s):    see MSDN
; Requirement(s):  minimum Win2000
; Return Value(s): see MSDN
;                  On error, @error will be set to 1
; Author(s):       Prog@ndy
;
;===============================================================================
;
Func _Thread_GetPriority($hThread)
    Local $result = DllCall("Kernel32.dll", "int", "GetThreadPriority", "ptr", $hThread)
    Return SetError($result[0] = 0, 0, $result[0])
EndFunc   ;==>_Thread_GetPriority
;===============================================================================
;
; Function Name:   _Thread_SetPriority
; Description::    sets priority of a thread
; Parameter(s):    see MSDN
; Requirement(s):  minimum Win2000
; Return Value(s): see MSDN
;                  On error, @error will be set to 1
; Author(s):       Prog@ndy
;
;===============================================================================
;
Func _Thread_SetPriority($hThread, $nPriority)
    Local $result = DllCall("Kernel32.dll", "int", "SetThreadPriority", "ptr", $hThread, "int", $nPriority)
    Return SetError($result[0] = 0, 0, $result[0])
EndFunc   ;==>_Thread_SetPriority
;===============================================================================
;
; Function Name:   _Thread_Suspend
; Description::    suspends a thread
; Parameter(s):    see MSDN
; Requirement(s):  minimum Win2000
; Return Value(s): see MSDN
;                  On error, @error will be set to 1
; Author(s):       Prog@ndy
;
;===============================================================================
;
Func _Thread_Suspend($hThread)
    Local $result = DllCall("Kernel32.dll", "int", "SuspendThread", "ptr", $hThread)
    Return SetError($result[0] = -1, 0, $result[0])
EndFunc   ;==>_Thread_Suspend
;===============================================================================
;
; Function Name:   _Thread_Resume
; Description::    resumes a thread
; Parameter(s):    see MSDN
; Requirement(s):  minimum Win2000
; Return Value(s): see MSDN
;                  On error, @error will be set to 1
; Author(s):       Prog@ndy
;
;===============================================================================
;
Func _Thread_Resume($hThread)
    Local $result = DllCall("Kernel32.dll", "int", "ResumeThread", "ptr", $hThread)
    Return SetError($result[0] = -1, 0, $result[0])
EndFunc   ;==>_Thread_Resume
;===============================================================================
;
; Function Name:   _Thread_Wait
; Description::    Waits for a thread to terminate
; Parameter(s):    $hThread  - Handle of thread
;                  $nTimeOut - [optional] Timeout (default: 0xFFFFFFFF => INFINTE)
; Requirement(s):  minimum Win2000
; Return Value(s): Success: true
;                  on TimeOut, @eeor will be set to -1
;                  On error, @error will be set to 1
; Author(s):       Prog@ndy
;
;===============================================================================
;
Func _Thread_Wait($hThread, $nTimeout = 0xFFFFFFFF)
    Local $result = DllCall("Kernel32.dll", "dword", "WaitForSingleObject", "ptr", $hThread, "int", $nTimeout)
    If @error Then Return SetError(2, 0, 0)
    Switch $result[0]
        Case -1, 0xFFFFFFFF
            Return SetError(1, 0, 0)
        Case 0x00000102
            Return SetError(-1, 0, 1)
        Case Else
            Return 1
    EndSwitch
EndFunc   ;==>_Thread_Wait




; creates a struct for an Unicode-String
Func _UnicodeStruct($text)
    ; Prog@ndy
    Local $s = DllStructCreate("wchar[" & StringLen($text) + 1 & "]")
    DllStructSetData($s, 1, $text)
    Return $s
EndFunc   ;==>_UnicodeStruct

; retrieves Address of a function
Func _Thread_GetProcAddress($hModule, $sProcname)
    ; Prog@ndy
    Local $result = DllCall("kernel32.dll", "ptr", "GetProcAddress", "hwnd", $hModule, "str", $sProcname)
    Return $result[0]
EndFunc   ;==>_Thread_GetProcAddress

#cs
$tagMSGBOXPARAMS = _
        "UINT cbSize;" & _
        "HWND hwndOwner;" & _
        "ptr hInstance;" & _
        "ptr lpszText;" & _
        "ptr lpszCaption;" & _
        "DWORD dwStyle;" & _
        "ptr lpszIcon;" & _
        "UINT_PTR dwContextHelpId;" & _
        "ptr lpfnMsgBoxCallback;" & _
        "DWORD dwLanguageId;"
#ce
;#include "VarDump.au3"
#include <WinAPIDiag.au3>
;#include "NomadMemory.au3"
#include <WinAPIConstants.au3>
#include <WinAPIProc.au3>
#include <WinAPIRes.au3>

Func _m()
    Local $t = "WORKZ"
    Return MsgBox(0, "test", $t)
EndFunc   ;==>_m

Local $x = 3

If $x = 3 Then

    ;works
    Local $a = ""
    Dim $CallBack = DllCallbackRegister("_m", "int", "str") ;, "int", "str")
    ConsoleWrite("!DllCallbackRegister:    " & $CallBack & @CRLF)
    $a = DllCallbackGetPtr($CallBack)
    ConsoleWrite("!DllCallbackGetPtr:    " & $a & @CRLF)

    ;Dim $Ret = DllCallAddress("int", $a , "str", "DID IT WORK" )
    ;ConsoleWrite("!"&$a&@CRLF)
    ;DllCallbackFree($CallBack)
    ;ConsoleWrite( "!" & $Ret[0] & @CRLF )

    Local $stText
    Local $struct = DllStructCreate("str; text")
    $stText = _UnicodeStruct("The messageBox in a separate thead!")
    DllStructSetData($struct, "text", DllStructGetPtr($stText))

    ;Local $hThreadProc = _Thread_GetProcAddress(_WinAPI_GetModuleHandle("user32.dll"),"MessageBoxIndirectW")
    ;            ($lpThreadAttributes, $dwStackSize, $lpStartAddress, $lpParameter, $dwCreationFlags)
    $hThread = _Thread_Create(0, 0, $a, Null, 0) ;DllStructGetPtr($struct), 0)
    $ThreadID = @extended

    ConsoleWrite("Callback ptr:    " & $a & @CRLF & "hThread:    " & $hThread & @CRLF & "!ThreadID:    " & $ThreadID)
    While MsgBox(69, "main", "Main script is not blocked") = 4
    WEnd
    MsgBox(0, "Thread-Info", "Handle: " & $hThread & @CRLF & "Thread-ID: " & $ThreadID & @CRLF)


    _Thread_Wait($hThread)
    $code = _Thread_GetExitCode($hThread)
    MsgBox(0, 'Thread ended', "Threaded MsgBox returned: " & $code)


ElseIf $x = 0 Then

    Local $me = @AutoItPID, $t, $r, $s, $test, $a, $test2, $test3, $i
    $s = "_m"
    $t = ProcessExists($me)
;    $r = _MemoryModuleGetBaseAddress($t, $s)
    $test = _WinAPI_GetModuleHandle(@AutoItExe)
    $test2 = _WinAPI_LoadLibraryEx(@AutoItExe, $LOAD_LIBRARY_AS_DATAFILE)
    $test3 = _WinAPI_GetProcAddress($test, "")

    $i = _WinAPI_GetModuleInformation($test)
    MsgBox(0, "result", $i)


    MsgBox(0, "PID: " & $me & "/" & $t, "filename:        " & $me & @CRLF & "searching for:    " & $s & @CRLF & "found:        " & $r & @CRLF & "test:        " & $test & @CRLF & "test2:        " & $test2 & @CRLF & "test3:        " & $test3)



    Exit

ElseIf $x = 1 Then
    ; Struct to send to the Thread
    ; in this case the MsgBox-Params
    $MSGBOXPARAMS = DllStructCreate($tagMSGBOXPARAMS)
    DllStructSetData($MSGBOXPARAMS, "cbSize", DllStructGetSize($MSGBOXPARAMS))
    $stText = _UnicodeStruct("The messageBox in a separate thead!")
    DllStructSetData($MSGBOXPARAMS, "lpszText", DllStructGetPtr($stText))
    $stCaption = _UnicodeStruct("Caption")
    DllStructSetData($MSGBOXPARAMS, "lpszCaption", DllStructGetPtr($stCaption))
    DllStructSetData($MSGBOXPARAMS, "dwStyle", 17) ; msgBox-style

    ; Use MessageBoxIndirect Unicode as ThreadProc
    ; normal MessageBox doesn't work, since CreateThread just has one possible parameter.
    Local $hThreadProc = _Thread_GetProcAddress(_WinAPI_GetModuleHandle("user32.dll"), "MessageBoxIndirectW")

    $hThread = _Thread_Create(0, 0, $hThreadProc, DllStructGetPtr($MSGBOXPARAMS), 0)
    $ThreadID = @extended

    While MsgBox(69, "main", "Main script is not blocked") = 4
    WEnd
    MsgBox(0, "Thread-Info", "Handle: " & $hThread & @CRLF & "Thread-ID: " & $ThreadID)

    _Thread_Wait($hThread)
    $code = _Thread_GetExitCode($hThread)
    MsgBox(0, 'Thread ended', "Threaded MsgBox returned: " & $code)

EndIf
Edited by Busti

My UDF's : Startet on : 06.06.2006_CaseSearchOrReplaceStr();~> Searches OR Replaces a String,;~> With or Without Casesensivity

Share this post


Link to post
Share on other sites

1/ Threads are evil
2/ AutoIt isn't and can't be made threadsafe
3/ AutoIt functions are not executable code (that would require an AutoIt compiler)


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
Posted (edited)
11 minutes ago, jchd said:

1/ Threads are evil
2/ AutoIt isn't and can't be made threadsafe
3/ AutoIt functions are not executable code (that would require an AutoIt compiler)

I knew that answer will be coming, that's why i tried to not to hand out too much informations at the beginning, as - i dont know. i just can't believe that there is no way to do that.

Like cant i run another second autoit script and call from that second autoit script the function in my first autoit script? will this crash autoit?

Or create a second "temporary" autoit script then run that script and memcopy the function of the first autoitscript to the memspace of the second autoit script - which will run the code copied from the memory? Because this would be better than the available methods of co processing i found - as you would not need to create every function again and can just "pseudo-call" the functions already created.

Is all of this impossible?

Can you send me a link to a detailed explanation on why this is impossible? I just would like to understand it 😕

 

Edit: and why does the example of prog@ndy work without crashing?

Is there realy no way to convert this without the usage of an external dll?

 

Edit:

or another thought of mine would be to duplicate the current running autoit script in the memory, and then call the second script and call the function from there and after the function is done, receive the result und terminate the duplicate and free up the space.

 

-

look, the big problem i have is, my ideas are floating in my head and im not realy expierierenced enough to put them into working code - therefore im unable to deny them and this hinders me to believe its not possible.

i know the fault in this case is in my own brain, but ye - i try to do my best to disprove myself.

Edited by Busti

My UDF's : Startet on : 06.06.2006_CaseSearchOrReplaceStr();~> Searches OR Replaces a String,;~> With or Without Casesensivity

Share this post


Link to post
Share on other sites

Once again, AutoIt is interpreted, period. Calling the xxx.exe output made by autoit3.exe a compiled program is kinda a fraud: it's merely an interpreter along with you code source text.

There is no way to persuade the interpreter in progA to magically deroute itself towards some function source in the middle of progB.

What you can do (beside copying common code in every prog needing it, which BTW is exactly what #include does) is implement IPC (inter process comm) between your programs to pass some arguments and politely ask the other side to perform function XYZ on that, then return a result. Your duty is to implement all the needed IPC for doing that. There are plenty of working IPC examples already posted.

Of course, any IPC scheme is way slower and less secure than direct local code invokation.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
Posted (edited)
22 minutes ago, jchd said:

Once again, AutoIt is interpreted, period. Calling the xxx.exe output made by autoit3.exe a compiled program is kinda a fraud: it's merely an interpreter along with you code source text.

There is no way to persuade the interpreter in progA to magically deroute itself towards some function source in the middle of progB.

What you can do (beside copying common code in every prog needing it, which BTW is exactly what #include does) is implement IPC (inter process comm) between your programs to pass some arguments and politely ask the other side to perform function XYZ on that, then return a result. Your duty is to implement all the needed IPC for doing that. There are plenty of working IPC examples already posted.

Of course, any IPC scheme is way slower and less secure than direct local code invokation.

Thank you, so that means - if i compile the sourcecode to an exe file, its basically the autoit3.exe interpreter* + the sourcecode, and if i call the compiled exe, it's starting the autoit3.exe which interpretes the sourcecode from top to bottom.

is that correct?

 

Edit: 

Would this also be the case for A3X files?

 

 

Edit:

could i run a CreateThread and Call a Run(not from autoit - like from user32.dll or whereever it is sitting) function, which then calls my script with \autoit3execute and give it the function code as argument? 

Or do the same thing just with the internal autoit run() command, but dont give it the entire "function" in clear text as a parameter - just give it the code from the memory as parameter, this would prevent the need of adding the code to each function you want to run

 

like for example:

Run(@autoitexe & "\executescript " & _function_read_from_the_memory_by_pointer )

This way i could execute a function directly out of the script, if i create the function that way - that it acts like a "main" function if its not called with any arguments for example

Edited by Busti

My UDF's : Startet on : 06.06.2006_CaseSearchOrReplaceStr();~> Searches OR Replaces a String,;~> With or Without Casesensivity

Share this post


Link to post
Share on other sites

The answer to all of your questions have already been answered.

A3X files are just the source code without the interpreter, just as if it would be inside the container .exe file without being able to be ran directly.

What you want/need is to create a DLL and use that in both scripts, but they wouldn't be talking to each other even then. Read the answers given to you, and understand what you want isn't possible.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Correct.

A3X = just the packed source code (omitting the interpreter).


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
Posted (edited)
3 minutes ago, BrewManNH said:

The answer to all of your questions have already been answered.

A3X files are just the source code without the interpreter, just as if it would be inside the container .exe file without being able to be ran directly.

What you want/need is to create a DLL and use that in both scripts, but they wouldn't be talking to each other even then. Read the answers given to you, and understand what you want isn't possible.

Yes, i did leave from the  CreateThread, i got it know.

My question is now another question, which i edited to my post:

Or do the same thing just with the internal autoit run() command, but dont give it the entire "function" in clear text as a parameter - just give it the code from the memory as parameter, this would prevent the need of adding the code to each function you want to run
     
    like for example:
    Run(@autoitexe & "\executescript " & _function_read_from_the_memory_by_pointer )
    This way i could execute a function directly out of the script, if i create the function that way - that it acts like a "main" function if its not called with any arguments for example

Would this work? - or is there any way to get the "function" text without having to hardcode it?

 

Edit:

and thank you for your patience and assistance.

 

Edited by Busti

My UDF's : Startet on : 06.06.2006_CaseSearchOrReplaceStr();~> Searches OR Replaces a String,;~> With or Without Casesensivity

Share this post


Link to post
Share on other sites

How many times do you need to hear no before you'll get it?


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
Posted (edited)
6 minutes ago, BrewManNH said:

How many times do you need to hear no before you'll get it?

Sorry but i don't see this as the answer to the other question?

You told me, that the sourcecode is included in the compiled .exe file, so why can't i just take the code from the ram and directly execute it with the

Run(@AutoItExe & ' /AutoIt3ExecuteLine "MsgBox(4096, ''Hello World!'', ''Hi!'')"')

or

Run(@AutoItExe & ' /AutoIt3ExecuteScript "MsgBox(4096, ''Hello World!'', ''Hi!'')"')

 

Sorry if i'm the dumb person here, but i dont see an answer regarding to this question.

This is no thread attempt and all the co process UDF's work like this, only that they are hardcoding this text - and i would like to create it more flexible.

And sorry if you really did answer this question, as unfortunately I'm unable to recognise it. - "CreateThread" is not the question anymore, I'm now looking for another solution, thanks to your' explanations.

Edited by Busti

My UDF's : Startet on : 06.06.2006_CaseSearchOrReplaceStr();~> Searches OR Replaces a String,;~> With or Without Casesensivity

Share this post


Link to post
Share on other sites
14 minutes ago, Busti said:

so why can't i just take the code from the ram and directly execute it with the

Because it doesn't work that way. The line you're running in the first example is a single line of code not in a script file. The second example won't run because it's looking for a file, not a line of code.

Why don't you just stop thinking in this train of thought, and come up with another way of doing whatever it is you're trying to do. It won't work the way you want it to, and it's never going to be any clearer than that. 


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

It looks like two scripts need to communicate advice to search for

Mailslot

Memory mapped files

Client server tcp ip communication tcpsend and tcpreceive in help files

Check clr runtime and related threads to run c# on the fly.

...

 

Share this post


Link to post
Share on other sites
Posted (edited)
16 hours ago, junkew said:

It looks like two scripts need to communicate advice to search for

Mailslot

Memory mapped files

Client server tcp ip communication tcpsend and tcpreceive in help files

Check clr runtime and related threads to run c# on the fly.

...

 

Yes, i got nearly all of those files here - but nothing of those is realy what i would like.

The new idea would be somehow like this:

 

Local $l = @ScriptDir & "\tmp_call.au3", $r, $e, $a
     
       Dim $CallBack = DllCallbackRegister("_CallMeFunction", "int", "int;int;int;bool") ; i want the address of  the autoit function

    ConsoleWrite( "!$CallBack:        "& $CallBack & @CRLF )
        $a = DllCallbackGetPtr($CallBack)
        ConsoleWrite( "!DllCallbackGetPtr:    "& $a & @CRLF )  ; i got the address of  the autoit function
    ; here should be a part which "extract" runnable autoit code from the memory / i would also map the code into the memory/ if possible - but i want to avoid creating a function like:
    #cs
        $test_string = 'Func _CallMeFunction( $a=1, $b=2, $c=3, $externalCall=False )' & @CRLF & _
                    'If ($externalCall = True) Then' & @CRLF & _
                        'MsgBox(0, "external", "call - running in its own script " & $a & $b & $c  )' & @CRLF & _
                    'ElseIf ($externalCall = False) Then' & @CRLF & _
                        'MsgBox(0, "internal", "call - running in the main script " & $a & $b & $c  )' & @CRLF & _
                    'EndIf' & @CRLF & _
                    'Return 1' & @CRLF & _
                    'EndFunc' & @CRLF & _
                    '_CallMeFunction()'
     
    and preferable be able to just to something like this :
    #ce
       $r = _ExtractAutoItCodeFromMemory( $a, '_CallMeFunction', $lenght )
        FileWrite( $l , $r )
        $e = Run(@AutoItExe & ' /AutoIt3ExecuteScript "' & $l & '"' )
        ConsoleWrite( "!Run:            "& $e & @CRLF )
        MsgBox(0, $e, $a )
        Exit
 
Func _CallMeFunction( $a=1, $b=2, $c=3, $externalCall=True )
    If $externalCall = True Then
        MsgBox(0, "external", "call - running in its own script " & $a & $b & $c  )
    ElseIf $externalCall = False Then
        MsgBox(0, "internal", "call - running in the main script " & $a & $b & $c  )
    EndIf
    Return 1
EndFunc

 

i hope this is understandable - if this is also not possible, okay - then im going to look for another solution, got some more freaky ideas in mind.

Edited by Busti

My UDF's : Startet on : 06.06.2006_CaseSearchOrReplaceStr();~> Searches OR Replaces a String,;~> With or Without Casesensivity

Share this post


Link to post
Share on other sites
8 minutes ago, Busti said:

$test_string = <source code of function>

Possible but then how do you pass arguments?
And how is that simpler or more efficient than just put your function in an #include file?

9 minutes ago, Busti said:

$r = _ExtractAutoItCodeFromMemory( $a, '_CallMeFunction', $lenght )

Once again (sigh!) NO.

The only sensible way beside #include is IPC but I hardly see that necessary in the use case.

Perhaps instead of an XY problem you could expose why on earth you insist on not using #include.  Is that because you persist to try multithreading?  If yes, then best of luck.  Remember that threads are (still today) evil.  No multithreaded program can be formally proven correct, which speaks volume about the [lack of] robustness of the paradigm!

On 5/22/2019 at 1:35 PM, Busti said:

this would be insane

It actually is.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
28 minutes ago, jchd said:

Possible but then how do you pass arguments?
And how is that simpler or more efficient than just put your function in an #include file?

Once again (sigh!) NO.

The only sensible way beside #include is IPC but I hardly see that necessary in the use case.

Perhaps instead of an XY problem you could expose why on earth you insist on not using #include.  Is that because you persist to try multithreading?  If yes, then best of luck.  Remember that threads are (still today) evil.  No multithreaded program can be formally proven correct, which speaks volume about the [lack of] robustness of the paradigm!

It actually is.

I have to write a multi-functional tool for my work, and on certrain button presses - different scripts have to run, but i don't want to use multiple exe files neither do i want to include the source code.

This is not even about communicating between two scripts / which maybe in areas of the application should also be used - but for this i wanted to use the mailslot UDF.

But i want a nice and clean way to start the already created functions, without the need of adding the functions i want to use in "clear text".

 

The only thing which i still can't understand is:

Why can my script run the memory part of my function, but cant be run by another script which copies exactly the same area of the memory into its own memory space (cause if I dont think completly wrong - it should be now the function of the other script) and then run it?

Like where is the difference between memory space a and (after you copied the function from a to b) memoryspace b

Or

If i copy the function out of the memory - and save it into a file, what would be needed to actually make this code runable again, i dont want to be able to read it - it just should be runable by autoit itself.

Like a stupid question now, if i compile my script X.au3 -> then inside of the X.exe will be an autoit.exe (/autoit64.exe) + the script - now the question is,  into what is the script converted?


My UDF's : Startet on : 06.06.2006_CaseSearchOrReplaceStr();~> Searches OR Replaces a String,;~> With or Without Casesensivity

Share this post


Link to post
Share on other sites
1 hour ago, Busti said:

Like a stupid question now, if i compile my script X.au3 -> then inside of the X.exe will be an autoit.exe (/autoit64.exe) + the script - now the question is,  into what is the script converted?

That's getting dangerously close to decompiling the script.

The reason you can't call a function from memory in another script to yours is that the function has to exist in the first script or it won't be recognized, you can't create phantom functions in a script by pulling them in from elsewhere. The calling script has to know that the function exists, and has to know where in the script this function is, at runtime, so if it's not there when the script starts, the interpreter doesn't know about it.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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

×
×
  • Create New...