我正在创建一个UWP应用程序,它将允许我将DLL注入到应用程序中。使用Windows API函数时,UWP似乎认为这些函数未定义。
我一直在网上寻找DLL源代码,但没有一个真正使用UWP。我尝试从此处仅使用注入源代码:https://github.com/saeedirha/DLL-Injector。我怀疑UWP无法识别功能的原因是因为它不在正确的名称空间中。我可能是错的,但我怀疑这就是原因。
#include <ctype.h>
#include <Windows.h>
#include <tlhelp32.h>
#include <Shlwapi.h>
#include <tchar.h>
#pragma comment(lib, "Shlwapi.lib")
#pragma comment(lib, "user32.lib")
bool InjectDLL(const int& pid, const std::string& DLL_Path)
{
long dll_size = DLL_Path.length() + 1;
HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
if (hProc == NULL)
{
//cerr << "[!]Fail to open target process!" << endl;
return false;
}
//cout << "[+]Opening Target Process..." << endl;
LPVOID MyAlloc = VirtualAllocEx(hProc, NULL, dll_size, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
if (MyAlloc == NULL)
{
//cerr << "[!]Fail to allocate memory in Target Process." << endl;
return false;
}
//cout << "[+]Allocating memory in Targer Process." << endl;
int IsWriteOK = WriteProcessMemory(hProc, MyAlloc, DLL_Path.c_str(), dll_size, 0);
if (IsWriteOK == 0)
{
// cerr << "[!]Fail to write in Target Process memory." << endl;
return false;
}
//cout << "[+]Creating Remote Thread in Target Process" << endl;
DWORD dWord;
LPTHREAD_START_ROUTINE addrLoadLibrary = (LPTHREAD_START_ROUTINE)GetProcAddress(LoadLibrary("kernel32"), "LoadLibraryA");
HANDLE ThreadReturn = CreateRemoteThread(hProc, NULL, 0, addrLoadLibrary, MyAlloc, 0, &dWord);
if (ThreadReturn == NULL)
{
//cerr << "[!]Fail to create Remote Thread" << endl;
return false;
}
if ((hProc != NULL) && (MyAlloc != NULL) && (IsWriteOK != ERROR_INVALID_HANDLE) && (ThreadReturn != NULL))
{
//cout << "[+]DLL Successfully Injected :)" << endl;
return true;
}
return false;
}
我希望编译时不会出现错误消息,但实际上我得到了:
C3861'VirtualAllocEx':找不到标识符
C3861'WriteProcessMemory':找不到标识符
C3861'LoadLibrary':找不到标识符
C3861'CreateRemoteThread':找不到标识符