mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 10:17:22 +01:00
Reduce usage of exceptions from Boot (#2373)
* wip * make pretty * Remove CRT version check from IM * fix * Simplify IsDebuggerPresent hook
This commit is contained in:
parent
f613b177a2
commit
9092e36b33
16 changed files with 494 additions and 295 deletions
|
|
@ -82,37 +82,14 @@ void hooks::getprocaddress_singleton_import_hook::initialize() {
|
|||
s_dllChanged = 1;
|
||||
if (notiReason == LDR_DLL_NOTIFICATION_REASON_LOADED) {
|
||||
const auto dllName = unicode::convert<std::string>(pData->Loaded.FullDllName->Buffer);
|
||||
std::wstring version = L"<unknown>";
|
||||
std::wstring description = L"<unknown>";
|
||||
DWORD versionSize = GetFileVersionInfoSizeA(dllName.c_str(), NULL);
|
||||
|
||||
if (versionSize > 0) {
|
||||
std::vector<BYTE> versionData(versionSize);
|
||||
if (GetFileVersionInfoA(dllName.c_str(), 0, versionSize, versionData.data())) {
|
||||
struct LANGANDCODEPAGE {
|
||||
WORD wLanguage;
|
||||
WORD wCodePage;
|
||||
} *translate = nullptr;
|
||||
utils::loaded_module mod(pData->Loaded.DllBase);
|
||||
const auto version = mod.get_file_version()
|
||||
.transform([](const auto& v) { return utils::format_file_version(v.get()); })
|
||||
.value_or(L"<unknown>");
|
||||
|
||||
UINT uLen = 0;
|
||||
LPVOID lpBuffer;
|
||||
if (VerQueryValueW(versionData.data(), L"\\VarFileInfo\\Translation", (LPVOID*)&translate, &uLen) && uLen >= sizeof(LANGANDCODEPAGE)) {
|
||||
// Use the first language/codepage
|
||||
wchar_t subBlock[256];
|
||||
swprintf(subBlock, 256, L"\\StringFileInfo\\%04x%04x\\FileDescription", translate[0].wLanguage, translate[0].wCodePage);
|
||||
|
||||
if (VerQueryValueW(versionData.data(), subBlock, &lpBuffer, &uLen)) {
|
||||
description = std::wstring((wchar_t *)lpBuffer, uLen - 1);
|
||||
}
|
||||
|
||||
swprintf(subBlock, 256, L"\\StringFileInfo\\%04x%04x\\FileVersion", translate[0].wLanguage, translate[0].wCodePage);
|
||||
|
||||
if (VerQueryValueW(versionData.data(), subBlock, &lpBuffer, &uLen)) {
|
||||
version = std::wstring((wchar_t*)lpBuffer, uLen - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const auto description = mod.get_description()
|
||||
.value_or(L"<unknown>");
|
||||
|
||||
logging::I(R"({} "{}" ("{}" ver {}) has been loaded at 0x{:X} ~ 0x{:X} (0x{:X}); finding import table items to hook.)",
|
||||
LogTag, dllName, description, version,
|
||||
|
|
@ -142,7 +119,9 @@ void hooks::getprocaddress_singleton_import_hook::hook_module(const utils::loade
|
|||
if (mod.is_current_process())
|
||||
return;
|
||||
|
||||
const auto path = unicode::convert<std::string>(mod.path().wstring());
|
||||
const auto path = mod.path()
|
||||
.transform([](const auto& p) { return unicode::convert<std::string>(p.wstring()); })
|
||||
.value_or("<unknown>");
|
||||
|
||||
for (const auto& [hModule, targetFns] : m_targetFns) {
|
||||
for (const auto& [targetFn, pfnThunk] : targetFns) {
|
||||
|
|
@ -150,7 +129,7 @@ void hooks::getprocaddress_singleton_import_hook::hook_module(const utils::loade
|
|||
if (void* pGetProcAddressImport; mod.find_imported_function_pointer(dllName.c_str(), targetFn.c_str(), 0, pGetProcAddressImport)) {
|
||||
auto& hook = m_hooks[hModule][targetFn][mod];
|
||||
if (!hook) {
|
||||
logging::I("{} Hooking {}!{} imported by {}", LogTag, dllName, targetFn, unicode::convert<std::string>(mod.path().wstring()));
|
||||
logging::I("{} Hooking {}!{} imported by {}", LogTag, dllName, targetFn, path);
|
||||
|
||||
hook.emplace(std::format("getprocaddress_singleton_import_hook::hook_module({}!{})", dllName, targetFn), static_cast<void**>(pGetProcAddressImport), pfnThunk);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue