Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable more flexible logging redirection #1456

Merged
merged 3 commits into from
Mar 13, 2024
Merged

Conversation

elicn
Copy link
Member

@elicn elicn commented Mar 6, 2024

Modified logger setup to allow more flexible logging redirection and multiplexing.

Interface changes

The current interface in which log_file is used to optionally specify a filename to log into:

ql = Qiling(argv, rootfs, log_file=r'/tmp/myprog.log')

Was changed into an optional variable that accepts a Collection of either filenames or open streams:

ql = Qiling(argv, rootfs, log_devices=[sys.stderr, r'/tmp/myprog.log'])

Notes

  • While the current design creates a file logger in addition to the normal sys.stderr logger, the new implementation replaces it. That is, if a list of log devices is specified there would be be no sys.stderr logger by default anymore, unless it is specified (as seen in the example above)
  • The default behavior (i.e. not specifying any log_file / log_devices) is maintained: only sys.stderr will be created
  • Specifying an empty Collection, such as log_devices=[], would result in no logger (same as setting console=False)
  • For that reason the console argument has no use anymore. However the console argument was not removed to maintain compatibility and maybe will be used in the future for other purposes

Advantages

It is now way easier to open multiple loggers and redirect them to any file, stream or socket. This is very useful when trying to separate the emulated program output from logging output, or enable logging while fuzzing (which is currently hidden "behind" AFL box).

In the following example the logging output is redirected to another terminal pane to separate program output from logging output:

ql = Qiling(argv, rootfs, log_devices=['/dev/pts/6'])

image

@elicn elicn marked this pull request as ready for review March 6, 2024 13:45
@xwings
Copy link
Member

xwings commented Mar 11, 2024

Cool idea!

@elicn elicn merged commit bc83042 into qilingframework:dev Mar 13, 2024
7 checks passed
@elicn elicn deleted the dev-logging branch March 13, 2024 07:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants