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

📄 main.cpp

📁 从国外网站上下载的关于 逆向工程和协议分析练习 的一个分析文档 对你的加密与解密很有帮助
💻 CPP
字号:
/*
 *	主程序入口
 */

#include "StdAfx.h"
#include <stdio.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <io.h>
#include <string.h>
#include "eflow.h"
#include "crypt.h"
#include "Getopt.h"
#include "service.h"
#include "options.h"
#include <windows.h>


/**
 * 加密/加密 ethereal export 出的报文内容文件  
 */
static int crypt_file(const char *file,int is_encrypt)
{
	int len;
	int fd;
	unsigned char buf[512];

	fd = open(file,O_RDWR|O_BINARY);
	if (fd < 0)
	{
		perror("open");
		return -1;
	}

	memset(buf,0,sizeof(buf));
	len = read(fd,buf,sizeof(buf));

	if ( is_encrypt )
		encrypt(buf,len);
	else
		decrypt(buf,len);

	lseek(fd,0,SEEK_SET);
	write(fd,buf,len);

	close(fd);
	return 0;
}


static BOOL control_handler(DWORD fdwCtrlType)
{
	switch( fdwCtrlType ) 
	{
	case CTRL_C_EVENT:
	case CTRL_CLOSE_EVENT:
	case CTRL_BREAK_EVENT:
		eflow_stop();
		return TRUE;
	}

	return FALSE;
}


int main(int argc, char* argv[])
{
	int c;
	int opt_encrypt = 0,opt_decrypt = 0,opt_console = 0;
	const char *file = NULL;

	while ( (c = getopt(argc,argv,"cediuh")) != EOF )
	{
		switch (c)
		{
		case 'e':
			opt_encrypt = 1;
			break;
		case 'd':
			opt_decrypt = 1;
			break;
		case 'i':
			service_install();
			return 0;
		case 'u':
			service_uninstall();
			return 0;
		case 'c':
			opt_console = 1;
			break;
		case 'h':
		default:
			fprintf(stderr,"Usage: %s [-(i|u)|c|((e|d) file)] \n"
							"-e		加密数据\n"
							"-d		解密数据\n"
							"-i		安装为服务\n"
							"-u		卸载服务\n"
							"-c		运行在 Console\n",argv[0]);
			return -1;
		}
	}

	if ( (opt_decrypt || opt_encrypt) )
	{
		if ( optind == argc )
		{
			fprintf(stderr,"Pls specify file to encrypt/decrypt\n");
			return -1;
		}

		file = argv[optind];

		return crypt_file(file,opt_encrypt);
	}
	
	if ( eflow_init() < 0 )
	{
		fprintf(stderr,"eflow_init failed\n");
		return -1;
	}

	if ( opt_console )
	{
		g_options.console = opt_console;
		SetConsoleCtrlHandler((PHANDLER_ROUTINE)control_handler,TRUE);
		eflow_loop();
	}
	else
	{
		service_run();
	}
	
	eflow_exit();	
	return 0;
}

⌨️ 快捷键说明

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