| import gradio as gr |
| import base64 |
| import json |
| import re |
| import html |
|
|
| def decode_proxy_entry(encoded_str): |
| try: |
| |
| decoded_bytes = base64.b64decode(encoded_str) |
| |
| |
| hex_string = decoded_bytes.decode('ascii') |
| json_string = bytes.fromhex(hex_string).decode('ascii') |
| |
| |
| return json.loads(json_string) |
| except Exception as e: |
| return {"error": f"Decoding failed: {str(e)}"} |
|
|
| def process_html_input(html_content): |
| try: |
| |
| unescaped_html = html.unescape(html_content) |
| |
| |
| pattern = r'data-ss="\[(.*?)\]"' |
| match = re.search(pattern, unescaped_html, re.DOTALL) |
| |
| if not match: |
| return {"error": "No data-ss attribute found in the HTML"} |
| |
| data_ss_content = match.group(1) |
| |
| |
| entries = re.findall(r'"([A-Za-z0-9+/=]+)"', data_ss_content) |
| |
| |
| if not entries: |
| entries = re.findall(r'"([A-Za-z0-9+/=]+)"', data_ss_content) |
| |
| if not entries: |
| return {"error": "No base64 encoded entries found in data-ss attribute"} |
| |
| results = [] |
| for i, entry in enumerate(entries): |
| try: |
| result = decode_proxy_entry(entry) |
| results.append({ |
| "entry": i + 1, |
| "decoded_data": result |
| }) |
| except Exception as e: |
| results.append({ |
| "entry": i + 1, |
| "error": f"Failed to decode: {str(e)}" |
| }) |
| |
| return {"results": results, "total_entries": len(results)} |
| except Exception as e: |
| return {"error": f"Error processing HTML: {str(e)}"} |
|
|
| def decode_single_entry(encoded_string): |
| try: |
| result = decode_proxy_entry(encoded_string) |
| return result |
| except Exception as e: |
| return {"error": str(e)} |
|
|
| |
| test_html = '''<script |
| id="serverSelectorScript" |
| data-ss="["N2IyMjY5NjQyMjNhMzIzMDMxMmMyMjc1NzI2YzIyM2EyMjY4NzQ3NDcwNzMzYTVjMmY1YzJmMzEzMDM4MmUzMTM4MzEyZTMxMzEyZTMxMzczMTVjMmY1ZjVmNjM3MDMyMmU3MDY4NzAyMjJjMjI2ZTYxNmQ2NTIyM2EyMjcwNzM3OTYzNjg3YTRjNmY3MzQxNmU2NzY1NmM2NTczMzI0ZDIyN2Q="]" |
| ></script>''' |
|
|
| |
| def create_simple_interface(): |
| with gr.Blocks(title="Proxy Decoder", css=".gradio-container {max-width: 1200px !important}") as demo: |
| gr.Markdown("# Proxy Server Decoder") |
| |
| with gr.Tab("Single Entry"): |
| with gr.Row(): |
| with gr.Column(): |
| single_input = gr.Textbox( |
| label="Base64 String", |
| placeholder="Paste base64 string here...", |
| lines=3 |
| ) |
| single_btn = gr.Button("Decode", variant="primary") |
| with gr.Column(): |
| single_output = gr.JSON(label="Result") |
| |
| with gr.Tab("HTML Parser"): |
| with gr.Row(): |
| with gr.Column(): |
| html_input = gr.Textbox( |
| label="HTML Content", |
| value=test_html, |
| lines=10 |
| ) |
| html_btn = gr.Button("Parse HTML", variant="primary") |
| with gr.Column(): |
| html_output = gr.JSON(label="Results") |
| |
| |
| single_btn.click( |
| decode_single_entry, |
| inputs=single_input, |
| outputs=single_output |
| ) |
| |
| html_btn.click( |
| process_html_input, |
| inputs=html_input, |
| outputs=html_output |
| ) |
| |
| return demo |
|
|
| |
| if __name__ == "__main__": |
| demo = create_simple_interface() |
| demo.launch( |
| server_name="0.0.0.0", |
| server_port=7860, |
| share=False, |
| inbrowser=True, |
| show_error=True |
| ) |