-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_syscalls.c
38 lines (31 loc) · 1.01 KB
/
list_syscalls.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
#include <stdio.h>
#include <stdlib.h>
int main() {
FILE *file;
char *line = NULL;
size_t len = 0;
ssize_t read;
// Open the unistd_64.h file which contains syscall numbers
file = fopen("/usr/include/x86_64-linux-gnu/asm/unistd_64.h", "r");
if (file == NULL) {
perror("fopen");
exit(EXIT_FAILURE);
}
printf("Syscall Number\tSyscall Name\n");
printf("-------------\t------------\n");
// Read the file line by line
while ((read = getline(&line, &len, file)) != -1) {
// Look for lines defining syscall numbers
if (strstr(line, "#define __NR_") != NULL) {
char syscall_name[256];
int syscall_number;
// Parse the line to extract syscall name and number
sscanf(line, "#define __NR_%s %d", syscall_name, &syscall_number);
// Print the syscall number and name
printf("%-13d\t%s\n", syscall_number, syscall_name);
}
}
free(line);
fclose(file);
return 0;
}