Skip to content

fix(grpc): forward IL2CPP MethodInfo* and contain swap failures - #2

Merged
tkgstrator merged 1 commit into
mainfrom
fix/grpc-il2cpp-abi
Jun 26, 2026
Merged

tkgstrator merged 1 commit into
mainfrom
fix/grpc-il2cpp-abi

Conversation

@tkgstrator

Copy link
Copy Markdown
Contributor

Summary

Fixes a class of crashes around HttpMessageInvoker.SendAsync / HttpHeaders.Remove / HttpHeaders.TryAdd caused by missing IL2CPP ABI alignment, and adds defensive containment around the x-user-id swap so the login flow degrades gracefully instead of aborting the process.

IL2CPP ABI (root cause)

IL2CPP instance methods take a trailing MethodInfo* in the next free arg register (x3 on ARM64). Dropping it leaves x3 polluted from the caller, and orig SendAsync / HttpHeadersRemove / TryAdd crash the moment orig dereferences MethodInfo->methodPointer.

  • Add trailing void *mi to HttpHeadersTryAdd_t, HttpHeadersRemove_t, and GenericSendAsync_t — lockstep with AnalysisTune.m's ..., void *mi convention.
  • KFHookHttpMsgInvokerSendAsync now receives mi and forwards it to orig.
  • The two header-swap callers pass NULL for mi (we don't have one to forward).

Crash containment

  • Add @catch (id e) alongside @catch (NSException *e) to catch non-NSException throws (e.g. C++ exceptions bridged as id).
  • Wrap the swapUserIdHeader call site in its own @try/@catch so any escape still falls through to orig SendAsync — login can proceed with a stale x-user-id instead of aborting the process.

Behavior

Verified locally by tkgstrator.

🤖 Generated with Claude Code

IL2CPP instance methods take a trailing MethodInfo* in the next free arg
register (x3 on ARM64).  Dropping it leaves x3 polluted from the caller
and orig SendAsync / HttpHeadersRemove / TryAdd crash the moment orig
dereferences MethodInfo->methodPointer.

  * Add trailing `void *mi` to HttpHeadersTryAdd_t, HttpHeadersRemove_t,
    and GenericSendAsync_t — lockstep with AnalysisTune.m's convention.
  * KFHookHttpMsgInvokerSendAsync now receives mi and forwards it to orig.
  * Header swap callers pass NULL for mi (we don't have one to forward).

Also harden swapUserIdHeader against unexpected throws so login can
proceed with a stale x-user-id instead of aborting the process:

  * Add `@catch (id e)` alongside `@catch (NSException *e)` to catch
    non-NSException throws (e.g. C++ exceptions bridged as id).
  * Wrap the swapUserIdHeader call site in its own @try/@catch so any
    escape still falls through to orig SendAsync.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 26, 2026 10:51

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens the gRPC header swap hook by aligning IL2CPP instance method ABI (forwarding the trailing MethodInfo*) and containing swap failures so the original HttpMessageInvoker.SendAsync is always invoked.

Changes:

  • Update function pointer typedefs and the KFHookHttpMsgInvokerSendAsync hook signature to include/forward the trailing void *mi (IL2CPP MethodInfo*).
  • Add defensive @try/@catch containment around swapUserIdHeader and broaden catch handling for non-NSException throws.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Hook/GrpcLogging.m
Comment on lines +35 to +38
// IL2CPP instance methods are called with a trailing MethodInfo* in x3 (or
// the next available arg register). Omitting it leaves x3 polluted, and
// orig crashes the moment it dereferences MethodInfo. Keep these signatures
// in lockstep with AnalysisTune.m's `..., void *mi` convention.
@tkgstrator
tkgstrator merged commit a47be0a into main Jun 26, 2026
1 check passed
tkgstrator added a commit to IPA-Patch/KiouForge that referenced this pull request Jun 26, 2026
)

Picks up IPA-Patch/KIOU-Hook#2:
  fix(grpc): forward IL2CPP MethodInfo* and contain swap failures

Resolves crashes around HttpMessageInvoker.SendAsync / HttpHeaders.Remove
/ HttpHeaders.TryAdd by adding the trailing MethodInfo* arg expected by
IL2CPP, and hardens the x-user-id swap path with extra @try/@catch (id e)
so login degrades to a stale x-user-id instead of aborting.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude <noreply@anthropic.com>
@tkgstrator
tkgstrator deleted the fix/grpc-il2cpp-abi branch July 1, 2026 16:32
tkgstrator added a commit that referenced this pull request Jul 27, 2026
IL2CPP instance methods take a trailing MethodInfo* in the next free arg
register (x3 on ARM64).  Dropping it leaves x3 polluted from the caller
and orig SendAsync / HttpHeadersRemove / TryAdd crash the moment orig
dereferences MethodInfo->methodPointer.

  * Add trailing `void *mi` to HttpHeadersTryAdd_t, HttpHeadersRemove_t,
    and GenericSendAsync_t — lockstep with AnalysisTune.m's convention.
  * KFHookHttpMsgInvokerSendAsync now receives mi and forwards it to orig.
  * Header swap callers pass NULL for mi (we don't have one to forward).

Also harden swapUserIdHeader against unexpected throws so login can
proceed with a stale x-user-id instead of aborting the process:

  * Add `@catch (id e)` alongside `@catch (NSException *e)` to catch
    non-NSException throws (e.g. C++ exceptions bridged as id).
  * Wrap the swapUserIdHeader call site in its own @try/@catch so any
    escape still falls through to orig SendAsync.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude <noreply@anthropic.com>
tkgstrator added a commit to IPA-Patch/KiouForge that referenced this pull request Jul 27, 2026
)

Picks up IPA-Patch/KIOU-Hook#2:
  fix(grpc): forward IL2CPP MethodInfo* and contain swap failures

Resolves crashes around HttpMessageInvoker.SendAsync / HttpHeaders.Remove
/ HttpHeaders.TryAdd by adding the trailing MethodInfo* arg expected by
IL2CPP, and hardens the x-user-id swap path with extra @try/@catch (id e)
so login degrades to a stale x-user-id instead of aborting.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude <noreply@anthropic.com>
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.

2 participants