gpt4 book ai didi

c++ - 编译 DLL 注入(inject)器时构建失败

转载 作者:行者123 更新时间:2023-11-28 06:49:05 30 4
gpt4 key购买 nike

我是 C++ 编码新手。我一直在尝试通过 Internet 教程编译我自己的 DLL Injector

这是我的代码:

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


#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;

int main(int argc, char * argv[])
{
// The name of the process you want to inject
DWORD pID = GetTargetThreadIDFromProcName("notepad.exe");

// Get the dll's full path name
char buf[MAX_PATH] = {0};
GetFullPathName("Project1.dll", MAX_PATH, buf, NULL); // On the place where is Project1.dll you can put the name of your dll
printf(buf);
printf("\n");

// Inject our main dll
if(!Inject(pID, buf))
{
printf("Not loaded!"); // If injection is not sucsessfull
}
else
{
printf("Loaded!"); // If injection is sucsessfull
}
_getch();
return 0;
}

BOOL Inject(DWORD pID, const char * DLL_NAME)
{
HANDLE Proc;
HMODULE hLib;
char buf[50] = {0};
LPVOID RemoteString, LoadLibAddy;
if(!pID)
return false;
Proc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pID);
if(!Proc)
{
sprintf(buf, "OpenProcess() failed: %d", GetLastError());
//MessageBox(NULL, buf, "Loader", MB_OK);
printf(buf);
return false;
}
LoadLibAddy = (LPVOID)GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA");
// Allocate space in the process for our DLL
RemoteString = (LPVOID)VirtualAllocEx(Proc, NULL, strlen(DLL_NAME), MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
// Write the string name of our DLL in the memory allocated
WriteProcessMemory(Proc, (LPVOID)RemoteString, DLL_NAME, strlen(DLL_NAME), NULL);
// Load our <strong class="highlight">DLL</strong>
CreateRemoteThread(Proc, NULL, NULL, (LPTHREAD_START_ROUTINE)LoadLibAddy, (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)
{
//MessageBox(NULL, "Error: Unable to create toolhelp snapshot!", "2MLoader", MB_OK);
printf("Error: Unable to create toolhelp snapshot!");
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;
}

我不断收到错误:

"1>Injector.obj : error LNK2019: unresolved external symbol __imp__StrStrIA@8 referenced in function "unsigned long __cdecl GetTargetThreadIDFromProcName(char const *)" (?GetTargetThreadIDFromProcName@@YAKPBD@Z)
1>C:\Users\Rizker\documents\visual studio 2010\Projects\Injector\Debug\Injector.exe : fatal error LNK1120: 1 unresolved externals"

感谢任何帮助。哦,是的,这段代码在我格式化我的电脑之前是有效的,但在那之后,我认为它以某种方式崩溃了。

原帖:http://www.mpgh.net/forum/showthread.php?t=209479

最佳答案

链接器找不到StrStrI函数,您应该在文件中添加 Shlwapi.lib

#pragma comment(lib, "Shlwapi.lib")

关于c++ - 编译 DLL 注入(inject)器时构建失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24362925/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com