// Project: XorLib - Xor Encryption Libary.
// Copyright: Copyright © 2009-2010 Shadowscape Studios. All Rights Reserved.
// Developer: Shadowscape Studios
// Website: http://www.shadowscape.co.uk
// Support: support@shadowscape.co.uk
// Version: 1.0.0.0
// Release: 151220102240

#define export __declspec (dllexport)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>

long filesize(FILE *f)
{
	long fs;
	fseek(f,0L,SEEK_END);
	fs = ftell(f);
	fseek(f,0L,SEEK_SET);
	return fs;
}

export double xorcrypt(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 xorcryptf(char *fn, char *tn, char *sn)
{
	FILE *f;
	char *sb;
	double ss, r;

	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);
	r = xorcrypt(fn,tn,sb,ss);
	free(sb);
	return r;
}

export double xorcrypto(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 xorcryptof(char *fn, char *sn)
{
	FILE *f;
	char *sb;
	double ss, r;

	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);
	r = xorcrypto(fn,sb,ss);
	free(sb);
	return r;
}

hi i have made this dll and was wondering how would i write the functions in devc++ for the ".h" file because i have been informed i need to do that as it just seems to crash the application at the moment and im new to this language so im very unsure how they should look and all i have for refrence is the following which doesnt really seem to help so much as my functions seem diffrent to this. it would be amazing if someone could help me its taken me months to get this far and i am so determined to get this out to developers soon as i think it could prove useful to have.

#ifndef _DLL_H_
#define _DLL_H_

#include <windows.h>

#ifndef DLL_EXPORT
#define DLL_EXPORT extern "C" __declspec(dllexport)
#endif

DLL_EXPORT void SayHello();
DLL_EXPORT int Addition(int arg1,int arg2);
DLL_EXPORT LPTSTR CombineString(LPTSTR arg1,LPTSTR arg2);

#endif

i forgot to add the functions, silly me. they are as follows:

xorcrypt(from,to,seed)
xorcryptf(from,to,seedfile)
xorcrypto(file,seed)
xorcryptof(file,seedfile)

im not even sure if the code is correct as its using export but all the other scripts seem to be using DLL_EXPORT, the functions look like they arnt declared correctly from other scripts made in decc++ im confused and have been trying to make this work for months im pulling my hair out trying to make this work and i dont understand what is going wrong as im new to c and devc++, this is a desperate cry for someones help any time you spend trying to help i cant express how much gratitude i have for you so thanks to anyone that dares to correct this horribly coded DLL.

i have the original file below (which is the only file i have to work with and im working in DevC++) and i hope someone can help me, because i wont be able to thank them enough :)

#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 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;
	unsigned 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;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.