wip
This commit is contained in:
42
crc.c
42
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);
|
||||
|
||||
Reference in New Issue
Block a user