Guest User

Untitled

a guest
Jun 22nd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. public static void Inject(MethodInfo ToReplace, MethodInfo ToInject)
  2. {
  3. RuntimeHelpers.PrepareMethod(ToReplace.MethodHandle);
  4. RuntimeHelpers.PrepareMethod(ToInject.MethodHandle);
  5. unsafe
  6. {
  7. byte* inject = (byte*)(IntPtr.Size == 4 ? *((int*)ToInject.MethodHandle.Value.ToPointer() + 2) : *((long*)ToInject.MethodHandle.Value.ToPointer() + 1));
  8. byte* target = (byte*)(IntPtr.Size == 4 ? *((int*)ToReplace.MethodHandle.Value.ToPointer() + 2) : *((long*)ToReplace.MethodHandle.Value.ToPointer() + 1));
  9. int* injectSrc = (int*)(inject + 1);
  10. int* targetSrc = (int*)(target + 1);
  11. *targetSrc = (((int)inject + 5) + *injectSrc) - ((int)target + 5);
  12. }
  13. }
Add Comment
Please, Sign In to add comment