ClamAV学习【2】——clamscan入口函数浏览
就简单给代码加上些注释,方便理解。第一次浏览,应该会有不正确的理解。后面会继续学习修改。
文件:clamscan\clamscan.c
代码如下:
nt main(int argc, char **argv)
{
int ds, dms, ret;
double mb;
struct timeval t1, t2;
#ifndef C_WINDOWS
struct timezone tz;
#endif
struct optstruct *opt;
const char *pt; //pthread是一个通用的跨平台高性能线程库
//暂时没发现加入的地方
//在程序开始的时候要调用
#if defined(C_WINDOWS) && defined(CL_THREAD_SAFE)
if(!pthread_win32_process_attach_np()) {
mprintf("!Can't start the win32 pthreads layer\n");
return 72;
}
#endif //这里进行参数解析
//具体规则待会查看下
opt = opt_parse(argc, argv, clamscan_shortopt, clamscan_longopt, NULL);
if(!opt) {
mprintf("!Can't parse the command line\n");
return 40;
} //以下开始进行命令判断
if(opt_check(opt, "verbose")) {
mprintf_verbose = 1;
logg_verbose = 1;
} if(opt_check(opt, "quiet"))
mprintf_quiet = 1; if(opt_check(opt, "stdout"))
mprintf_stdout = 1; if(opt_check(opt, "debug")) {
#if defined(C_LINUX)
/* njh@bandsman.co.uk: create a dump if needed */
struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = RLIM_INFINITY;
if(setrlimit(RLIMIT_CORE, &rlim) < 0)
perror("setrlimit");
#endif
cl_debug(); /* enable debug messages */
} if(opt_check(opt, "version")) {
print_version(opt_arg(opt, "database"));
opt_free(opt);
return 0;
} if(opt_check(opt, "help")) {
opt_free(opt);
help();
return 0;
} if(opt_check(opt, "recursive"))
recursion = 1; if(opt_check(opt, "infected"))
printinfected = 1; if(opt_check(opt, "bell"))
bell = 1; if(opt_check(opt, "tempdir"))
cl_settempdir(opt_arg(opt, "tempdir"), 0); if(opt_check(opt, "leave-temps"))
cl_settempdir(NULL, 1); //日志初始化
if(opt_check(opt, "log")) {
logg_file = opt_arg(opt, "log");
if(logg("#\n-------------------------------------------------------------------------------\n\n")) {
mprintf("!Problem with internal logger.\n");
opt_free(opt);
return 62;
}
} else
logg_file = NULL; //一些数字参数合法化检验 if(opt_check(opt, "max-scansize")) {
pt = opt_arg(opt, "max-scansize");
if(!strchr(pt, 'M') && !strchr(pt, 'm')) {
if(!cli_isnumber(pt)) {
logg("!--max-scansize requires a natural number\n");
opt_free(opt);
return 40;
}
}
} if(opt_check(opt, "max-filesize")) {
pt = opt_arg(opt, "max-filesize");
if(!strchr(pt, 'M') && !strchr(pt, 'm')) {
if(!cli_isnumber(pt)) {
logg("!--max-filesize requires a natural number\n");
opt_free(opt);
return 40;
}
}
} if(opt_check(opt, "max-files")) {
if(!cli_isnumber(opt_arg(opt, "max-files"))) {
logg("!--max-files requires a natural number\n");
opt_free(opt);
return 40;
}
} if(opt_check(opt, "max-recursion")) {
if(!cli_isnumber(opt_arg(opt, "max-recursion"))) {
logg("!--max-recursion requires a natural number\n");
opt_free(opt);
return 40;
}
} if(opt_check(opt, "max-mail-recursion")) {
if(!cli_isnumber(opt_arg(opt, "max-mail-recursion"))) {
logg("!--max-mail-recursion requires a natural number\n");
opt_free(opt);
return 40;
}
} if(opt_check(opt, "max-dir-recursion")) {
if(!cli_isnumber(opt_arg(opt, "max-dir-recursion"))) {
logg("!--max-dir-recursion requires a natural number\n");
opt_free(opt);
return 40;
}
} if(opt_check(opt, "max-ratio")) {
if(!cli_isnumber(opt_arg(opt, "max-ratio"))) {
logg("!--max-ratio requires a natural number\n");
opt_free(opt);
return 40;
}
} memset(&info, 0, sizeof(struct s_info)); //设置默认的文件I/O操作
//Windows下二进制
//DEBUG下设置报告方式?
#ifdef C_WINDOWS
_set_fmode(_O_BINARY);
#ifdef CL_DEBUG
{
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
}
#endif
gettimeofday(&t1, NULL);
#else
gettimeofday(&t1, &tz);
#endif //这里就开始调用一个扫描的管理类方法来扫毒
//返回的ret说明信息
ret = scanmanager(opt); //下面开始就是日志记录?
if(!opt_check(opt, "disable-summary") && !opt_check(opt, "no-summary")) {
#ifdef C_WINDOWS
gettimeofday(&t2, NULL);
#else
gettimeofday(&t2, &tz);
#endif
ds = t2.tv_sec - t1.tv_sec;
dms = t2.tv_usec - t1.tv_usec;
ds -= (dms < 0) ? (1):(0);
dms += (dms < 0) ? (1000000):(0);
logg("\n----------- SCAN SUMMARY -----------\n");
logg("Known viruses: %u\n", info.sigs);
logg("Engine version: %s\n", cl_retver());
logg("Scanned directories: %u\n", info.dirs);
logg("Scanned files: %u\n", info.files);
logg("Infected files: %u\n", info.ifiles);
if(info.notremoved) {
logg("Not removed: %u\n", info.notremoved);
}
if(info.notmoved) {
logg("Not %s: %u\n", opt_check(opt, "copy") ? "moved" : "copied", info.notmoved);
}
mb = info.blocks * (CL_COUNT_PRECISION / 1024) / 1024.0;
logg("Data scanned: %2.2lf MB\n", mb);
logg("Time: %u.%3.3u sec (%u m %u s)\n", ds, dms/1000, ds/60, ds%60);
} opt_free(opt); //对应于上面的pthread开始函数
#if defined(C_WINDOWS) && defined(CL_THREAD_SAFE)
if(!pthread_win32_process_detach_np()) {
logg("!Can't stop the win32 pthreads layer\n");
return 72;
}
#endif return ret;
}
原文:http://blog.csdn.net/betabin/article/details/7421910
ClamAV学习【2】——clamscan入口函数浏览的更多相关文章
- C++学习--入口函数
在学习第一个C++程序的时候发现控制台程序的入口函数是int _tmain而不是main,查了资料才发现_tmain()是为了支持unicode所使用的main一个别名,宏定义在<stdafx. ...
- JQuery学习:事件绑定&入口函数&样式控制
1.基础语法学习: 1.事件绑定 2.入口函数 3.样式控制 <!DOCTYPE html> <html lang="en"> <head> & ...
- Egret 学习之 入口函数 及开始编写程序(三)
1,Egret的程序入口: C和java是以一个main函数作为入口,但egret类似于ActionScript 是以一个文档类作为入口,确切的说是以这个文档类的构造函数作为入口: 2,文档类的构造函 ...
- Qt Windows下链接子系统与入口函数(终结版)(可同时存在main和WinMain函数)
Qt Windows下链接子系统与入口函数(终结版) 转载自:http://blog.csdn.net/dbzhang800/article/details/6358996 能力所限,本讨论仅局限于M ...
- C++的入口函数
我们最开始学习c++时,就知道要写一个main()函数,并且知道这是整个函数的入口,但是c++不只有main()函数这一个入口. 一.对于不同的程序函数入口是不同的. main()是WINDOWS的控 ...
- 2、jQuery的基本概念-必看-版本-入口函数- jq对象和dom对象区别
1.4. jQuery的版本 官网下载地址:http://jquery.com/download/ jQuery版本有很多,分为1.x 2.x 3.x 大版本分类: 1.x版本:能够兼容IE678浏览 ...
- 01-老马jQuery教程-jQuery入口函数及选择器
前言 这套jQuery教程是老马专门为寒门子弟而录制,希望大家看到后能转发给更多的寒门子弟.视频都是免费,请参考课程地址:https://chuanke.baidu.com/s5508922.html ...
- u-boot-1.1.6第2阶段入口函数start_armboot分析
学习目标: 1.分析u-boot-1.1.6第2阶段入口函数void start_armboot (void),熟悉该函数所实现的功能 2.为后面能够掌握u-boot-1.1.6如何启动内核过程打下基 ...
- [C#] 了解过入口函数 Main() 吗?带你用批处理玩转 Main 函数
了解过入口函数 Main() 吗?带你用批处理玩转 Main 函数 目录 简介 特点 方法的参数 方法的返回值 与批处理交互的一个示例 简介 我们知道,新建一个控制台应用程序的时候,IDE 会同时创建 ...
随机推荐
- Git----时光穿梭机之撤销修改05
自然,你是不会犯错,不过现在是凌晨两点,你正在赶一份工作报告,你在readme.txt中添加了一行: $ cat readme.txtGit is a distributed version cont ...
- 下拉列表插件bootstrap-select使用实例
网页实例 http://www.jq22.com/yanshi302 使用bootstrap-select插件来实现下来菜单搜索匹配功能,如图 实现代码如下 <html> <head ...
- LUA表与函数的深入理解
local heroInfo = {} --直接打印 table的名字,就会输出该table的内存地址 print("表地址---------------",heroInfo) - ...
- hibernate查询出的实体,set值后,自动更新到数据库
1.问题症状描述 最近在处理一个新需求问题,代码的大致逻辑是获取一个实体对象,调用该对象的set方法设置其中的某些字段,然后把修改后的实体作为参数供其他地方调用,根据返回值来决定是否更新这个 ...
- 什么是First-class citizen?
[什么是First-class citizen?] In programming language design, a first-class citizen (also type, object, ...
- sql unsigned
1.数字类型无符号化,取0以上的值 学习传送门 http://www.cnblogs.com/blankqdb/archive/2012/11/03/blank_qdb.html
- 宽字符、多字节、unicode、utf-8、gbk编码转化
今天遇到一个编码的问题,困惑了我很长时间,所以就简要的的了解了一下常用的编码类型. 我们最常见的是assic编码,它是一种单字节编码,对多容纳256个字符. 我们在编程的时候经常遇到unicode,u ...
- [Jmeter]如何才能通过ant运行jmeter
在开始运行build.xml之前,还有一步必须要做,那就是将JMeter所在目录下extras子目录里的ant-JMeter-1.1.1.jar复制到Ant所在目录lib子目录之下,这样Ant运行时才 ...
- max文件属性设置,
之前一直都没找到 用到的时候就是用net 弄了.哎.还在开发东西都是在9上面, 这次脚本必须在 max8 上面 逼的我找到了他 getFileAttribute <filename_string ...
- C语言基础课First作业
一.大学和高中最大的不同是没有人天天看着你,也不会担心上课的时候班主任在后门偷偷瞄着我们,通过阅读邹欣老师的博客后,心目中理想的师生关系就是Coach/Trainee(健身教练/健身学员)的关系,想到 ...