implement agent_release
This commit is contained in:
parent
11a3488883
commit
b8f96fc411
11 changed files with 576 additions and 0 deletions
39
src/agent_release/platform.hpp
Normal file
39
src/agent_release/platform.hpp
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
// platform.hpp — Linux substitutes for the Win32 calls used by
|
||||
// Agent_Release_x64.exe (see decomp/Agent_Release_x64/cpp/AgentProcessControl.cpp).
|
||||
#pragma once
|
||||
#include <sys/types.h>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
namespace platform {
|
||||
|
||||
// Replaces CreateMutexW(L"Global\\RustyHearts_Agent") (0x1400100b0).
|
||||
// Uses an exclusive flock() on a lock file; released automatically on exit.
|
||||
class SingleInstanceLock {
|
||||
public:
|
||||
explicit SingleInstanceLock(const std::string& name);
|
||||
~SingleInstanceLock();
|
||||
bool acquired() const { return fd_ >= 0; }
|
||||
private:
|
||||
int fd_ = -1;
|
||||
};
|
||||
|
||||
// Replaces CreateProcessW(..., CREATE_NEW_CONSOLE, ..., workDir) (0x1400094e0).
|
||||
// commandLine is split on whitespace (the original passes one string to Windows).
|
||||
// The child gets its own session (setsid) as the nearest analogue of a new console.
|
||||
// Returns pid > 0, or 0 on failure (same contract as the original).
|
||||
pid_t LaunchProcess(const std::string& commandLine, const std::string& workDir);
|
||||
|
||||
// Replaces the watcher's GetExitCodeProcess polling loop (0x140008c90) with a
|
||||
// blocking waitpid(). Calls onExit(pid) on a detached thread once the child exits.
|
||||
void WatchProcess(pid_t pid, std::function<void(pid_t)> onExit);
|
||||
|
||||
// Replaces Toolhelp32 + OpenProcess + TerminateProcess (0x140009780).
|
||||
// Scans /proc, matches basename of argv[0] case-insensitively, kills the FIRST
|
||||
// match with SIGKILL (TerminateProcess is unconditional), returns true if killed.
|
||||
bool KillProcessByName(const std::string& exeName);
|
||||
|
||||
// Replaces Sleep(ms).
|
||||
void SleepMs(unsigned ms);
|
||||
|
||||
} // namespace platform
|
||||
Loading…
Add table
Add a link
Reference in a new issue