⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 模板.c

📁 一个用ZIP算法实现的自解压程序制作
💻 C
字号:
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <dir.h>
#include "zlib.h"
#include "name_def.h"

#define Quit(T) {\
				printf (T);\
				getch ();\
				return 0;\
				}
typedef unsigned int uint;

long	start_read		= 0x5380;
uint	i				= 0;
uint	k				= 0;
uint	n				= 0;
uint	t				= 0;
uint	rec_len			= 0;
uint	dat_len			= 0;
uint	dll_len			= 0;
FILE	*myself			= 0;
FILE	*cFile			= 0;
FILE	*wt				= 0;
gzFile	data			= 0;
char	*buffer			= 0;
char	*name			= 0;
char	*mls			= 0;
char	*end_flag		= _END;
HMODULE	hDLL			= NULL;
int (*pFunc_read)(gzFile, voidp, unsigned);
gzFile (*pFunc_open)(const char *, const char *);
int (*pFunc_close)(gzFile);


FILE *try_open (char *p, char *flag){
	FILE *fp = 0;
	uint x, y;
	char path[260];
	for (x=0; x<strlen (p); x++){
		if (p[x] == '\\'){
			strcpy (path, p);
			path[x] = 0;
			_mkdir (path);
		}
	}
	fp = fopen (p, flag);
	return fp;
}

int main(int argc, char* argv[]){
	printf ("欢迎使用双双版安装程序制作\n"
		"~~~~~~鄙视我们寝室的色狼们,嘿嘿。\n");
	myself	= fopen (argv[0], "rb");
	system	("@echo off");
	printf	("Install from file:%s\n", argv[0]);
	fseek	(myself, start_read, SEEK_SET);
	fread	(&rec_len, sizeof(uint), 1, myself);
	fread	(&dat_len, sizeof(uint), 1, myself);
	fread	(&dll_len, sizeof(uint), 1, myself);
	printf	("<---------------------------------------->\n"
			"\trec_len:\t%d\n"
			"\tdat_len:\t%d\n"
			"\tdll_len:\t%d\n"
			"\tnow we are:\t0x%08x\n"
			"<---------------------------------------->\n",
			rec_len, dat_len, dll_len, ftell (myself)
			);
	buffer	= malloc (1024);
	
	printf ("开始释放记录文件\n");
	//record
	t		= rec_len;
	cFile	= fopen (_REC, "wb");
	do{
		i = fread (buffer, 1, t>1024?1024:t, myself);
		fwrite	(buffer, 1, t>1024?1024:t, cFile);
		t = t>1024?(t-1024):0;
	}while (t != 0);
	fclose (cFile);
	
	printf ("开始释放数据文件\n");
	//data
	t		= dat_len;
	cFile	= fopen (_DAT, "wb");
	do{
		i = fread (buffer, 1, t>1024?1024:t, myself);
		fwrite	(buffer, 1, t>1024?1024:t, cFile);
		t = t>1024?(t-1024):0;
	}while (t != 0);
	fclose	(cFile);
	
	printf ("开始释放运行时库\n");
	//dll
	t		= dll_len;
	cFile	= fopen (_DLL, "wb");
	do{
		i = fread (buffer, 1, t>1024?1024:t, myself);
		fwrite	(buffer, 1, t>1024?1024:t, cFile);
		t = t>1024?(t-1024):0;
	}while (t != 0);
	fclose	(cFile);
	
	printf ("加载运行所需函数。。。\n");
	fclose	(myself);
	hDLL	= LoadLibrary (_DLL);
	pFunc_read	= GetProcAddress (hDLL, "gzread");
	pFunc_open	= GetProcAddress (hDLL, "gzopen");
	pFunc_close	= GetProcAddress (hDLL, "gzclose");
	
	printf ("对资源文件进行解压\n");
	mls		= malloc (300);
	name	= malloc (260);
	cFile	= fopen  (_REC, "rb");
	data	= pFunc_open (_DAT, "rb");
	if (data == NULL){
		printf ("打开资源文件失败\n");
		return 0;
	}
	else
		printf ("资源文件打开成功\n");
BeginLoop:
	fgets	(mls, 300, cFile);
	if (strncmp (mls, end_flag, strlen(end_flag)) == 0)
		goto ExitLoop;
	sscanf	(mls, "%d:%s", &n, name);
	printf ("开始释放:%s\n", name);
	wt		= fopen (name, "wb");
	if (wt == NULL){
		wt = try_open (name, "wb");
	}
	if (wt == NULL){
		printf ("无法创建文件\n");
		return 0;
	}
	else printf ("\t-->创建文件%s成功\n", name);
	t		= n;
	do{
		t = n>1024?1024:n;
		pFunc_read (data, buffer, t);
		fwrite (buffer, t, 1, wt);
		n -= t;
	}while (t != 0);
	fclose (wt);
	printf ("文件%s释放成功\n", name);
	goto BeginLoop;
ExitLoop:
	
	
	fclose	(cFile);
	pFunc_close	(data);
	free	(mls);
	free	(name);
	system	("del _fuck_dat");
	system	("del _fuck_rec");
	system	("cmd.exe /c if exist _fuck_run.bat _fuck_run.bat");
	system	("cmd.exe /c if exist Installed-Run.bat Installed-Run.bat");
	free 	(buffer);
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -