Skip to content

Commit

Permalink
feat: add switch to disableErrorOutput
Browse files Browse the repository at this point in the history
  • Loading branch information
OEOTYAN committed Dec 4, 2023
1 parent af8c677 commit 10eff15
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
10 changes: 6 additions & 4 deletions src/ll/api/memory/Hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,18 @@ bool unhook(FuncPtr target, FuncPtr detour) {
}
}

FuncPtr resolveIdentifier(std::string_view identifier) {
if (auto pl = resolveSymbol(identifier.data()); pl) {
FuncPtr resolveIdentifier(std::string_view identifier, bool disableErrorOutput) {
if (auto pl = resolveSymbol(identifier.data(), true); pl) {
return pl;
} else if (auto sig = resolveSignature(identifier); sig) {
return sig;
} else if (auto dbgeng = (FuncPtr)stacktrace_utils::tryGetSymbolAddress(identifier); dbgeng) {
return dbgeng;
}
logger.fatal("Could not find symbol/signature in memory: {}", identifier);
logger.fatal("In module: {}", win_utils::getCallerModuleFileName());
if (!disableErrorOutput) {
logger.fatal("Could not find symbol/signature in memory: {}", identifier);
logger.fatal("In module: {}", win_utils::getCallerModuleFileName());
}
return nullptr;
}

Expand Down
2 changes: 1 addition & 1 deletion src/ll/api/memory/Hook.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ LLAPI bool unhook(FuncPtr target, FuncPtr detour);
* @param identifier symbol or signature
* @return FuncPtr
*/
LLNDAPI FuncPtr resolveIdentifier(std::string_view identifier);
LLNDAPI FuncPtr resolveIdentifier(std::string_view identifier, bool disableErrorOutput = false);

template <class T>
concept FuncPtrType = std::is_function_v<std::remove_pointer_t<T>> || std::is_member_function_pointer_v<T>;
Expand Down
7 changes: 6 additions & 1 deletion src/ll/api/memory/Memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ namespace ll::memory {

FuncPtr resolveSymbol(char const* symbol) { return pl::symbol_provider::pl_resolve_symbol(symbol); }

FuncPtr resolveSymbol(std::string_view symbol, bool) // TODO: add support in preloader
{
return pl::symbol_provider::pl_resolve_symbol(symbol.data());
}

FuncPtr resolveSignature(std::string_view signature) {
static auto bdsSpan = win_utils::getImageRange();
std::span<uchar> span;
Expand Down Expand Up @@ -50,7 +55,7 @@ FuncPtr resolveSignature(std::string_view signature) {
if (pattern.empty()) {
return nullptr;
}
for (size_t i = 0; i < span.size() - pattern.size(); ++i) { // TODO: optimize this search
for (size_t i = 0; i < span.size() - pattern.size(); ++i) {
bool match = true;
size_t iter = 0;
for (auto& c : pattern) {
Expand Down
2 changes: 2 additions & 0 deletions src/ll/api/memory/Memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ inline void memcpy_t(void* dst, void const* src) {
*/
LLNDAPI FuncPtr resolveSymbol(char const* symbol);

LLNDAPI FuncPtr resolveSymbol(std::string_view symbol, bool disableErrorOutput);

/**
* @brief resolve signature to function pointer
* @param t Signature
Expand Down

0 comments on commit 10eff15

Please sign in to comment.