wip
This commit is contained in:
43
crc_util.c
Normal file
43
crc_util.c
Normal file
@@ -0,0 +1,43 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "crc_util.h"
|
||||
|
||||
const long png_signature[8] = { 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a };
|
||||
|
||||
|
||||
int check_header_length(unsigned char *addr, long offset) {
|
||||
unsigned int res = 0;
|
||||
for( int i = 0; i < 4; i++ ) {
|
||||
res |= addr[offset+i];
|
||||
if (i < 3) {
|
||||
res <<= 8;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
int check_file_header(char *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 create_cc_file(unsigned char *addr, unsigned long file_length) {
|
||||
FILE *fp;
|
||||
fp = fopen("png2.png", "w");
|
||||
|
||||
if(fp == NULL) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
for(int i = 0; i < file_length; i++){
|
||||
fputc(addr[i], fp);
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
Reference in New Issue
Block a user