dromenox Posted September 12, 2014 Posted September 12, 2014 (edited) 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: expandcollapse popup#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 September 12, 2014 by dromenox
232showtime Posted September 13, 2014 Posted September 13, 2014 are you trying to create a bot using autoit? ill get to that... i still need to learn and understand a lot of codes Correct answer, learn to walk before you take on that marathon.
dromenox Posted September 13, 2014 Author Posted September 13, 2014 are you trying to create a bot using autoit? Not. Will be a packet sniffer.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now