add: getpid
This commit is contained in:
@@ -5,7 +5,7 @@ int main() {
|
|||||||
if (!open_device())
|
if (!open_device())
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
int pid = 55803;
|
int pid = get_pid("nsnake");
|
||||||
if (!open_process(pid))
|
if (!open_process(pid))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,38 @@ void close_device(void)
|
|||||||
close(file_desc);
|
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)
|
void *RPM(uintptr_t address, ssize_t size)
|
||||||
{
|
{
|
||||||
struct s_RPM args;
|
struct s_RPM args;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
int open_device(void);
|
int open_device(void);
|
||||||
void close_device(void);
|
void close_device(void);
|
||||||
|
int get_pid(const char *program_name);
|
||||||
void *RPM(uintptr_t address, ssize_t size);
|
void *RPM(uintptr_t address, ssize_t size);
|
||||||
void WPM(uintptr_t addr, uintptr_t value, ssize_t size);
|
void WPM(uintptr_t addr, uintptr_t value, ssize_t size);
|
||||||
int open_process(int pid);
|
int open_process(int pid);
|
||||||
|
|||||||
Reference in New Issue
Block a user