Type resolution can give surprisingly different results for local variables in similar code

未关闭
#7,367 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
objective-c

调研方向

Reproduce the discrepancy using the attached good and bad binaries, switch to HLIL at 0x100000890, and apply the shown _objc_msgSendSuper2 call type override. Compare how obj_3 is resolved, including the objc_retain call at 0x100000918. Done means both cases resolve obj_3 as MyClass* after the override, rather than leaving bad at id.

由索引模型根据 Issue 内容生成。

描述

Core: Type Propagation Effort: Medium Impact: Low

Version and Platform (required):

  • Binary Ninja Version: 5.2.8236-dev Ultimate, d8af0ff0
  • OS: macos
  • OS Version: 26.0
  • CPU Architecture: arm64

Bug Description:
While working on applying more type information from Objective-C binaries I noticed that the type resolution algorithm gives different results in code that is very similar. Specifically, in cases when the return type of a function that is used to initialize a variable and a function to which the variable is passed have a) different types and b) the same confidence, the function parameter type can end up taking precedence over the return type. This can give the effect of a call type adjustment not being applied.

Whether the return type or later parameter type ends up being selected for the local variable's type depends on the order the algorithm traverses the basic blocks and their edges.

Steps To Reproduce:

  1. Open both good and bad. Switch to HLIL and go to 0x100000890.
  2. Right-click on the call to _objc_msgSendSuper2 and add a call type override to:
    MyClass* _objc_msgSendSuper2(struct objc_super* super, SEL sel)
    

Expected Behavior:
The type of the local variable obj_3 should update to MyClass* to reflect the new type information.

good behaves as expected.

In bad it stays at id as the type information from the objc_retain call at 0x100000918 is seen first. Since it has the same full confidence as the return type of the call type override, it ends up being used.

Workaround:

Apply a type to the local variable.

Binaries:

bad.zip
good.zip

These can be built from this source file (call-type-override.m by doing:

cc -DBAD -o bad -fobjc-arc -framework Foundation -Os call-type-override.m
cc -UBAD -o good -fobjc-arc -framework Foundation -Os call-type-override.m

The only difference between them is if (!a || !b || !c) becomes if (!a && !b && !c)

主要语言
C++
星标
1.3k
派生
298
平均合并
5 天 5 小时
30 天内合并 PR
19

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Vector35/binaryninja-api 的其他 Issue

查看 Vector35/binaryninja-api 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。