IL TestBit operation result isn't known even when testing a constant

Open
#1,921 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
cpp, python

Research direction

Reproduce the report by comparing func.llil.instructions and func.mlil.instructions for the test_bit and equivalent and conditions shown. Then inspect the MLIL constant-folding path for test_bit; the work is done when the constant test is folded to a known conditional result like the equivalent and expression.

Written by the indexing model from the issue text.

Description

Component: Core Effort: Low Impact: Low

even though mlil should know the result of testing a single bit of a constant, it doesn't

>>> pprint.pprint(list(func.llil.instructions))
[<il: x20 = 0x3210>,
 <il: x20 = x20 | 0x76540000>,
 <il: x20 = x20 | 0xba9800000000>,
 <il: x20 = x20 | 0x7edc000000000000>,
 <il: x0 = x20 << 5>,
 <il: if (test_bit(x20, 0x20)) then 6 else 8>,
 <il: x0 = x0 | 0xffffffe000000000>,
 <il: goto 10 @ 0x14>,
 <il: x0 = x0 & 0x1fffffffff>,
 <il: goto 10 @ 0x14>,
 <il: <return> jump(x30)>]

>>> pprint.pprint(list(func.mlil.instructions))
[<il: if ( test_bit(0x7edcba9876543210, 0x20)) then 1 else 3>,
 <il: x0 = -0x113579be00>,
 <il: goto 5 @ 0x14>,
 <il: x0 = 0xeca864200>,
 <il: goto 5 @ 0x14>,
 <il: return x0>]

doing the same thing with an and operation allows mlil to know the result of the conditional

>>> pprint.pprint(list(func.llil.instructions))
[<il: x20 = 0x3210>,
 <il: x20 = x20 | 0x76540000>,
 <il: x20 = x20 | 0xba9800000000>,
 <il: x20 = x20 | 0x7edc000000000000>,
 <il: x0 = (x20 & 0xffffffff) << 5>,
 <il: if (x20 & 0x80000000 == 0) then 6 else 8>,
 <il: x0 = x0 & 0x1fffffffff>,
 <il: goto 10 @ 0x14>,
 <il: x0 = x0 | 0xffffffe000000000>,
 <il: goto 10 @ 0x14>,
 <il: <return> jump(x30)>]

>>> pprint.pprint(list(func.mlil.instructions))
[<il: if (true) then 1 else 3>,
 <il: x0 = 0xeca864200>,
 <il: goto 5 @ 0x14>,
 <il: x0 = -0x113579be00>,
 <il: goto 5 @ 0x14>,
 <il: return x0>]
Dominant language
C++
Stars
1.3k
Forks
298
Avg merge
5d 5h
Merged PRs (30d)
19

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.

More from Vector35/binaryninja-api

All issues in Vector35/binaryninja-api

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.