Not sure if the title is that telling but what I want to do is hack into an executable and do as little as necessary to get the code from my DLL running since I want to write as few lines of assembly code as possible.
I already have the place where I'd like to jump in and I am ready to insert the necessary assembly instructions into the executable using ollydbg but since I never did that before I'm afraid I need a little help on those last steps.
What I want to do is basically:
- Force the executable to load my DLL
- Push a few parameters onto the stack for
init_my_dll() - call
init_dll()
but I'm not sure what's the best way to accomplish that. Is there a straight forward way to get this done?
Btw: Is what I'm doing here actually called "dll-injection"?
VirtualAllocEx->CreateRemoteThread(..., LoadLibraryA, "your_dll.dll", ...)). You can do it yourself if you want, too (that's called manual mapping). – Martin Dec 05 '16 at 23:08CreateRemoteThread()in order to load my dll, then callGetProcAddress()to get the address ofinit_my_dll()and call it? The link you are referring seems to do something different - if I get this right there are two processes in the end. I don't get how I would make the target process callinit_my_dll()as described there. – Stefan Falk Dec 06 '16 at 09:46GetProcAddressto call your function. You use it to findLoadLibraryA, and call it. That function will load your DLL, and will call itsDllMain- and that function could be calling yourinit_my_dllfunction. That said - if you're trying to do this with a game, be careful, those have anti-cheats which usually detect this technique and ban you. – Martin Dec 06 '16 at 18:41LoadLibraryAis. Now I see it's a kernel function which expects the name of the dll as first parameter. The problem I see here is that this will call theDllMainfrom a different thread - just not the main thread - which might cause some problems. Not sure if there is a synchronous way to do that? Well, yes, I am trying to do something with a game here but not for cheating - I want to extend the script language provided for modders with additional functionality. But thanks for the hint - didn't think about anti-cheats yet ^^ – Stefan Falk Dec 06 '16 at 20:51init_my_dll(you can have an emptyDllMainfor the purpose of usingLoadLibraryA) and then resume it, so that your function gets called. But be careful - anticheats detect code modifications like this too. – Martin Dec 06 '16 at 21:46