Vector35 / Vector35/binaryninja-api

Simplify `sbb` ternary pattern

Open
#5,688 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Component: Core Core: HLIL Effort: Low IL Optimization Impact: Medium
Dominant language
C++
Stars
1.3k
Forks
298
Avg merge
5d 5h
Merged PRs (30d)
19

Description

The following pattern:

a = sbb(x, x, y != 0) & -4

Can be simplified down to:

if (y != 0)
  a = -4
else
  a = 0

Example: sparkle giraffe juggling toaster.zip @ 1c00013a0

Seen @ 1c00013a0 as

a = (sbb(x, x, y != 0) & -4) + 5

notice the additional + 5 at the end. Most likely we'd need to take that into account too and do the whole simplification in one step. So the output becomes

if (y != 0)
  a = 1
else
  a = 5

Compare with other tools here: https://dogbolt.org/?id=eed48ff1-8c4b-4a5d-8fc8-abc82a21b1fe#BinaryNinja=215&Hex-Rays=523

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

Reproduce the pattern from commit 1c00013a0, including the added +5 case, and inspect how the decompiler currently handles sbb(x, x, y != 0) & -4. Compare the result with Binary Ninja and Hex-Rays using the linked Dogbolt example. Done means the output becomes a conditional with 1 and 5 for the full expression, rather than simplifying only the masked subexpression.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
reverse-engineering
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.