Skip to content

Instantly share code, notes, and snippets.

@MrGossett
Created May 11, 2022 20:15
Show Gist options
  • Save MrGossett/327bee6b49e87b612754e38af62e534c to your computer and use it in GitHub Desktop.
Save MrGossett/327bee6b49e87b612754e38af62e534c to your computer and use it in GitHub Desktop.
package main
import (
"bytes"
"crypto/rand"
"encoding/hex"
"io"
"os"
)
func main() {
hexkey, err := os.ReadFile("key")
if err != nil {
panic(err)
}
key := make([]byte, len(hexkey)>>1)
if _, err := hex.Decode(key, hexkey); err != nil {
panic(err)
}
newkey := make([]byte, len(key))
if _, err := io.ReadFull(rand.Reader, newkey); err != nil {
panic(err)
}
bs, err := io.ReadAll(os.Stdin)
if err != nil {
panic(err)
}
i := bytes.Index(bs, key)
if i == -1 {
println("key not found in binary")
os.Exit(1)
}
copy(bs[i:], newkey)
if err := os.WriteFile("patched", bs, 0o755); err != nil {
panic(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment