From 5b45337d98ad1930059c9c7e77cab63442249a86 Mon Sep 17 00:00:00 2001 From: Pin Date: Fri, 3 Dec 2021 18:41:30 -0500 Subject: [PATCH] Added README and other changes --- README.md | 35 +++++++++++++++++++++++++++++++++++ cmd/pspng.c | 13 ++++++++----- src/compress_util.c | 1 + 3 files changed, 44 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e69de29..6b6a3e7 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,35 @@ +# PSPNG + +Sample program to embed messages into PNG images + +## Install + +Requires zlib, pthread, and sodium header files to compile (These will be distro specific packages) + +Build: + +```bash +make +``` + +System Wide: + +```bash +make +make install +``` + +## Usage + +Embed Message: + +pspng --compress -f {input file name} -o {output file name} -m "{input message}" + +Extract Message: + +pspng --uncompress -f {input file name} + +Help Message: + +pspng --help + diff --git a/cmd/pspng.c b/cmd/pspng.c index 1e89d69..2bf9d7a 100644 --- a/cmd/pspng.c +++ b/cmd/pspng.c @@ -187,14 +187,17 @@ static void random_window_bit_change(unsigned char *data, unsigned char *raw_dat raw_data[random_num]++; } // Update Current Pixel - data[random_num] = raw_data[random_num] - floor((raw_data[random_num-color_range] + raw_data[random_num-((width * color_range) + 1)]) / 2); + data[random_num] = raw_data[random_num] - floor((raw_data[random_num-color_range] + + raw_data[random_num-((width * color_range) + 1)]) / 2); // Fixing Next Pixel in Scanline if(!(random_num+color_range > (filter_chunk_byte + (width * color_range) + 1))){ - data[random_num+color_range] = raw_data[random_num+color_range] - floor((raw_data[random_num] + raw_data[random_num-((width * color_range)+ 1)+color_range]) / 2); + data[random_num+color_range] = raw_data[random_num+color_range] - + floor((raw_data[random_num] + raw_data[random_num-((width * color_range)+ 1)+color_range]) / 2); } // Checking Next Scanline type if(data[filter_chunk_byte+((width * color_range) + 1)] == 3){ - data[random_num+((width * color_range)+1)] = raw_data[random_num+((width * color_range)+1)] - floor((raw_data[random_num+((width * color_range)+1)-color_range] + raw_data[random_num]) / 2); + data[random_num+((width * color_range)+1)] = raw_data[random_num+((width * color_range)+1)] - + floor((raw_data[random_num+((width * color_range)+1)-color_range] + raw_data[random_num]) / 2); } } else if(data[filter_chunk_byte] == 4) { // Add Support @@ -265,9 +268,9 @@ static int crc_embed_data(unsigned char *data, unsigned int data_length, int bit 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]; + new_data[k] = data[offset-(offset-prior_offset-1)+k]; } - zlib_compress_data(new_data, 110000, &check_data, &check_data_length); + zlib_compress_data(new_data, 100000, &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); diff --git a/src/compress_util.c b/src/compress_util.c index 9407c8a..5764cbf 100644 --- a/src/compress_util.c +++ b/src/compress_util.c @@ -82,6 +82,7 @@ void zlib_compress_data(unsigned char *data_chunk, size_t file_length, unsigned unsigned char out[CHUNK]; int level = 9; int method = Z_DEFLATED; + //int windowBits = 15; int windowBits = 10; int memLevel = 9; //int strategy = Z_DEFAULT_STRATEGY;