| View previous topic :: View next topic |
| Author |
Message |
rapion124 Grandmaster Cheater Supreme
Reputation: 0
Joined: 25 Mar 2007 Posts: 1095
|
Posted: Sat Jul 12, 2008 4:29 pm Post subject: [Help] Passing Pointer to Array as Argument |
|
|
I'm trying to make a DLL injector. I want to inject multiple DLLs, so I pass an array of strings to my inject function. The problem is how do I do that? I want to pass them by reference, not by value. Here's the code.
| Code: |
void __stdcall InjectDllEx(LPCSTR lpszProcessName, LPCSTR* lpDllArray, int nNumberOfElements)
{
int nIndex;
DWORD dwProcessId = 0xFFFFFFFF;
HANDLE hProcess = INVALID_HANDLE_VALUE;
while(TRUE)
{
if (GetProcessIdByName(lpszProcessName, &dwProcessId, 0xFFFFFFFF)) //Found first process
{
if (GetProcessIdByName(lpszProcessName, &dwProcessId, dwProcessId)) //Found second process
{
hProcess = OpenProcess(dwProcessInjectDll, FALSE, dwProcessId);
if (hProcess != INVALID_HANDLE_VALUE)
{
for (nIndex = 0; nIndex < nNumberOfElements; nIndex++)
{
InjectDll(hProcess, (lpDllArray)[nIndex]);
}
break;
}
}
}
}
return;
}
|
|
|
| Back to top |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
Posted: Sat Jul 12, 2008 4:39 pm Post subject: |
|
|
| Code: | LPCSTR array[] = { "String1, "String2, "String3" };
InjectDllEx("notepad.exe", array, 3); |
|
|
| Back to top |
|
 |
rapion124 Grandmaster Cheater Supreme
Reputation: 0
Joined: 25 Mar 2007 Posts: 1095
|
Posted: Sat Jul 12, 2008 5:00 pm Post subject: |
|
|
| And C++ will pass "array" variable as a pointer?
|
|
| Back to top |
|
 |
Symbol I'm a spammer
Reputation: 0
Joined: 18 Apr 2007 Posts: 5094 Location: Israel.
|
Posted: Sat Jul 12, 2008 5:19 pm Post subject: |
|
|
You can also call InjectDll in a loop:
| Code: | for (int i = 0; i < 3; ++i)
InjectDll("notepad.exe", array[i]); |
|
|
| Back to top |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
Posted: Sat Jul 12, 2008 6:03 pm Post subject: |
|
|
| rapion124 wrote: | | And C++ will pass "array" variable as a pointer? |
The variable that denotes the array is a pointer to the first element in the array, not the value of the first element in the array.
Basically: array == &array;
So yes, you will be passing a pointer to the array.
|
|
| Back to top |
|
 |
|