Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import bz2
|
| 3 |
|
| 4 |
-
def
|
| 5 |
if file is None:
|
| 6 |
return "", ""
|
| 7 |
|
|
@@ -9,16 +9,20 @@ def analyze_cps(file):
|
|
| 9 |
with open(file.name, "rb") as f:
|
| 10 |
raw_data = f.read()
|
| 11 |
|
| 12 |
-
# Показываем первые 256 байт в HEX
|
| 13 |
hex_dump = ' '.join(f'{byte:02x}' for byte in raw_data[:256])
|
| 14 |
hex_display = f"HEX дамп (первые 256 байт):\n{hex_dump}"
|
| 15 |
|
| 16 |
-
# Про
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
try:
|
| 18 |
-
decompressed = bz2.decompress(
|
| 19 |
text_output = decompressed.decode("utf-8", errors="replace")
|
| 20 |
except Exception as e:
|
| 21 |
-
text_output = f"[
|
| 22 |
|
| 23 |
return hex_display, text_output
|
| 24 |
|
|
@@ -26,14 +30,14 @@ def analyze_cps(file):
|
|
| 26 |
return f"Ошибка чтения файла: {e}", ""
|
| 27 |
|
| 28 |
with gr.Blocks() as demo:
|
| 29 |
-
gr.Markdown("##
|
| 30 |
|
| 31 |
file_input = gr.File(label="Загрузите .cps файл", file_types=[".cps"])
|
| 32 |
hex_output = gr.Textbox(label="HEX дамп файла", lines=5)
|
| 33 |
-
text_output = gr.Textbox(label="Распакованный текст
|
| 34 |
|
| 35 |
file_input.change(
|
| 36 |
-
fn=
|
| 37 |
inputs=file_input,
|
| 38 |
outputs=[hex_output, text_output]
|
| 39 |
)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import bz2
|
| 3 |
|
| 4 |
+
def analyze_and_unpack_cps(file):
|
| 5 |
if file is None:
|
| 6 |
return "", ""
|
| 7 |
|
|
|
|
| 9 |
with open(file.name, "rb") as f:
|
| 10 |
raw_data = f.read()
|
| 11 |
|
|
|
|
| 12 |
hex_dump = ' '.join(f'{byte:02x}' for byte in raw_data[:256])
|
| 13 |
hex_display = f"HEX дамп (первые 256 байт):\n{hex_dump}"
|
| 14 |
|
| 15 |
+
# Проверяем заголовок
|
| 16 |
+
if raw_data.startswith(b'OPS1'):
|
| 17 |
+
compressed_data = raw_data[4:] # Пропускаем OPS1
|
| 18 |
+
else:
|
| 19 |
+
compressed_data = raw_data
|
| 20 |
+
|
| 21 |
try:
|
| 22 |
+
decompressed = bz2.decompress(compressed_data)
|
| 23 |
text_output = decompressed.decode("utf-8", errors="replace")
|
| 24 |
except Exception as e:
|
| 25 |
+
text_output = f"[Ошибка распаковки]: {e}"
|
| 26 |
|
| 27 |
return hex_display, text_output
|
| 28 |
|
|
|
|
| 30 |
return f"Ошибка чтения файла: {e}", ""
|
| 31 |
|
| 32 |
with gr.Blocks() as demo:
|
| 33 |
+
gr.Markdown("## Распаковка .cps файла (OPS1 + BZIP2)")
|
| 34 |
|
| 35 |
file_input = gr.File(label="Загрузите .cps файл", file_types=[".cps"])
|
| 36 |
hex_output = gr.Textbox(label="HEX дамп файла", lines=5)
|
| 37 |
+
text_output = gr.Textbox(label="Распакованный текст", lines=15)
|
| 38 |
|
| 39 |
file_input.change(
|
| 40 |
+
fn=analyze_and_unpack_cps,
|
| 41 |
inputs=file_input,
|
| 42 |
outputs=[hex_output, text_output]
|
| 43 |
)
|