Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 652
  • Last Modified:

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

0
drakeshe
Asked:
drakeshe
  • 6
  • 4
1 Solution
 
jkrCommented:
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

0
 
drakesheAuthor Commented:
Anyone else?
0
 
jkrCommented:
What's wrong with what you've got?
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
drakesheAuthor Commented:
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. : /
0
 
jkrCommented:
Well, you cannot do that unless you manipulate the command line of the launched process, and that could imply that this one exits with an error then. But if you wan to do so, 'GetCommandLine()' will give you the actual command line in your DLL.
0
 
drakesheAuthor Commented:
Thank you for your reply.

I will see what I can manage to come up with.
0
 
drakesheAuthor Commented:
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.
0
 
jkrCommented:
(Sorry for the late reply, missed the mail)

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

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now