ImportsLogger/README.md

24 lines
1.1 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# ImportsLogger
It logs. That's it.
```bash
cat f.py
import requests
r = requests.get("https://fsf.org")
print(r.status_code)
python hijack.py f.py # Supports -m too
[INFO] In function hijacked_import@74 [root] => Imported name='requests', pkg='', fromlist=None
[INFO] In function __getattr__@42 [requests] => getattr(get) -> <function get at 0x7fde1ee669e0>
[INFO] In function _@26 [requests.get] => Called with ('https://fsf.org',), {}
[DEBUG] In function _new_conn@1003 [urllib3.connectionpool] => Starting new HTTPS connection (1): fsf.org:443
[DEBUG] In function _make_request@456 [urllib3.connectionpool] => https://fsf.org:443 "GET / HTTP/1.1" 301 185
[DEBUG] In function _new_conn@1003 [urllib3.connectionpool] => Starting new HTTPS connection (1): www.fsf.org:443
[DEBUG] In function _make_request@456 [urllib3.connectionpool] => https://www.fsf.org:443 "GET / HTTP/1.1" 200 13643
[INFO] In function __getattr__@42 [ret_requests.get] => getattr(status_code) -> 200
[DEBUG] In function getLogger@50 [root] => Returning real value 200
200
```
It also sucks and it's hacky.