update: some loader/ code to C

This commit changes some code from "loader" folder to use C keywords and not C++ only keywords.
This commit is contained in:
ThePedroo
2024-06-16 21:13:44 -03:00
parent c50d89e28e
commit d0da6efd79
8 changed files with 693 additions and 534 deletions
+45 -47
View File
@@ -1,55 +1,53 @@
#include <cstdio>
#include <cstdlib>
#include <string_view>
#include <unistd.h>
#include <fcntl.h>
#include <time.h>
#include <sys/system_properties.h>
#include "main.hpp"
#include "main.h"
#include "utils.hpp"
#include "daemon.h"
#include <sys/mount.h>
using namespace std::string_view_literals;
int main(int argc, char **argv) {
zygiskd::Init(getenv("TMP_PATH"));
if (argc >= 2 && argv[1] == "monitor"sv) {
init_monitor();
return 0;
} else if (argc >= 3 && argv[1] == "trace"sv) {
if (argc >= 4 && argv[3] == "--restart"sv) {
zygiskd::ZygoteRestart();
}
auto pid = strtol(argv[2], 0, 0);
if (!trace_zygote(pid)) {
kill(pid, SIGKILL);
return 1;
}
return 0;
} else if (argc >= 2 && argv[1] == "ctl"sv) {
if (argc == 3) {
if (argv[2] == "start"sv) {
send_control_command(START);
return 0;
} else if (argv[2] == "stop"sv) {
send_control_command(STOP);
return 0;
} else if (argv[2] == "exit"sv) {
send_control_command(EXIT);
return 0;
}
}
printf("ReZygisk Tracer %s\n", ZKSU_VERSION);
printf("Usage: %s ctl start|stop|exit\n", argv[0]);
zygiskd::Init(getenv("TMP_PATH"));
if (argc >= 2 && strcmp(argv[1], "monitor") == 0) {
init_monitor();
return 0;
} else if (argc >= 3 && strcmp(argv[1], "trace") == 0) {
if (argc >= 4 && strcmp(argv[3], "--restart") == 0) zygiskd::ZygoteRestart();
long pid = strtol(argv[2], 0, 0);
if (!trace_zygote(pid)) {
kill(pid, SIGKILL);
return 1;
} else if (argc >= 2 && argv[1] == "version"sv) {
printf("ReZygisk Tracer %s\n", ZKSU_VERSION);
}
return 0;
} else if (argc >= 2 && strcmp(argv[1], "ctl") == 0) {
if (argc == 3) {
if (strcmp(argv[2], "start") == 0) {
send_control_command(START);
return 0;
} else {
printf("ReZygisk Tracer %s\n", ZKSU_VERSION);
printf("usage: %s monitor | trace <pid> | ctl <start|stop|exit> | version\n", argv[0]);
return 1;
} else if (strcmp(argv[2], "stop") == 0) {
send_control_command(STOP);
return 0;
} else if (strcmp(argv[2], "exit") == 0) {
send_control_command(EXIT);
return 0;
}
}
printf("ReZygisk Tracer %s\n", ZKSU_VERSION);
printf("Usage: %s ctl start|stop|exit\n", argv[0]);
return 1;
} else if (argc >= 2 && strcmp(argv[1], "version") == 0) {
printf("ReZygisk Tracer %s\n", ZKSU_VERSION);
return 0;
} else {
printf("ReZygisk Tracer %s\n", ZKSU_VERSION);
printf("usage: %s monitor | trace <pid> | ctl <start|stop|exit> | version\n", argv[0]);
return 1;
}
}