Link to home
Start Free TrialLog in
Avatar of drakeshe
drakesheFlag for Australia

asked on

Injecting DLL with Params

Language: Visual Basic 6

Ok, so I'm currently working on a game and I need to have my program inject a DLL into one of it's sub programs. I have already been able to do the injecting part using a DLL that I found.

What I want to now do is be able to inject my DLL's with parameters. I cannot just inject it normally and hardcode the settings as the params are variable per user.
Private Declare Function ForceLibrary Lib "forcelibrary.dll" (ByVal szDll As String, lpProcessInformation As PROCESS_INFORMATION) As Long
Private Declare Function CreateProcess Lib "kernel32" Alias "CreateProcessA" _
(ByVal lpApplicationName As Long, ByVal lpCommandLine As String, _
ByVal lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, _
lpStartupInfo As STARTUPINFO, _
lpProcessInformation As PROCESS_INFORMATION) As Long
Private Declare Function ResumeThread Lib "kernel32.dll" (ByVal hThread As Long) As Long
 
Private Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
 
Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadID As Long
End Type
 
 
Private Sub Command4_Click()
Dim ret As Long
Dim inicio As STARTUPINFO
Dim proce As PROCESS_INFORMATION
 
inicio.cb = Len(inicio)
proce.hProcess = -1
proce.hThread = -1
 
ret& = CreateProcess(0&, "C:\Program Files\Loxor\Loxor.exe -nomaster -game", 0&, 0&, 0&, CREATE_SUSPENDED, 0&, 0, inicio, proce)
If ret = 0 Then
MsgBox ("Error in CreateProcess";)
End If
 
ret = ForceLibrary(CurDir & "\anticheat.dll", proce)
If ret = 0 Then
MsgBox ("Error in ForceLibrary";)
End If
 
ret = ResumeThread(proce.hThread)
End Sub

Open in new window

Avatar of jkr
jkr
Flag of Germany image

You could set your parameters in the spawned process' environment block, e.g. (sorry, C/C++-like example, dunno VB)
SetEnvironmentVariable("DllOption1","42");
SetEnvironmentVariable("DllOption2","verbose");
 
LPVOID pEnv = GetEnvironmentStrings();
 
// Now, pass 'pEnv' as the 'lpEnvironment' parameter in 'CreateProcess()'
// and you can read these values using 'GetEnvironmentVariable()'
// (http://msdn.microsoft.com/en-us/library/ms683188(VS.85).aspx)
// in your injected DLL

Open in new window

Avatar of drakeshe

ASKER

Anyone else?
What's wrong with what you've got?
I need to be able to inject the DLL with parameters. Just like what you do when you start an executable.
eg. c:\program dir\some folder\application.exe \c -option2 -"canned"

I need to be able to inject the DLL with parameters like that. : /
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you for your reply.

I will see what I can manage to come up with.
I am unable to delete an answered Question as far I know... Im sorry if I offended you.

Do you know a way to delete? I cannot see any way that I can.
(Sorry for the late reply, missed the mail)

I'll ask CS to handle that, thaks ;o)
That was so cheating going to an admin asking them to re-open because you wanted a higher score lol =P Oh well.
That was so cheating going to an admin asking them to re-open because you wanted a higher score lol =P Oh well.