Last active
August 17, 2019 05:17
-
-
Save tarunon/7c51a89993f7c2e087eee6ced22de24e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private struct SwiftFuncWrapper { | |
var trampolinePtr: UnsafeMutablePointer<UInt64> | |
var functionObject: UnsafeMutablePointer<SwiftFuncObject> | |
var functionPtr: UnsafeMutableRawPointer { | |
let pointer = UnsafeMutablePointer<UInt64>(bitPattern: UInt(functionObject.pointee.address))! | |
// Getting actual function ptr from instruction. | |
// 0: 55 push rbp | |
// 1: 48 89 e5 mov rbp,rsp | |
// 4: 5d pop rbp | |
// 5: e9 XX XX ff ff jmp 0xffffXXXX | |
let relativeJmpRel = pointer.pointee >> 48 + (pointer.advanced(by: 1).pointee << 48) >> 32 + 0xffffffff0000000a | |
return UnsafeMutableRawPointer(bitPattern: UInt(functionObject.pointee.address &+ relativeJmpRel))! | |
} | |
} | |
private struct SwiftFuncObject { | |
var originalTypePtr: UnsafeMutablePointer<UInt64> | |
var unknown: UnsafeMutablePointer<UInt64> | |
var address: UInt64 | |
var selfPtr: UnsafeMutablePointer<UInt64> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment