-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusr.c
45 lines (39 loc) · 954 Bytes
/
usr.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
void info() {
fprintf(stderr, "Usage: ./usr struct_id PID\n Avaliable struct_id:\n 0 - pt_regs \n 1 - task_struct\n");
}
int main(int argc, char *argv[]) {
if (argc != 3) {
info();
return 0;
}
char *p;
long structure_ID = strtol(argv[1], &p, 10);
long PID = strtol(argv[2], &p, 10);
if (structure_ID !=0 && structure_ID !=1) {
fprintf(stderr, "struct_id is not supported.\n");
info();
return 0;
}
char inbuf[4096];
char outbuf[4096];
int fd = open("/proc/lab/struct_info", O_RDWR);
sprintf(inbuf, "%s %s", argv[1], argv[2]);
write(fd, inbuf, 17);
lseek(fd, 0, SEEK_SET);
read(fd, outbuf, 4096);
if (structure_ID == 0){
printf("pt_regs structure: \n\n");
} else {
printf("task_struct structure data for PID: \n\n");
}
puts(outbuf);
return 0;
}