wip
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
*.png
|
||||||
|
*.out
|
||||||
42
crc.c
42
crc.c
@@ -6,31 +6,65 @@
|
|||||||
int png_signature[8] = { 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a };
|
int png_signature[8] = { 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a };
|
||||||
//int idat_signature[4] = { 0x, 0x, 0x, 0x}
|
//int idat_signature[4] = { 0x, 0x, 0x, 0x}
|
||||||
|
|
||||||
int CheckPNG(int *addr) {
|
int check_header(int *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]) {
|
||||||
signature_match = 1;
|
signature_match = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf("%d", signature_match);
|
printf("Sig Match: %d\n", signature_match);
|
||||||
return 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() {
|
void main() {
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
int c;
|
int c;
|
||||||
int myArray[255] = {};
|
int myArray[255] = {};
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
int offset = 0;
|
||||||
fp = fopen("./1.png", "rt");
|
fp = fopen("./1.png", "rt");
|
||||||
while((c = fgetc(fp)) != EOF) {
|
while((c = fgetc(fp)) != EOF) {
|
||||||
//printf("Value: %X\n", c);
|
|
||||||
myArray[i] = c;
|
myArray[i] = c;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
fclose(fp);
|
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));
|
//printf("%d\n", CheckPNG(myArray));
|
||||||
//int crcnum = crc(myArray, 19);
|
//int crcnum = crc(myArray, 19);
|
||||||
//printf("%08X\n", crcnum);
|
//printf("%08X\n", crcnum);
|
||||||
|
|||||||
Reference in New Issue
Block a user