wip
This commit is contained in:
114
crc.c
114
crc.c
@@ -14,18 +14,16 @@
|
||||
const long idat_signature = 1229209940;
|
||||
const long iend_signature = 1229278788;
|
||||
|
||||
int zlib_compress_data(unsigned char *data_chunk, size_t file_length) {
|
||||
FILE *zlib_decompress_data(unsigned char *data_chunk, size_t file_length) {
|
||||
int ret;
|
||||
unsigned int have;
|
||||
z_stream strm;
|
||||
unsigned char out[CHUNK];
|
||||
unsigned char in[CHUNK];
|
||||
|
||||
printf("Len: %zu\n", file_length);
|
||||
|
||||
errno=0;
|
||||
FILE *data_stream = fmemopen(data_chunk, file_length-1, "r");
|
||||
FILE *of = fopen("wow.wow", "w");
|
||||
FILE *data_stream = fmemopen(data_chunk, file_length, "r");
|
||||
FILE *of = open_memstream(NULL, NULL);
|
||||
if(data_stream == NULL) {
|
||||
perror("F MEM OPEN");
|
||||
}
|
||||
@@ -37,20 +35,20 @@ int zlib_compress_data(unsigned char *data_chunk, size_t file_length) {
|
||||
strm.next_in = Z_NULL;
|
||||
ret = inflateInit(&strm);
|
||||
if(ret != Z_OK) {
|
||||
return ret;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
do {
|
||||
strm.avail_in = fread(in, 1, CHUNK, data_stream);
|
||||
if(ferror(data_stream)) {
|
||||
(void)inflateEnd(&strm);
|
||||
return Z_ERRNO;
|
||||
return NULL;
|
||||
}
|
||||
if(strm.avail_in == 0) {
|
||||
break;
|
||||
}
|
||||
strm.next_in = in;
|
||||
|
||||
|
||||
do {
|
||||
strm.avail_out = CHUNK;
|
||||
strm.next_out = out;
|
||||
@@ -64,7 +62,7 @@ int zlib_compress_data(unsigned char *data_chunk, size_t file_length) {
|
||||
(void)inflateEnd(&strm);
|
||||
printf("Error: %d\n", ret);
|
||||
printf("MSG: %s\n", (char*)strm.msg);
|
||||
return ret;
|
||||
return NULL;
|
||||
}
|
||||
have = CHUNK - strm.avail_out;
|
||||
fwrite(out, 1, have, of);
|
||||
@@ -73,9 +71,8 @@ int zlib_compress_data(unsigned char *data_chunk, size_t file_length) {
|
||||
|
||||
(void)inflateEnd(&strm);
|
||||
|
||||
printf("String: %s\n", out);
|
||||
|
||||
return 1;
|
||||
return of;
|
||||
}
|
||||
|
||||
unsigned long first_idat(unsigned char *addr) {
|
||||
@@ -125,6 +122,31 @@ int update_file_crc(unsigned char *addr, unsigned long offset , unsigned int crc
|
||||
}
|
||||
}
|
||||
|
||||
void random_data_change(unsigned char *color_data, int width, int length) {
|
||||
int searching = 1;
|
||||
width = 16;
|
||||
int color_range = 3;
|
||||
unsigned char temp_color_data[length];
|
||||
|
||||
memcpy(temp_color_data, color_data, length);
|
||||
|
||||
do {
|
||||
// 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]++;
|
||||
}
|
||||
}
|
||||
|
||||
} while(searching == 1);
|
||||
}
|
||||
|
||||
int change_idat_content(unsigned char *addr, char *message, int accuracy, unsigned long offset) {
|
||||
//printf("Starting IDAT Tranform\n");
|
||||
if(accuracy > 4) {
|
||||
@@ -160,33 +182,41 @@ int change_idat_content(unsigned char *addr, char *message, int accuracy, unsign
|
||||
for(int i = 0; i <= idat_length; i++) {
|
||||
temp_idat_data[i] = idat_data[i];
|
||||
}
|
||||
int r = randombytes_uniform(5) + 1;
|
||||
int j = randombytes_uniform(idat_length);
|
||||
//int r = randombytes_uniform(5) + 1;
|
||||
//int j = randombytes_uniform(idat_length);
|
||||
|
||||
temp_idat_data[j] = (temp_idat_data[j] + r) % 255;
|
||||
unsigned char crc_check[size+4];
|
||||
unsigned int idat_header[] = { 0x49, 0x44, 0x41, 0x54 };
|
||||
for(int i = 0; i < 4; i++) {
|
||||
crc_check[i] = idat_header[i];
|
||||
}
|
||||
for(int i = 0; i < idat_byte_length; i++) {
|
||||
crc_check[i] = temp_idat_data[i+4];
|
||||
}
|
||||
unsigned int crcnum = crc(crc_check, idat_length);
|
||||
//printf("New CRC: %08X\n", crcnum);
|
||||
//printf("Test: %X\n", crcnum >> (8*3));
|
||||
unsigned int checked_crc = crcnum >> (8*3);
|
||||
rounds++;
|
||||
if(checked_crc == 61) {
|
||||
zlib_compress_data(temp_idat_data, idat_byte_length);
|
||||
printf("Found %d in %d rounds\n", checked_crc ,rounds);
|
||||
//temp_idat_data[j] = (temp_idat_data[j] + r) % 255;
|
||||
//unsigned char crc_check[size+4];
|
||||
//unsigned int idat_header[] = { 0x49, 0x44, 0x41, 0x54 };
|
||||
//for(int i = 0; i < 4; i++) {
|
||||
// crc_check[i] = idat_header[i];
|
||||
//}
|
||||
//for(int i = 0; i < idat_byte_length; i++) {
|
||||
// crc_check[i] = temp_idat_data[i+4];
|
||||
//}
|
||||
//unsigned int crcnum = crc(crc_check, idat_length);
|
||||
//unsigned int checked_crc = crcnum >> (8*3);
|
||||
//rounds++;
|
||||
//if(checked_crc == 61) {
|
||||
// Setting TEMP IDAT DATA BACK TO ORIGINAL
|
||||
// TO STOP DECOMPRESSION CORRUPTION
|
||||
//temp_idat_data[j] = addr[offset+8+j];
|
||||
// Decompressing Data
|
||||
FILE *uncom_data = zlib_decompress_data(temp_idat_data, idat_byte_length);
|
||||
size_t uncom_data_size = 0;
|
||||
|
||||
unsigned char *uncom_data_array = file_to_char_array(uncom_data, &uncom_data_size);
|
||||
printf("UnCom: %zu\n", uncom_data_size);
|
||||
random_data_change(uncom_data_array, 16, uncom_data_size);
|
||||
|
||||
//printf("Found %d in %d rounds\n", checked_crc ,rounds);
|
||||
//printf("Full CRC: %08X\n", crcnum);
|
||||
//printf("Original: %02X\n", idat_data[j]);
|
||||
//printf("Change offset: %d to hex: %02X\n", j, temp_idat_data[j]);
|
||||
addr[offset+8+j] = temp_idat_data[j];
|
||||
update_file_crc(addr, offset, crcnum);
|
||||
//addr[offset+8+j] = temp_idat_data[j];
|
||||
//update_file_crc(addr, offset, crcnum);
|
||||
prop_found = 1;
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -194,28 +224,18 @@ int change_idat_content(unsigned char *addr, char *message, int accuracy, unsign
|
||||
|
||||
int main() {
|
||||
FILE *fp;
|
||||
unsigned int c;
|
||||
unsigned long file_data_cap = 8;
|
||||
unsigned char* file_data = calloc(file_data_cap, sizeof(unsigned char));
|
||||
size_t i = 0;
|
||||
unsigned long offset = 0;
|
||||
char message[1];
|
||||
|
||||
if(sodium_init() == -1) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
fp = fopen("./1.png", "rt");
|
||||
for(size_t i = 0;(c = fgetc(fp)) != EOF; i++) {
|
||||
if(i == file_data_cap) {
|
||||
file_data_cap *= 2;
|
||||
file_data = reallocarray(file_data, file_data_cap, sizeof(unsigned char));
|
||||
if(file_data == NULL) {
|
||||
perror("FAILED ARRAY RESIZE");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
file_data[i] = c;
|
||||
}
|
||||
unsigned char *file_data = file_to_char_array(fp, &i);
|
||||
fclose(fp);
|
||||
|
||||
offset = first_idat(file_data);
|
||||
change_idat_content(file_data, message, 1, offset);
|
||||
//create_cc_file(file_data, i);
|
||||
|
||||
20
crc_util.c
20
crc_util.c
@@ -41,3 +41,23 @@ int create_cc_file(unsigned char *addr, unsigned long file_length) {
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
unsigned char* file_to_char_array(FILE *in_file, size_t* size) {
|
||||
unsigned int c;
|
||||
unsigned long file_data_cap = 8;
|
||||
unsigned char* file_data = calloc(file_data_cap, sizeof(unsigned char));
|
||||
|
||||
for(size_t i = 0;(c = fgetc(in_file)) != EOF; i++) {
|
||||
if(i == file_data_cap) {
|
||||
file_data_cap *= 2;
|
||||
file_data = reallocarray(file_data, file_data_cap, sizeof(unsigned char));
|
||||
if(file_data == NULL) {
|
||||
perror("FAILED ARRAY RESIZE");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
file_data[i] = c;
|
||||
*size += 1;
|
||||
}
|
||||
return file_data;
|
||||
}
|
||||
|
||||
@@ -4,3 +4,4 @@ extern const long png_signature[8];
|
||||
int check_header_length(unsigned char *addr, long offset);
|
||||
int check_file_header(char *addr);
|
||||
int create_cc_file(unsigned char *addr, unsigned long file_length);
|
||||
unsigned char* file_to_char_array(FILE *in_file, size_t* size);
|
||||
|
||||
Reference in New Issue
Block a user