72 lines
1.4 KiB
C
72 lines
1.4 KiB
C
#include <stdio.h>
|
|
#include <unistd.h>
|
|
#include <string.h>
|
|
#include "CRCLib.h"
|
|
|
|
int png_signature[8] = { 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a };
|
|
//int idat_signature[4] = { 0x, 0x, 0x, 0x}
|
|
|
|
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("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) {
|
|
myArray[i] = c;
|
|
i++;
|
|
}
|
|
fclose(fp);
|
|
//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);
|
|
}
|