User:Remark/dec-flipbook.c: Difference between revisions
No edit summary |
No edit summary |
||
| (2 intermediate revisions by 2 users not shown) | |||
| Line 7: | Line 7: | ||
#include <stdlib.h> | #include <stdlib.h> | ||
char key [0x40] = { | char key [0x40] = { | ||
0xF7, 0x4C, 0x6A, 0x3A, 0xFB, 0x82, 0xA6, 0x37, 0x6E, 0x11, 0x38, 0xCF, 0xA0, 0xDD, 0x85, 0xC0, | 0xF7, 0x4C, 0x6A, 0x3A, 0xFB, 0x82, 0xA6, 0x37, 0x6E, 0x11, 0x38, 0xCF, 0xA0, 0xDD, 0x85, 0xC0, | ||
| Line 37: | Line 36: | ||
FILE* f = fopen(argv[1], "rb"); | FILE* f = fopen(argv[1], "rb"); | ||
if(f | if(!f) | ||
PERR("fopen"); | PERR("fopen"); | ||
int len = fsize(f); | int len = fsize(f); | ||
char* buf = malloc(len); | //char* buf = malloc(len); | ||
if(buf | char* buf = (char*) malloc(len); | ||
if(!buf) | |||
{ | |||
fclose(f); | |||
PERR("malloc"); | PERR("malloc"); | ||
} | |||
if(fread(buf,len,1,f) != 1) | if(fread(buf,len,1,f) != 1) | ||
{ | |||
fclose(f); | |||
free(buf); | |||
PERR("fread"); | PERR("fread"); | ||
} | |||
int i; | int i; | ||
| Line 55: | Line 62: | ||
FILE* fout = fopen(argv[2], "wb+"); | FILE* fout = fopen(argv[2], "wb+"); | ||
if(fout | if(!fout) | ||
{ | |||
fclose(f); | |||
free(buf); | |||
PERR("fopen"); | PERR("fopen"); | ||
} | |||
if(fwrite(buf, len, 1, fout) != 1) | if(fwrite(buf, len, 1, fout) != 1) | ||
{ | |||
fclose(f); | |||
free(buf); | |||
fclose(fout); | |||
PERR("fwrite"); | PERR("fwrite"); | ||
} | |||
free(buf); | free(buf); | ||