|
12 | 12 | from multiprocessing import Process |
13 | 13 |
|
14 | 14 | from qiling import Qiling |
15 | | -from qiling.const import QL_ARCH, QL_OS, QL_VERBOSE |
| 15 | +from qiling.const import QL_ARCH, QL_OS |
16 | 16 | from qiling.os.posix.filestruct import ql_pipe |
17 | 17 | from qiling.os.posix.const import * |
18 | 18 | from qiling.os.posix.stat import Stat |
@@ -159,12 +159,20 @@ def ql_syscall_lseek(ql: Qiling, fd: int, offset: int, origin: int): |
159 | 159 |
|
160 | 160 |
|
161 | 161 | def ql_syscall__llseek(ql: Qiling, fd: int, offset_high: int, offset_low: int, result: int, whence: int): |
| 162 | + if fd not in range(NR_OPEN): |
| 163 | + return -EBADF |
| 164 | + |
| 165 | + f = ql.os.fd[fd] |
| 166 | + |
| 167 | + if f is None: |
| 168 | + return -EBADF |
| 169 | + |
162 | 170 | # treat offset as a signed value |
163 | 171 | offset = ql.unpack64s(ql.pack64((offset_high << 32) | offset_low)) |
164 | 172 | origin = whence |
165 | 173 |
|
166 | 174 | try: |
167 | | - ret = ql.os.fd[fd].seek(offset, origin) |
| 175 | + ret = f.seek(offset, origin) |
168 | 176 | except OSError: |
169 | 177 | regreturn = -1 |
170 | 178 | else: |
@@ -278,19 +286,29 @@ def ql_syscall_read(ql: Qiling, fd, buf: int, length: int): |
278 | 286 |
|
279 | 287 |
|
280 | 288 | def ql_syscall_write(ql: Qiling, fd: int, buf: int, count: int): |
| 289 | + if fd not in range(NR_OPEN): |
| 290 | + return -EBADF |
| 291 | + |
| 292 | + f = ql.os.fd[fd] |
| 293 | + |
| 294 | + if f is None: |
| 295 | + return -EBADF |
| 296 | + |
281 | 297 | try: |
282 | 298 | data = ql.mem.read(buf, count) |
283 | 299 | except: |
284 | 300 | regreturn = -1 |
285 | 301 | else: |
286 | 302 | ql.log.debug(f'write() CONTENT: {bytes(data)}') |
287 | 303 |
|
288 | | - if hasattr(ql.os.fd[fd], 'write'): |
289 | | - ql.os.fd[fd].write(data) |
| 304 | + if hasattr(f, 'write'): |
| 305 | + f.write(data) |
| 306 | + |
| 307 | + regreturn = count |
290 | 308 | else: |
291 | 309 | ql.log.warning(f'write failed since fd {fd:d} does not have a write method') |
| 310 | + regreturn = -1 |
292 | 311 |
|
293 | | - regreturn = count |
294 | 312 |
|
295 | 313 | return regreturn |
296 | 314 |
|
|
0 commit comments