Compare commits
6 Commits
06390c4df2
...
wip
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9afed448df | ||
|
|
5b45337d98 | ||
|
|
8e8ad60d9e | ||
|
|
b8600c17d5 | ||
|
|
7caca5e7e6 | ||
|
|
0c3df85ea0 |
37
README.md
37
README.md
@@ -0,0 +1,37 @@
|
|||||||
|
# PSPNG
|
||||||
|
|
||||||
|
Sample program to embed messages into PNG images
|
||||||
|
|
||||||
|
## Install
|
||||||
|
|
||||||
|
**NOTE:** Set the core_count variable to one value lower than maximum cores on the host in cmd/pspng.c
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|||||||
304
cmd/crc.c
304
cmd/crc.c
@@ -1,304 +0,0 @@
|
|||||||
#pragma GCC optimize("Ofast")
|
|
||||||
|
|
||||||
#include <endian.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <sodium.h>
|
|
||||||
#include <getopt.h>
|
|
||||||
#include "crc_util.h"
|
|
||||||
#include "CRCLib.h"
|
|
||||||
#include "crc.h"
|
|
||||||
#include "compress_util.h"
|
|
||||||
|
|
||||||
const long idat_signature = 1229209940;
|
|
||||||
const long iend_signature = 1229278788;
|
|
||||||
|
|
||||||
unsigned long first_idat(unsigned char *addr) {
|
|
||||||
int idat_found = 0;
|
|
||||||
unsigned long offset = 8;
|
|
||||||
int jump_offset = 0;
|
|
||||||
int header_type = 0;
|
|
||||||
while(idat_found == 0) {
|
|
||||||
jump_offset = check_header_length(addr, offset);
|
|
||||||
header_type = check_header_length(addr, offset+4);
|
|
||||||
if(header_type == idat_signature) {
|
|
||||||
idat_found = 1;
|
|
||||||
} else {
|
|
||||||
offset = offset + jump_offset + 12;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
int total_idat(unsigned char *addr) {
|
|
||||||
int iend_found = 0;
|
|
||||||
int found_idat = 0;
|
|
||||||
unsigned long offset = 8;
|
|
||||||
int jump_offset = 0;
|
|
||||||
int header_type = 0;
|
|
||||||
while(iend_found == 0) {
|
|
||||||
jump_offset = check_header_length(addr, offset);
|
|
||||||
header_type = check_header_length(addr, offset+4);
|
|
||||||
if(header_type == iend_signature) {
|
|
||||||
iend_found = 1;
|
|
||||||
} else {
|
|
||||||
if(header_type == idat_signature) {
|
|
||||||
found_idat++;
|
|
||||||
}
|
|
||||||
offset = offset + jump_offset + 12;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return found_idat;
|
|
||||||
}
|
|
||||||
|
|
||||||
int update_file_crc(unsigned char *addr, unsigned long offset , unsigned int crc_num) {
|
|
||||||
int startCRC = 8 + offset + check_header_length(addr, offset);
|
|
||||||
unsigned char new_crc;
|
|
||||||
for(int i = 0; i < 4; i++) {
|
|
||||||
new_crc = crc_num >> (8*(3-i)) & 0xFF;
|
|
||||||
addr[startCRC+i] = new_crc;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void random_data_change(unsigned char *color_data, int width, int length) {
|
|
||||||
int searching = 1;
|
|
||||||
size_t rounds = 0;
|
|
||||||
width = 16;
|
|
||||||
int color_range = 3;
|
|
||||||
unsigned char temp_color_data[length];
|
|
||||||
|
|
||||||
do {
|
|
||||||
rounds++;
|
|
||||||
// Creating temporary data set
|
|
||||||
memcpy(temp_color_data, color_data, length);
|
|
||||||
// Generating random byte to change
|
|
||||||
int random_num = randombytes_uniform(length);
|
|
||||||
// Checking for index break
|
|
||||||
if(random_num % ((width * color_range) + 1)) {
|
|
||||||
if(color_data[random_num] == 255) {
|
|
||||||
temp_color_data[random_num]--;
|
|
||||||
} else {
|
|
||||||
temp_color_data[random_num]++;
|
|
||||||
}
|
|
||||||
unsigned char *check_data_buff = NULL;
|
|
||||||
size_t check_data_length = 0;
|
|
||||||
zlib_compress_data(temp_color_data, length, &check_data_buff, &check_data_length);
|
|
||||||
|
|
||||||
unsigned char full_data[check_data_length+4];
|
|
||||||
full_data[0] = 0x49;
|
|
||||||
full_data[1] = 0x44;
|
|
||||||
full_data[2] = 0x41;
|
|
||||||
full_data[3] = 0x54;
|
|
||||||
for(int i = 0; i < check_data_length; i++) {
|
|
||||||
full_data[i+4] = check_data_buff[i];
|
|
||||||
}
|
|
||||||
unsigned int temp_crc = crc(full_data, check_data_length);
|
|
||||||
if ((temp_crc >> (8*3)) == 10 ) {
|
|
||||||
printf("Found in %zu rounds!\n", rounds);
|
|
||||||
memcpy(color_data, temp_color_data, length);
|
|
||||||
searching = 0;
|
|
||||||
}
|
|
||||||
free(check_data_buff);
|
|
||||||
}
|
|
||||||
|
|
||||||
} while(searching == 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void build_png_file(struct PNG_FILE_STRUCT *png_file, char *out_file_name) {
|
|
||||||
FILE *fp;
|
|
||||||
|
|
||||||
fp = fopen(out_file_name, "w");
|
|
||||||
|
|
||||||
union{
|
|
||||||
unsigned char data[sizeof(struct PNG_START_FILE_STRUCT)];
|
|
||||||
struct PNG_START_FILE_STRUCT png_data;
|
|
||||||
}start_data;
|
|
||||||
|
|
||||||
start_data.png_data = png_file->png_start_data;
|
|
||||||
|
|
||||||
// IHDR Data
|
|
||||||
for(int i = 0; i < sizeof(start_data.data); i++) {
|
|
||||||
fputc(start_data.data[i], fp);
|
|
||||||
}
|
|
||||||
// IDAT Data
|
|
||||||
for(int i = 0; i < 4; i++) {
|
|
||||||
fputc(png_file->png_idat_data.idat_length[i], fp);
|
|
||||||
}
|
|
||||||
for(int i = 0; i < 4; i++) {
|
|
||||||
fputc(png_file->png_idat_data.idat_header[i], fp);
|
|
||||||
}
|
|
||||||
for(int i = 0; i < be32toh(png_file->png_idat_data.idat_data_length); i++) {
|
|
||||||
fputc(png_file->png_idat_data.idat_data[i], fp);
|
|
||||||
}
|
|
||||||
// Generating CRC
|
|
||||||
unsigned char full_data[be32toh(png_file->png_idat_data.idat_data_length)+4];
|
|
||||||
for(int i = 0; i < 4; i++) {
|
|
||||||
full_data[i] = png_file->png_idat_data.idat_header[i];
|
|
||||||
}
|
|
||||||
for(int i = 0; i < be32toh(png_file->png_idat_data.idat_data_length); i++) {
|
|
||||||
full_data[i+4] = png_file->png_idat_data.idat_data[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int int_crc = crc(full_data, be32toh(png_file->png_idat_data.idat_data_length));
|
|
||||||
unsigned char new_crc[4];
|
|
||||||
|
|
||||||
for(int i = 0; i < 4; i++) {
|
|
||||||
new_crc[i] = int_crc >> (8*(3-i)) & 0xFF;
|
|
||||||
fputc(new_crc[i], fp);
|
|
||||||
}
|
|
||||||
// IEND Data
|
|
||||||
unsigned char IEND_DATA[12] = { 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4E, 0x44, 0xAE, 0x42, 0x60, 0x82};
|
|
||||||
for(int i = 0; i < 12; i++) {
|
|
||||||
fputc(IEND_DATA[i], fp);
|
|
||||||
}
|
|
||||||
fclose(fp);
|
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
|
||||||
printf("Warning, accuracy cannot be larger than 4");
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
if(accuracy > 2) {
|
|
||||||
printf("Notice, this could take a long time...");
|
|
||||||
}
|
|
||||||
if(total_idat(addr) < strlen((char*)message)) {
|
|
||||||
printf("Warning, message exceeds IDAT amount\n");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
int idat_length = check_header_length(addr, offset);
|
|
||||||
printf("IDAT Length: %d\n", idat_length);
|
|
||||||
|
|
||||||
long size = 1;
|
|
||||||
size_t idat_byte_length = 0;
|
|
||||||
unsigned char* idat_data = calloc(size, sizeof(unsigned char));
|
|
||||||
for(size_t i = 0; i <= idat_length; i++) {
|
|
||||||
if(i == size) {
|
|
||||||
size *= 2;
|
|
||||||
idat_data = reallocarray(idat_data, size, sizeof(unsigned char));
|
|
||||||
}
|
|
||||||
idat_data[i] = addr[i+offset+8];
|
|
||||||
idat_byte_length = i;
|
|
||||||
}
|
|
||||||
unsigned char temp_idat_data[idat_byte_length];
|
|
||||||
for(int i = 0; i <= idat_length; i++) {
|
|
||||||
temp_idat_data[i] = idat_data[i];
|
|
||||||
}
|
|
||||||
// Decompressing Data
|
|
||||||
unsigned char *uncom_data_buff = NULL;
|
|
||||||
size_t uncom_data_size = 0;
|
|
||||||
zlib_decompress_data(temp_idat_data, idat_byte_length, &uncom_data_buff, &uncom_data_size);
|
|
||||||
|
|
||||||
random_data_change(uncom_data_buff, 16, uncom_data_size);
|
|
||||||
|
|
||||||
// Compress Data
|
|
||||||
unsigned char *com_data_buff;
|
|
||||||
size_t com_data_size = 0;
|
|
||||||
zlib_compress_data(uncom_data_buff, uncom_data_size, &com_data_buff, &com_data_size);
|
|
||||||
|
|
||||||
png_file->png_idat_data.idat_data = calloc(com_data_size, sizeof(unsigned char));
|
|
||||||
|
|
||||||
png_file->png_idat_data.idat_data_length = be32toh(com_data_size);
|
|
||||||
|
|
||||||
for(size_t i = 0; i < com_data_size; i++) {
|
|
||||||
png_file->png_idat_data.idat_data[i] = com_data_buff[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build PNG File
|
|
||||||
build_png_file(png_file, out_file_name);
|
|
||||||
|
|
||||||
free(uncom_data_buff);
|
|
||||||
free(com_data_buff);
|
|
||||||
free(idat_data);
|
|
||||||
free(png_file->png_idat_data.idat_data);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// This is where it all starts
|
|
||||||
int main(int argc, char **argv) {
|
|
||||||
FILE *fp;
|
|
||||||
size_t i = 0;
|
|
||||||
unsigned long offset = 0;
|
|
||||||
struct PNG_FILE_STRUCT png_file_data;
|
|
||||||
char *in_file_name = NULL;
|
|
||||||
char *out_file_name = NULL;
|
|
||||||
char *message = NULL;
|
|
||||||
|
|
||||||
static const struct option long_options[] = {
|
|
||||||
{"help", no_argument, NULL, 'h'},
|
|
||||||
{"file", required_argument, NULL, 'f'},
|
|
||||||
{"outfile", required_argument, NULL, 'o'},
|
|
||||||
{"message", required_argument, NULL, 'm'},
|
|
||||||
{0, 0, 0, 0}
|
|
||||||
};
|
|
||||||
|
|
||||||
const char* usage =
|
|
||||||
"Usage: crc [options]\n"
|
|
||||||
" -h, --help Shows help message\n"
|
|
||||||
" -f, --file Denotes input file\n"
|
|
||||||
" -o, --outfile Denotes output file\n"
|
|
||||||
" -m, --message Encoded message\n"
|
|
||||||
"\n";
|
|
||||||
|
|
||||||
int c;
|
|
||||||
while (1) {
|
|
||||||
int option_index = 0;
|
|
||||||
c = getopt_long(argc, argv, "hf:o:m:", long_options ,&option_index);
|
|
||||||
if(c == -1) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
switch(c) {
|
|
||||||
case 'h':
|
|
||||||
printf("%s", usage);
|
|
||||||
exit(EXIT_SUCCESS);
|
|
||||||
case 'f':
|
|
||||||
in_file_name = optarg;
|
|
||||||
break;
|
|
||||||
case 'o':
|
|
||||||
out_file_name = optarg;
|
|
||||||
break;
|
|
||||||
case 'm':
|
|
||||||
message = optarg;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(in_file_name == NULL) {
|
|
||||||
printf("Input file required!\n");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
} else if(out_file_name == NULL) {
|
|
||||||
printf("Output file required!\n");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
} else if(message == NULL) {
|
|
||||||
printf("Message required!\n");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(sodium_init() == -1) {
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
fp = fopen(in_file_name, "rt");
|
|
||||||
if (fp == NULL) {
|
|
||||||
printf("File error\n");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned char *file_data = file_to_char_array(fp, &i);
|
|
||||||
fclose(fp);
|
|
||||||
|
|
||||||
populate_start_png(file_data, &png_file_data.png_start_data);
|
|
||||||
|
|
||||||
offset = first_idat(file_data);
|
|
||||||
|
|
||||||
populate_idat_png(file_data, &png_file_data.png_idat_data, offset);
|
|
||||||
|
|
||||||
change_idat_content(file_data, &png_file_data, message, 1, offset, out_file_name);
|
|
||||||
|
|
||||||
free(file_data);
|
|
||||||
}
|
|
||||||
205
cmd/pspng.c
205
cmd/pspng.c
@@ -8,6 +8,7 @@
|
|||||||
#include <sodium.h>
|
#include <sodium.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
#include <math.h>
|
||||||
#include "crc_util.h"
|
#include "crc_util.h"
|
||||||
#include "CRCLib.h"
|
#include "CRCLib.h"
|
||||||
#include "pspng.h"
|
#include "pspng.h"
|
||||||
@@ -70,11 +71,74 @@ int update_file_crc(unsigned char *addr, unsigned long offset , unsigned int crc
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void random_window_bit_change(unsigned char *data, int width, int rounds, int color_range, size_t length, size_t offset) {
|
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
|
||||||
|
length = length * 4;
|
||||||
|
//length = 500000;
|
||||||
|
unsigned char* raw_data = calloc(length, sizeof(unsigned char*));
|
||||||
|
size_t filter_chunk_byte = 0;
|
||||||
|
|
||||||
|
for(size_t i = 0; i < length; i++) {
|
||||||
|
filter_chunk_byte = i - (i % ((width * color_range) + 1));
|
||||||
|
// Grabbing raw pixel data
|
||||||
|
if(data[filter_chunk_byte] == 0) {
|
||||||
|
// Filter: None
|
||||||
|
raw_data[i] = data[i];
|
||||||
|
} else if(data[filter_chunk_byte] == 1) {
|
||||||
|
// Filter: Sub
|
||||||
|
if ((i % ((width * color_range) + 1)) == 0) {
|
||||||
|
// Setting filter type
|
||||||
|
raw_data[i] = data[i];
|
||||||
|
} else if ((i - filter_chunk_byte) <= color_range) {
|
||||||
|
// Setting initial color_range byte
|
||||||
|
raw_data[i] = data[i];
|
||||||
|
} else {
|
||||||
|
// Setting remaining bytes
|
||||||
|
raw_data[i] = data[i] + raw_data[i - color_range];
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if(data[filter_chunk_byte] == 3) {
|
||||||
|
// Filter: Average
|
||||||
|
if((i % ((width * color_range) + 1)) == 0) {
|
||||||
|
// Setting filter type
|
||||||
|
raw_data[i] = data[i];
|
||||||
|
} else {
|
||||||
|
// Setting remaining bytes
|
||||||
|
if(filter_chunk_byte == 0) {
|
||||||
|
// If no scanline is present before current
|
||||||
|
if((i - filter_chunk_byte) <= color_range) {
|
||||||
|
// If no pixel present before current
|
||||||
|
raw_data[i] = data[i] + floor((0 + 0) / 2);
|
||||||
|
} else {
|
||||||
|
// If pixel present before current
|
||||||
|
raw_data[i] = data[i] + floor((data[i - color_range] + 0) / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// Scanline is present before current
|
||||||
|
if((i - filter_chunk_byte) <= color_range) {
|
||||||
|
// If no pixel present before current
|
||||||
|
raw_data[i] = data[i] + floor((0 + raw_data[i - ((width * color_range) + 1)]) / 2);
|
||||||
|
} else {
|
||||||
|
// If pixel present before current
|
||||||
|
raw_data[i] = data[i] + floor((raw_data[i - color_range] + raw_data[i - ((width * color_range) + 1)]) / 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// Filter: Error Unsupported
|
||||||
|
printf("Exiting due to unsupported filter type\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return raw_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void random_window_bit_change(unsigned char *data, unsigned char *raw_data, int width, int rounds, int color_range, size_t length, size_t offset) {
|
||||||
size_t random_num = 0;
|
size_t random_num = 0;
|
||||||
size_t filter_chunk_byte = 0;
|
size_t filter_chunk_byte = 0;
|
||||||
size_t change_num = 0;
|
|
||||||
long prior_chuck_check = 0;
|
|
||||||
for (int i = 0; i < rounds; i++) {
|
for (int i = 0; i < rounds; i++) {
|
||||||
random_num = 0;
|
random_num = 0;
|
||||||
do {
|
do {
|
||||||
@@ -86,24 +150,30 @@ static void random_window_bit_change(unsigned char *data, int width, int rounds,
|
|||||||
// 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
|
||||||
if(data[random_num] == 255) {
|
if(data[random_num] == 255) {
|
||||||
data[random_num]--;
|
data[random_num]--;
|
||||||
change_num = 1;
|
raw_data[random_num]--;
|
||||||
} else {
|
} else {
|
||||||
data[random_num]++;
|
data[random_num]++;
|
||||||
change_num = -1;
|
raw_data[random_num]++;
|
||||||
}
|
}
|
||||||
// Starting after random change
|
// Fixing Next Pixel in Scanline
|
||||||
for(int j = 1; j < 2; j++) {
|
if(!(random_num+3 > (filter_chunk_byte + (width * color_range) + 1))){
|
||||||
data[random_num+(color_range * j)] = (data[random_num+(color_range * j)] + change_num) % 256;
|
data[random_num+color_range] = raw_data[random_num+color_range] - raw_data[random_num];
|
||||||
|
}
|
||||||
|
// 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);
|
||||||
}
|
}
|
||||||
} else if(data[filter_chunk_byte] == 2) {
|
} else if(data[filter_chunk_byte] == 2) {
|
||||||
printf("2\n");
|
// Add Support
|
||||||
if(data[random_num] == 255) {
|
if(data[random_num] == 255) {
|
||||||
data[random_num]--;
|
data[random_num]--;
|
||||||
} else {
|
} else {
|
||||||
@@ -111,21 +181,26 @@ static void random_window_bit_change(unsigned char *data, int width, int rounds,
|
|||||||
}
|
}
|
||||||
} else if(data[filter_chunk_byte] == 3) {
|
} else if(data[filter_chunk_byte] == 3) {
|
||||||
// Average Filter Type Change
|
// Average Filter Type Change
|
||||||
//printf("HEE: %d\n", data[(filter_chunk_byte - (width * color_range))-1]);
|
if(raw_data[random_num] == 255) {
|
||||||
prior_chuck_check = filter_chunk_byte;
|
raw_data[random_num]--;
|
||||||
do {
|
|
||||||
//printf("C: %d\n", data[prior_chuck_check]);
|
|
||||||
prior_chuck_check = (prior_chuck_check - (width * color_range)-1);
|
|
||||||
//printf("CH: %ld\n", prior_chuck_check);
|
|
||||||
} while(prior_chuck_check >= 0);
|
|
||||||
|
|
||||||
if(data[random_num] == 255) {
|
|
||||||
data[random_num]--;
|
|
||||||
} else {
|
} else {
|
||||||
data[random_num]++;
|
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);
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
|
// 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);
|
||||||
}
|
}
|
||||||
} else if(data[filter_chunk_byte] == 4) {
|
} else if(data[filter_chunk_byte] == 4) {
|
||||||
printf("4\n");
|
// Add Support
|
||||||
if(data[random_num] == 255) {
|
if(data[random_num] == 255) {
|
||||||
data[random_num]--;
|
data[random_num]--;
|
||||||
} else {
|
} else {
|
||||||
@@ -166,7 +241,7 @@ static int verify_crc_chunks(unsigned char *data, size_t data_length, int crc_de
|
|||||||
}
|
}
|
||||||
crc_check_length = test_data_length+4;
|
crc_check_length = test_data_length+4;
|
||||||
crc_check = crc(testing_chunk, crc_check_length);
|
crc_check = crc(testing_chunk, crc_check_length);
|
||||||
|
|
||||||
if ((crc_check >> (8*3)) != message ) {
|
if ((crc_check >> (8*3)) != message ) {
|
||||||
free(testing_chunk);
|
free(testing_chunk);
|
||||||
return 1;
|
return 1;
|
||||||
@@ -180,23 +255,39 @@ 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 *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);
|
||||||
|
random_window_bit_change(data, raw_data, bit_width, 2, color_range, sliding_window, offset);
|
||||||
|
|
||||||
random_window_bit_change(data, bit_width, 2, color_range, sliding_window, offset);
|
//if(offset > 500000) {
|
||||||
|
if(offset == -1) {
|
||||||
// Compressing data for test
|
new_data = calloc(300000, sizeof(unsigned char));
|
||||||
zlib_compress_data(data, data_length, &check_data, &check_data_length);
|
for(int k = 0; k < 300000; k++) {
|
||||||
|
new_data[k] = data[offset-(offset-prior_offset-1)+k];
|
||||||
int match_crc = verify_crc_chunks(check_data, check_data_length, 1, MAX_IDAT_SIZE, message, iteration);
|
}
|
||||||
|
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);
|
||||||
|
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);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,21 +300,21 @@ 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 {
|
||||||
data->data_len = data->uncom_data_len;
|
data->data_len = data->uncom_data_len;
|
||||||
}
|
}
|
||||||
if(data->uncom_data_len > 16000) {
|
if(data->uncom_data_len > 36000) {
|
||||||
data->win_size = 9000 + (9000 * data->cur_iteration);
|
data->win_size = 36000 + (36000 * data->cur_iteration);
|
||||||
} else {
|
} else {
|
||||||
data->win_size = data->uncom_data_len;
|
data->win_size = data->uncom_data_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
@@ -247,6 +338,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);
|
||||||
@@ -260,7 +352,7 @@ size_t generate_offset(unsigned char *data, size_t data_len, size_t iteration) {
|
|||||||
|
|
||||||
void random_data_change(unsigned char *color_data, unsigned char *width, size_t length, char *message) {
|
void random_data_change(unsigned char *color_data, unsigned char *width, size_t length, char *message) {
|
||||||
int searching = 1;
|
int searching = 1;
|
||||||
int core_count = 24;
|
int core_count = 28;
|
||||||
unsigned int sliding_window = 0;
|
unsigned int sliding_window = 0;
|
||||||
unsigned int compress_data_length = 0;
|
unsigned int compress_data_length = 0;
|
||||||
// Needs to be turned into a variable
|
// Needs to be turned into a variable
|
||||||
@@ -279,11 +371,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;
|
||||||
@@ -307,7 +401,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;
|
||||||
@@ -417,13 +514,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);
|
||||||
}
|
}
|
||||||
@@ -431,20 +529,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;
|
||||||
@@ -467,7 +561,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;
|
||||||
@@ -570,35 +663,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) {
|
||||||
printf("%c", file_data[offset+cur_idat_len+8]);
|
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]);
|
||||||
|
} 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);
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
int check_file_header(char *addr);
|
|
||||||
int check_header_length(unsigned char *addr, long offset);
|
|
||||||
unsigned long first_idat(unsigned char *addr);
|
|
||||||
int total_idat(unsigned char *addr);
|
|
||||||
void build_png_file(struct PNG_FILE_STRUCT *png_file, 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);
|
|
||||||
@@ -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;
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ void zlib_compress_data(unsigned char *data_chunk, size_t file_length, unsigned
|
|||||||
unsigned char out[CHUNK];
|
unsigned char out[CHUNK];
|
||||||
int level = 9;
|
int level = 9;
|
||||||
int method = Z_DEFLATED;
|
int method = Z_DEFLATED;
|
||||||
|
//int windowBits = 15;
|
||||||
int windowBits = 10;
|
int windowBits = 10;
|
||||||
int memLevel = 9;
|
int memLevel = 9;
|
||||||
//int strategy = Z_DEFAULT_STRATEGY;
|
//int strategy = Z_DEFAULT_STRATEGY;
|
||||||
|
|||||||
Reference in New Issue
Block a user