-2

I can't really see the reason I am getting this error, I have had a look arround and apparently it's something to do with defining a function that does nothing? I can't really tell what the issue is here unfortunately so any help would be appreciated.

Here is my source code:

main.cpp

#include <Windows.h> 
#include <tlhelp32.h> 
#include <shlwapi.h> 
#include <conio.h> 
#include <stdio.h> 
#include <iostream>

using namespace std;

#define WIN32_LEAN_AND_MEAN 
#define CREATE_THREAD_ACCESS (PROCESS_CREATE_THREAD |    PROCESS_QUERY_INFORMATION | PROCESS_VM_OPERATION | PROCESS_VM_WRITE |    PROCESS_VM_READ) 

BOOL Inject(DWORD pID, const char * DLL_NAME); 
DWORD GetTargetThreadIDFromProcName(const char * ProcName); 

using namespace std;

char buf[MAX_PATH];
LPVOID RemoteString, LoadLib;
HANDLE Proc;
DWORD pID;

__int32 main() 
{
   pID = GetTargetThreadIDFromProcName("Program.exe"); 

   buf[MAX_PATH] = {0}; 
   GetFullPathName("DLL.dll", MAX_PATH, buf, NULL);

   if(!Inject(pID, buf)) cout << ("Failed to inject!\n\n\n");
   system("pause");
   return 0; 
} 

BOOL Inject(DWORD pID, const char * DLL_NAME) 
{  
   char buf[50] = {0}; 

   if(!pID) return false; 

   Proc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pID); 
   if(!Proc) return false; 

   LoadLib = (LPVOID)GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA"); 
   RemoteString = (LPVOID)VirtualAllocEx(Proc, NULL, strlen(DLL_NAME), MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); 
   WriteProcessMemory(Proc, (LPVOID)RemoteString, DLL_NAME, strlen(DLL_NAME),    NULL); 
   CreateRemoteThread(Proc, NULL, NULL, (LPTHREAD_START_ROUTINE)LoadLib,    (LPVOID)RemoteString, NULL, NULL); 
   CloseHandle(Proc); 
   return true; 
} 

DWORD GetTargetThreadIDFromProcName(const char * ProcName) 
{ 
   PROCESSENTRY32 pe; 
   HANDLE thSnapShot; 
   BOOL retval, ProcFound = false; 

   thSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); 
   if(thSnapShot == INVALID_HANDLE_VALUE) return false; 

   pe.dwSize = sizeof(PROCESSENTRY32); 
   retval = Process32First(thSnapShot, &pe); 
   while(retval) 
   { 
      if(StrStrI(pe.szExeFile, ProcName)) return pe.th32ProcessID; 
      retval = Process32Next(thSnapShot, &pe); 
   } 
   return 0; 
}

The error I am getting is the following:

main.obj

unresolved external symbol __imp__StrStrIA@8 referenced in function "unsigned long __cdecl GetTargetThreadIDFromProcName(char const *)" (?GetTargetThreadIDFromProcName@@YAKPBD@Z)

Injector.exe

1 unresolved externals

Any solutions or just some help on understanding why this occurs would be great!

1 Answers1

0

As mentioned in the comments, it looks like you are not linking with shlwapi.lib. You need to do this in order to call StrStrI.

Sean
  • 60,939
  • 11
  • 97
  • 136