yes
This commit is contained in:
1 parent
d7799f51a7
commit
a0f2d732f8
4 files changed
+258
-32
No files matched your search
@@ -464,8 +464,7 @@ class GuiState:
|
||||
te.TextEditor.LanguageDefinitionId.json)
|
||||
self.json_editor.set_read_only_enabled(True)
|
||||
self.json_editor.set_show_whitespaces_enabled(False)
|
||||
# Replay / edit-send state
|
||||
self.edit_mode: bool = False # True = JSON editor is writable
|
||||
# Replay state
|
||||
self.replay_dir: int = 0 # 0 = same as original, 1 = C->S, 2 = S->C
|
||||
# Wire tab
|
||||
self.selected_wire: int = -1
|
||||
@@ -674,42 +673,37 @@ def _tab_packet_inspector(shared: SharedState) -> None:
|
||||
f"[GUI] replay {send_dir} msg_id={sel.get('msg_id')}")
|
||||
imgui.same_line()
|
||||
|
||||
_, gs.edit_mode = imgui.checkbox("Edit mode", gs.edit_mode)
|
||||
gs.json_editor.set_read_only_enabled(not gs.edit_mode)
|
||||
if gs.edit_mode:
|
||||
imgui.same_line()
|
||||
if imgui.button("Send Edited JSON"):
|
||||
_send_edited_json(shared, gs, sel, send_dir)
|
||||
if imgui.button("Open in Composer"):
|
||||
_open_in_composer(gs, sel, send_dir)
|
||||
imgui.end_tab_item()
|
||||
imgui.end_tab_bar()
|
||||
|
||||
|
||||
def _send_edited_json(shared: SharedState, gs, sel: dict,
|
||||
direction: str) -> None:
|
||||
"""Parse the JSON editor content back to protobuf and push to inject queue."""
|
||||
jtext = gs.json_editor.get_text()
|
||||
msg_id = sel.get("msg_id", 0)
|
||||
def _open_in_composer(gs, sel: dict, direction: str) -> None:
|
||||
"""Copy a captured packet's JSON into the Composer tab for editing."""
|
||||
type_name = sel.get("msg_type", "")
|
||||
cls = getattr(pb_mod, type_name, None)
|
||||
if cls is None:
|
||||
shared.log_lines.append(f"[!] unknown type: {type_name}")
|
||||
return
|
||||
# Find the type in the composer dropdown list.
|
||||
try:
|
||||
from google.protobuf import json_format
|
||||
m = cls()
|
||||
json_format.Parse(jtext, m)
|
||||
body = m.SerializeToString()
|
||||
except Exception as e:
|
||||
shared.log_lines.append(f"[!] JSON parse error: {e}")
|
||||
return
|
||||
shared.inject_queue.append({
|
||||
"direction": direction,
|
||||
"msg_id": msg_id,
|
||||
"body": body,
|
||||
})
|
||||
shared.log_lines.append(
|
||||
f"[GUI] send edited {direction} msg_id={msg_id} "
|
||||
f"type={type_name} body={len(body)}B")
|
||||
idx = _COMPOSER_TYPES.index(type_name)
|
||||
except ValueError:
|
||||
idx = gs.composer_type_idx # keep current if not found
|
||||
gs.composer_type_idx = idx
|
||||
gs._composer_loaded_idx = -1 # force reload on next frame
|
||||
# Set direction.
|
||||
gs.composer_dir = 0 if direction == "C->S" else 1
|
||||
# Load the packet's JSON into composer editor.
|
||||
jtext = sel.get("json_str", "")
|
||||
if not jtext:
|
||||
fields = sel.get("fields")
|
||||
if fields:
|
||||
try:
|
||||
jtext = json.dumps(fields, indent=2, ensure_ascii=False,
|
||||
default=str)
|
||||
except Exception:
|
||||
jtext = "{}"
|
||||
if jtext:
|
||||
gs.composer_editor.set_text(jtext)
|
||||
gs._composer_loaded_idx = idx # prevent overwrite on next frame
|
||||
|
||||
|
||||
def _tab_configuration(shared: SharedState) -> None:
|
||||
|
||||
Reference in new issue
Block a user