mirror of
https://github.com/mirkobrombin/raven.git
synced 2026-11-03 21:46:32 +00:00
GetModuleHandleExW looked modules up by file name only, so a full path never matched, and on 64 bits GetModuleHandleW had no path lookup either. The .NET host loads hostfxr.dll by its full path and then pins it with GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_PIN, path), so PowerShell 7 stopped with "Failed to pin library". Both now use GetModuleHandle's own lookup: by name, with API sets and the trailing-dot rule, or by path, where the 64-bit loader matches the module of that file name to the file it was loaded from (or, for the libraries Raven serves, to the system folder GetModuleFileName reports for them). Assisted-by: Claude Code:claude-opus-5-5 AI-Scope: the shared lookup and the 64-bit path lookup (cherry picked from commit 9ea61e7f3c61546be696103a103181cd6ed3e5c3)
37 lines
1.3 KiB
C++
37 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include "environment.h"
|
|
|
|
#include <optional>
|
|
#include <functional>
|
|
|
|
namespace raven {
|
|
|
|
class NativeModuleAPI {
|
|
public:
|
|
NativeModuleAPI(NativeProcess &process, NativeEnvironment &environment,
|
|
const ModuleSet &modules, const PEModule &entry);
|
|
bool dispatch(std::string_view name);
|
|
void set_loader(std::function<uint64_t(std::string)> load, std::function<bool(uint64_t)> free);
|
|
// The flags of the LoadLibraryEx call being served, zero for LoadLibrary.
|
|
uint32_t load_flags() const { return flags; }
|
|
// A library asked for by a path is a particular file, which only the loader that read it can tell is already in the process.
|
|
void set_path_lookup(std::function<uint64_t(const std::string &)> lookup) { path_lookup = std::move(lookup); }
|
|
// GetModuleHandle's lookup: the program for a null name, else the loaded module the guest string names.
|
|
uint64_t module_handle(uint64_t address, bool wide);
|
|
|
|
private:
|
|
NativeProcess &process;
|
|
NativeEnvironment &environment;
|
|
const ModuleSet &modules;
|
|
const PEModule &entry;
|
|
std::function<uint64_t(std::string)> load;
|
|
std::function<bool(uint64_t)> free;
|
|
std::function<uint64_t(const std::string &)> path_lookup;
|
|
uint32_t flags = 0;
|
|
std::optional<std::string> guest_name(uint64_t address, bool wide) const;
|
|
uint64_t procedure(uint64_t handle, uint64_t name);
|
|
};
|
|
|
|
}
|