wip
This commit is contained in:
95
crc.c
95
crc.c
@@ -14,18 +14,16 @@
|
|||||||
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, char *buff) {
|
void zlib_decompress_data(unsigned char *data_chunk, size_t file_length, unsigned char **buff, size_t *sz) {
|
||||||
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 = NULL;
|
FILE *of = open_memstream((char**)buff, sz);
|
||||||
of = open_memstream(&buff, &sz);
|
|
||||||
if(data_stream == NULL) {
|
if(data_stream == NULL) {
|
||||||
perror("F MEM OPEN");
|
perror("F MEM OPEN");
|
||||||
}
|
}
|
||||||
@@ -37,14 +35,14 @@ FILE *zlib_decompress_data(unsigned char *data_chunk, size_t file_length, char *
|
|||||||
strm.next_in = Z_NULL;
|
strm.next_in = Z_NULL;
|
||||||
ret = inflateInit(&strm);
|
ret = inflateInit(&strm);
|
||||||
if(ret != Z_OK) {
|
if(ret != Z_OK) {
|
||||||
return NULL;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
strm.avail_in = fread(in, 1, CHUNK, data_stream);
|
strm.avail_in = fread(in, 1, CHUNK, data_stream);
|
||||||
if(ferror(data_stream)) {
|
if(ferror(data_stream)) {
|
||||||
(void)inflateEnd(&strm);
|
(void)inflateEnd(&strm);
|
||||||
return NULL;
|
return;
|
||||||
}
|
}
|
||||||
if(strm.avail_in == 0) {
|
if(strm.avail_in == 0) {
|
||||||
break;
|
break;
|
||||||
@@ -64,7 +62,7 @@ FILE *zlib_decompress_data(unsigned char *data_chunk, size_t file_length, char *
|
|||||||
(void)inflateEnd(&strm);
|
(void)inflateEnd(&strm);
|
||||||
printf("Error: %d\n", ret);
|
printf("Error: %d\n", ret);
|
||||||
printf("MSG: %s\n", (char*)strm.msg);
|
printf("MSG: %s\n", (char*)strm.msg);
|
||||||
return NULL;
|
return;
|
||||||
}
|
}
|
||||||
have = CHUNK - strm.avail_out;
|
have = CHUNK - strm.avail_out;
|
||||||
fwrite(out, 1, have, of);
|
fwrite(out, 1, have, of);
|
||||||
@@ -74,11 +72,10 @@ FILE *zlib_decompress_data(unsigned char *data_chunk, size_t file_length, char *
|
|||||||
(void)inflateEnd(&strm);
|
(void)inflateEnd(&strm);
|
||||||
|
|
||||||
fclose(data_stream);
|
fclose(data_stream);
|
||||||
|
fclose(of);
|
||||||
return of;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE *zlib_compress_data(unsigned char *data_chunk, size_t file_length, char *buff) {
|
void zlib_compress_data(unsigned char *data_chunk, size_t file_length, unsigned char **buff, size_t *sz) {
|
||||||
int ret, flush;
|
int ret, flush;
|
||||||
unsigned int have;
|
unsigned int have;
|
||||||
z_stream strm;
|
z_stream strm;
|
||||||
@@ -90,25 +87,24 @@ FILE *zlib_compress_data(unsigned char *data_chunk, size_t file_length, char *bu
|
|||||||
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 = NULL;
|
FILE *out_data_stream = NULL;
|
||||||
out_data_stream = open_memstream(&buff, &sz);
|
out_data_stream = open_memstream((char**)buff, sz);
|
||||||
|
|
||||||
strm.zalloc = Z_NULL;
|
strm.zalloc = Z_NULL;
|
||||||
strm.zfree = Z_NULL;
|
strm.zfree = Z_NULL;
|
||||||
strm.opaque = Z_NULL;
|
strm.opaque = Z_NULL;
|
||||||
ret = deflateInit2(&strm, level, method, windowBits, memLevel, strategy);
|
ret = deflateInit2(&strm, level, method, windowBits, memLevel, strategy);
|
||||||
if (ret != Z_OK) {
|
if (ret != Z_OK) {
|
||||||
return NULL;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
strm.avail_in = fread(in, 1, CHUNK, data_stream);
|
strm.avail_in = fread(in, 1, CHUNK, data_stream);
|
||||||
if (ferror(data_stream)) {
|
if (ferror(data_stream)) {
|
||||||
(void)deflateEnd(&strm);
|
(void)deflateEnd(&strm);
|
||||||
return NULL;
|
return;
|
||||||
}
|
}
|
||||||
flush = feof(data_stream) ? Z_FINISH : Z_NO_FLUSH;
|
flush = feof(data_stream) ? Z_FINISH : Z_NO_FLUSH;
|
||||||
strm.next_in = in;
|
strm.next_in = in;
|
||||||
@@ -122,7 +118,7 @@ FILE *zlib_compress_data(unsigned char *data_chunk, size_t file_length, char *bu
|
|||||||
have = CHUNK - strm.avail_out;
|
have = CHUNK - strm.avail_out;
|
||||||
if(fwrite(out, 1, have, out_data_stream) != have || ferror(out_data_stream)) {
|
if(fwrite(out, 1, have, out_data_stream) != have || ferror(out_data_stream)) {
|
||||||
(void)deflateEnd(&strm);
|
(void)deflateEnd(&strm);
|
||||||
return NULL;
|
return;
|
||||||
}
|
}
|
||||||
} while(strm.avail_out == 0);
|
} while(strm.avail_out == 0);
|
||||||
assert(strm.avail_in == 0);
|
assert(strm.avail_in == 0);
|
||||||
@@ -131,9 +127,9 @@ FILE *zlib_compress_data(unsigned char *data_chunk, size_t file_length, char *bu
|
|||||||
assert(ret == Z_STREAM_END);
|
assert(ret == Z_STREAM_END);
|
||||||
|
|
||||||
fclose(data_stream);
|
fclose(data_stream);
|
||||||
|
fclose(out_data_stream);
|
||||||
|
|
||||||
(void)deflateEnd(&strm);
|
(void)deflateEnd(&strm);
|
||||||
return out_data_stream;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long first_idat(unsigned char *addr) {
|
unsigned long first_idat(unsigned char *addr) {
|
||||||
@@ -205,14 +201,9 @@ void random_data_change(unsigned char *color_data, int width, int length) {
|
|||||||
} else {
|
} else {
|
||||||
temp_color_data[random_num]++;
|
temp_color_data[random_num]++;
|
||||||
}
|
}
|
||||||
char *check_data_buff = NULL;
|
unsigned 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;
|
||||||
|
zlib_compress_data(temp_color_data, length, &check_data_buff, &check_data_length);
|
||||||
unsigned char *check_data_array = file_to_char_array(check_data, &check_data_length);
|
|
||||||
|
|
||||||
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;
|
||||||
@@ -220,15 +211,14 @@ void random_data_change(unsigned char *color_data, int width, int length) {
|
|||||||
full_data[2] = 0x41;
|
full_data[2] = 0x41;
|
||||||
full_data[3] = 0x54;
|
full_data[3] = 0x54;
|
||||||
for(int i = 0; i < check_data_length; i++) {
|
for(int i = 0; i < check_data_length; i++) {
|
||||||
full_data[i+4] = check_data_array[i];
|
full_data[i+4] = check_data_buff[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)) == 10 ) {
|
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);
|
free(check_data_buff);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} while(searching == 1);
|
} while(searching == 1);
|
||||||
@@ -269,47 +259,26 @@ int change_idat_content(unsigned char *addr, char *message, int accuracy, unsign
|
|||||||
for(int i = 0; i <= idat_length; i++) {
|
for(int i = 0; i <= idat_length; i++) {
|
||||||
temp_idat_data[i] = idat_data[i];
|
temp_idat_data[i] = idat_data[i];
|
||||||
}
|
}
|
||||||
//int r = randombytes_uniform(5) + 1;
|
// Decompressing Data
|
||||||
//int j = randombytes_uniform(idat_length);
|
unsigned char *uncom_data_buff = NULL;
|
||||||
|
size_t uncom_data_size = 0;
|
||||||
//temp_idat_data[j] = (temp_idat_data[j] + r) % 255;
|
zlib_decompress_data(temp_idat_data, idat_byte_length, &uncom_data_buff, &uncom_data_size);
|
||||||
//unsigned char crc_check[size+4];
|
|
||||||
//unsigned int idat_header[] = { 0x49, 0x44, 0x41, 0x54 };
|
|
||||||
//for(int i = 0; i < 4; i++) {
|
|
||||||
// crc_check[i] = idat_header[i];
|
|
||||||
//}
|
|
||||||
//for(int i = 0; i < idat_byte_length; i++) {
|
|
||||||
// crc_check[i] = temp_idat_data[i+4];
|
|
||||||
//}
|
|
||||||
//unsigned int crcnum = crc(crc_check, idat_length);
|
|
||||||
//unsigned int checked_crc = crcnum >> (8*3);
|
|
||||||
//rounds++;
|
|
||||||
//if(checked_crc == 61) {
|
|
||||||
// Setting TEMP IDAT DATA BACK TO ORIGINAL
|
|
||||||
// TO STOP DECOMPRESSION CORRUPTION
|
|
||||||
//temp_idat_data[j] = addr[offset+8+j];
|
|
||||||
// Decompressing Data
|
|
||||||
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;
|
|
||||||
|
|
||||||
unsigned char *uncom_data_array = file_to_char_array(uncom_data, &uncom_data_size);
|
random_data_change(uncom_data_buff, 16, uncom_data_size);
|
||||||
|
|
||||||
random_data_change(uncom_data_array, 16, uncom_data_size);
|
free(uncom_data_buff);
|
||||||
|
|
||||||
fclose(uncom_data);
|
//printf("Found %d in %d rounds\n", checked_crc ,rounds);
|
||||||
free(uncom_data_buff);
|
//printf("Full CRC: %08X\n", crcnum);
|
||||||
|
//printf("Original: %02X\n", idat_data[j]);
|
||||||
//printf("Found %d in %d rounds\n", checked_crc ,rounds);
|
//printf("Change offset: %d to hex: %02X\n", j, temp_idat_data[j]);
|
||||||
//printf("Full CRC: %08X\n", crcnum);
|
//addr[offset+8+j] = temp_idat_data[j];
|
||||||
//printf("Original: %02X\n", idat_data[j]);
|
//update_file_crc(addr, offset, crcnum);
|
||||||
//printf("Change offset: %d to hex: %02X\n", j, temp_idat_data[j]);
|
prop_found = 1;
|
||||||
//addr[offset+8+j] = temp_idat_data[j];
|
|
||||||
//update_file_crc(addr, offset, crcnum);
|
|
||||||
prop_found = 1;
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(idat_data);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -330,5 +299,7 @@ int main() {
|
|||||||
|
|
||||||
offset = first_idat(file_data);
|
offset = first_idat(file_data);
|
||||||
change_idat_content(file_data, message, 1, offset);
|
change_idat_content(file_data, message, 1, offset);
|
||||||
|
free(file_data);
|
||||||
|
free(message);
|
||||||
//create_cc_file(file_data, i);
|
//create_cc_file(file_data, i);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
const long png_signature[8] = { 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a };
|
const long png_signature[8] = { 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a };
|
||||||
|
|
||||||
|
|
||||||
int check_header_length(unsigned char *addr, long offset) {
|
int check_header_length(unsigned char *addr, long offset) {
|
||||||
unsigned int res = 0;
|
unsigned int res = 0;
|
||||||
for( int i = 0; i < 4; i++ ) {
|
for( int i = 0; i < 4; i++ ) {
|
||||||
@@ -61,3 +60,4 @@ unsigned char* file_to_char_array(FILE *in_file, size_t* size) {
|
|||||||
}
|
}
|
||||||
return file_data;
|
return file_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
extern const long png_signature[8];
|
extern const long png_signature[8];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user