Last active
May 23, 2018 08:25
-
-
Save nurpax/98b7abc9b67ab9e99f0ead847eb3dd45 to your computer and use it in GitHub Desktop.
remove effings from bintris
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run it like: