Created
October 26, 2019 20:02
-
-
Save adrianosela/b8a8bd7a4935874125aba641be0c6b79 to your computer and use it in GitHub Desktop.
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 ( | |
"crypto/sha1" | |
"errors" | |
"flag" | |
"fmt" | |
"io" | |
"log" | |
"os" | |
) | |
const ( | |
position = 122860 | |
) | |
var ( | |
path = flag.String("path", "", "path of program to patch") | |
password = flag.String("password", "", "new password for program") | |
) | |
func main() { | |
flag.Parse() | |
if *path == "" { | |
log.Fatal(errors.New("no path provided")) | |
} | |
if *password == "" { | |
log.Fatal(errors.New("no password provided")) | |
} | |
// open program file | |
fd, err := os.OpenFile(*path, os.O_APPEND|os.O_WRONLY, os.ModeAppend) | |
if err != nil { | |
log.Fatal(fmt.Errorf("could not open file: %s", err)) | |
} | |
defer fd.Close() | |
// move file descriptor to correct position | |
if _, err := fd.Seek(position, io.SeekStart); err != nil { | |
log.Fatal(fmt.Errorf("could not seek file position: %s", err)) | |
} | |
// take the sha1 of the password | |
hashWriter := sha1.New() | |
hashWriter.Write([]byte(*password)) | |
sha1 := hashWriter.Sum(nil) | |
if _, err := fd.Write(sha1); err != nil { | |
log.Fatal(fmt.Errorf("could not write new password hash to program: %s", err)) | |
} | |
fmt.Println("program patched!") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment