?? main.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 + -