c++ - 向 UWP 注入(inject)一个 dll 文件

标签 c++ uwp hook

我制作了一个简单的 UWP 应用程序和一个桌面应用程序。此代码将 ConsoleApplication1.dll 文件注入(inject)桌面是正常的,但我无法注入(inject) UWP 应用程序。 我有两个问题: 为什么此代码无法注入(inject) UWP 应用程序? 以及如何解决?

这段代码注入(inject)一个DLL文件

#include "pch.h"
#include <vector>
#include <string>
#include <windows.h>
#include <Tlhelp32.h>

using std::vector;
using std::string;

int main(void)
{
while (true)
{
    vector<string>processNames;
    PROCESSENTRY32 pe32;
    pe32.dwSize = sizeof(PROCESSENTRY32);
    HANDLE hTool32 = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
    BOOL bProcess = Process32First(hTool32, &pe32);
    if (bProcess == TRUE)
    {
        while ((Process32Next(hTool32, &pe32)) == TRUE)
        {
            processNames.push_back(pe32.szExeFile);
            if (strcmp(pe32.szExeFile, "ConsoleApplication4.exe") == 0 || strcmp(pe32.szExeFile, "UWP.exe") == 0)
            {
                printf("Hooked %s, %d \n", pe32.szExeFile, pe32.th32ProcessID);
                char* DirPath = new char[MAX_PATH];
                char* FullPath = new char[MAX_PATH];
                GetCurrentDirectory(MAX_PATH, DirPath);
                sprintf_s(FullPath, MAX_PATH, "%s\\..\\ConsoleApplication1\\ConsoleApplication1.dll", DirPath);
                FILE *pFile;
                if (fopen_s(&pFile, FullPath, "r") || !pFile)
                {
                    OutputDebugString("[Hook] File name or file does not exist");
                    OutputDebugString(FullPath);
                    return -1;
                }
                fclose(pFile);

                HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pe32.th32ProcessID);
                LPVOID LoadLibraryAddr = (LPVOID)GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA");
                LPVOID LLParam = (LPVOID)VirtualAllocEx(hProcess, NULL, strlen(FullPath), MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);

                bool result = WriteProcessMemory(hProcess, LLParam, FullPath, strlen(FullPath), NULL);
                CreateRemoteThread(hProcess, NULL, NULL, (LPTHREAD_START_ROUTINE)LoadLibraryAddr, LLParam, NULL, NULL);

                CloseHandle(hProcess);
                delete[] DirPath;
                delete[] FullPath;

                OutputDebugString("[Hook] Hooked success");

                system("pause");

                return 0;
            }
        }
    }
    CloseHandle(hTool32);
}
return 0;
}

谢谢

最佳答案

注入(inject) UWP 应用程序的 DLL 与注入(inject) Win32 程序没有区别;相同的技术和通用 DLL 注入(inject)器将适用于 UWP 应用程序。但是,如果只是尝试将任何常规 DLL 注入(inject) UWP 应用程序,则 DLL 可能不会加载。这是因为 ALL APPLICATION PACKAGES 组必须对被注入(inject)的 DLL 具有读取和执行权限。

要手动设置这些权限:右键单击 DLL,进入属性,转到安全选项卡,点击编辑,点击添加,在弹出的对话框中键入“ALL”并点击确定。在英文系统上,这会将所有应用程序包添加到默认启用读取/执行的权限列表中;对于非英语系统,该组将被命名为不同的东西。

https://www.unknowncheats.me/forum/general-programming-and-reversing/177183-basic-intermediate-techniques-uwp-app-modding.html

谢谢

关于c++ - 向 UWP 注入(inject)一个 dll 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52833300/

相关文章:

c# - 如何在 Realm-dotnet 中存储 System.Collections.Generic.Dictionary

c# - 在 WinRT/UWP 中创建自定义虚拟化控件

c++ - 挂接到特定线程时,SetWindowsHookEx 返回 null

c++ - 如何获取成员函数的地址指针

c# - 使用 Azure 移动服务对现有 Windows 10 UWP 应用程序进行 Google 身份验证

javascript - WordPress - 无法使用变量

mercurial - 如何根据脚本拒绝推送到 Mercurial 服务器,而不会在此期间冒坏拉取的风险?

c++ - undefined symbol -在centos 7中使用log4cxx

c++ - `std::memory_order_acquire` 的语义是否需要 x86/x86_64 上的处理器指令?

c++ - 如何标记字符串