file write
This commit is contained in:
35
crc.c
35
crc.c
@@ -4,6 +4,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <sodium.h>
|
||||
#include "CRCLib.h"
|
||||
#include "crc.h"
|
||||
|
||||
const long png_signature[8] = { 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a };
|
||||
const long idat_signature = 1229209940;
|
||||
@@ -34,7 +35,7 @@ int check_header_length(unsigned char *addr, long offset) {
|
||||
return res;
|
||||
}
|
||||
|
||||
unsigned long first_idat(char *addr) {
|
||||
unsigned long first_idat(unsigned char *addr) {
|
||||
int idat_found = 0;
|
||||
unsigned long offset = 8;
|
||||
int jump_offset = 0;
|
||||
@@ -51,7 +52,7 @@ unsigned long first_idat(char *addr) {
|
||||
return offset;
|
||||
}
|
||||
|
||||
int total_idat(char *addr) {
|
||||
int total_idat(unsigned char *addr) {
|
||||
int iend_found = 0;
|
||||
int found_idat = 0;
|
||||
unsigned long offset = 8;
|
||||
@@ -72,6 +73,15 @@ int total_idat(char *addr) {
|
||||
return found_idat;
|
||||
}
|
||||
|
||||
int update_file_crc(unsigned char *addr, unsigned long offset , unsigned int crc_num) {
|
||||
int startCRC = 8 + offset + check_header_length(addr, offset);
|
||||
unsigned char new_crc;
|
||||
for(int i = 0; i < 4; i++) {
|
||||
new_crc = crc_num >> (8*(3-i)) & 0xFF;
|
||||
addr[startCRC+i] = new_crc;
|
||||
}
|
||||
}
|
||||
|
||||
int change_idat_content(unsigned char *addr, char *message, int accuracy, unsigned long offset) {
|
||||
printf("Starting IDAT Tranform\n");
|
||||
if(accuracy > 4) {
|
||||
@@ -125,6 +135,8 @@ int change_idat_content(unsigned char *addr, char *message, int accuracy, unsign
|
||||
printf("Full CRC: %08X\n", crcnum);
|
||||
printf("Original: %02X\n", idat_data[j]);
|
||||
printf("Change offset: %d to hex: %02X\n", j, temp_idat_data[j]);
|
||||
addr[offset+8+j] = temp_idat_data[j];
|
||||
update_file_crc(addr, offset, crcnum);
|
||||
prop_found = 1;
|
||||
}
|
||||
}
|
||||
@@ -132,12 +144,24 @@ int change_idat_content(unsigned char *addr, char *message, int accuracy, unsign
|
||||
return 0;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
int main() {
|
||||
FILE *fp;
|
||||
unsigned int c;
|
||||
//unsigned char myArray[838860];
|
||||
unsigned char * myArray = NULL;
|
||||
myArray = calloc(880388560, sizeof(char));
|
||||
unsigned char* myArray = calloc(1000, sizeof(unsigned char));
|
||||
unsigned long i = 0;
|
||||
unsigned long offset = 0;
|
||||
char message[1];
|
||||
@@ -152,6 +176,7 @@ int main() {
|
||||
fclose(fp);
|
||||
offset = first_idat(myArray);
|
||||
change_idat_content(myArray, message, 2, offset);
|
||||
create_cc_file(myArray, i);
|
||||
//int crcnum = crc(myArray, 19);
|
||||
//printf("%08X\n", crcnum);
|
||||
}
|
||||
|
||||
6
crc.h
Normal file
6
crc.h
Normal file
@@ -0,0 +1,6 @@
|
||||
|
||||
int check_file_header(char *addr);
|
||||
int check_header_length(unsigned char *addr, long offset);
|
||||
unsigned long first_idat(unsigned char *addr);
|
||||
int total_idat(unsigned char *addr);
|
||||
int change_idat_content(unsigned char *addr, char *message, int accuracy, unsigned long offset);
|
||||
Reference in New Issue
Block a user