当前位置: 首页>>代码示例>>C++>>正文


C++ Process::GetHandle方法代码示例

本文整理汇总了C++中Process::GetHandle方法的典型用法代码示例。如果您正苦于以下问题:C++ Process::GetHandle方法的具体用法?C++ Process::GetHandle怎么用?C++ Process::GetHandle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Process的用法示例。


在下文中一共展示了Process::GetHandle方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: CreateRemoteThreadAndWait

inline SmartHandle CreateRemoteThreadAndWait(Process const& process,
                                             LPTHREAD_START_ROUTINE func,
                                             DWORD timeout = INFINITE)
{
  SmartHandle remote_thread{::CreateRemoteThread(
    process.GetHandle(), nullptr, 0, func, nullptr, 0, nullptr)};
  if (!remote_thread.GetHandle())
  {
    DWORD const last_error = ::GetLastError();
    HADESMEM_DETAIL_THROW_EXCEPTION(Error{}
                                    << ErrorString{"CreateRemoteThread failed."}
                                    << ErrorCodeWinLast{last_error});
  }

  DWORD const wait_res =
    ::WaitForSingleObject(remote_thread.GetHandle(), timeout);
  if (wait_res != WAIT_OBJECT_0)
  {
    if (wait_res == WAIT_TIMEOUT)
    {
      HADESMEM_DETAIL_THROW_EXCEPTION(
        Error{} << ErrorString{"WaitForSingleObject timeout."});
    }

    DWORD const last_error = ::GetLastError();
    HADESMEM_DETAIL_THROW_EXCEPTION(
      Error{} << ErrorString{"WaitForSingleObject failed."}
              << ErrorCodeWinLast{last_error});
  }

  return remote_thread;
}
开发者ID:GliderPro,项目名称:hadesmem,代码行数:32,代码来源:remote_thread.hpp

示例2: TryAlloc

inline PVOID TryAlloc(Process const& process, SIZE_T size, PVOID base = nullptr)
{
  return ::VirtualAllocEx(process.GetHandle(),
                          base,
                          size,
                          MEM_COMMIT | MEM_RESERVE,
                          PAGE_EXECUTE_READWRITE);
}
开发者ID:GliderPro,项目名称:hadesmem,代码行数:8,代码来源:alloc.hpp

示例3: Free

inline void Free(Process const& process, LPVOID address)
{
  if (!::VirtualFreeEx(process.GetHandle(), address, 0, MEM_RELEASE))
  {
    DWORD const last_error = ::GetLastError();
    HADESMEM_DETAIL_THROW_EXCEPTION(Error{}
                                    << ErrorString{"VirtualFreeEx failed."}
                                    << ErrorCodeWinLast{last_error});
  }
}
开发者ID:GliderPro,项目名称:hadesmem,代码行数:10,代码来源:alloc.hpp

示例4: Alloc

inline PVOID Alloc(Process const& process, SIZE_T size, PVOID base = nullptr)
{
  PVOID const address = ::VirtualAllocEx(process.GetHandle(),
                                         base,
                                         size,
                                         MEM_COMMIT | MEM_RESERVE,
                                         PAGE_EXECUTE_READWRITE);
  if (!address)
  {
    DWORD const last_error = ::GetLastError();
    HADESMEM_DETAIL_THROW_EXCEPTION(Error{}
                                    << ErrorString{"VirtualAllocEx failed."}
                                    << ErrorCodeWinLast{last_error});
  }

  return address;
}
开发者ID:GliderPro,项目名称:hadesmem,代码行数:17,代码来源:alloc.hpp

示例5: Protect

inline DWORD Protect(Process const& process,
                     MEMORY_BASIC_INFORMATION const& mbi,
                     DWORD protect)
{
  DWORD old_protect = 0;
  if (!::VirtualProtectEx(process.GetHandle(),
                          mbi.BaseAddress,
                          mbi.RegionSize,
                          protect,
                          &old_protect))
  {
    DWORD const last_error = ::GetLastError();
    HADESMEM_DETAIL_THROW_EXCEPTION(Error{}
                                    << ErrorString{"VirtualProtectEx failed."}
                                    << ErrorCodeWinLast{last_error});
  }

  return old_protect;
}
开发者ID:lvous,项目名称:hadesmem,代码行数:19,代码来源:protect_region.hpp

示例6: WriteUnchecked

inline void WriteUnchecked(Process const& process,
                           PVOID address,
                           LPCVOID data,
                           std::size_t len)
{
  HADESMEM_DETAIL_ASSERT(address != nullptr);
  HADESMEM_DETAIL_ASSERT(data != nullptr);
  HADESMEM_DETAIL_ASSERT(len != 0);

  SIZE_T bytes_written = 0;
  if (!::WriteProcessMemory(
        process.GetHandle(), address, data, len, &bytes_written) ||
      bytes_written != len)
  {
    DWORD const last_error = ::GetLastError();
    HADESMEM_DETAIL_THROW_EXCEPTION(Error{}
                                    << ErrorString{"WriteProcessMemory failed."}
                                    << ErrorCodeWinLast{last_error});
  }
}
开发者ID:GliderPro,项目名称:hadesmem,代码行数:20,代码来源:write_impl.hpp


注:本文中的Process::GetHandle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。