Skip to content

Fix view clearing bug in #45 and add Windows RE operations#61

Open
kiwids0220 wants to merge 1 commit intofosdickio:mainfrom
kiwids0220:main
Open

Fix view clearing bug in #45 and add Windows RE operations#61
kiwids0220 wants to merge 1 commit intofosdickio:mainfrom
kiwids0220:main

Conversation

@kiwids0220
Copy link
Copy Markdown

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.

@kiwids0220
Copy link
Copy Markdown
Author

@CX330Blake The new PR is here, but please review and test before merging 😄

@CX330Blake
Copy link
Copy Markdown
Collaborator

CX330Blake commented Jan 18, 2026

@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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +213 to +225
# 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()}

Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
# 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()}

Copilot uses AI. Check for mistakes.

# Numeric forms
signed = False
neg = text.startswith("-")
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
neg = text.startswith("-")

Copilot uses AI. Check for mistakes.
Comment thread plugin/api/endpoints.py

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
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
if func_length <= 0:
func_length = 1024 # Use a reasonable default if length not available
except Exception:
except:
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
except:
except Exception:

Copilot uses AI. Check for mistakes.


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:
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
callees.append(node)
except Exception:
continue
except Exception:
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'except' clause does nothing but pass and there is no explanatory comment.

Copilot uses AI. Check for mistakes.
Comment on lines +759 to +760
except Exception:
pass
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'except' clause does nothing but pass and there is no explanatory comment.

Suggested change
except Exception:
pass
except Exception as e:
bn.log_error(f"Error while collecting callees for function {getattr(f, 'name', '<unknown>')}: {e}")

Copilot uses AI. Check for mistakes.
"tag_type": tag.type.name,
"comment": tag.data if hasattr(tag, 'data') else "",
})
except Exception:
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'except' clause does nothing but pass and there is no explanatory comment.

Suggested change
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.

Copilot uses AI. Check for mistakes.
Comment on lines +938 to +939
pass

Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'except' clause does nothing but pass and there is no explanatory comment.

Suggested change
pass
# Some HLIL instructions may not support get_possible_values(); ignore and continue.
pass

Copilot uses AI. Check for mistakes.
Comment on lines +1144 to +1145
except Exception:
pass
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'except' clause does nothing but pass and there is no explanatory comment.

Suggested change
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}")

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants