m0_50244597
m0_50244597
2021-03-20 15:13
采纳率: 16.7%
浏览 25

一些错误[这是一个占位符]

void Code::asm_code_inject(HANDLE handle)
{
    LPVOID addr = VirtualAllocEx(handle, nullptr, this->length, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
    if (addr == nullptr)
        return;

    DWORD write_size = 0;
    BOOL ret = WriteProcessMemory(handle, addr, this->code, this->length, &write_size);
    if (ret == 0 || write_size != this->length)
    {
        VirtualFreeEx(handle, addr, 0, MEM_RELEASE);
        return;
    }

    HANDLE thread = CreateRemoteThread(handle, nullptr, 0, LPTHREAD_START_ROUTINE(addr), nullptr, 0, nullptr);
    if (thread == nullptr)
    {
        VirtualFreeEx(handle, addr, 0, MEM_RELEASE);
        return;
    }

    [[maybe_unused]] DWORD wait_status = WaitForSingleObject(thread, INFINITE);
    CloseHandle(thread);
    VirtualFreeEx(handle, addr, 0, MEM_RELEASE);

#ifdef _DEBUG
    std::wcout << L"Wait Status: " << wait_status << std::endl;
    std::wcout << L"Asm Code: ";
    for (size_t i = 0; i < this->length; i++)
        std::cout << std::hex << int(code[i]) << " ";
    std::cout << std::endl;
    std::wcout << L"Code Length: " << std::dec << this->length << std::endl;
#endif
}

我要把这些从网上得到的代码(一部分)编译dll

[Error] cannot convert 'DWORD* {aka long unsigned int*}' to 'SIZE_T* {aka long long unsigned int*}' for argument '5' to 'WINBOOL WriteProcessMemory(HANDLE, LPVOID, LPCVOID, SIZE_T, SIZE_T*)'

[Warning] 'maybe_unused' attribute directive ignored [-Wattributes]

环境:ISOC++11

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • huanhuilong
    幻灰龙 2021-03-20 23:41
    已采纳

    要读错误提示:

    [Error] cannot convert 'DWORD* {aka long unsigned int*}' to 'SIZE_T* {aka long long unsigned int*}' for argument '5' to 'WINBOOL WriteProcessMemory(HANDLE, LPVOID, LPCVOID, SIZE_T, SIZE_T*)'

    [Warning] 'maybe_unused' attribute directive ignored [-Wattributes]

     

    加粗部分就是说 WriteProcessMemory 的第 5 个参数类型不匹配。需要的是 SIZE_T* ,你传入的是 &write_size,而 write_size 是 DWORD 类型

     

    点赞 评论
  • m0_50244597
    m0_50244597 2021-03-21 16:43

    好的,我编译了,然后...

     

    点赞 评论
  • m0_50244597
    m0_50244597 2021-03-21 16:43

     

    点赞 评论
  • m0_50244597
    m0_50244597 2021-03-21 16:44

    如图所见,大量函数不能用

    点赞 评论

相关推荐