Injector compilation error

Posts 14 of 4 · Page 1 of 1
Injector compilation error
As some may have seen, I am trying to learn about internals and need to obviously start learning how injectors work. I got a basic source code to go through and am having an error during compilation. I followed some fixes and it still didn't work for whatever reason.

Here is the code:

Code:
#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; 
}
And the error:

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

Code:
1 unresolved externals
I tried linking shlwapi.lib in additional dependencies. But that didn't fix it either (Was a recommended fix for it)
This is definitely an issue with linking. Are all the necessary libraries linked correctly? Is this the only file that is being compiled, no other. cpp or .h files? If you send me the project zipped up I can take a look at it.

Update
I looked at the documentation and it appears that you have the necessary library and include already.

Try adding,
Code:
#pragma comment (lib, 'Shlwapi.lib')
below your other includes.
Quote Originally Posted by OhStarQ View Post
As some may have seen, I am trying to learn about internals and need to obviously start learning how injectors work. I got a basic source code to go through and am having an error during compilation. I followed some fixes and it still didn't work for whatever reason.

Here is the code:

Code:
#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; 
}
And the error:

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

Code:
1 unresolved externals
I tried linking shlwapi.lib in additional dependencies. But that didn't fix it either (Was a recommended fix for it)
It is indeed an external symbol missing meaning it has to be highly sure from a library. Make sure you either pragma comment, or go to project settings and add all the libraries properly. There are many tutorials on how to add libraries to your project.
You probably have a missing library.
Posts 14 of 4 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?