Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CallTrace: Disassemble managed prestubs to find the real method address #26

Open
alexrp opened this issue Jul 13, 2022 · 1 comment
Open
Labels
area: diagnostics Issues related to the call stack tracing APIs. state: approved Enhancements and tasks that have been approved.
Milestone

Comments

@alexrp
Copy link
Member

alexrp commented Jul 13, 2022

// TODO: To do this correctly for managed methods, we have to disassemble the prestub and follow the jump.
if (ManagedMethod == null && (byte*)IP - (byte*)Symbol.Address is var offset and not 0)
_ = sb.Append(culture, $"+0x{offset:x}");

The issue is that the function pointer we get from RuntimeMethodHandle.GetFunctionPointer() points to the prestub for the method, but the instruction pointer we have (of course) points to the actual JIT'd method that was executed.

One way we might solve this is by disassembling the prestub and following the jump to the actual method. But we would need to know for sure that RuntimeMethodHandle.GetFunctionPointer() always returns a pointer to a prestub.

@alexrp alexrp added state: approved Enhancements and tasks that have been approved. type: feature area: hooking Issues related to the function hooking APIs. labels Jul 13, 2022
@alexrp alexrp added this to the v2.0 milestone Jul 13, 2022
@alexrp alexrp self-assigned this Jul 13, 2022
@alexrp
Copy link
Member Author

alexrp commented Jul 23, 2022

Lots of useful information here: https://github.com/MonoMod/MonoMod.Common/blob/master/RuntimeDetour/Platforms/Runtime/DetourRuntimeNETPlatform.cs

Looks like this is not going to be fun.

@alexrp alexrp modified the milestones: v2.0, v3.0 Jul 23, 2022
@alexrp alexrp added area: diagnostics Issues related to the call stack tracing APIs. and removed area: hooking Issues related to the function hooking APIs. labels Jul 28, 2022
@alexrp alexrp removed their assignment Jan 27, 2024
@alexrp alexrp modified the milestones: v4.0, Future Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: diagnostics Issues related to the call stack tracing APIs. state: approved Enhancements and tasks that have been approved.
Development

No branches or pull requests

1 participant