tests
This commit is contained in:
parent
da26edc508
commit
f795943521
|
|
@ -8,6 +8,7 @@
|
|||
"*.wxs": "javascript",
|
||||
"*.json": "jsonc",
|
||||
"string.h": "c",
|
||||
"shm.h": "c"
|
||||
"shm.h": "c",
|
||||
"unistd.h": "c"
|
||||
}
|
||||
}
|
||||
6
Makefile
6
Makefile
|
|
@ -1,5 +1,5 @@
|
|||
CC = gcc
|
||||
CFLAGS = -shared -fPIC -Wall -Wextra -Werror
|
||||
CFLAGS = -shared -fPIC -Wall -Wextra -Werror -O2 -fno-strict-aliasing -fPIC -fno-omit-frame-pointer -fno-stack-protector -Wl,-z,relro,-z,now
|
||||
LDFLAGS = -ldl -ljson-c
|
||||
TARGET = intercept.so
|
||||
SRC = execve_intercept.c
|
||||
|
|
@ -16,3 +16,7 @@ $(TARGET): $(SRC)
|
|||
|
||||
clean:
|
||||
rm -f $(TARGET)
|
||||
|
||||
debug:
|
||||
$(MAKE) DEBUG=1
|
||||
|
||||
BIN
intercept.so
BIN
intercept.so
Binary file not shown.
BIN
tests/a.out
BIN
tests/a.out
Binary file not shown.
|
|
@ -0,0 +1,76 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/shm.h>
|
||||
#include <time.h>
|
||||
|
||||
#define SHM_KEY 12345
|
||||
#define MAX_RULES 100
|
||||
#define MAX_ARGS 10
|
||||
|
||||
typedef struct {
|
||||
char cmd[256];
|
||||
char type[32];
|
||||
char msg[1024];
|
||||
char args[MAX_ARGS][256];
|
||||
int arg_count;
|
||||
} Rule;
|
||||
|
||||
typedef struct {
|
||||
bool enabled;
|
||||
Rule rules[MAX_RULES];
|
||||
int rule_count;
|
||||
} ConfigData;
|
||||
|
||||
void print_config(const ConfigData *cfg) {
|
||||
printf("=== Config ===\n");
|
||||
printf("Enabled: %s\n", cfg->enabled ? "true" : "false");
|
||||
printf("Rule count: %d\n", cfg->rule_count);
|
||||
for (int i = 0; i < cfg->rule_count && i < MAX_RULES; i++) {
|
||||
const Rule *r = &cfg->rules[i];
|
||||
printf("Rule %d:\n", i + 1);
|
||||
printf(" CMD : %s\n", r->cmd);
|
||||
printf(" Type: %s\n", r->type);
|
||||
printf(" Msg : %s\n", r->msg);
|
||||
printf(" Args(%d):\n", r->arg_count);
|
||||
for (int j = 0; j < r->arg_count && j < MAX_ARGS; j++) {
|
||||
printf(" - %s\n", r->args[j]);
|
||||
}
|
||||
}
|
||||
printf("=====================\n\n");
|
||||
}
|
||||
|
||||
int main() {
|
||||
int shmid = shmget(SHM_KEY, sizeof(ConfigData), 0666);
|
||||
if (shmid < 0) {
|
||||
perror("shmget failed");
|
||||
return 1;
|
||||
}
|
||||
|
||||
ConfigData *shared_cfg = (ConfigData *)shmat(shmid, NULL, SHM_RDONLY);
|
||||
if (shared_cfg == (void *)-1) {
|
||||
perror("shmat failed");
|
||||
return 1;
|
||||
}
|
||||
|
||||
ConfigData last_cfg = {0};
|
||||
|
||||
struct timespec ts;
|
||||
ts.tv_sec = 0;
|
||||
ts.tv_nsec = 100 * 1000000; // 100ms
|
||||
|
||||
while (1) {
|
||||
if (memcmp(&last_cfg, shared_cfg, sizeof(ConfigData)) != 0) {
|
||||
printf(">>> Config changed:\n");
|
||||
print_config(shared_cfg);
|
||||
memcpy(&last_cfg, shared_cfg, sizeof(ConfigData));
|
||||
}
|
||||
nanosleep(&ts, NULL); // 每 100 毫秒检查一次
|
||||
}
|
||||
|
||||
shmdt(shared_cfg);
|
||||
return 0;
|
||||
}
|
||||
Loading…
Reference in New Issue