Skip to content

Instantly share code, notes, and snippets.

@chaoskagami
Created March 11, 2019 03:32
Show Gist options
  • Save chaoskagami/fe8d7dd3151d3bfc3c12401626bc93b7 to your computer and use it in GitHub Desktop.
Save chaoskagami/fe8d7dd3151d3bfc3c12401626bc93b7 to your computer and use it in GitHub Desktop.
fixbmp
// Usage: prog input_file output_file
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(int c, char** v) {
FILE* in = fopen(v[1], "r");
fseek(in, 0, SEEK_END);
size_t off = ftell(in);
rewind(in);
char *arr = (char*)malloc(off);
fread(arr, 1, off, in);
fclose(in);
for (size_t l = 54; l < off; l += 4) {
char tmp;
tmp = arr[l];
arr[l] = arr[l+3];
arr[l+3] = tmp;
tmp = arr[l+1];
arr[l+1] = arr[l+2];
arr[l+2] = tmp;
}
FILE *out = fopen(v[2], "w");
fwrite(arr, 1, off, out);
fclose(out);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment