#include #include #include typedef uint32_t u32; typedef uint8_t u8; void decrypt_bin(u8 *binary, u32 size) { u8 magic[4] = { 0x6C, 0x37, 0x51, 0x73 }; u32 idx, window; for ( window=0, idx=0; idx < size; idx++, window++ ) { window &= 3; binary[idx] ^= magic[window]; } } int main(int argc, char *argv[]) { if ( argc < 3 ) { fprintf(stderr, "Usage:\n\t%s in.bin out.bin\n", argv[0]); return EXIT_FAILURE; } FILE *fp = fopen(argv[1], "rb"); if ( fp == NULL ) return EXIT_FAILURE; fseek(fp, 0, SEEK_END); u32 size = ftell(fp); fseek(fp, 0, SEEK_SET); u8 *binary = malloc(size); if ( binary == NULL ) { fclose(fp); return EXIT_FAILURE; } fread(binary, size, 1, fp); fclose(fp); decrypt_bin(binary, size); fp = fopen(argv[2], "wb"); if ( fp == NULL ) { free(binary); return EXIT_FAILURE; } fwrite(binary, size, 1, fp); fclose(fp); free(binary); return EXIT_SUCCESS; }