Edit strings in binary files
Instead of using alternative bash commands, you just use this basic util
Compile & setup: gcc stredit.c -o stredit && sudo cp stredit /usr/local/bin/stredit
Usage: stredit file.bin "old string" "new string"Code taken from my gist
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[]){
FILE * f = fopen(argv[1], "rb+");
fseek(f, 0, SEEK_END);
unsigned long long int size = ftell(f);
fseek(f, 0, SEEK_SET);
unsigned char *data = (unsigned char *)malloc(size);
fread(data, 1, size, f);
size_t old_len = strlen(argv[2]), new_len = strlen(argv[3]);
for (unsigned long long int i=0; i<size-old_len; i++) {
if(!memcmp(&data[i], argv[2], old_len)) {
memmove(&data[i+new_len], &data[i+old_len], size-(i+old_len));
memcpy(&data[i], argv[3], new_len);
break;
}
}
fseek(f, 0, SEEK_SET);
fwrite(data, 1, size, f);
fclose(f);
free(data);
return 0;
}