wip
This commit is contained in:
38
crc.c
38
crc.c
@@ -14,16 +14,18 @@
|
|||||||
const long idat_signature = 1229209940;
|
const long idat_signature = 1229209940;
|
||||||
const long iend_signature = 1229278788;
|
const long iend_signature = 1229278788;
|
||||||
|
|
||||||
FILE *zlib_decompress_data(unsigned char *data_chunk, size_t file_length) {
|
FILE *zlib_decompress_data(unsigned char *data_chunk, size_t file_length, char *buff) {
|
||||||
int ret;
|
int ret;
|
||||||
unsigned int have;
|
unsigned int have;
|
||||||
z_stream strm;
|
z_stream strm;
|
||||||
unsigned char out[CHUNK];
|
unsigned char out[CHUNK];
|
||||||
unsigned char in[CHUNK];
|
unsigned char in[CHUNK];
|
||||||
|
size_t sz;
|
||||||
|
|
||||||
errno=0;
|
errno=0;
|
||||||
FILE *data_stream = fmemopen(data_chunk, file_length, "r");
|
FILE *data_stream = fmemopen(data_chunk, file_length, "r");
|
||||||
FILE *of = open_memstream(NULL, NULL);
|
FILE *of = NULL;
|
||||||
|
of = open_memstream(&buff, &sz);
|
||||||
if(data_stream == NULL) {
|
if(data_stream == NULL) {
|
||||||
perror("F MEM OPEN");
|
perror("F MEM OPEN");
|
||||||
}
|
}
|
||||||
@@ -71,10 +73,12 @@ FILE *zlib_decompress_data(unsigned char *data_chunk, size_t file_length) {
|
|||||||
|
|
||||||
(void)inflateEnd(&strm);
|
(void)inflateEnd(&strm);
|
||||||
|
|
||||||
|
fclose(data_stream);
|
||||||
|
|
||||||
return of;
|
return of;
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE *zlib_compress_data(unsigned char *data_chunk, size_t file_length) {
|
FILE *zlib_compress_data(unsigned char *data_chunk, size_t file_length, char *buff) {
|
||||||
int ret, flush;
|
int ret, flush;
|
||||||
unsigned int have;
|
unsigned int have;
|
||||||
z_stream strm;
|
z_stream strm;
|
||||||
@@ -86,9 +90,11 @@ FILE *zlib_compress_data(unsigned char *data_chunk, size_t file_length) {
|
|||||||
int memLevel = 9;
|
int memLevel = 9;
|
||||||
//int strategy = Z_DEFAULT_STRATEGY;
|
//int strategy = Z_DEFAULT_STRATEGY;
|
||||||
int strategy = Z_FILTERED;
|
int strategy = Z_FILTERED;
|
||||||
|
size_t sz;
|
||||||
|
|
||||||
FILE *data_stream = fmemopen(data_chunk, file_length, "r");
|
FILE *data_stream = fmemopen(data_chunk, file_length, "r");
|
||||||
FILE *out_data_stream = open_memstream(NULL, NULL);
|
FILE *out_data_stream = NULL;
|
||||||
|
out_data_stream = open_memstream(&buff, &sz);
|
||||||
|
|
||||||
strm.zalloc = Z_NULL;
|
strm.zalloc = Z_NULL;
|
||||||
strm.zfree = Z_NULL;
|
strm.zfree = Z_NULL;
|
||||||
@@ -124,6 +130,8 @@ FILE *zlib_compress_data(unsigned char *data_chunk, size_t file_length) {
|
|||||||
} while(flush != Z_FINISH);
|
} while(flush != Z_FINISH);
|
||||||
assert(ret == Z_STREAM_END);
|
assert(ret == Z_STREAM_END);
|
||||||
|
|
||||||
|
fclose(data_stream);
|
||||||
|
|
||||||
(void)deflateEnd(&strm);
|
(void)deflateEnd(&strm);
|
||||||
return out_data_stream;
|
return out_data_stream;
|
||||||
}
|
}
|
||||||
@@ -197,10 +205,16 @@ void random_data_change(unsigned char *color_data, int width, int length) {
|
|||||||
} else {
|
} else {
|
||||||
temp_color_data[random_num]++;
|
temp_color_data[random_num]++;
|
||||||
}
|
}
|
||||||
FILE *check_data = zlib_compress_data(temp_color_data, length);
|
char *check_data_buff = NULL;
|
||||||
|
FILE *check_data = zlib_compress_data(temp_color_data, length, check_data_buff);
|
||||||
size_t check_data_length = 0;
|
size_t check_data_length = 0;
|
||||||
|
|
||||||
unsigned char *check_data_array = file_to_char_array(check_data, &check_data_length);
|
unsigned char *check_data_array = file_to_char_array(check_data, &check_data_length);
|
||||||
|
|
||||||
|
fflush(check_data);
|
||||||
|
fclose(check_data);
|
||||||
|
free(check_data_buff);
|
||||||
|
|
||||||
unsigned char full_data[check_data_length+4];
|
unsigned char full_data[check_data_length+4];
|
||||||
full_data[0] = 0x49;
|
full_data[0] = 0x49;
|
||||||
full_data[1] = 0x44;
|
full_data[1] = 0x44;
|
||||||
@@ -210,10 +224,11 @@ void random_data_change(unsigned char *color_data, int width, int length) {
|
|||||||
full_data[i+4] = check_data_array[i];
|
full_data[i+4] = check_data_array[i];
|
||||||
}
|
}
|
||||||
unsigned int temp_crc = crc(full_data, check_data_length);
|
unsigned int temp_crc = crc(full_data, check_data_length);
|
||||||
if ((temp_crc >> (8*3)) == 61 ) {
|
if ((temp_crc >> (8*3)) == 10 ) {
|
||||||
printf("Found in %zu rounds!\n", rounds);
|
printf("Found in %zu rounds!\n", rounds);
|
||||||
searching = 0;
|
searching = 0;
|
||||||
}
|
}
|
||||||
|
free(check_data_array);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -275,13 +290,18 @@ int change_idat_content(unsigned char *addr, char *message, int accuracy, unsign
|
|||||||
// TO STOP DECOMPRESSION CORRUPTION
|
// TO STOP DECOMPRESSION CORRUPTION
|
||||||
//temp_idat_data[j] = addr[offset+8+j];
|
//temp_idat_data[j] = addr[offset+8+j];
|
||||||
// Decompressing Data
|
// Decompressing Data
|
||||||
FILE *uncom_data = zlib_decompress_data(temp_idat_data, idat_byte_length);
|
char *uncom_data_buff = NULL;
|
||||||
|
FILE *uncom_data = zlib_decompress_data(temp_idat_data, idat_byte_length, uncom_data_buff);
|
||||||
size_t uncom_data_size = 0;
|
size_t uncom_data_size = 0;
|
||||||
|
|
||||||
unsigned char *uncom_data_array = file_to_char_array(uncom_data, &uncom_data_size);
|
unsigned char *uncom_data_array = file_to_char_array(uncom_data, &uncom_data_size);
|
||||||
printf("UnCom: %zu\n", uncom_data_size);
|
|
||||||
random_data_change(uncom_data_array, 16, uncom_data_size);
|
random_data_change(uncom_data_array, 16, uncom_data_size);
|
||||||
|
|
||||||
|
fflush(uncom_data);
|
||||||
|
fclose(uncom_data);
|
||||||
|
free(uncom_data_buff);
|
||||||
|
|
||||||
//printf("Found %d in %d rounds\n", checked_crc ,rounds);
|
//printf("Found %d in %d rounds\n", checked_crc ,rounds);
|
||||||
//printf("Full CRC: %08X\n", crcnum);
|
//printf("Full CRC: %08X\n", crcnum);
|
||||||
//printf("Original: %02X\n", idat_data[j]);
|
//printf("Original: %02X\n", idat_data[j]);
|
||||||
@@ -299,7 +319,7 @@ int main() {
|
|||||||
FILE *fp;
|
FILE *fp;
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
unsigned long offset = 0;
|
unsigned long offset = 0;
|
||||||
char message[1];
|
char message[1] = "";
|
||||||
|
|
||||||
if(sodium_init() == -1) {
|
if(sodium_init() == -1) {
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|||||||
Reference in New Issue
Block a user