wip
This commit is contained in:
81
crc.c
81
crc.c
@@ -5,12 +5,12 @@
|
|||||||
#include <sodium.h>
|
#include <sodium.h>
|
||||||
#include "CRCLib.h"
|
#include "CRCLib.h"
|
||||||
|
|
||||||
const int png_signature[8] = { 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a };
|
const long png_signature[8] = { 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a };
|
||||||
const int idat_signature = 1229209940;
|
const long idat_signature = 1229209940;
|
||||||
const int iend_signature = 1229278788;
|
const long iend_signature = 1229278788;
|
||||||
const int working = 1;
|
const int working = 1;
|
||||||
|
|
||||||
int check_file_header(int *addr) {
|
int check_file_header(char *addr) {
|
||||||
int signature_match = 0;
|
int signature_match = 0;
|
||||||
for( int i = 0; i < 8; i++ ) {
|
for( int i = 0; i < 8; i++ ) {
|
||||||
if (addr[i] != png_signature[i]) {
|
if (addr[i] != png_signature[i]) {
|
||||||
@@ -23,7 +23,7 @@ int check_file_header(int *addr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int check_header_length(int *addr, int offset) {
|
int check_header_length(unsigned char *addr, long offset) {
|
||||||
unsigned int res = 0;
|
unsigned int res = 0;
|
||||||
for( int i = 0; i < 4; i++ ) {
|
for( int i = 0; i < 4; i++ ) {
|
||||||
res |= addr[offset+i];
|
res |= addr[offset+i];
|
||||||
@@ -34,9 +34,9 @@ int check_header_length(int *addr, int offset) {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int first_idat(int *addr) {
|
unsigned long first_idat(char *addr) {
|
||||||
int idat_found = 0;
|
int idat_found = 0;
|
||||||
int offset = 8;
|
unsigned long offset = 8;
|
||||||
int jump_offset = 0;
|
int jump_offset = 0;
|
||||||
int header_type = 0;
|
int header_type = 0;
|
||||||
while(idat_found == 0) {
|
while(idat_found == 0) {
|
||||||
@@ -51,10 +51,10 @@ int first_idat(int *addr) {
|
|||||||
return offset;
|
return offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
int total_idat(int *addr) {
|
int total_idat(char *addr) {
|
||||||
int iend_found = 0;
|
int iend_found = 0;
|
||||||
int found_idat = 0;
|
int found_idat = 0;
|
||||||
int offset = 8;
|
unsigned long offset = 8;
|
||||||
int jump_offset = 0;
|
int jump_offset = 0;
|
||||||
int header_type = 0;
|
int header_type = 0;
|
||||||
while(iend_found == 0) {
|
while(iend_found == 0) {
|
||||||
@@ -72,8 +72,8 @@ int total_idat(int *addr) {
|
|||||||
return found_idat;
|
return found_idat;
|
||||||
}
|
}
|
||||||
|
|
||||||
int change_idat_content(int *addr, char *message, int accuracy, int offset) {
|
int change_idat_content(unsigned char *addr, char *message, int accuracy, unsigned long offset) {
|
||||||
printf("Starting IDAT Tranform");
|
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;
|
||||||
@@ -86,36 +86,47 @@ int change_idat_content(int *addr, char *message, int accuracy, int offset) {
|
|||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comment
|
|
||||||
int i = total_idat(addr);
|
|
||||||
printf("Total IDAT %d\n", i);
|
|
||||||
|
|
||||||
int idat_length = check_header_length(addr, offset);
|
int idat_length = check_header_length(addr, offset);
|
||||||
|
printf("IDAT: %d\n", idat_length);
|
||||||
|
|
||||||
int prop_found = 0;
|
int prop_found = 0;
|
||||||
int size = 1;
|
long size = 1;
|
||||||
int* idat_data = malloc(size * sizeof(int));
|
long rounds = 0;
|
||||||
|
unsigned int* idat_data = malloc(size * sizeof(unsigned int));
|
||||||
|
for(int i = 0; i < idat_length; i++) {
|
||||||
|
idat_data[i] = addr[i+offset+8];
|
||||||
|
size++;
|
||||||
|
int* new_idat_data = realloc(idat_data, size * sizeof(unsigned int));
|
||||||
|
}
|
||||||
|
unsigned int temp_idat_data[size];
|
||||||
while(prop_found == 0) {
|
while(prop_found == 0) {
|
||||||
for(i = 0; i < idat_length; i++) {
|
for(int i = 0; i < idat_length; i++) {
|
||||||
idat_data[i] = addr[i+offset+8];
|
temp_idat_data[i] = idat_data[i];
|
||||||
size++;
|
|
||||||
int* new_idat_data = realloc(idat_data, size * sizeof(int));
|
|
||||||
}
|
}
|
||||||
int r = randombytes_uniform(5) + 1;
|
int r = randombytes_uniform(5) + 1;
|
||||||
int j = randombytes_uniform(idat_length);
|
int j = randombytes_uniform(idat_length);
|
||||||
|
|
||||||
idat_data[j] = (idat_data[j] + r) % 255;
|
temp_idat_data[j] = (temp_idat_data[j] + r) % 255;
|
||||||
unsigned char crc_check[size+4];
|
unsigned char crc_check[size+4];
|
||||||
int idat_header[] = { 0x49, 0x44, 0x41, 0x54 };
|
unsigned int idat_header[] = { 0x49, 0x44, 0x41, 0x54 };
|
||||||
for(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(i = 0; i < size; i++) {
|
for(int i = 0; i < size; i++) {
|
||||||
crc_check[i] = idat_data[i+4];
|
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) {
|
||||||
|
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]);
|
||||||
|
prop_found = 1;
|
||||||
}
|
}
|
||||||
int crcnum = crc(crc_check, idat_length);
|
|
||||||
printf("New CRC: %08X\n", crcnum);
|
|
||||||
printf("Test: %X\n", crcnum >> (8*3));
|
|
||||||
prop_found = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -123,10 +134,12 @@ int change_idat_content(int *addr, char *message, int accuracy, int offset) {
|
|||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
int c;
|
unsigned int c;
|
||||||
int myArray[255] = {};
|
//unsigned char myArray[838860];
|
||||||
int i = 0;
|
unsigned char * myArray = NULL;
|
||||||
int offset = 0;
|
myArray = calloc(880388560, sizeof(char));
|
||||||
|
unsigned long i = 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;
|
||||||
|
|||||||
Reference in New Issue
Block a user