wip
This commit is contained in:
80
cmd/crc.c
80
cmd/crc.c
@@ -4,6 +4,7 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sodium.h>
|
||||
#include <getopt.h>
|
||||
#include "crc_util.h"
|
||||
#include "CRCLib.h"
|
||||
#include "crc.h"
|
||||
@@ -106,10 +107,10 @@ void random_data_change(unsigned char *color_data, int width, int length) {
|
||||
} while(searching == 1);
|
||||
}
|
||||
|
||||
void build_png_file(struct PNG_FILE_STRUCT *png_file) {
|
||||
void build_png_file(struct PNG_FILE_STRUCT *png_file, char *out_file_name) {
|
||||
FILE *fp;
|
||||
|
||||
fp = fopen("TESTPNG.png", "w");
|
||||
fp = fopen(out_file_name, "w");
|
||||
|
||||
union{
|
||||
unsigned char data[sizeof(struct PNG_START_FILE_STRUCT)];
|
||||
@@ -158,7 +159,7 @@ void build_png_file(struct PNG_FILE_STRUCT *png_file) {
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
int change_idat_content(unsigned char *addr, struct PNG_FILE_STRUCT *png_file, unsigned char *message, int accuracy, unsigned long offset) {
|
||||
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;
|
||||
@@ -167,8 +168,8 @@ int change_idat_content(unsigned char *addr, struct PNG_FILE_STRUCT *png_file, u
|
||||
printf("Notice, this could take a long time...");
|
||||
}
|
||||
if(total_idat(addr) < strlen((char*)message)) {
|
||||
printf("Warning, message exceeds IDAT amount");
|
||||
return EXIT_FAILURE;
|
||||
printf("Warning, message exceeds IDAT amount\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
int idat_length = check_header_length(addr, offset);
|
||||
@@ -211,7 +212,7 @@ int change_idat_content(unsigned char *addr, struct PNG_FILE_STRUCT *png_file, u
|
||||
}
|
||||
|
||||
// Build PNG File
|
||||
build_png_file(png_file);
|
||||
build_png_file(png_file, out_file_name);
|
||||
|
||||
free(uncom_data_buff);
|
||||
free(com_data_buff);
|
||||
@@ -222,24 +223,74 @@ int change_idat_content(unsigned char *addr, struct PNG_FILE_STRUCT *png_file, u
|
||||
}
|
||||
|
||||
// This is where it all starts
|
||||
int main() {
|
||||
int main(int argc, char **argv) {
|
||||
FILE *fp;
|
||||
size_t i = 0;
|
||||
unsigned long offset = 0;
|
||||
struct PNG_FILE_STRUCT png_file_data;
|
||||
unsigned char *message = malloc(sizeof(char));
|
||||
message[0] = '\0';
|
||||
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("./1.png", "rt");
|
||||
// Written by Robert Zambito <contact@robbyzambito.me>
|
||||
fp = fopen(in_file_name, "rt");
|
||||
if (fp == NULL) {
|
||||
return EXIT_FAILURE;
|
||||
printf("File error\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
// No longer written by Robert Zambito <contact@robbyzambito.me>
|
||||
|
||||
unsigned char *file_data = file_to_char_array(fp, &i);
|
||||
fclose(fp);
|
||||
@@ -251,8 +302,7 @@ int main() {
|
||||
|
||||
populate_idat_png(file_data, &png_file_data.png_idat_data, offset);
|
||||
|
||||
change_idat_content(file_data, &png_file_data, message, 1, offset);
|
||||
change_idat_content(file_data, &png_file_data, message, 1, offset, out_file_name);
|
||||
|
||||
free(file_data);
|
||||
free(message);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user