Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,54 +1,63 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import bz2
|
| 3 |
-
|
| 4 |
|
| 5 |
-
def
|
| 6 |
-
if
|
| 7 |
-
return "", "", ""
|
| 8 |
|
| 9 |
try:
|
| 10 |
with open(file.name, "rb") as f:
|
| 11 |
-
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
|
|
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
|
|
|
| 18 |
|
| 19 |
-
#
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
-
#
|
| 24 |
-
|
| 25 |
-
|
| 26 |
|
| 27 |
-
#
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
-
return
|
| 32 |
|
| 33 |
except Exception as e:
|
| 34 |
-
return
|
| 35 |
|
| 36 |
with gr.Blocks() as demo:
|
| 37 |
-
gr.Markdown("## Распаковка и
|
| 38 |
-
|
| 39 |
file_input = gr.File(label="Загрузите .cps файл", file_types=[".cps"])
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
| 42 |
|
| 43 |
file_input.change(
|
| 44 |
-
fn=
|
| 45 |
inputs=file_input,
|
| 46 |
-
outputs=[
|
| 47 |
)
|
| 48 |
|
| 49 |
file_input.clear(
|
| 50 |
-
fn=lambda: ("", ""),
|
| 51 |
-
outputs=[
|
| 52 |
)
|
| 53 |
|
| 54 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import bz2
|
| 3 |
+
import bson
|
| 4 |
|
| 5 |
+
def analyze_cps(file):
|
| 6 |
+
if file is None:
|
| 7 |
+
return "", "", "", ""
|
| 8 |
|
| 9 |
try:
|
| 10 |
with open(file.name, "rb") as f:
|
| 11 |
+
raw_data = f.read()
|
| 12 |
|
| 13 |
+
# HEX дамп оригинала
|
| 14 |
+
hex_orig = ' '.join(f'{b:02x}' for b in raw_data[:256])
|
| 15 |
+
hex_original = f"Оригинал (первые 256 байт):\n{hex_orig}"
|
| 16 |
|
| 17 |
+
# Проверка сигнатуры
|
| 18 |
+
if raw_data[:4] != b'OPS1':
|
| 19 |
+
return hex_original, "[Ошибка] Неверная сигнатура файла.", "", ""
|
| 20 |
|
| 21 |
+
# Пропустить заголовок (12 байт)
|
| 22 |
+
compressed = raw_data[12:]
|
| 23 |
+
try:
|
| 24 |
+
decompressed = bz2.decompress(compressed)
|
| 25 |
+
except Exception as e:
|
| 26 |
+
return hex_original, f"[Ошибка bzip2]: {e}", "", ""
|
| 27 |
|
| 28 |
+
# HEX дамп распакованных данных
|
| 29 |
+
hex_decomp = ' '.join(f'{b:02x}' for b in decompressed[:512])
|
| 30 |
+
hex_decomp_view = f"Распакованные данные (первые 512 байт):\n{hex_decomp}"
|
| 31 |
|
| 32 |
+
# Парсим BSON
|
| 33 |
+
try:
|
| 34 |
+
bson_doc = bson.decode(decompressed)
|
| 35 |
+
json_like = str(bson_doc)
|
| 36 |
+
except Exception as e:
|
| 37 |
+
json_like = f"[Ошибка BSON]: {e}"
|
| 38 |
|
| 39 |
+
return hex_original, hex_decomp_view, json_like
|
| 40 |
|
| 41 |
except Exception as e:
|
| 42 |
+
return f"[Ошибка]: {e}", "", "", ""
|
| 43 |
|
| 44 |
with gr.Blocks() as demo:
|
| 45 |
+
gr.Markdown("## Распаковка и анализ .cps (The Powder Toy Save)")
|
|
|
|
| 46 |
file_input = gr.File(label="Загрузите .cps файл", file_types=[".cps"])
|
| 47 |
+
|
| 48 |
+
hex_orig_out = gr.Textbox(label="HEX оригинала", lines=5)
|
| 49 |
+
hex_decomp_out = gr.Textbox(label="HEX распакованных данных", lines=10)
|
| 50 |
+
bson_parsed = gr.Textbox(label="Распарсенный BSON (Python dict)", lines=20)
|
| 51 |
|
| 52 |
file_input.change(
|
| 53 |
+
fn=analyze_cps,
|
| 54 |
inputs=file_input,
|
| 55 |
+
outputs=[hex_orig_out, hex_decomp_out, bson_parsed]
|
| 56 |
)
|
| 57 |
|
| 58 |
file_input.clear(
|
| 59 |
+
fn=lambda: ("", "", ""),
|
| 60 |
+
outputs=[hex_orig_out, hex_decomp_out, bson_parsed]
|
| 61 |
)
|
| 62 |
|
| 63 |
demo.launch()
|