Getting data appended to a file and searching
Hi all,
In continuation, albeit a different task, I am trying to get data that has been appended to the end of an image. The delimiter is "Test" and I was trying to use strstr and shift the pointer. It isn't working and I tried all sorts of methods. I clearly am missing something - the image should fit in an array of 1000. If I took this image: http://www.pacificsimplicity.ca/site...stDateIcon.png
and appended to the image (no \n) TestWhatIWouldLike Sans quotes, I want the "WhatIWouldLike"
Here is the console output:
Code:
./decrypt-tool.o
BUFFER:<��B�PNG
PTR_B:<��B�PNG
ANS:
Code:
void decrypt(){
//Initializing the encryption KEY
AES_set_encrypt_key(ckey, 128, &key);
init_ctr(&state, iv);
char buffer[1000];
char path[1000];
char *ptr_b[1000];
op=fopen(ENCIMAGENAME,"r");
if (op==NULL) { fputs ("File error",stderr); }
/* Read the output a line at a time */
while (fgets(path, 1000, op) != NULL) {
strcat(buffer,path);
}
close(op);
printf("BUFFER:%s \n",buffer);
memcpy(ptr_b,buffer,sizeof(buffer));
printf("PTR_B:%s \n",ptr_b);
char *ans;
ans = strstr((char *)ptr_b,"Test");
ans = &ans + sizeof("Test");
printf("ANS:%s \n",ans);
fp=fopen(TMPFILE,"wb");
fwrite(ans,strlen(ans),1,fp);
fclose(fp);
rp=fopen(OUTCMD,"wb");
fp=fopen(TMPFILE,"rb");
//Decrypt blocks of 16 bytes and write to decrypted.txt
while (1) {
bytes_read = fread(indata, 1, AES_BLOCK_SIZE, fp);
AES_ctr128_encrypt(indata, outdata, bytes_read, &key, state.ivec, state.ecount, &state.num);
bytes_written = fwrite(outdata, 1, bytes_read, rp);
if (bytes_read < AES_BLOCK_SIZE)
break;
}
fclose (fp);
fclose (rp);
}
Pretty please with a cherry on top help please?