qilingframework / qiling

A True Instrumentable Binary Emulation Framework
https://qiling.io
GNU General Public License v2.0
5.14k stars 744 forks source link

Hook ioctl in QlFsMappedObject #1280

Open Tim--- opened 1 year ago

Tim--- commented 1 year ago

Is your feature request related to a problem? Please describe.

Hi,

I am trying to implement a custom QlFsMappedObject with ioctl support. Looking at the class, it seems that I need to override the ioctl method.

https://github.com/qilingframework/qiling/blob/f3e66ec290b8c7a0ee60bc2f2715ddc6e9389216/qiling/os/mapper.py#L44-L45

However, my handler is never called, and the "strace" output shows a -EPERM result when the ioctl syscall is made.

From what I see, the ioctl calls ends up in ql_syscall_ioctl, which only handles a few ioctl commands, and returns -1 (aka -EPERM) if the ioctl is not in the whitelist.

Contrary to other methods like ql_syscall_read, it does not seem to call the handler method.

Describe the solution you'd like

Did I miss something, or is the ioctl not currently implemented ?

psparc82 commented 8 months ago

@Tim--- Did you ever find a fix for this?

Tim--- commented 8 months ago

Well, it's been a while, so I don't remember what I did. But the code has barely changed since then. Apparently, the hook is only called for specific network interface ioctls here:

https://github.com/qilingframework/qiling/blob/f3e66ec290b8c7a0ee60bc2f2715ddc6e9389216/qiling/os/posix/syscall/ioctl.py#L94

I guess you have to modify the code of ql_syscall_ioctl if you want it to call your hook.

elicn commented 8 months ago

Hi there, Qiling is flexible enough to let you add your own customized handling. Here you could hook ioctl on exit to let your custom handler review the given parameters and take action for a certain set of values.

psparc82 commented 8 months ago

@Tim--- , @elicn Thanks for the tips. I'll give them a go