我制作了一个简单的DLL注入器,工作正常(x64)。但是当我尝试升级它以便用户可以通过std :: cin选择dll文件的名称时,我还没有找到一个有效的方法。要么我在编译时遇到某种错误,要么一切似乎都很好,除了注入不起作用。
有效的代码:
#define DLLPATH "C:\\Users\\user\\Desktop\\folder name\\test_dll.dll"
bool InjectDll(DWORD pid, char* dll);
int main() {
SetConsoleTitle(_T("Simple Injector"));
wstring pName;
cout << "Enter target process name: ";
wcin >> pName;
DWORD pid = FindProcessId(pName);
if (!pid || pid == 0) {
wcout << "Couldn't find process: " << pName << endl;
system("pause");
return 0;
}
if (InjectDll(pid, (char*)DLLPATH)) {
cout << "DLL injected successfully" << endl;
}
else {
cout << "DLL injection failed" << endl;
cout << pid << endl;
}
system("pause");
return 0;
}
但是当我尝试使DLL路径来自用户输入时它不起作用(没有错误但注入不会发生):
bool InjectDll(DWORD pid, char* dll);
int main() {
SetConsoleTitle(_T("Simple Injector"));
wstring pName;
cout << "Enter target process name: ";
wcin >> pName;
DWORD pid = FindProcessId(pName);
if (!pid || pid == 0) {
wcout << "Couldn't find process: " << pName << endl;
system("pause");
return 0;
}
char t_dll[MAX_PATH];
cout << "Enter the name of the dll: ";
cin >> t_dll;
if (InjectDll(pid, t_dll)) {
cout << "DLL injected successfully" << endl;
}
else {
cout << "DLL injection failed" << endl;
cout << pid << endl;
}
system("pause");
return 0;
}
一些帮助会很棒。 (通过用户输入找到流程工作正常)
答案 0 :(得分:0)
我找到了一个有效的解决方案。 我的两个问题是:
<强>解:强> 我使用了GetFullPathNameA(另一个GetFullPathName对我不起作用),如下所示:
char dllPath[MAX_PATH];
GetFullPathNameA(dllName, MAX_PATH, dllPath, 0);