mirror of
https://github.com/mumble-voip/mumble.git
synced 2025-10-26 11:19:16 +00:00
This commit introduces a new plugin framework into the codebase of the Mumble client. Note that "plugin" here really refers to a (more or less) general purpose plugin and is therefore not to be confused with the previously available positional data plugins (only responsible for fetching positional data from a running game and passing that to Mumble). The plugin interface is written in C, removing the compiler-dependence the old "plugins" had. Instead plugins can now be written in an arbitrary language as long as that language is capable of being compiled into a shared library and also being capable of being C-compatible. As already indicated a plugin is essentially a shared library that provides certain functions that allow Mumble to interface with it. Inside Mumble the so-called PluginManager is responsible for managing the plugins and relaying events to the respective callbacks. Plugins themselves can also interact with Mumble on their own initiative by using the provided API functions. Fixes #2455 Fixes #2148 Fixes #1594 Fixes #2051 Fixes #3742 Fixes #4575 Fixes #4751
83 lines
2.2 KiB
C++
83 lines
2.2 KiB
C++
// Copyright 2020-2021 The Mumble Developers. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license
|
|
// that can be found in the LICENSE file at the root of the
|
|
// Mumble source tree or at <https://www.mumble.info/LICENSE>.
|
|
|
|
#include "HostWindows.h"
|
|
|
|
#include "mumble_positional_audio_utils.h"
|
|
|
|
#include <windows.h>
|
|
#include <tlhelp32.h>
|
|
|
|
HostWindows::HostWindows(const procid_t pid) : m_pid(pid) {
|
|
}
|
|
|
|
HostWindows::~HostWindows() {
|
|
}
|
|
|
|
bool HostWindows::peek(const procptr_t address, void *dst, const size_t size) const {
|
|
SIZE_T read;
|
|
const auto ok = Toolhelp32ReadProcessMemory(m_pid, reinterpret_cast< void * >(address), dst, size, &read);
|
|
return (ok && read == size);
|
|
}
|
|
|
|
Modules HostWindows::modules() const {
|
|
const auto processHandle = OpenProcess(PROCESS_QUERY_INFORMATION, false, m_pid);
|
|
if (!processHandle) {
|
|
return {};
|
|
}
|
|
|
|
const auto snapshotHandle = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, m_pid);
|
|
if (snapshotHandle == INVALID_HANDLE_VALUE) {
|
|
return {};
|
|
}
|
|
|
|
Modules modules;
|
|
|
|
MODULEENTRY32 me;
|
|
me.dwSize = sizeof(me);
|
|
for (auto ok = Module32First(snapshotHandle, &me); ok; ok = Module32Next(snapshotHandle, &me)) {
|
|
const auto name = utf16ToUtf8(reinterpret_cast< char16_t * >(me.szModule));
|
|
if (modules.find(name) != modules.cend()) {
|
|
continue;
|
|
}
|
|
|
|
Module module(name);
|
|
MEMORY_BASIC_INFORMATION64 mbi;
|
|
auto address = reinterpret_cast< procptr_t >(me.modBaseAddr);
|
|
while (VirtualQueryEx(processHandle, reinterpret_cast< LPCVOID >(address),
|
|
reinterpret_cast< PMEMORY_BASIC_INFORMATION >(&mbi), sizeof(mbi))) {
|
|
MemoryRegion region{};
|
|
region.address = address;
|
|
region.size = mbi.RegionSize;
|
|
switch (mbi.Protect) {
|
|
case PAGE_READWRITE:
|
|
region.writable = true;
|
|
case PAGE_READONLY:
|
|
case PAGE_WRITECOPY:
|
|
region.readable = true;
|
|
break;
|
|
case PAGE_EXECUTE_READWRITE:
|
|
region.writable = true;
|
|
case PAGE_EXECUTE_READ:
|
|
case PAGE_EXECUTE_WRITECOPY:
|
|
region.readable = true;
|
|
case PAGE_EXECUTE:
|
|
region.executable = true;
|
|
break;
|
|
}
|
|
module.addRegion(region);
|
|
|
|
address += region.size;
|
|
}
|
|
|
|
modules.insert(std::make_pair(name, module));
|
|
}
|
|
|
|
CloseHandle(processHandle);
|
|
CloseHandle(snapshotHandle);
|
|
|
|
return modules;
|
|
}
|