mirror of
https://github.com/qilingframework/qiling.git
synced 2026-10-12 02:21:40 +00:00
39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
#!/usr/bin/env python3
|
|
#
|
|
# Cross Platform and Multi Architecture Advanced Binary Emulation Framework
|
|
#
|
|
|
|
import sys
|
|
sys.path.append("..")
|
|
|
|
from qiling import Qiling
|
|
from qiling.const import QL_VERBOSE
|
|
|
|
def my_syscall_write(ql: Qiling, write_fd, write_buf, write_count, *args, **kw):
|
|
regreturn = 0
|
|
|
|
try:
|
|
buf = ql.mem.read(write_buf, write_count)
|
|
ql.log.info("\n+++++++++\nmy write(%d,%x,%i) = %d\n+++++++++" % (write_fd, write_buf, write_count, regreturn))
|
|
ql.os.fd[write_fd].write(buf)
|
|
regreturn = write_count
|
|
except:
|
|
regreturn = -1
|
|
ql.log.info("\n+++++++++\nmy write(%d,%x,%i) = %d\n+++++++++" % (write_fd, write_buf, write_count, regreturn))
|
|
|
|
return regreturn
|
|
|
|
|
|
if __name__ == "__main__":
|
|
ql = Qiling(["rootfs/arm_linux/bin/arm_hello"], "rootfs/arm_linux", verbose=QL_VERBOSE.DEBUG)
|
|
# Custom syscall handler by syscall name or syscall number.
|
|
# Known issue: If the syscall func is not be implemented in qiling, qiling does
|
|
# not know which func should be replaced.
|
|
# In that case, you must specify syscall by its number.
|
|
ql.set_syscall(0x04, my_syscall_write)
|
|
|
|
# set syscall by syscall name
|
|
#ql.set_syscall("write", my_syscall_write)
|
|
|
|
ql.run()
|