|
6 | 6 | from qiling import Qiling |
7 | 7 | from qiling.os.posix.const import NR_OPEN |
8 | 8 |
|
9 | | -def ql_syscall_sendfile64(ql: Qiling, out_fd: int, in_fd: int, offest: int, count: int): |
10 | | - if (0 <= out_fd < NR_OPEN and ql.os.fd[out_fd] != 0) and (0 <= in_fd < NR_OPEN and ql.os.fd[in_fd] != 0): |
11 | | - ql.os.fd[in_fd].lseek(ql.unpack32(ql.mem.read(offest, 4))) |
| 9 | + |
| 10 | +def ql_syscall_sendfile64(ql: Qiling, out_fd: int, in_fd: int, offset: int, count: int): |
| 11 | + # https://linux.die.net/man/2/sendfile64 |
| 12 | + return ql_syscall_sendfile(ql, out_fd, in_fd, offset, count) |
| 13 | + |
| 14 | + |
| 15 | +def ql_syscall_sendfile(ql: Qiling, out_fd: int, in_fd: int, offset: int, count: int): |
| 16 | + # https://man7.org/linux/man-pages/man2/sendfile.2.html |
| 17 | + if 0 <= out_fd < NR_OPEN and 0 <= in_fd < NR_OPEN \ |
| 18 | + and ql.os.fd[out_fd] != 0 and ql.os.fd[in_fd] != 0: |
| 19 | + |
| 20 | + in_fd_pos = ql.os.fd[in_fd].tell() |
| 21 | + if offset: |
| 22 | + # Handle sendfile64 and sendfile offset_ptr |
| 23 | + offset = ql.unpack(ql.mem.read(offset, ql.pointersize)) |
| 24 | + else: |
| 25 | + offset = in_fd_pos |
| 26 | + |
| 27 | + ql.os.fd[in_fd].lseek(offset) |
12 | 28 | buf = ql.os.fd[in_fd].read(count) |
| 29 | + if offset: |
| 30 | + current_offset = ql.os.fd[in_fd].tell() |
| 31 | + ql.mem.write(offset, ql.pack(current_offset)) |
| 32 | + ql.os.fd[in_fd].lseek(in_fd_pos) |
| 33 | + |
13 | 34 | regreturn = ql.os.fd[out_fd].write(buf) |
| 35 | + |
14 | 36 | else: |
15 | 37 | regreturn = -1 |
16 | 38 |
|
|
0 commit comments