Skip to content

Instantly share code, notes, and snippets.

@mdsitton
Created November 1, 2023 09:06
Show Gist options
  • Save mdsitton/95fc0040d01cdf198961cb72255c234a to your computer and use it in GitHub Desktop.
Save mdsitton/95fc0040d01cdf198961cb72255c234a to your computer and use it in GitHub Desktop.
#include "NativeNamedPipe.h"
#include <iostream>
#include <string>
#include <fmt/format.h>
#include <cstdlib>
#include <thread>
std::string paths[] = {
"discord-ipc-",
"app/com.discordapp.Discord/discord-ipc-",
"snap.discord-canary/discord-ipc-",
"snap.discord/discord-ipc-"};
static const char *get_temp_path()
{
const char *temp = std::getenv("XDG_RUNTIME_DIR");
temp = temp ? temp : std::getenv("TMPDIR");
temp = temp ? temp : std::getenv("TMP");
temp = temp ? temp : std::getenv("TEMP");
temp = temp ? temp : "/tmp";
return temp;
}
int main()
{
fmt::println("Starting sockets!");
BaseNamedPipeClient *client = UNP::createClient();
try
{
while (true)
{
int pathCount = sizeof(paths) / sizeof(std::string);
for (int i = 0; i < pathCount; ++i)
{
fmt::println("Checking path: {}/{}", get_temp_path(), paths[i]);
for (int j = 0; j < 10; ++j)
{
std::string fmtPath = fmt::format("{}/{}/{}", get_temp_path(), paths[i], j);
int status = UNP::open(client, (char *)(fmtPath.c_str()));
if (status == 0)
{
fmt::println("open success!");
}
else
{
fmt::println("open failure: {}", status);
}
fmt::println("Connected: {}", UNP::isConnected(client));
UNP::close(client);
}
std::this_thread::sleep_for(std::chrono::seconds(3));
}
}
}
catch (const std::exception &e)
{
std::cerr << e.what() << '\n';
}
UNP::destroyClient(client);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment