Skip to content

Commit

Permalink
Avoid compilation failure in ARM64 (#3)
Browse files Browse the repository at this point in the history
* Adding support for arm

* Dummy method for arm and arm64

* Improve error handling

* Apply review feedback
  • Loading branch information
drodriguezhdez authored Mar 26, 2020
1 parent 0044123 commit 1a86426
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
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
}

0 comments on commit 1a86426

Please sign in to comment.