Skip to content

Instantly share code, notes, and snippets.

@mstaack
Created November 10, 2024 13:19
Show Gist options
  • Save mstaack/d6e9f685ff2d78b110de3b01a1409ae0 to your computer and use it in GitHub Desktop.
Save mstaack/d6e9f685ff2d78b110de3b01a1409ae0 to your computer and use it in GitHub Desktop.
main.go
package main
import (
"bytes"
"fmt"
"os"
)
func main() {
if len(os.Args) != 5 {
fmt.Println("Usage: go run main.go <inputFirmware> <outputFirmware> <originalFontFile> <fixedFontFile>")
return
}
inputFirmware := os.Args[1]
outputFirmware := os.Args[2]
originalFontFile := os.Args[3]
fixedFontFile := os.Args[4]
// read firmware
originalFirmwareData, err := os.ReadFile(inputFirmware)
if err != nil {
fmt.Println("Error reading input file:", err)
return
}
// read original font
originalFontData, err := os.ReadFile(originalFontFile)
if err != nil {
fmt.Println("Error reading input file:", err)
return
}
// read fixed font file
fixedFontData, err := os.ReadFile(fixedFontFile)
if err != nil {
fmt.Println("Error reading input file:", err)
return
}
// Replace occurrences of oldBytes with newBytes
originalFirmwareData = bytes.ReplaceAll(originalFirmwareData, originalFontData, fixedFontData)
// Write the modified data to the output file
err = os.WriteFile(outputFirmware, originalFirmwareData, 0644)
if err != nil {
fmt.Println("Error writing output file:", err)
return
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment