Skip to content

HLIL instruction that sets structure gets removed by optimization #7344

@mostobriv

Description

@mostobriv

Version and Platform (required):

  • Binary Ninja Version:5.2.8211-dev Personal (a464fda8)
  • Edition: Non-Commercial
  • OS: MacOS
  • OS Version: 15.5
  • CPU Architecture: M1

Bug Description:
Idk how even describe it properly, sorry.

When there is store instruction outside of structure bounds, in some cases HLIL just drops it and doesn't render at all. For example, i have the function in arm64:

.foo:
    stp     x1, x2, [x0, #0x8]
    ret 

As pseudocode it is:

*(arg1+8) = arg2
*(arg1+16) = arg3

and if arg1 is void* for example, then things works fine and HLIL showing accesses as is it should:
Image

even if i create an empty structure Foo and set arg1 to be struct Foo*, still ok:
Image

even if i append field of 1 byte size to the Foo:
Image

but, if i set the size of Foo to be 8 (the exact amount of shift in stp), then HLIL just loses the instructions:
Image

however in MLIL instructions still there:
Image

Idk may be this is caused by stp instruction, as when i tried to reproduce it with regular function with stack, things worked fine, magick happens only with naked func.

Also, this give me vibes of #7195, i believe this issue has same root cause.

Steps To Reproduce:
Please provide all steps required to reproduce the behavior:

  1. Open binary
  2. Create structure of size 8
  3. Set the type of first argument of _foo to this structure pointer
  4. Done

Expected Behavior:
Anything other than just hiding this accesses in HLIL

Binary:
bin.zip

Additional Information:
Here is code i've tested it on:

__attribute__((naked))
void foo(void* ptr, void* a, void* b) {
	__asm __volatile__ (
		"stp x1, x2, [x0, 0x8]\n"
		"ret\n"
	);
}

int main() {
	char kek[123];

	__asm__ __volatile__(
        "mov x0, %0\n"  // Move ptr into register r0
        "mov x1, %1\n"  // Move a into register r1
        "mov x2, %2\n"  // Move b into register r2
        "bl _foo\n"  // Branch to the naked function
        :
        : "r" (kek), "r" (NULL), "r" (NULL)
		: "x0", "x1", "x2"
    );

	return 0;
}

Metadata

Metadata

Assignees

Labels

Component: CoreIssue needs changes to the coreCore: HLILIssue involves High Level ILEffort: MediumIssues require < 1 month of workImpact: MediumIssue is impactful with a bad, or no, workaround

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions