| 12 | # customized system calls always use the same arguments list as the original ones, |
| 13 | # but with a Qiling instance as first argument |
| 14 | def my_syscall_write(ql: Qiling, fd: int, buf: int, count: int): |
| 15 | try: |
| 16 | # read data from emulated memory |
| 17 | data = ql.mem.read(buf, count) |
| 18 | |
| 19 | # select the emulated file object that corresponds to the requested |
| 20 | # file descriptor |
| 21 | fobj = ql.os.fd[fd] |
| 22 | |
| 23 | # write the data into the file object, if it supports write operations |
| 24 | if hasattr(fobj, 'write'): |
| 25 | fobj.write(data) |
| 26 | except: |
| 27 | ret = -1 |
| 28 | else: |
| 29 | ret = count |
| 30 | |
| 31 | ql.log.info(f'my_syscall_write({fd}, {buf:#x}, {count}) = {ret}') |
| 32 | |
| 33 | return ret |
| 34 | |
| 35 | if __name__ == "__main__": |
| 36 | ql = Qiling([r'rootfs/arm_linux/bin/arm_hello'], r'rootfs/arm_linux', verbose=QL_VERBOSE.DEBUG) |