Skip to content

Commit

Permalink
Implement get_module for Win32
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeroMemes committed Aug 16, 2023
1 parent 3cb8e60 commit 35ea12b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 3 additions & 3 deletions include/libhat/Process.hpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#pragma once

#include <ranges>
#include <span>
#include <string_view>

namespace hat::process {

// TODO: Consider using a typedef or class instead? idk
enum class module_t : uintptr_t {};

/// Returns the module for the curent process's base executable
/// Returns the module for the current process's base executable
auto get_process_module() -> module_t;

/// Returns a module by its given name in the current process
auto get_module(std::string_view name) -> module_t;
auto get_module(const std::string& name) -> module_t;

/// Returns the module located at the specified base address
auto module_at(uintptr_t address) -> module_t;
Expand Down
4 changes: 4 additions & 0 deletions src/os/Win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ namespace hat::process {
return module_t{reinterpret_cast<uintptr_t>(GetModuleHandleA(nullptr))};
}

module_t get_module(const std::string& name) {
return module_at(reinterpret_cast<uintptr_t>(GetModuleHandleA(name.c_str())));
}

std::span<std::byte> get_module_data(module_t mod) {
auto* const scanBytes = reinterpret_cast<std::byte*>(mod);
auto* const ntHeaders = GetNTHeaders(mod);
Expand Down

0 comments on commit 35ea12b

Please sign in to comment.