Jump to content
Sign in to follow this  
dromenox

DLL Call AutoIt Function

Recommended Posts

dromenox
How do I get a DLL that is injected into a process to call a function of a AutoIt program that is running? I will not use DllCall because I want the DLL call AutoIt and not otherwise. 
 
I tried to do the following:
 
Test program ( C ):
 
#include <windows.h>
#include <stdio.h>

void func(int a, int b)
{
    printf("\nParameters: %d and %d\n", a, b);
}

int main()
{
    while (1)
    {
        if (GetAsyncKeyState(VK_INSERT) & 1)
            func(1, 2);
    }
}

My DLL:

#include <windows.h>
#include <stdio.h>

typedef void(*pFunc)(int a, int b);
pFunc oFunc;

DWORD addr = 9999;
DWORD *ptr = &addr;

VOID Main()
{
    while (*ptr == 9999)
    {
        Sleep(100);
    }

    printf("\nAddress: %x\n", *ptr);
    oFunc = (pFunc)ptr;


    while (1)
    {
        if (GetAsyncKeyState(VK_F1) & 1)
        {
            printf("\nCalling function...\n");
            oFunc(5, 6); // crash here
        }
    }   
}

BOOL __stdcall DllMain( HMODULE hthis, DWORD dwReason, DWORD lpUNK ){

    DisableThreadLibraryCalls(hthis);

    if(dwReason == 1)
    {

        AllocConsole();
        freopen("CONOUT$", "w", stdout);
        CreateThread(0, 0, (LPTHREAD_START_ROUTINE)Main, 0, 0, 0);
    }
    return true;
}

My AutoIt program:

#include <NomadMemory.au3>

Func myFunc($a, $b)
   MsgBox((0, "AUTOIT", $a)
   MsgBox((0, "AUTOIT", $b)
EndFunc

$cb = DllCallbackRegister("myFunc", "none", "int;int")
$ptr = DllCallbackGetPtr($cb)
ConsoleWrite($ptr)

$proc = _MemoryOpen(ProcessExists("test.exe"))
_MemoryWrite(0x74613010, $proc, $ptr)

while 1

WEnd

Where 0x74613010 is the address of "addr" in DLL.

But it crashes when i call the function.

Edited by dromenox

Share this post


Link to post
Share on other sites
232showtime

are you trying to create a bot using autoit?


ill get to that... i still need to learn and understand a lot of codes graduated.gif

Correct answer, learn to walk before you take on that marathon.

Share this post


Link to post
Share on other sites
dromenox

are you trying to create a bot using autoit?

Not. Will be a packet sniffer.

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  

×