C++带有用户输入的喷油器

C++ injector with user input

本文关键字:输入 用户 C++      更新时间:2023-10-16

我做了一个简单的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;
}

一些帮助会很棒。(通过用户输入查找进程工作正常(

我找到了一个可行的解决方案。我的两个问题是:

  • 我需要 dll 的完整路径
  • 当我在运行程序时尝试手动输入 std::cin 时,它似乎弄乱了路径中的空格。

溶液:我使用了GetFullPathNameA(另一个GetFullPathName对我不起作用(,如下所示:

char dllPath[MAX_PATH];
GetFullPathNameA(dllName, MAX_PATH, dllPath, 0);