summaryrefslogtreecommitdiff
path: root/src/plugins/PluginAPI.cpp
diff options
context:
space:
mode:
authoroutfoxxed <outfoxxed@outfoxxed.me>2023-05-16 13:39:14 -0700
committerGitHub <noreply@github.com>2023-05-16 23:39:14 +0300
commit642030f959efe7bd2692bf6a4236d4c1b39ee51a (patch)
tree2df2fdf2b237e2fc7279d6bda76ea4b9b3cc97c1 /src/plugins/PluginAPI.cpp
parent78826c6d18ee587a28cf39479f9a015888d2e096 (diff)
Fix not finding function symbols for hooking (#2292)
Fixes no useful feedback about failing subcommand. Fixes function hooks breaking when running under a path containing spaces. Replaced old usages with this function where possible. Complex shell usages now use `execAndGetShell` which is equal to the old function.
Diffstat (limited to 'src/plugins/PluginAPI.cpp')
-rw-r--r--src/plugins/PluginAPI.cpp21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/plugins/PluginAPI.cpp b/src/plugins/PluginAPI.cpp
index d8b3c82d..48500ee4 100644
--- a/src/plugins/PluginAPI.cpp
+++ b/src/plugins/PluginAPI.cpp
@@ -280,11 +280,11 @@ APICALL std::vector<SFunctionMatch> HyprlandAPI::findFunctionsByName(HANDLE hand
#endif
#ifdef __clang__
- static const auto SYMBOLS = execAndGet(("llvm-nm -D -j " + FPATH.string()).c_str());
- static const auto SYMBOLSDEMANGLED = execAndGet(("llvm-nm -D -j --demangle " + FPATH.string()).c_str());
+ static const auto SYMBOLS = execAndGet(("llvm-nm -D -j \"" + FPATH.string() + "\"").c_str());
+ static const auto SYMBOLSDEMANGLED = execAndGet(("llvm-nm -D -j --demangle \"" + FPATH.string() + "\"").c_str());
#else
- static const auto SYMBOLS = execAndGet(("nm -D -j " + FPATH.string()).c_str());
- static const auto SYMBOLSDEMANGLED = execAndGet(("nm -D -j --demangle=auto " + FPATH.string()).c_str());
+ static const auto SYMBOLS = execAndGet(("nm -D -j \"" + FPATH.string() + "\"").c_str());
+ static const auto SYMBOLSDEMANGLED = execAndGet(("nm -D -j --demangle=auto \"" + FPATH.string() + "\"").c_str());
#endif
auto demangledFromID = [&](size_t id) -> std::string {
@@ -301,6 +301,17 @@ APICALL std::vector<SFunctionMatch> HyprlandAPI::findFunctionsByName(HANDLE hand
return SYMBOLSDEMANGLED.substr(pos, SYMBOLSDEMANGLED.find('\n', pos + 1) - pos);
};
+ if (SYMBOLS.empty()) {
+ Debug::log(ERR, "Unable to search for function \"%s\": no symbols found in binary (is \"%s\" in path?)", name.c_str(),
+#ifdef __clang__
+ "llvm-nm"
+#else
+ "nm"
+#endif
+ );
+ return {};
+ }
+
std::vector<SFunctionMatch> matches;
std::istringstream inStream(SYMBOLS);
@@ -319,4 +330,4 @@ APICALL std::vector<SFunctionMatch> HyprlandAPI::findFunctionsByName(HANDLE hand
}
return matches;
-} \ No newline at end of file
+}