github.com/Rookout/GoSDK@v0.1.48/pkg/services/assembler/encoder_amd64.go (about) 1 package assembler 2 3 import ( 4 "encoding/binary" 5 "math" 6 7 "github.com/Rookout/GoSDK/pkg/rookoutErrors" 8 ) 9 10 const ( 11 j = "\xe9" 12 jl = "\x0f\x8c" 13 ) 14 15 func encodeBranch(src uintptr, dst uintptr, op string) ([]byte, rookoutErrors.RookoutError) { 16 relativeAddr := int64(dst - (src + uintptr(len(op)) + 4)) 17 if relativeAddr > math.MaxInt32 || relativeAddr < math.MinInt32 { 18 return nil, rookoutErrors.NewBranchDestTooFar(src, dst) 19 } 20 21 offset := make([]byte, 4) 22 binary.LittleEndian.PutUint32(offset, uint32(relativeAddr)) 23 24 return append([]byte(op), offset...), nil 25 } 26 27 func EncodeJmp(src uintptr, dst uintptr) ([]byte, rookoutErrors.RookoutError) { 28 return encodeBranch(src, dst, j) 29 } 30 31 func EncodeJL(src uintptr, dst uintptr) ([]byte, rookoutErrors.RookoutError) { 32 return encodeBranch(src, dst, jl) 33 }