Hey, I'm trying to convert some of my c++ code for dll injection to visual basic, for a buddy of mine. Having to define all the API calls is annoying, but I've done them correctly using API Viewer. I'm thinking the problem is how I've got my constant defined (possibly). Anyone mind checkin this code out and seeing if you can tell my why it's always returning 0.
Private Const PROCESS_ALL_ACCESS& = &H1F0FFF
Private Declare Function OpenProcess Lib "kernel32" _
(ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Call GetWindowThreadProcessId(procInfo.hTargetHwnd, procInfo.dwProcessId)
If ((procInfo.hProcess = OpenProcess(PROCESS_ALL_ACCESS, False, procInfo.dwProcessId)) = 0) Then
Inject = False
Exit Function
End If
Actually, the above problem was fixed due to visual basic syntax errors. Darn C++ messing up my Visual Basic. :-P
Anyways, the following error is what I believe to be a true problem with the call to CreateRemoteThread. It is being passed all correct data, and should work. It returns false, though. Anyone know why, maybe?
procInfo.hThread = CreateRemoteThread(procInfo.dwProcessId, 0, 0, GetProcAddress(procInfo.hLibrary, "LoadLibraryA"), procInfo.rAddress, 0, 0)
If procInfo.hThread = 0 Then
Call VirtualFreeEx(procInfo.hProcess, ByVal procInfo.rAddress, Len(procInfo.szLibrary), MEM_RELEASE Or MEM_DECOMMIT)
Inject = False
Exit Function
End If
Debug.Print "CreateRemoteThread OK (" & procInfo.hThread & ")"
Although I can't help you because I don't remember, tonight I can post some C++ code that runs CreateRemoteProcess, if that'll help.
Quote from: iago on May 15, 2006, 09:25:38 AM
Although I can't help you because I don't remember, tonight I can post some C++ code that runs CreateRemoteProcess, if that'll help.
Ah, that's alright. I wrote this thing in C++ originally, and it works. I'm just trying to convert it to visual basic for a buddy of mine.
Anyways, I managed to fix it. I was passing the process id to CreateRemoteThread instead of the handle to the process. Big problem :-)
Here's the working source code, binary and my basic stats hack (unfinished) bwlib.dll: Download (http://rafm.org/files/vb%20dll%20injector.zip)
I went ahead and forced myself to not be lazy. I finished my GUI version of BWLoader, my C++ version of the dll injector.
This one supports:
* Utilizes the registry to save dll and game paths (HKEY_CURRENT_USER\Software\BroodwarThreat\BWLoader)
* automatically starting sc/bw
* injecting dll's into target processes via LoadLibrary
It's fairly idiot proof. If you're dumb it will not allow you to press Inject!. :-P The source code to this, just like my visual basic one, is available to the public also. It provides a decent demo of win32 programming without MFC. You can find both source code zips at www.rafm.org as well as the zip containing only the dll injector if you want to use it. I think it's pretty neat. ;-)
I made a program exactly like that. I don't know where my source is, but it's available upon request. The binary can be found at http://www.valhallalegends.com/iago/Injector.rar
You sent me the source before, it's very messy. It does the job though, I had some fun with it and Starcraft... :)