fix client access for linux

This commit is contained in:
MrBesen 2022-08-24 19:24:18 +02:00
parent c8341ef491
commit 0d43798a1c
Signed by untrusted user: MrBesen
GPG Key ID: 596B2350DCD67504
3 changed files with 4 additions and 49 deletions

View File

@ -9,7 +9,7 @@ class ClientAccess {
ClientAccess();
public:
ClientAccess(const std::string& token, uint16_t port);
static std::shared_ptr<ClientAccess> find(bool uselockfile = true);
static std::shared_ptr<ClientAccess> find();
public:
std::string getBasicAuth() const;

View File

@ -21,8 +21,6 @@
static const std::string CLIENTNAME = "LeagueClientUx.exe"; // returns the name and value of a argument or empty string if it could not be parsed
static std::string parseArg(const std::string& input, std::string& value);
static std::shared_ptr<ClientAccess> findUsingArgs(const std::vector<std::string>& cmdline);
static std::shared_ptr<ClientAccess> findUsingLockfile(const std::vector<std::string>& cmdline, pid_t pid);
static bool endsWith(const std::string& all, const std::string& end) {
@ -42,7 +40,7 @@ static std::vector<std::string> readProcFile(const std::string& path) {
return out;
}
std::shared_ptr<ClientAccess> ClientAccess::find(bool uselockfile) {
std::shared_ptr<ClientAccess> ClientAccess::find() {
DIR* procdir = opendir("/proc");
if(!procdir) return nullptr;
@ -77,11 +75,7 @@ std::shared_ptr<ClientAccess> ClientAccess::find(bool uselockfile) {
std::shared_ptr<ClientAccess> out;
if(uselockfile) {
out = findUsingLockfile(args, pid);
} else {
out = findUsingArgs(args);
}
out = findUsingLockfile(args, pid);
if(out) {
return out;
@ -92,40 +86,6 @@ std::shared_ptr<ClientAccess> ClientAccess::find(bool uselockfile) {
return nullptr;
}
std::string parseArg(const std::string& input, std::string& value) {
if(input.find("--") != 0) return {};
size_t pos = input.find('=');
if(pos == std::string::npos) return {};
value = input.substr(pos+1);
return input.substr(2, pos-2);
}
std::shared_ptr<ClientAccess> findUsingArgs(const std::vector<std::string>& cmdline) {
// parse args
std::shared_ptr<ClientAccess> access(new ClientAccess());
for(const std::string& arg : cmdline) {
std::string value;
std::string argname = parseArg(arg, value);
if(argname == "riotclient-auth-token") {
access->authcode = value;
} else if(argname == "riotclient-app-port") {
try {
access->port = std::stoi(value);
} catch(std::exception& e) {
Log::warn << "could not parse port: " << std::quoted(value);
}
}
}
if(access->port > 0 && !access->authcode.empty()) {
return access;
}
return nullptr;
}
std::shared_ptr<ClientAccess> findUsingLockfile(const std::vector<std::string>& cmdline, pid_t pid) {
// get WINEPREFIX env
std::vector<std::string> envs = readProcFile("/proc/" + std::to_string(pid) + "/environ");

View File

@ -66,12 +66,7 @@ static std::shared_ptr<ClientAccess> findUsingLockfile(PROCESSENTRY32& proc) {
return createFromLockfile(lockfile);
}
std::shared_ptr<ClientAccess> ClientAccess::find(bool uselockfile) {
if(!uselockfile) {
Log::error << __PRETTY_FUNCTION__ << " uselockfile = false is unimplemented";
return nullptr;
}
std::shared_ptr<ClientAccess> ClientAccess::find() {
// example code: https://docs.microsoft.com/de-de/windows/win32/toolhelp/taking-a-snapshot-and-viewing-processes
// Take a snapshot of all processes in the system.