Setting function return_type clobbers other function type changes

Aberta
#8,690 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 2 dias

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
4/5
Tempo estimado
3-5 dias
Facilidade para iniciantes
52/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
cpp, python
Domínio
api, backend

Direção de pesquisa

The reproducer uses the Python API to show that setting return_type resets other function properties; it does not identify an implementation file or test path. Start by locating the return_type setter and the function type update logic it calls, then trace how property changes are preserved before analysis. Done means the reproducer no longer prints any “lost after setting” messages across its property combinations.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

Version and Platform (required):

  • Binary Ninja Version: 6.1.11009-dev
  • Edition: Commercial
  • OS: macOS
  • OS Version: 27.0.1 (26A434)
  • CPU Architecture: arm64

Bug Description:
In general you can make multiple changes before reanalyzing and BN will batch all of those changes. This applies even if you're changing multiple properties of the same object, and even if those properties are function properties which aren't stored separately but as part of the function type, such as is_pure, can_return, return_value, etc.

The one exception is return_type. If you set return_type, it resets all other aspects of the function type to what it was after the last analysis, clobbering any prior changes.

Steps To Reproduce:
This reproducer is somewhat long, but it tests every combination of function-type properties.

import binaryninja
from binaryninja import Type, types, variable
from binaryninja.types import *
from binaryninja.variable import *

platform = binaryninja.Platform["linux-x86_64"]

def location(register):
    return ValueLocation.parse(register, platform.arch)

# Various function properties, along with values we can set them to (any
# arbitrary value except that it shouldn't match what we originally got from
# analysis).
PROPERTIES = [
    ("return_type",            "int16_t"),
    ("return_value",           ReturnValue(Type.char(), None)),
    ("return_value_location",  location("rdx").with_confidence(255)),
    ("calling_convention",     platform.arch.calling_conventions["win64"]),
    ("parameter_locations",    ParameterLocations([location("rsi"), location("r8")])),
    ("has_variable_arguments", BoolWithConfidence(True)),
    ("can_return",             BoolWithConfidence(False)),
    ("is_pure",                BoolWithConfidence(False)),
    ("stack_adjustment",       OffsetWithConfidence(8)),
    ("reg_stack_adjustments",  {"x87": RegisterStackAdjustmentWithConfidence(1)}),
    ("clobbered_regs",         RegisterSet(["rax", "rcx"])),
]

# In general we expect all of those properties to be able to vary
# independently.  Changing one shouldn't affect any of the others.
# But there are exceptions:
EXPECTED_INTERFERENCE = [
    # return_value consists of return_type + return_value_location.
    {"return_value", "return_type"},
    {"return_value", "return_value_location"},
    # noreturn functions are forced to never clobber anything.
    {"can_return", "clobbered_regs"},
]

for analyze_in_between in [True, False]:
    print(f"for {analyze_in_between=}:")
    for first, first_value in PROPERTIES:
        for second, second_value in PROPERTIES:
            if first == second:
                continue
            if {first, second} in EXPECTED_INTERFERENCE:
                continue

            # Create a new BV and function.
            view = binaryninja.BinaryView.new(b"\xc3")  # ret
            view.platform = platform
            function = view.create_user_function(0)
            view.update_analysis_and_wait()

            # Make sure we are actually changing something:
            orig_value = getattr(function, first)
            if str(orig_value) == str(first_value):
                print(f"    bug in test: {first} was already {first_value}")

            # Set the first function property.
            setattr(function, first, first_value)

            # Maybe run a reanalysis.
            if analyze_in_between:
                view.update_analysis_and_wait()

            # Set the second function property.
            setattr(function, second, second_value)
            view.update_analysis_and_wait()
            read_back = getattr(function, first)

            # Check if we got back the expected value.
            if str(read_back) != str(first_value):
                print(f"    {first} lost after setting {second}: got {str(read_back)}, expected {str(first_value)}")
    print("...done")

Expected Behavior:
The script should not print any "lost after setting" messages.

In reality, it prints one for every test where second is "return_type".

Linguagem predominante
C++
Estrelas
1.3k
Forks
304
Merge médio
2d 20h
PRs com merge (30d)
10

Preparar o ambiente

Este projeto não oferece contêiner de desenvolvimento, Dockerfile nem guia de contribuição, então a configuração fica por sua conta: comece pelo README e veja nosso guia da primeira contribuição para os passos gerais.

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de Vector35/binaryninja-api

Todas as issues de Vector35/binaryninja-api

Issues semelhantes

Mais issues de C++

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.