diff --git a/patcher.go b/patcher.go index 0aae94e..8c3fafb 100644 --- a/patcher.go +++ b/patcher.go @@ -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 } diff --git a/patcher_unsupported.go b/patcher_unsupported.go new file mode 100644 index 0000000..8a796fd --- /dev/null +++ b/patcher_unsupported.go @@ -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)) +} \ No newline at end of file diff --git a/patcher_x32.go b/patcher_x32.go index d723062..ddb676f 100644 --- a/patcher_x32.go +++ b/patcher_x32.go @@ -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{ 0xBA, byte(to), @@ -11,5 +11,5 @@ func getJumpFuncBytes(to uintptr) []byte { byte(to >> 16), byte(to >> 24), 0xFF, 0x22, - } + }, nil } diff --git a/patcher_x64.go b/patcher_x64.go index ab56a05..392a954 100644 --- a/patcher_x64.go +++ b/patcher_x64.go @@ -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), @@ -15,5 +15,5 @@ func getJumpFuncBytes(to uintptr) []byte { byte(to >> 48), byte(to >> 56), 0xFF, 0x22, - } + }, nil }