Skip to content

swift: add auto increase frame size#17

Open
eladciuraru wants to merge 1 commit into
yoavst:masterfrom
eladciuraru:feature/auto-increase-stack-for-blocks
Open

swift: add auto increase frame size#17
eladciuraru wants to merge 1 commit into
yoavst:masterfrom
eladciuraru:feature/auto-increase-stack-for-blocks

Conversation

@eladciuraru

Copy link
Copy Markdown

sometimes in swift code, when there is a code that runs a closure on dispatch queue,
it dynamically allocates on the stack as can seen below:

MOV             X8, SP
SUB             X2, X8, #0x30 ; '0' ; params
MOV             SP, X2
...
BL              _$sSo17OS_dispatch_queueC8DispatchE4sync5flags7executexAC0D13WorkItemFlagsV_xyKXEtKlF ; OS_dispatch_queue.sync<A>(flags:execute:)

IDA does not recognize this and when looking at the disassembly,
it looks like it tries to access negative offsets:

    *(_QWORD *)&v12[-32] = v9;
    *(Swift::String *)&v12[-24] = v8;
    OS_dispatch_queue.sync<A>(flags:execute:)(
      &type metadata for (),
      v10,
      (int)v7,
      sub_100033624,
      &v12[-48],
      &type metadata for () + 1);
    (*(void (__fastcall **)(_BYTE *, __int64))(v5 + 8))(v7, v4);

to be able to manually define a struct there you first need to manually edit the function
and increase the frame size.

this commit introduces a simple solution to automatically increase the frame size
in case of finding this pattern, it is not a good solution but it gets the job done when needed. let me know what do you think of this.

@doronz88 doronz88 mentioned this pull request Jun 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant