|
1 | | -import os, CurrOS |
2 | | -from re import sub |
3 | | - |
4 | | - |
5 | | -file_dir = os.path.dirname(os.path.abspath(__file__)) |
6 | | -formatted_scripts = "" |
7 | | - |
8 | | - |
9 | | -def load_scripts(): |
10 | | - global formatted_scripts |
11 | | - scripts = [ |
12 | | - filename for filename in os.listdir(file_dir) if filename.endswith(".user.js") |
13 | | - ] |
14 | | - formatted_scripts = "" |
15 | | - for script in scripts: |
16 | | - with open(script, "r", encoding="utf-8") as f: |
17 | | - formatted_scripts += f"<script>{f.read()}</script>" |
18 | | - htmls = [ |
19 | | - filename for filename in os.listdir(file_dir) if filename.endswith(".html") |
20 | | - ] |
21 | | - for html in htmls: |
22 | | - with open(html, "r", encoding="utf-8") as f: |
23 | | - formatted_scripts += f.read() |
24 | | - |
25 | | - |
26 | | -def response(flow): |
27 | | - if flow.response.headers.get("content-type", "").startswith("text/html"): |
28 | | - load_scripts() |
29 | | - flow.response.set_text( |
30 | | - sub( |
31 | | - r"</head>", |
32 | | - f"{formatted_scripts}</head>", |
33 | | - flow.response.get_text(), |
34 | | - count=1, |
35 | | - ) |
36 | | - ) |
37 | | - |
38 | | - |
39 | | -def done(): |
40 | | - CurrOS.clearProxy() |
41 | | - |
42 | | - |
43 | | -addons = [response, done] |
44 | | -CurrOS.setProxy("127.0.0.1", "8080") |
| 1 | +# pylint: disable=missing-module-docstring,missing-function-docstring,missing-class-docstring |
| 2 | +# pylint: disable=invalid-name |
| 3 | +from addon import addon |
| 4 | +import CurrOS |
| 5 | +from backend import ThreadedMitmProxy |
| 6 | + |
| 7 | +try: |
| 8 | + CurrOS.setProxy("127.0.0.1", "8080") |
| 9 | +except AttributeError: |
| 10 | + pass |
| 11 | + |
| 12 | +if __name__ == "__main__": |
| 13 | + from mitmproxy.tools.main import mitmdump |
| 14 | + |
| 15 | + mitmdump( |
| 16 | + args=["-s", "addon.py", "--listen-port", "8080", "--listen-host", "127.0.0.1"] |
| 17 | + ) |
| 18 | +input() |
| 19 | +with ThreadedMitmProxy(addon, listen_port=8080, listen_host="127.0.0.1"): |
| 20 | + input() |
| 21 | + |
| 22 | +CurrOS.clearProxy() |
0 commit comments