Skip to content

Setting data variable name via Python API changes symbol type to DataSymbol #7306

@bdash

Description

@bdash

Version and Platform (required):

  • Binary Ninja Version: 5.2.8161-dev, 98bf34dd
  • OS: macos
  • OS Version: 15.6
  • CPU Architecture: arm64

Bug Description:
The Python binding for DataVariable changes the symbol's type when changing the variable's name.

The name setter delegates to the symbol setter:

@name.setter
def name(self, value: str) -> None:
	self.symbol = value

The symbol setter looks like so:

@symbol.setter
def symbol(self, value: Optional[Union[str, '_types.CoreSymbol']]) -> None:  # type: ignore
	if value is None or value == "":
		if self.symbol is not None:
			self.view.undefine_user_symbol(self.symbol)
	elif isinstance(value, (str, _types.QualifiedName)):
		symbol = _types.Symbol(SymbolType.DataSymbol, self.address, str(value))
		self.view.define_user_symbol(symbol)

You can see when assigning a string it hard-codes the symbol type to SymbolType.DataSymbol, irrespective of what the existing symbol type is.

Steps To Reproduce:

  1. Open a binary. I used /usr/libexec/syspolicyd, but it shouldn't matter so long as it has external symbols.
  2. Run the following in the Python console:
    var = [var for var in bv.data_vars.values() if var.symbol and var.symbol.type == SymbolType.ExternalSymbol][0]
    bv.navigate("Linear:%s" % bv.view_type, var.address)
    var.symbol.type
    var.name = var.name
    var.symbol.type

Expected Behavior:
Nothing should change, and the result of var.symbol.type should display as <SymbolType.ExternalSymbol: 5> before and after the name change.

Actual Behavior:
The symbol type changes to <SymbolType.DataSymbol: 3> and the rendering of the symbol updates in the linear view. In my case it changes from orange to blue.

Additional Information:
This was originally noticed due to it causing a poor interaction between the Swift Demangler plug-in, available via the plug-in manager, and the Pseudo Objective-C language representation. The Pseudo Objective-C language representation checks the symbol types in a few places and does not expect imported symbols, for instance, to be reported as being ordinary data symbols.

Metadata

Metadata

Assignees

Labels

Component: Python APIIssue needs changes to the python APIEffort: LowIssues require < 1 week of workImpact: LowIssue is a papercut or has a good, supported workaround

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions