Vector35 / Vector35/binaryninja-api

Stack analysis fails in delphi prologue

Open
#8,433 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Core: LLIL
Dominant language
C++
Stars
1.3k
Forks
298
Avg merge
5d 5h
Merged PRs (30d)
19

Description

Version and Platform (required):

  • Binary Ninja Version: 6.0.10489-dev
  • Edition: Ultimate
  • OS: macOS
  • OS Version: 26.6
  • CPU Architecture: arm64

Bug Description:
One of the common types of Delphi function prologue uses a loop to allocate a fixed amount of stack space, causing LLIL's stack recovery to break.

Steps To Reproduce:

  1. Open binary, dogbolt corpus sha256 60bdc2d5e9728214d5c5cf43e9abb62d62c0afbeecdc737a7f482e09b5c773e1
  2. Navigate to 0x004180f4
  3. Observe broken stack recovery

Expected Behavior:
I expected stack recovery to work

Screenshots/Video Recording:
Image
Image

Binary:
See dogbolt corpus 60bdc2d5e9728214d5c5cf43e9abb62d62c0afbeecdc737a7f482e09b5c773e1 or on internal slack under caesar_cipher.exe

Additional Information:
On public slack Michael F reported the same issue with a different (unknown) binary. The binary in this issue is compiled with Delphi ~2010 and uses this pattern in a number of places to set up a stack frame, and seems like it has the identical prologue and behavior.

We already have support for patterns nearly identical to this one, see Vector35/binaryninja@1f93de3128bc086aedc4c7f5580ab98632fef568, but due to this using x86's dec ecx causing a spill to a temporary register during the loop, this specific pattern is not handled.

I had Codex generate a workflow plugin that attempts to handle this case, which seems to work for exactly this function but unconfirmed in the general case. That is available here: wf_delphi_intro.py

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 with the dogbolt corpus binary at 0x004180f4, then compare it with the existing support in commit 1f93de3128bc086aedc4c7f5580ab98632fef568. Read wf_delphi_intro.py to understand the attempted handling of the Delphi prologue and verify the behavior on the other occurrences described in the issue. Done means stack recovery works for this pattern without breaking similar prologues.

Written by the indexing model from the issue text.

Assessment

Domain
reverse-engineering
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.