From fb945457e6b8388a83321182b5ac67a654b69bbe Mon Sep 17 00:00:00 2001 From: Pin Date: Wed, 22 Sep 2021 22:10:39 -0400 Subject: [PATCH] wip --- .gitignore | 2 ++ crc.c | 42 ++++++++++++++++++++++++++++++++++++++---- 2 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dcfc80f --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.png +*.out diff --git a/crc.c b/crc.c index 06a74be..58df9c2 100644 --- a/crc.c +++ b/crc.c @@ -6,31 +6,65 @@ int png_signature[8] = { 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a }; //int idat_signature[4] = { 0x, 0x, 0x, 0x} -int CheckPNG(int *addr) { +int check_header(int *addr) { int signature_match = 0; for( int i = 0; i < 8; i++ ) { if (addr[i] != png_signature[i]) { signature_match = 1; } } - printf("%d", signature_match); + printf("Sig Match: %d\n", signature_match); return signature_match; } + +int check_header_length(int *addr, int offset) { + unsigned int res = 0; + for( int i = 0; i < 4; i++ ) { + res |= addr[offset+i]; + if (i < 3) { + res <<= 8; + } + } + return res; +} + +int first_idat(int *addr) { + int idat_found = 0; + int offset = 8; + int jump_offset = 0; + int header_type = 0; + while(idat_found == 0) { + jump_offset = check_header_length(addr, offset); + header_type = check_header_length(addr, offset+4); + printf("Jump: %d\n", jump_offset); + printf("Type: %d\n", header_type); + if(header_type == 1229209940) { + idat_found = 1; + } else { + offset = offset + jump_offset + 12; + } + } + return offset; +} + void main() { FILE *fp; int c; int myArray[255] = {}; int i = 0; + int offset = 0; fp = fopen("./1.png", "rt"); while((c = fgetc(fp)) != EOF) { - //printf("Value: %X\n", c); myArray[i] = c; i++; } fclose(fp); - CheckPNG(myArray); + //check_header(myArray); + //check_header_length(myArray, 54); + offset = first_idat(myArray); + printf("First Chunk: %d\n", offset); //printf("%d\n", CheckPNG(myArray)); //int crcnum = crc(myArray, 19); //printf("%08X\n", crcnum);