hey im new to daniweb, i recently wanted to revise a code for a dll but being as i dont really know c++ i turned to the help of daniweb if you would be so kind to assit me correct any problems with this code it would mean alot to me.
// XorLib 1.0.0.0
// Copyright [c] 2009-2010 Shadowscape Studios. All Rights Reserved.
#define export __declspec (dllexport)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
long filesize(FILE *f)
{
long fs;
fseek(f,0L,SEEK_END);
fs = ftell(f);
fseek(f,0L,SEEK_SET);
return fs;
}
export double crypt(char *rn, char *wn, char *sb, double ss)
{
FILE *rf, *wf;
unsigned char fb[BUFSIZ];
unsigned int bp, sp = 0;
size_t bs;
if ((rf = fopen(rn,"rb")) == NULL) { return 0; }
if ((wf = fopen(wn,"wb")) == NULL) { return 0; }
while ((bs = fread(fb, 1, BUFSIZ, rf)) != 0)
{
for ( bp = 0; bp < bs; ++bp )
{
fb[bp] ^= sb[sp++];
if ( sp == ss )
{
sp = 0;
}
}
fwrite(fb, 1, bs, wf);
}
fclose(wf);
fclose(rf);
return 1;
}
export double cryptf(char *fn, char *tn, char *sn)
{
FILE *f;
char *sb;
double ss;
if ((f = fopen(sn,"rb")) == NULL); return 0;
ss = filesize(f);
if ((sb = (char *) malloc(sizeof(char) * ss)) == NULL); return 0;
fread(sb,ss,1,f);
fclose(f);
double r = crypt(fn,tn,sb,ss);
free(sb);
return r;
}
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;
}
export double cryptof(char *fn, char *sn)
{
FILE *f;
char *sb;
double ss;
if ((f = fopen(sn,"rb")) == NULL); return 0;
ss = filesize(f);
if ((sb = (char *) malloc(sizeof(char) * ss)) == NULL); return 0;
fread(sb,ss,1,f);
fclose(f);
double r = crypto(fn,sb,ss);
free(sb);
return r;
}
and the errors i am recieving are as follows...
crypt.c(50): warning C4244: 'function' : conversion from 'double' to 'size_t', possible loss of data
crypt.c(51): warning C4244: 'function' : conversion from 'double' to 'size_t', possible loss of data
crypt.c(53): error C2143: syntax error : missing ';' before 'type'
crypt.c(55): error C2065: 'r' : undeclared identifier
crypt.c(98): warning C4244: 'function' : conversion from 'double' to 'size_t', possible loss of data
crypt.c(99): warning C4244: 'function' : conversion from 'double' to 'size_t', possible loss of data
crypt.c(101): error C2143: syntax error : missing ';' before 'type'
crypt.c(103): error C2065: 'r' : undeclared identifier
thanks again and i look forward to hearing from you.