helper
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
#include <sys/syscall.h>
|
||||
#include <stdio.h>
|
||||
#include <linux/openat2.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(void){
|
||||
// get syscall num
|
||||
printf("openat2: %d\n", SYS_openat2);
|
||||
printf("pread64: %d\n", SYS_pread64);
|
||||
printf("writev: %d\n", SYS_writev);
|
||||
|
||||
// struct
|
||||
struct open_how how;
|
||||
memset(&how, 0, sizeof(how));
|
||||
how.flags = O_RDWR;
|
||||
how.resolve = RESOLVE_IN_ROOT;
|
||||
size_t size = sizeof(how);
|
||||
|
||||
// openat2
|
||||
const char *file = "flag.txt";
|
||||
long rax = syscall(SYS_openat2, AT_FDCWD, file, &how, size);
|
||||
printf("fd: %d\n", rax);
|
||||
|
||||
// pread64
|
||||
char buf[64];
|
||||
long rax2 = syscall(SYS_pread64, rax, buf, 100, 0);
|
||||
printf("string size: %d\n", rax2);
|
||||
|
||||
// struct
|
||||
char *str = "Some string here";
|
||||
struct iovec {
|
||||
void *iov_base;
|
||||
size_t iov_len;
|
||||
};
|
||||
struct iovec iov[1];
|
||||
iov[0].iov_base = str;
|
||||
iov[0].iov_len = strlen(str);
|
||||
|
||||
// writev
|
||||
syscall(SYS_writev, 1, iov, 1);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user