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

Avoid compilation failure in ARM64 #3

Merged
merged 4 commits into from
Mar 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions patcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,14 @@ func applyPatch(patch *Patch) error {
defer patchLock.Unlock()
tPointer := patch.target.Pointer()
rPointer := getInternalPtrFromValue(*patch.redirection)
rPointerJumpBytes := getJumpFuncBytes(rPointer)
rPointerJumpBytes, err := getJumpFuncBytes(rPointer)
if err != nil {
return err
}
tPointerBytes := getMemorySliceFromPointer(tPointer, len(rPointerJumpBytes))
targetBytes := make([]byte, len(tPointerBytes))
copy(targetBytes, tPointerBytes)
err := copyDataToPtr(tPointer, rPointerJumpBytes)
err = copyDataToPtr(tPointer, rPointerJumpBytes)
if err != nil {
return err
}
Expand Down
15 changes: 15 additions & 0 deletions patcher_unsupported.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// +build !386
// +build !amd64

package mpatch

import (
"errors"
"fmt"
"runtime"
)

// Gets the jump function rewrite bytes
func getJumpFuncBytes(to uintptr) ([]byte, error) {
return nil, errors.New(fmt.Sprintf("Unsupported architecture: %s", runtime.GOARCH))
}
4 changes: 2 additions & 2 deletions patcher_x32.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
package mpatch

// Gets the jump function rewrite bytes
func getJumpFuncBytes(to uintptr) []byte {
func getJumpFuncBytes(to uintptr) ([]byte, error) {
return []byte{
0xBA,
byte(to),
byte(to >> 8),
byte(to >> 16),
byte(to >> 24),
0xFF, 0x22,
}
}, nil
}
4 changes: 2 additions & 2 deletions patcher_x64.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
package mpatch

// Gets the jump function rewrite bytes
func getJumpFuncBytes(to uintptr) []byte {
func getJumpFuncBytes(to uintptr) ([]byte, error) {
return []byte{
0x48, 0xBA,
byte(to),
Expand All @@ -15,5 +15,5 @@ func getJumpFuncBytes(to uintptr) []byte {
byte(to >> 48),
byte(to >> 56),
0xFF, 0x22,
}
}, nil
}