slsp is a lightweight, dependency-free command-line utility for quick and precise string replacement in files.
Its primary feature is that it's offset-safe: it enforces that the replacement string is the exact same byte length as the search string. This preserves all file offsets, making it 100% safe for patching binaries, executables, and other offset-sensitive files where changing the file size would cause corruption.
-
🔒 Offset Preservation:
slspguarantees file integrity by requiring the search and replace strings to be the exact same length. - 🧬 Binary Safe: Works directly on bytes, making it safe for executables and text files alike.
- ⚙️ Scope Control: Use the
-lflag to limit patching to only the first$N$ bytes of a file (perfect for header manipulation). - 🔢 Occurrence Limiting: Use the
-nflag to control the maximum number of replacements performed.
Requires Go 1.23+
go install github.com/g-vvv/slsp/cmd/slsp@latestslsp -s <search> -r <replace> [-l <bytes>] [-n <count>] <filename>Important: The byte length of the string for
-smust equal the byte length of the string for-r. The tool will exit with an error if they do not match.
| Flag | Description | Default |
|---|---|---|
-s |
(Required) The string to search for. | N/A |
-r |
(Required) The string to replace with. | N/A |
-l |
Optional: Limit patching to the first |
-1 (Full file) |
-n |
Optional: Max number of patches to perform. |
-1 (All occurrences) |
Replace all instances of ver_01 with ver_02 in config.ini.
# "ver_01" and "ver_02" are both 6 bytes
slsp -s "ver_01" -r "ver_02" config.iniReplace the first occurrence of LAME_MAGIC with GOOD_MAGIC within the first 1024 bytes of an executable.
# "LAME_MAGIC" and "GOOD_MAGIC" are both 10 bytes
slsp -s "LAME_MAGIC" -r "GOOD_MAGIC" -l 1024 -n 1 program.exeUpdate only the first 5 instances of DEBUG=1 to DEBUG=0 in a large log file.
slsp -s "DEBUG=1" -r "DEBUG=0" -n 5 massive.logThe following command will fail because the string lengths do not match:
# "Error" (5 bytes) vs "Warn" (4 bytes)
slsp -s "Error" -r "Warn" app.log
# Error: -s (search) and -r (replace/patch) strings must be the same length.After changes and patches, please git tag the versions and notify proxy.golang.org for version changes.
Example for v1.0.0:
git tag v1.0.0
git push origin v1.0.0
go list -m github.com/g-vvv/slsp@v1.0.0