This commit is contained in:
Pin
2021-11-12 20:18:09 -05:00
parent b8600c17d5
commit 8e8ad60d9e
2 changed files with 46 additions and 35 deletions

View File

@@ -73,7 +73,7 @@ int update_file_crc(unsigned char *addr, unsigned long offset , unsigned int crc
static unsigned char* create_raw_pixel_values(unsigned char *data, int width, int color_range, size_t length) { static unsigned char* create_raw_pixel_values(unsigned char *data, int width, int color_range, size_t length) {
// Generating twice the size we migth need // Generating twice the size we migth need
length = length * 2; length = length * 4;
//length = 500000; //length = 500000;
unsigned char* raw_data = calloc(length, sizeof(unsigned char*)); unsigned char* raw_data = calloc(length, sizeof(unsigned char*));
size_t filter_chunk_byte = 0; size_t filter_chunk_byte = 0;
@@ -150,8 +150,10 @@ static void random_window_bit_change(unsigned char *data, unsigned char *raw_dat
// None Filter Type Change // None Filter Type Change
if(data[random_num] == 255) { if(data[random_num] == 255) {
data[random_num]--; data[random_num]--;
raw_data[random_num]--;
} else { } else {
data[random_num]++; data[random_num]++;
raw_data[random_num]++;
} }
} else if(data[filter_chunk_byte] == 1) { } else if(data[filter_chunk_byte] == 1) {
// Sub Filter Type Change // Sub Filter Type Change
@@ -250,24 +252,36 @@ static int verify_crc_chunks(unsigned char *data, size_t data_length, int crc_de
return 0; return 0;
} }
static int crc_embed_data(unsigned char *data, unsigned int data_length, int bit_width, int color_range, unsigned int sliding_window, char message, size_t offset , size_t iteration) { static int crc_embed_data(unsigned char *data, unsigned int data_length, int bit_width, int color_range, unsigned int sliding_window, char message, size_t offset , size_t iteration, size_t prior_offset) {
unsigned char *check_data; unsigned char *check_data;
unsigned char *raw_data; unsigned char *raw_data;
unsigned char *new_data = calloc(1, sizeof(unsigned char));
size_t check_data_length = 0; size_t check_data_length = 0;
int match_crc = 1;
raw_data = create_raw_pixel_values(data, bit_width, color_range, sliding_window); raw_data = create_raw_pixel_values(data, bit_width, color_range, sliding_window);
random_window_bit_change(data, raw_data, bit_width, 1, color_range, sliding_window, offset); random_window_bit_change(data, raw_data, bit_width, 2, color_range, sliding_window, offset);
// Compressing data for test if(offset > 500000) {
new_data = calloc(300000, sizeof(unsigned char));
for(int k = 0; k < 300000; k++) {
new_data[k] = data[offset-(offset-prior_offset)+k];
}
zlib_compress_data(new_data, 110000, &check_data, &check_data_length);
match_crc = verify_crc_chunks(check_data, check_data_length, 1, MAX_IDAT_SIZE, message, 1);
} else {
zlib_compress_data(data, data_length, &check_data, &check_data_length); zlib_compress_data(data, data_length, &check_data, &check_data_length);
match_crc = verify_crc_chunks(check_data, check_data_length, 1, MAX_IDAT_SIZE, message, iteration);
int match_crc = verify_crc_chunks(check_data, check_data_length, 1, MAX_IDAT_SIZE, message, iteration); }
if(match_crc == 0) { if(match_crc == 0) {
printf("COM SIZE: %zu\n", check_data_length); printf("COM SIZE: %zu\n", check_data_length);
free(new_data);
free(check_data); free(check_data);
free(raw_data);
return 0; return 0;
} }
free(new_data);
free(check_data); free(check_data);
free(raw_data); free(raw_data);
return 1; return 1;
@@ -282,7 +296,7 @@ void *random_data_change_thread_call(void *w) {
// Creating temporary data set // Creating temporary data set
memcpy(temp_color_data, data->data, data->uncom_data_len); memcpy(temp_color_data, data->data, data->uncom_data_len);
// Look into testing these values more // Look into testing these values more for speed
if(data->uncom_data_len > 800000) { if(data->uncom_data_len > 800000) {
data->data_len = 90000 + (90000 * data->cur_iteration); data->data_len = 90000 + (90000 * data->cur_iteration);
} else { } else {
@@ -296,7 +310,7 @@ void *random_data_change_thread_call(void *w) {
cur_message = data->message[data->cur_iteration]; cur_message = data->message[data->cur_iteration];
searching = crc_embed_data(temp_color_data, data->data_len, data->width, data->color_range, data->win_size, cur_message, data->cur_offset, data->cur_iteration); searching = crc_embed_data(temp_color_data, data->data_len, data->width, data->color_range, data->win_size, cur_message, data->cur_offset, data->cur_iteration, data->offset[data->cur_iteration-1]);
pthread_mutex_lock(&data->mutex_lock); pthread_mutex_lock(&data->mutex_lock);
if (searching == 0 && *data->searching == 1) { if (searching == 0 && *data->searching == 1) {
@@ -320,6 +334,7 @@ size_t generate_offset(unsigned char *data, size_t data_len, size_t iteration) {
size_t uncom_data_size = 0; size_t uncom_data_size = 0;
printf("Gen Offset\n"); printf("Gen Offset\n");
// See if we can make this call faster
zlib_compress_data(data, data_len, &com_data_buff, &com_data_size); zlib_compress_data(data, data_len, &com_data_buff, &com_data_size);
zlib_decompress_data(com_data_buff, (MAX_WINDOW_SIZE * (iteration+1)), &uncom_data_buff, &uncom_data_size); zlib_decompress_data(com_data_buff, (MAX_WINDOW_SIZE * (iteration+1)), &uncom_data_buff, &uncom_data_size);
@@ -352,11 +367,13 @@ void random_data_change(unsigned char *color_data, unsigned char *width, size_t
printf("Mutex Lock Error\n"); printf("Mutex Lock Error\n");
return; return;
} }
// Building Struct Data
t_data->searching = &searching; t_data->searching = &searching;
t_data->message = message; t_data->message = message;
t_data->data = color_data; t_data->data = color_data;
t_data->data_len = compress_data_length; t_data->data_len = compress_data_length;
t_data->uncom_data_len = length; t_data->uncom_data_len = length;
// Original Offset set to 0
t_data->cur_offset = 0; t_data->cur_offset = 0;
t_data->width = be32toh(w.width_int); t_data->width = be32toh(w.width_int);
t_data->color_range = color_range; t_data->color_range = color_range;
@@ -380,7 +397,10 @@ void random_data_change(unsigned char *color_data, unsigned char *width, size_t
// Only generate new offset if not last char in message // Only generate new offset if not last char in message
if(j != (strlen(message) - 1)) { if(j != (strlen(message) - 1)) {
t_data->cur_offset = generate_offset(color_data, t_data->uncom_data_len, j); // Changing offset check size to not be full length of picture to speed up generation
//t_data->cur_offset = generate_offset(color_data, t_data->uncom_data_len, j);
t_data->cur_offset = generate_offset(color_data, (200000 * (j+1)), j);
t_data->offset[j] = t_data->cur_offset;
} }
} }
return; return;
@@ -490,13 +510,14 @@ unsigned char* populate_idat_array(unsigned char *addr, unsigned long offset, si
int change_idat_content(unsigned char *addr, struct PNG_FILE_STRUCT *png_file, char *message, int accuracy, unsigned long offset, char *out_file_name) { int change_idat_content(unsigned char *addr, struct PNG_FILE_STRUCT *png_file, char *message, int accuracy, unsigned long offset, char *out_file_name) {
if(accuracy > 4) { if(accuracy > 4) {
// Accuracy is currently unused
printf("Warning, accuracy cannot be larger than 4"); printf("Warning, accuracy cannot be larger than 4");
return EXIT_FAILURE; return EXIT_FAILURE;
} } else if (accuracy > 2) {
if(accuracy > 2) {
printf("Notice, this could take a long time..."); printf("Notice, this could take a long time...");
} }
if(total_idat(addr) < strlen(message)) { // Checking if total IDAT / 4 (Since Sliding Window is assumed to be 32k)
if((total_idat(addr) / 4) < strlen(message)) {
printf("Warning, message exceeds IDAT amount\n"); printf("Warning, message exceeds IDAT amount\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@@ -504,20 +525,16 @@ int change_idat_content(unsigned char *addr, struct PNG_FILE_STRUCT *png_file, c
size_t idat_byte_length = 0; size_t idat_byte_length = 0;
unsigned char *idat_data = populate_idat_array(addr, offset, &idat_byte_length); unsigned char *idat_data = populate_idat_array(addr, offset, &idat_byte_length);
unsigned char* temp_idat_data = calloc(idat_byte_length, sizeof(unsigned char));
memcpy(temp_idat_data, idat_data, idat_byte_length);
// Decompressing Data // Decompressing Data
unsigned char *uncom_data_buff = NULL; unsigned char *uncom_data_buff = NULL;
size_t uncom_data_size = 0; size_t uncom_data_size = 0;
zlib_decompress_data(temp_idat_data, idat_byte_length, &uncom_data_buff, &uncom_data_size); zlib_decompress_data(idat_data, idat_byte_length, &uncom_data_buff, &uncom_data_size);
printf("ORIG UNCOM LEN: %zu\n", uncom_data_size); printf("ORIG UNCOM LEN: %zu\n", uncom_data_size);
// Start data testing // Start data testing
random_data_change(uncom_data_buff, png_file->png_start_data.file_width, uncom_data_size, message); random_data_change(uncom_data_buff, png_file->png_start_data.file_width, uncom_data_size, message);
//return 0;
// Compress Data // Compress Data
unsigned char *com_data_buff; unsigned char *com_data_buff;
size_t com_data_size = 0; size_t com_data_size = 0;
@@ -540,7 +557,6 @@ int change_idat_content(unsigned char *addr, struct PNG_FILE_STRUCT *png_file, c
free(uncom_data_buff); free(uncom_data_buff);
free(com_data_buff); free(com_data_buff);
free(idat_data); free(idat_data);
free(temp_idat_data);
free(png_file->png_idat_data.idat_data); free(png_file->png_idat_data.idat_data);
return 0; return 0;
@@ -643,35 +659,29 @@ int main(int argc, char **argv) {
if(uncompress_call == 1) { if(uncompress_call == 1) {
size_t idat_byte_length = 0; size_t idat_byte_length = 0;
unsigned long cur_idat_len = 0; unsigned long cur_idat_len = 0;
//unsigned char message_data[8192];
unsigned char* idat_data = populate_idat_array(file_data, offset, &idat_byte_length); unsigned char* idat_data = populate_idat_array(file_data, offset, &idat_byte_length);
//for(int i = 0; i < idat_byte_length; i++) { printf("Decompressed Data:\n");
//printf("%02X ", idat_data[i]);
//}
printf("\nDecompressed Data:\n\n");
// Decompressing data
//unsigned char *uncom_data_buff = NULL;
//size_t uncom_data_size = 0;
//zlib_decompress_data(idat_data, idat_byte_length, &uncom_data_buff, &uncom_data_size);
//for(int i = 0; i < uncom_data_size; i++) {
// printf("%02X ", uncom_data_buff[i]);
//}
//printf("\n");
do { do {
for(int j = 0; j < 64; j++) { for(int j = 0; j < 1020; j++) {
cur_idat_len = 0; cur_idat_len = 0;
for(int i = 0; i < 4; i++) { for(int i = 0; i < 4; i++) {
cur_idat_len += (file_data[offset+i] << (24-(8*i))); cur_idat_len += (file_data[offset+i] << (24-(8*i)));
} }
//printf("%c", file_data[offset+cur_idat_len+8]); //printf("%c", file_data[offset+cur_idat_len+8]);
if((j % 4) == 0) { if((j % 4) == 0) {
if(31 < file_data[offset+cur_idat_len+8] && file_data[offset+cur_idat_len+8] < 128) {
printf("%c", file_data[offset+cur_idat_len+8]); printf("%c", file_data[offset+cur_idat_len+8]);
} else {
offset = idat_byte_length;
break;
}
} }
// Offset Plus idat length + 3 bytes // Offset Plus idat length + 3 bytes
offset += cur_idat_len + 12; offset += cur_idat_len + 12;
} }
printf("\n");
} while(offset < idat_byte_length); } while(offset < idat_byte_length);
free(idat_data); free(idat_data);

View File

@@ -41,6 +41,7 @@ struct EMBED_THREAD_STRUCT {
unsigned int data_len; unsigned int data_len;
size_t uncom_data_len; size_t uncom_data_len;
size_t cur_offset; size_t cur_offset;
size_t offset[8096];
size_t cur_iteration; size_t cur_iteration;
int width; int width;
int color_range; int color_range;