Hello, i have created a Xor function for a DLL i am developing. I have a problem with this function as the decoded text isn't matching its original state and i am unsure as to the cause of this, please could you help me?
#define export __declspec (dllexport)
#include <stdio.h>
long filesize(FILE *f)
{
long fs;
fseek(f,0L,SEEK_END);
fs = ftell(f);
fseek(f,0L,SEEK_SET);
return fs;
}
export double crypto(char *fn, char *sb, double ss)
{
FILE *f;
unsigned char fb[BUFSIZ];
unsigned int bp, sp = 0;
long rp, wp;
size_t bs;
if ((f = fopen(fn,"rb+")) == NULL)
{
return 0;
}
rp = wp = ftell(f);
while ((bs = fread(fb, 1, BUFSIZ, f)) != 0)
{
rp = ftell(f);
for ( bp = 0; bp < bs; ++bp )
{
fb[bp] ^= sb[sp++];
if ( sp == ss )
{
sp = 0;
}
}
fseek(f,wp,SEEK_SET);
fwrite(fb, 1, bs, f);
fflush(f);
wp = ftell(f);
fseek(f,rp,SEEK_SET);
}
fclose(f);
return 1;
}
I have managed to get all the other functions working but the decoding process doesnt seem to be working quite right and it seems to be crashing applications that call the DLL with larger files.
Best Wishes,
Nathaniel Blackburn