wip
This commit is contained in:
3
Makefile
3
Makefile
@@ -14,3 +14,6 @@ output_dir:
|
|||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf $(OUTPUT_DIR) **.h.gch
|
rm -rf $(OUTPUT_DIR) **.h.gch
|
||||||
|
|
||||||
|
memcheck: debug
|
||||||
|
valgrind --tool=memcheck --leak-check=yes --show-reachable=yes --num-callers=20 --track-fds=yes -s ${OUTPUT_DIR}/crc
|
||||||
|
|||||||
80
cmd/crc.c
80
cmd/crc.c
@@ -4,6 +4,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sodium.h>
|
#include <sodium.h>
|
||||||
|
#include <getopt.h>
|
||||||
#include "crc_util.h"
|
#include "crc_util.h"
|
||||||
#include "CRCLib.h"
|
#include "CRCLib.h"
|
||||||
#include "crc.h"
|
#include "crc.h"
|
||||||
@@ -106,10 +107,10 @@ void random_data_change(unsigned char *color_data, int width, int length) {
|
|||||||
} while(searching == 1);
|
} 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;
|
FILE *fp;
|
||||||
|
|
||||||
fp = fopen("TESTPNG.png", "w");
|
fp = fopen(out_file_name, "w");
|
||||||
|
|
||||||
union{
|
union{
|
||||||
unsigned char data[sizeof(struct PNG_START_FILE_STRUCT)];
|
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);
|
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) {
|
if(accuracy > 4) {
|
||||||
printf("Warning, accuracy cannot be larger than 4");
|
printf("Warning, accuracy cannot be larger than 4");
|
||||||
return EXIT_FAILURE;
|
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...");
|
printf("Notice, this could take a long time...");
|
||||||
}
|
}
|
||||||
if(total_idat(addr) < strlen((char*)message)) {
|
if(total_idat(addr) < strlen((char*)message)) {
|
||||||
printf("Warning, message exceeds IDAT amount");
|
printf("Warning, message exceeds IDAT amount\n");
|
||||||
return EXIT_FAILURE;
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int idat_length = check_header_length(addr, offset);
|
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
|
||||||
build_png_file(png_file);
|
build_png_file(png_file, out_file_name);
|
||||||
|
|
||||||
free(uncom_data_buff);
|
free(uncom_data_buff);
|
||||||
free(com_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
|
// This is where it all starts
|
||||||
int main() {
|
int main(int argc, char **argv) {
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
unsigned long offset = 0;
|
unsigned long offset = 0;
|
||||||
struct PNG_FILE_STRUCT png_file_data;
|
struct PNG_FILE_STRUCT png_file_data;
|
||||||
unsigned char *message = malloc(sizeof(char));
|
char *in_file_name = NULL;
|
||||||
message[0] = '\0';
|
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) {
|
if(sodium_init() == -1) {
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
fp = fopen("./1.png", "rt");
|
fp = fopen(in_file_name, "rt");
|
||||||
// Written by Robert Zambito <contact@robbyzambito.me>
|
|
||||||
if (fp == NULL) {
|
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);
|
unsigned char *file_data = file_to_char_array(fp, &i);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
@@ -251,8 +302,7 @@ int main() {
|
|||||||
|
|
||||||
populate_idat_png(file_data, &png_file_data.png_idat_data, offset);
|
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(file_data);
|
||||||
free(message);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,5 +3,5 @@ int check_file_header(char *addr);
|
|||||||
int check_header_length(unsigned char *addr, long offset);
|
int check_header_length(unsigned char *addr, long offset);
|
||||||
unsigned long first_idat(unsigned char *addr);
|
unsigned long first_idat(unsigned char *addr);
|
||||||
int total_idat(unsigned char *addr);
|
int total_idat(unsigned char *addr);
|
||||||
void build_png_file(struct PNG_FILE_STRUCT *png_file);;;
|
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, 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);
|
||||||
|
|||||||
Reference in New Issue
Block a user