Vector35 / Vector35/binaryninja-api

Invalid register returned from clobbered register list for specific function

Open
#7,070 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Component: Python API Core: Calling Convention Effort: Trivial Impact: Low
Dominant language
C++
Stars
1.3k
Forks
298
Avg merge
5d 5h
Merged PRs (30d)
19

Description

Binary: gentle ocean dreams gracefully

  1. Go to 0x401000
  2. current_function.clobbered_regs
  3. Observe first register is "invalid"

The edit function dialog shows no such register, presumably it filters out invalid ones. Maybe the python bindings should as well?

Discovered when I tried to add the binary to the unit tests and it failed due to:

    def test_functions_attributes(bv: BinaryView):
        """Function attributes don't match"""
        funcinfo = []
        for func in bv.functions:
            func.comment = "testcomment " + func.name
            func.name = func.symbol
            func.can_return = func.can_return
            func.type = func.type
            func.return_type = func.return_type
            func.return_regs = func.return_regs
            func.calling_convention = func.calling_convention
            func.parameter_vars = func.parameter_vars
            func.has_variable_arguments = func.has_variable_arguments
            func.analysis_skipped = func.analysis_skipped
>           func.clobbered_regs = func.clobbered_regs

python/test_function.py:117: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
../..-../binaryninja/function.py:1524: in clobbered_regs
    regs.regs[i] = self.arch.get_reg_index(value[i])

self = <arch: x86>, reg = 'invalid'

    def get_reg_index(self, reg: RegisterType) -> RegisterIndex:
        if isinstance(reg, str):
                try:
                        index = self.regs[reg].index
                        assert index is not None
                        return index
                except KeyError:
                        log_error(f"Failed to map string {reg} to register index: ")
                        log_error(traceback.format_exc())
        elif isinstance(reg, lowlevelil.ILRegister):
                return reg.index
        elif isinstance(reg, int):
                return RegisterIndex(reg)
>       raise Exception("Attempting to get register index of non-existant register")
E    Exception: Attempting to get register index of non-existant register

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with python/test_function.py:test_functions_attributes and the clobbered_regs setter in function.py:1524. Reproduce the failure using the named binary and inspect how the edit dialog treats the invalid register. Done means the function attribute test handles this register consistently without raising an exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools, reverse-engineering
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.