Ooooh thanks!! well you got me up and running Tater. Code Karma.
From your code to writing a nasty little mystrstr which checks for the \x89 start of the PNG, I have arrived at the bottom.
Code:
char *mystrstr(char input[], char pat[])
{
/* x89 is the start of a PNG;) */
char *start, *p1, *p2;
for(start = &input[0]; *start != '\x89'; start++)
{ /* for each position in input string... */
p1 = pat; /* prepare to check for pattern string there */
p2 = start;
while(*p1 != '\0')
{
if(*p1 != *p2) /* characters differ */
break;
p1++;
p2++;
}
if(*p1 == '\0') /* found match */
return start;
}
return NULL;
}
void decrypt(){
// Initializing the encryption KEY
AES_set_encrypt_key(ckey, 128, &key);
init_ctr(&state, iv);
// Find and shift
char buffer[50]; // If you want to go back 50 chars
op=fopen(ENCIMAGENAME,"r");
fseek(op, -49, SEEK_END); //Same as buff -1 because it counts 0
bzero(buffer,50);
fread((char *)&buffer, 1, 50, op);
fclose(op);
printf("BUFFER:%s \n",buffer);
char *ans;
ans = mystrstr((char *)buffer,"Test");
printf("FOUND:%s \n",ans);
ans = ans + strlen("Test");
printf("SHIFT:%s \n",ans);
fp=fopen(TMPFILE,"w");
fwrite(ans,strlen(ans),1,fp);
fclose(fp);
//Decrypt blocks of 16 bytes and write to OUTPUT
rp=fopen(OUTCMD,"wb");
if (rp==NULL) { fputs ("File error",stderr); }
fp=fopen(TMPFILE,"rb");
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);
}