Fix view clearing bug in #45 and add Windows RE operations#61
Fix view clearing bug in #45 and add Windows RE operations#61kiwids0220 wants to merge 1 commit intofosdickio:mainfrom
Conversation
|
@CX330Blake The new PR is here, but please review and test before merging 😄 |
|
@kiwids0220 Could you please briefly explain what feature did you add, so that the review can be much more easier for us? Thanks for the PR! Oh, and please use Ruff to format the codes before committing to pass the linter check. |
There was a problem hiding this comment.
Pull request overview
This PR addresses a view clearing bug (#45) where the current binary view was being constantly reset by UI interaction monitoring, and adds comprehensive Windows reverse engineering operations to the MCP interface.
Changes:
- Fixed view clearing bug by removing UI-driven view resets that caused constant "Cleared/Set current binary view" log spam
- Added new WindowsREOperations class with 20+ specialized Windows RE analysis functions
- Replaced Python 3.10+ union type hints with typing module equivalents for better compatibility
- Removed get_stack_frame_vars endpoint (replaced by stackLayout in Windows RE ops)
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 43 comments.
Show a summary per file
| File | Description |
|---|---|
| plugin/init.py | CRITICAL FIX: Removed UI-driven view reset logic causing the bug |
| plugin/core/binary_operations.py | Fixed _prune_views to preserve current_view; updated type hints |
| plugin/core/windows_re_operations.py | NEW: Comprehensive Windows RE operations (1153 lines) |
| plugin/server/http_server.py | Added 15+ Windows RE HTTP endpoints; contains unreachable code bug |
| bridge/binja_mcp_bridge.py | Added 20+ MCP tools for Windows RE operations |
| plugin/api/endpoints.py | Removed get_stack_frame_vars; updated type hints |
| plugin/utils/python_detection.py | Fixed type hints for Optional parameters |
| scripts/*.py | Formatting/import reordering only |
| README.md | Updated docs to remove deprecated features; removed development section |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # Try all formats as fallback | ||
| try: | ||
| return json.loads(post_data) | ||
| except json.JSONDecodeError: | ||
| try: | ||
| parsed = dict(urllib.parse.parse_qsl(post_data)) | ||
| if parsed: | ||
| return parsed | ||
| except (ValueError, TypeError): | ||
| pass | ||
|
|
||
| return {"name": post_data.strip()} | ||
|
|
There was a problem hiding this comment.
Critical bug: Lines 213-224 contain unreachable code. This fallback parsing logic appears after a return statement on line 211, so it will never execute. This code should either be moved before the return statement or removed if it's dead code. This appears to be an accidental duplication or misplaced code block.
| # Try all formats as fallback | |
| try: | |
| return json.loads(post_data) | |
| except json.JSONDecodeError: | |
| try: | |
| parsed = dict(urllib.parse.parse_qsl(post_data)) | |
| if parsed: | |
| return parsed | |
| except (ValueError, TypeError): | |
| pass | |
| return {"name": post_data.strip()} |
|
|
||
| # Numeric forms | ||
| signed = False | ||
| neg = text.startswith("-") |
There was a problem hiding this comment.
The variable neg is assigned but never used in the function. If this was intended for some negative number handling logic, it's incomplete. Either implement the logic or remove the unused variable.
| neg = text.startswith("-") |
|
|
||
| def get_stack_frame_vars(self, function_identifier: str | int) -> list[dict[str, Any]]: | ||
| """Get stack frame variable information for a function. | ||
| # display_as removed per request |
There was a problem hiding this comment.
The function get_stack_frame_vars has been removed from the endpoints, but the corresponding endpoint handler /getStackFrameVars has also been removed from http_server.py without replacement. However, a new endpoint /stackLayout has been added in the Windows RE operations that appears to serve a similar purpose. Ensure this is intentional and that all callers have been updated to use the new endpoint.
| if func_length <= 0: | ||
| func_length = 1024 # Use a reasonable default if length not available | ||
| except Exception: | ||
| except: |
There was a problem hiding this comment.
Using bare except: is generally discouraged as it catches all exceptions including KeyboardInterrupt and SystemExit. Consider catching specific exceptions or at least using except Exception: to allow system exceptions to propagate.
| except: | |
| except Exception: |
|
|
||
|
|
||
| def create_venv_with_system_python(venv_dir: str, requirements_file: str | None = None) -> str: | ||
| def create_venv_with_system_python(venv_dir: str, requirements_file: str = None) -> str: |
There was a problem hiding this comment.
The type hint requirements_file: str = None is incorrect. In Python, using None as a default with a non-Optional type hint will cause type checkers to complain. This should be requirements_file: Optional[str] = None to match the actual usage where None is a valid value.
| callees.append(node) | ||
| except Exception: | ||
| continue | ||
| except Exception: |
There was a problem hiding this comment.
'except' clause does nothing but pass and there is no explanatory comment.
| except Exception: | ||
| pass |
There was a problem hiding this comment.
'except' clause does nothing but pass and there is no explanatory comment.
| except Exception: | |
| pass | |
| except Exception as e: | |
| bn.log_error(f"Error while collecting callees for function {getattr(f, 'name', '<unknown>')}: {e}") |
| "tag_type": tag.type.name, | ||
| "comment": tag.data if hasattr(tag, 'data') else "", | ||
| }) | ||
| except Exception: |
There was a problem hiding this comment.
'except' clause does nothing but pass and there is no explanatory comment.
| except Exception: | |
| except Exception: | |
| # Some Binary Ninja versions/plugins may raise when accessing or iterating | |
| # function_tags; ignore these per-function errors and continue scanning. |
| pass | ||
|
|
There was a problem hiding this comment.
'except' clause does nothing but pass and there is no explanatory comment.
| pass | |
| # Some HLIL instructions may not support get_possible_values(); ignore and continue. | |
| pass | |
| except Exception: | ||
| pass |
There was a problem hiding this comment.
'except' clause does nothing but pass and there is no explanatory comment.
| except Exception: | |
| pass | |
| except Exception as inner_exc: | |
| # MLIL SSA analysis is best-effort; log and continue if it fails | |
| bn.log_debug(f"MLIL SSA analysis failed for function {func.name}: {inner_exc}") |
Please test this before merging 😄 I rushed the fix because I needed to test the binja mcp with my other mcp servers. So Please be aware of any changes that may have broke other functionalities.