Vector35 / Vector35/binaryninja-api

Optimized modulus using a combination of divide and shifted multiply with masking of low bits fails to simplify

Open
#4,362 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Optimized modulus that combines the steps of an optimized divide with a multiplication using shifts, adds,
and masking of lower bits can fail to simplify into a modulus expression. An example is given below:

combined_with_mask

Binaries with examples:

combined_with_mask.zip

u32_mod_4k_x86.so: See 3, 5, 17, 36, and others
u64_mod_4k_arm64.so: See 3, 5, 9, 11, 17, and others
u64_mod_4k_x64.dylib: See 6, 10, 12, 18, 20, and others
u64_mod_4k_x64.so: See 3, 5, 9, 17, 22, and others

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 failure using combined_with_mask.zip, checking the listed cases in u32_mod_4k_x86.so, u64_mod_4k_arm64.so, u64_mod_4k_x64.dylib, and u64_mod_4k_x64.so. Trace the simplification of the optimized divide, shifted multiply, adds, and low-bit mask, and verify that the affected patterns simplify into a modulus expression.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers, reverse-engineering
Issue type
Bug
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.