wip
This commit is contained in:
154
crc.c
154
crc.c
@@ -1,38 +1,81 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <zlib.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <errno.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sodium.h>
|
#include <sodium.h>
|
||||||
|
#include "crc_util.h"
|
||||||
#include "CRCLib.h"
|
#include "CRCLib.h"
|
||||||
#include "crc.h"
|
#include "crc.h"
|
||||||
|
|
||||||
const long png_signature[8] = { 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a };
|
#define CHUNK 8
|
||||||
const long idat_signature = 1229209940;
|
const long idat_signature = 1229209940;
|
||||||
const long iend_signature = 1229278788;
|
const long iend_signature = 1229278788;
|
||||||
const int working = 1;
|
|
||||||
|
|
||||||
int check_file_header(char *addr) {
|
int zlib_compress_data(unsigned char *data_chunk, size_t file_length) {
|
||||||
int signature_match = 0;
|
int ret;
|
||||||
for( int i = 0; i < 8; i++ ) {
|
unsigned int have;
|
||||||
if (addr[i] != png_signature[i]) {
|
z_stream strm;
|
||||||
signature_match = 1;
|
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");
|
||||||
|
if(data_stream == NULL) {
|
||||||
|
perror("F MEM OPEN");
|
||||||
}
|
}
|
||||||
printf("Sig Match: %d\n", signature_match);
|
|
||||||
return signature_match;
|
|
||||||
|
|
||||||
}
|
strm.zalloc = Z_NULL;
|
||||||
|
strm.zfree = Z_NULL;
|
||||||
|
strm.opaque = Z_NULL;
|
||||||
int check_header_length(unsigned char *addr, long offset) {
|
strm.avail_in = 0;
|
||||||
unsigned int res = 0;
|
strm.next_in = Z_NULL;
|
||||||
for( int i = 0; i < 4; i++ ) {
|
ret = inflateInit(&strm);
|
||||||
res |= addr[offset+i];
|
if(ret != Z_OK) {
|
||||||
if (i < 3) {
|
return ret;
|
||||||
res <<= 8;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return res;
|
|
||||||
|
do {
|
||||||
|
strm.avail_in = fread(in, 1, CHUNK, data_stream);
|
||||||
|
if(ferror(data_stream)) {
|
||||||
|
(void)inflateEnd(&strm);
|
||||||
|
return Z_ERRNO;
|
||||||
|
}
|
||||||
|
if(strm.avail_in == 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
strm.next_in = in;
|
||||||
|
|
||||||
|
do {
|
||||||
|
strm.avail_out = CHUNK;
|
||||||
|
strm.next_out = out;
|
||||||
|
ret = inflate(&strm, Z_NO_FLUSH);
|
||||||
|
assert(ret != Z_STREAM_ERROR);
|
||||||
|
switch(ret) {
|
||||||
|
case Z_NEED_DICT:
|
||||||
|
ret = Z_DATA_ERROR;
|
||||||
|
case Z_DATA_ERROR:
|
||||||
|
case Z_MEM_ERROR:
|
||||||
|
(void)inflateEnd(&strm);
|
||||||
|
printf("Error: %d\n", ret);
|
||||||
|
printf("MSG: %s\n", (char*)strm.msg);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
have = CHUNK - strm.avail_out;
|
||||||
|
fwrite(out, 1, have, of);
|
||||||
|
} while(strm.avail_out == 0);
|
||||||
|
} while(ret != Z_STREAM_END);
|
||||||
|
|
||||||
|
(void)inflateEnd(&strm);
|
||||||
|
|
||||||
|
printf("String: %s\n", out);
|
||||||
|
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long first_idat(unsigned char *addr) {
|
unsigned long first_idat(unsigned char *addr) {
|
||||||
@@ -83,7 +126,7 @@ int update_file_crc(unsigned char *addr, unsigned long offset , unsigned int crc
|
|||||||
}
|
}
|
||||||
|
|
||||||
int change_idat_content(unsigned char *addr, char *message, int accuracy, unsigned long offset) {
|
int change_idat_content(unsigned char *addr, char *message, int accuracy, unsigned long offset) {
|
||||||
printf("Starting IDAT Tranform\n");
|
//printf("Starting IDAT Tranform\n");
|
||||||
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;
|
||||||
@@ -97,20 +140,24 @@ int change_idat_content(unsigned char *addr, char *message, int accuracy, unsign
|
|||||||
}
|
}
|
||||||
|
|
||||||
int idat_length = check_header_length(addr, offset);
|
int idat_length = check_header_length(addr, offset);
|
||||||
printf("IDAT: %d\n", idat_length);
|
printf("IDAT Length: %d\n", idat_length);
|
||||||
|
|
||||||
int prop_found = 0;
|
int prop_found = 0;
|
||||||
long size = 1;
|
long size = 1;
|
||||||
long rounds = 0;
|
long rounds = 0;
|
||||||
unsigned int* idat_data = malloc(size * sizeof(unsigned int));
|
size_t idat_byte_length = 0;
|
||||||
for(int i = 0; i < idat_length; i++) {
|
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_data[i] = addr[i+offset+8];
|
||||||
size++;
|
idat_byte_length = i;
|
||||||
int* new_idat_data = realloc(idat_data, size * sizeof(unsigned int));
|
|
||||||
}
|
}
|
||||||
unsigned int temp_idat_data[size];
|
unsigned char temp_idat_data[idat_byte_length];
|
||||||
while(prop_found == 0) {
|
while(prop_found == 0) {
|
||||||
for(int i = 0; i < idat_length; i++) {
|
for(int i = 0; i <= idat_length; i++) {
|
||||||
temp_idat_data[i] = idat_data[i];
|
temp_idat_data[i] = idat_data[i];
|
||||||
}
|
}
|
||||||
int r = randombytes_uniform(5) + 1;
|
int r = randombytes_uniform(5) + 1;
|
||||||
@@ -122,7 +169,7 @@ int change_idat_content(unsigned char *addr, char *message, int accuracy, unsign
|
|||||||
for(int i = 0; i < 4; i++) {
|
for(int i = 0; i < 4; i++) {
|
||||||
crc_check[i] = idat_header[i];
|
crc_check[i] = idat_header[i];
|
||||||
}
|
}
|
||||||
for(int i = 0; i < size; i++) {
|
for(int i = 0; i < idat_byte_length; i++) {
|
||||||
crc_check[i] = temp_idat_data[i+4];
|
crc_check[i] = temp_idat_data[i+4];
|
||||||
}
|
}
|
||||||
unsigned int crcnum = crc(crc_check, idat_length);
|
unsigned int crcnum = crc(crc_check, idat_length);
|
||||||
@@ -131,10 +178,11 @@ int change_idat_content(unsigned char *addr, char *message, int accuracy, unsign
|
|||||||
unsigned int checked_crc = crcnum >> (8*3);
|
unsigned int checked_crc = crcnum >> (8*3);
|
||||||
rounds++;
|
rounds++;
|
||||||
if(checked_crc == 61) {
|
if(checked_crc == 61) {
|
||||||
|
zlib_compress_data(temp_idat_data, idat_byte_length);
|
||||||
printf("Found %d in %d rounds\n", checked_crc ,rounds);
|
printf("Found %d in %d rounds\n", checked_crc ,rounds);
|
||||||
printf("Full CRC: %08X\n", crcnum);
|
//printf("Full CRC: %08X\n", crcnum);
|
||||||
printf("Original: %02X\n", idat_data[j]);
|
//printf("Original: %02X\n", idat_data[j]);
|
||||||
printf("Change offset: %d to hex: %02X\n", j, temp_idat_data[j]);
|
//printf("Change offset: %d to hex: %02X\n", j, temp_idat_data[j]);
|
||||||
addr[offset+8+j] = temp_idat_data[j];
|
addr[offset+8+j] = temp_idat_data[j];
|
||||||
update_file_crc(addr, offset, crcnum);
|
update_file_crc(addr, offset, crcnum);
|
||||||
prop_found = 1;
|
prop_found = 1;
|
||||||
@@ -144,39 +192,31 @@ int change_idat_content(unsigned char *addr, char *message, int accuracy, unsign
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int create_cc_file(unsigned char *addr, unsigned long file_length) {
|
|
||||||
FILE *fp;
|
|
||||||
fp = fopen("png2.png", "w");
|
|
||||||
|
|
||||||
if(fp == NULL) {
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int i = 0; i < file_length; i++){
|
|
||||||
fputc(addr[i], fp);
|
|
||||||
}
|
|
||||||
fclose(fp);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
unsigned int c;
|
unsigned int c;
|
||||||
unsigned char* myArray = calloc(1000, sizeof(unsigned char));
|
unsigned long file_data_cap = 8;
|
||||||
unsigned long i = 0;
|
unsigned char* file_data = calloc(file_data_cap, sizeof(unsigned char));
|
||||||
|
size_t i = 0;
|
||||||
unsigned long offset = 0;
|
unsigned long offset = 0;
|
||||||
char message[1];
|
char message[1];
|
||||||
if(sodium_init() == -1) {
|
if(sodium_init() == -1) {
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
fp = fopen("./1.png", "rt");
|
fp = fopen("./1.png", "rt");
|
||||||
while((c = fgetc(fp)) != EOF) {
|
for(size_t i = 0;(c = fgetc(fp)) != EOF; i++) {
|
||||||
myArray[i] = c;
|
if(i == file_data_cap) {
|
||||||
i++;
|
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;
|
||||||
}
|
}
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
offset = first_idat(myArray);
|
offset = first_idat(file_data);
|
||||||
change_idat_content(myArray, message, 2, offset);
|
change_idat_content(file_data, message, 1, offset);
|
||||||
create_cc_file(myArray, i);
|
//create_cc_file(file_data, i);
|
||||||
//int crcnum = crc(myArray, 19);
|
|
||||||
//printf("%08X\n", crcnum);
|
|
||||||
}
|
}
|
||||||
|
|||||||
43
crc_util.c
Normal file
43
crc_util.c
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "crc_util.h"
|
||||||
|
|
||||||
|
const long png_signature[8] = { 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a };
|
||||||
|
|
||||||
|
|
||||||
|
int check_header_length(unsigned char *addr, long offset) {
|
||||||
|
unsigned int res = 0;
|
||||||
|
for( int i = 0; i < 4; i++ ) {
|
||||||
|
res |= addr[offset+i];
|
||||||
|
if (i < 3) {
|
||||||
|
res <<= 8;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
int check_file_header(char *addr) {
|
||||||
|
int signature_match = 0;
|
||||||
|
for( int i = 0; i < 8; i++ ) {
|
||||||
|
if (addr[i] != png_signature[i]) {
|
||||||
|
signature_match = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("Sig Match: %d\n", signature_match);
|
||||||
|
return signature_match;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int create_cc_file(unsigned char *addr, unsigned long file_length) {
|
||||||
|
FILE *fp;
|
||||||
|
fp = fopen("png2.png", "w");
|
||||||
|
|
||||||
|
if(fp == NULL) {
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i = 0; i < file_length; i++){
|
||||||
|
fputc(addr[i], fp);
|
||||||
|
}
|
||||||
|
fclose(fp);
|
||||||
|
}
|
||||||
6
crc_util.h
Normal file
6
crc_util.h
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
|
||||||
|
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);
|
||||||
Reference in New Issue
Block a user