Skip to content

Instantly share code, notes, and snippets.

@nurpax
Last active May 23, 2018 08:25
Show Gist options
  • Save nurpax/98b7abc9b67ab9e99f0ead847eb3dd45 to your computer and use it in GitHub Desktop.
Save nurpax/98b7abc9b67ab9e99f0ead847eb3dd45 to your computer and use it in GitHub Desktop.
remove effings from bintris
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, const char **argv)
{
FILE* fpi = fopen(argv[1], "rb");
FILE* fpo = fopen(argv[2], "wb");
fseek(fpi, 0L, SEEK_END);
size_t sz = ftell(fpi);
fseek(fpi, 0L, SEEK_SET);
unsigned char* bytes = malloc(sz);
fread(bytes, 1, sz, fpi);
// fuckings
char str_to_replace[8];
char replace_with[8];
const char *effings = "fuckings";
const char *str = "darlings";
for (int i = 0; i < 8; i++) {
str_to_replace[i] = effings[i] - 'a' + 1;
replace_with[i] = str[i] - 'a' + 1;
}
size_t offs = 0;
while (offs < sz) {
if (memcmp(bytes + offs, str_to_replace, 8) == 0) {
memcpy(bytes + offs, replace_with, 8);
printf("replaced at offs %d\n", (int)offs);
offs += 8;
} else {
offs++;
}
}
fwrite(bytes, 1, sz, fpo);
free(bytes);
fclose(fpi);
fclose(fpo);
}
@nurpax
Copy link
Author

nurpax commented May 23, 2018

Run it like:

clang noprofanity.c -o patchbintris && ./patchbintris t/bintris.d64 t/bintris2.d64

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment