├── LICENSE ├── README.md └── link /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 eisenxp 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## macos-golink-wrapper 2 | 3 | solution to "syscall.Mprotect panic: permission denied" in Golang on macOS Catalina 10.15.x when using [gomonkey](https://github.com/agiledragon/gomonkey) or [gohook](https://github.com/brahma-adshonor/gohook) 4 | 5 | ## How it works 6 | 7 | Change the `max_prot` value to `0x7` after linking. 8 | 9 | refer to the question: 10 | https://stackoverflow.com/questions/60654834/using-mprotect-to-make-text-segment-writable-on-macos 11 | 12 | ## Usage 13 | 14 | Assuming Go is installed in `/opt/go` 15 | 16 | 1. Navigate to Path: `/opt/go/pkg/tool/darwin_amd64` 17 | 2. Rename file `link` to `original_link` 18 | 3. Download [link wrapper](https://github.com/eisenxp/macos-golink-wrapper/blob/main/link) for replacement 19 | 4. Make sure link wrapper is executable: `chmod +x link` 20 | 5. Enjoy it 21 | 22 | ## Thanks 23 | 24 | Thanks to [Elliott Darfink](https://stackoverflow.com/users/976724/elliott-darfink) for sharing. 25 | 26 | 27 | ## License 28 | 29 | [MIT](https://opensource.org/licenses/MIT) 30 | -------------------------------------------------------------------------------- /link: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import os 3 | import sys 4 | import argparse 5 | import subprocess 6 | 7 | # renamed 'link' file 8 | original_link_file = 'original_link' 9 | 10 | # link first 11 | output=None 12 | code=0 13 | try: 14 | output = subprocess.check_output([os.path.dirname(__file__) + '/' + original_link_file] + sys.argv[1:], cwd=os.getcwd()) 15 | except subprocess.CalledProcessError as e: 16 | output = e.output 17 | code = e.returncode 18 | 19 | if output: 20 | output_str = str(output, encoding='utf-8') 21 | print(output_str.replace(original_link_file, 'link')) 22 | 23 | # change max_prot value to 0x7 24 | parser = argparse.ArgumentParser() 25 | parser.add_argument('-o') 26 | args, _ = parser.parse_known_args() 27 | 28 | if args.o: 29 | binary_target = args.o 30 | # only for testing 31 | if binary_target.endswith('.test') or binary_target.endswith('_test_go'): 32 | with open(os.devnull, 'wb') as DEVNULL: 33 | try: 34 | subprocess.check_call(["printf '\x07' | dd of=%s bs=1 seek=160 count=1 conv=notrunc" % binary_target], shell=True, stdout=DEVNULL, stderr=DEVNULL) 35 | except subprocess.CalledProcessError as e: 36 | pass 37 | 38 | sys.exit(code) 39 | --------------------------------------------------------------------------------