|
7 | 7 | """ |
8 | 8 |
|
9 | 9 | from typing import Optional |
10 | | -from urllib.parse import urlparse |
| 10 | +import json |
11 | 11 | import msgpack |
12 | 12 | from Crypto.Cipher import AES |
13 | | -from mitmproxy import contentviews |
14 | | -from mitmproxy import flow |
15 | | -from mitmproxy import http |
16 | | -# from mitmproxy import ctx |
| 13 | +from mitmproxy.contentviews import Contentview |
17 | 14 |
|
18 | 15 | class SekaiCore: |
19 | | - # To use this you need a valid key and IV. |
| 16 | + # To use this class, you need a valid key and IV. |
20 | 17 | aes_key = b"" |
21 | 18 | aes_iv = b"" |
22 | 19 |
|
@@ -48,39 +45,31 @@ def decrypt_data(cls, crypttext): |
48 | 45 | return {} |
49 | 46 |
|
50 | 47 |
|
51 | | -class ViewSekai(contentviews.View): |
52 | | - name = "sekai" |
53 | | - |
54 | | - def __call__( |
55 | | - self, |
56 | | - data: bytes, |
57 | | - *, |
58 | | - content_type: Optional[str] = None, |
59 | | - flow: Optional[flow.Flow] = None, |
60 | | - http_message: Optional[http.Message] = None, |
61 | | - **unknown_metadata, |
62 | | - ) -> contentviews.TViewResult: |
63 | | - """ Decrypts data upon response. """ |
64 | | - try: |
65 | | - plaintext: Optional[dict] = SekaiCore.decrypt_data(data) |
66 | | - return "sekai", contentviews.json.format_json(plaintext) |
67 | | - except Exception as e: |
68 | | - return "sekai", contentviews.format_text(e) |
| 48 | +class ViewProjectSekai(Contentview): |
| 49 | + name = "pjsekai" |
69 | 50 |
|
70 | 51 | def render_priority( |
71 | 52 | self, |
72 | 53 | data: bytes, |
73 | | - *, |
74 | | - content_type: Optional[str] = None, |
75 | | - flow: Optional[flow.Flow] = None, |
76 | | - http_message: Optional[http.Message] = None, |
77 | | - **unknown_metadata, |
| 54 | + metadata |
78 | 55 | ) -> float: |
79 | 56 | """ prioritize using this when priority is set """ |
80 | 57 | try: |
81 | | - if not data: |
| 58 | + if not data or not metadata: |
82 | 59 | return 0 |
83 | | - _ = SekaiCore.decrypt_data(data) |
84 | | - return 1 |
| 60 | + |
| 61 | + decrypt_result = SekaiCore.decrypt_data(data) |
| 62 | + return 1 if decrypt_result else 0 |
85 | 63 | except Exception as e: |
86 | 64 | return 0 |
| 65 | + |
| 66 | + def prettify( |
| 67 | + self, |
| 68 | + data: bytes, |
| 69 | + _ |
| 70 | + ) -> str: |
| 71 | + try: |
| 72 | + plaintext: Optional[dict] = SekaiCore.decrypt_data(data) |
| 73 | + return json.dumps(plaintext, indent=4, ensure_ascii=False) |
| 74 | + except Exception as e: |
| 75 | + return e |
0 commit comments