diff --git a/src/client/main.c b/src/client/main.c index cb41221..e6b1e54 100644 --- a/src/client/main.c +++ b/src/client/main.c @@ -5,7 +5,7 @@ int main() { if (!open_device()) return -1; - int pid = 55803; + int pid = get_pid("nsnake"); if (!open_process(pid)) return -1; diff --git a/src/client/memory.c b/src/client/memory.c index 46e65f4..60214a7 100644 --- a/src/client/memory.c +++ b/src/client/memory.c @@ -24,6 +24,38 @@ void close_device(void) close(file_desc); } +int get_pid(const char *program_name) { + FILE *fp; + char command[128]; + char buffer[128]; + int pid = -1; + + // Create a command to run 'pidof' for the specified program + snprintf(command, sizeof(command), "pidof %s", program_name); + + // Open a pipe to execute the command and read the output + fp = popen(command, "r"); + if (fp == NULL) { + perror("popen"); + return -1; + } + + // Read the output (should be a space-separated list of PIDs) + if (fgets(buffer, sizeof(buffer), fp) != NULL) { + // Extract the first PID from the list + if (sscanf(buffer, "%d", &pid) == 1) { + } + } + + // Close the pipe and check for errors + if (pclose(fp) == -1) { + perror("pclose"); + return -1; + } + + return pid; +} + void *RPM(uintptr_t address, ssize_t size) { struct s_RPM args; diff --git a/src/client/memory.h b/src/client/memory.h index b7e581e..ff821e3 100644 --- a/src/client/memory.h +++ b/src/client/memory.h @@ -4,6 +4,7 @@ int open_device(void); void close_device(void); +int get_pid(const char *program_name); void *RPM(uintptr_t address, ssize_t size); void WPM(uintptr_t addr, uintptr_t value, ssize_t size); int open_process(int pid);