Created
June 25, 2020 04:32
-
-
Save ear7h/c23b65071edbb68d0b3c99a7982279b0 to your computer and use it in GitHub Desktop.
Replace instances of the string "master" with "main" in a git binary executable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bytes" | |
"fmt" | |
"io" | |
"io/ioutil" | |
"os" | |
"regexp" | |
) | |
func main() { | |
byt, err := ioutil.ReadFile(os.Args[1]) | |
if err != nil { | |
fmt.Println(err) | |
return | |
} | |
re := regexp.MustCompile("master([^\x00]*)") | |
out := re.ReplaceAll(byt, []byte("main${1}\x00\x00")) | |
io.Copy(os.Stdout, bytes.NewBuffer(out)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run with: