weixin_45461329 2019-11-22 21:28 采纳率: 0%
浏览 362

C,C++,在pc微信进程中写入一个文件,

为什么到OpenProcess就停了,图片说明

#include "stdafx.h"
#include "Project1.h"
#include <Windows.h>
#include "resource.h"
#include <TlHelp32.h>
#include<stdio.h>
constexpr auto WECHAT_PROCESS_NAME = "WeChat.exe";

INT_PTR CALLBACK DialogProc(
    HWND Arg1,
    UINT Arg2,
    WPARAM Arg3,
    LPARAM Arg4
);
VOID InjectDll();

int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
                     _In_opt_ HINSTANCE hPrevInstance,
                     _In_ LPWSTR    lpCmdLine,
                     _In_ int       nCmdShow)

{
    DialogBox(hInstance, MAKEINTRESOURCE(ID_MAIN), NULL,&DialogProc);
    return 0;}
INT_PTR CALLBACK DialogProc(
    HWND Arg1,
    UINT Arg2,
    WPARAM Arg3,
    LPARAM Arg4
)
{
    if (Arg2 == WM_INITDIALOG)
    {
        //MessageBox(NULL, "首次加载", "标题", 0);
    }
    if (Arg2 == WM_CLOSE) {
         EndDialog(Arg1, 0);
    }
    if (Arg2 == WM_COMMAND) {
        if (Arg3 == INJECT_DLL) {
            InjectDll();
        }
        if (Arg3 == UIN_DLL) {
        }
    }
    return FALSE;
}
DWORD ProcessNameFindPID(LPCSTR ProcessName) {

    HANDLE ProcessALL=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,NULL);
    PROCESSENTRY32 processInfo = { 0 };
    processInfo.dwSize = sizeof(PROCESSENTRY32);
    do
    {
        if (strcmp(ProcessName, processInfo.szExeFile) == 0) {
            return processInfo.th32ProcessID;
        }
    } while (Process32Next(ProcessALL, &processInfo));

    return 0;
}
VOID InjectDll() {
    CHAR pathStr[0x100] = { "D://wechatdell//Project1//DebugProject1.dll" };
    DWORD PID = ProcessNameFindPID(WECHAT_PROCESS_NAME);
    if (PID == 0)
    {
        MessageBox(NULL, "没有找到微信进程或者微信没有启动", "错误", 0);
        return;
    }
    HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, PID);
    if (NULL == hProcess) {
    }
    {
        MessageBox(NULL, "进程打开失败,可能权限不足或者关闭了应用", "错误", 0);
        return;

    }
    LPVOID  dllAdd =VirtualAllocEx(hProcess, NULL, sizeof(pathStr),MEM_COMMIT,PAGE_READWRITE);
    if (NULL == dllAdd) {
        MessageBox(NULL, "内存分配失败", "错误", 0);
        return;
    }
    if (WriteProcessMemory(hProcess, dllAdd, pathStr, strlen(pathStr), NULL) == 0) {
        MessageBox(NULL, "路径写入失败", "错误", 0);
        return;
    }
    CHAR test[0x100] = { 0 };
    sprintf_s(test, "写入的地址:%p", dllAdd);
    OutputDebugString(test);
}
  • 写回答

1条回答 默认 最新

  • threenewbee 2019-11-22 23:50
    关注

    HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, PID);
    调试这里,从提示信息看,是权限不够

    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮