Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Negative enumeration values on signed enums are returned as unsigned values when querying via the python api. #4183

Closed
cookiemon opened this issue Apr 5, 2023 · 1 comment
Labels
Component: API Issue needs changes to the API
Milestone

Comments

@cookiemon
Copy link

Version and Platform (required):

  • Binary Ninja Version: 3.4.4193-dev
  • OS: Fedora Linux
  • OS Version: 37
  • CPU Architecture: x64

Bug Description:
When defining signed enums with negative values, they show up as that inside the types window. But when querying the values via the python api, one gets the 64-bit two's complement representation.

Steps To Reproduce:
Run the following script in the python console with any binary opened:

builder = types.EnumerationBuilder.create(sign=True, width=2, members=[("first", -32)])
bv.define_user_type("foo", builder)
bv.get_type_by_name("foo").members[0].value

Expected Behavior:
The value returned by querying bv.get_type_by_name("foo").members[0].value returns -32, or at least is consistent with what's shown in the ui.

Screenshots:

image

image

Additional Information:
This behavior happens the same when you define enumerations via the ui and then query via the api.

@fuzyll fuzyll added the Component: API Issue needs changes to the API label May 17, 2023
@plafosse
Copy link
Member

plafosse commented May 30, 2023

This was fixed somewhat recently latest dev (3.5) produces

>>> bv.types['foo']
<type: immutable:EnumerationTypeClass 'enum foo'>
>>> bv.types['foo'].members
[<BAR = -0x1>]
>>> bv.types['foo'].members[0]
<BAR = -0x1>
>>> bv.types['foo'].members[0].value
-1

@plafosse plafosse added this to the Coruscant milestone Aug 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: API Issue needs changes to the API
Projects
None yet
Development

No branches or pull requests

3 participants