Skip to content

Commit 1a86426

Browse files
Avoid compilation failure in ARM64 (#3)
* Adding support for arm * Dummy method for arm and arm64 * Improve error handling * Apply review feedback
1 parent 0044123 commit 1a86426

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

patcher.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,14 @@ func applyPatch(patch *Patch) error {
109109
defer patchLock.Unlock()
110110
tPointer := patch.target.Pointer()
111111
rPointer := getInternalPtrFromValue(*patch.redirection)
112-
rPointerJumpBytes := getJumpFuncBytes(rPointer)
112+
rPointerJumpBytes, err := getJumpFuncBytes(rPointer)
113+
if err != nil {
114+
return err
115+
}
113116
tPointerBytes := getMemorySliceFromPointer(tPointer, len(rPointerJumpBytes))
114117
targetBytes := make([]byte, len(tPointerBytes))
115118
copy(targetBytes, tPointerBytes)
116-
err := copyDataToPtr(tPointer, rPointerJumpBytes)
119+
err = copyDataToPtr(tPointer, rPointerJumpBytes)
117120
if err != nil {
118121
return err
119122
}

patcher_unsupported.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// +build !386
2+
// +build !amd64
3+
4+
package mpatch
5+
6+
import (
7+
"errors"
8+
"fmt"
9+
"runtime"
10+
)
11+
12+
// Gets the jump function rewrite bytes
13+
func getJumpFuncBytes(to uintptr) ([]byte, error) {
14+
return nil, errors.New(fmt.Sprintf("Unsupported architecture: %s", runtime.GOARCH))
15+
}

patcher_x32.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
package mpatch
44

55
// Gets the jump function rewrite bytes
6-
func getJumpFuncBytes(to uintptr) []byte {
6+
func getJumpFuncBytes(to uintptr) ([]byte, error) {
77
return []byte{
88
0xBA,
99
byte(to),
1010
byte(to >> 8),
1111
byte(to >> 16),
1212
byte(to >> 24),
1313
0xFF, 0x22,
14-
}
14+
}, nil
1515
}

patcher_x64.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
package mpatch
44

55
// Gets the jump function rewrite bytes
6-
func getJumpFuncBytes(to uintptr) []byte {
6+
func getJumpFuncBytes(to uintptr) ([]byte, error) {
77
return []byte{
88
0x48, 0xBA,
99
byte(to),
@@ -15,5 +15,5 @@ func getJumpFuncBytes(to uintptr) []byte {
1515
byte(to >> 48),
1616
byte(to >> 56),
1717
0xFF, 0x22,
18-
}
18+
}, nil
1919
}

0 commit comments

Comments
 (0)