自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

逆风飞扬

关注 Unix高性能服务器/Big Data/数据挖掘/海量数据处理/用户行为分析/个性化推荐算法

  • 博客(220)
  • 资源 (50)
  • 收藏
  • 关注

原创 Rocksdb源码剖析一----Rocksdb概述与基本组件

因为本人对一些经典的开源项目很有兴趣,也想从大牛设计的开源系统中学习架构设计经验,所以喜欢分析一些开源代码,这次因为项目中需要使用rocksdb,故在使用的时候仔细分析了rocksdb的实现细节,从2015年11月11日下决心整理出这一系列的blog,也算是对工作的总结吧。分享出来希望能帮到有需要的朋友。因为之前已经读完LevelDB的源码,读的过程中也参考了网上的相关文章,此小节的介绍会与Lev

2015-11-29 16:38:59 29534 6

原创 GNU c __attribute__详解

GNU C的一大特色就是__attribute__机制。__attribute__可以设置函数属性(Function  Attribute)、变量属性(Variable Attribute)和类型属性(Type Attribute)。__attribute__书写特征是:__attribute__前后都有两个下划线,并切后面会紧跟一对原括弧,括弧里面是相应的__attribute__参数。

2015-01-22 20:16:08 2036

原创 redis 持久化机制AOF/RDB详解

Redis作为一个使用广泛的KV内存存储,其也支持一定的数据持久化,这里试着介绍一下Redis在源码层面对持久化的实现机制。总的来说,Redis支持的将其数据库里面的KV数据存储到磁盘,但可能会有短时间的丢失。官网关于持久化的介绍可以参考这里“Redis Persistence”,这篇文章介绍一下其在代码层面的实现。其支持2中不同的持久化机制:第一种RDB数据快照持久化。R

2014-11-27 15:43:21 1729

原创 redis源码分析-rehash过程详解

hash table是一种高效的数据结构,被广泛的用在key-value存储中,Redis的dict其实就是一个典型的hash table实现。rehash是在hash table的大小不能满足需求,造成过多hash碰撞后需要进行的扩容hash table的操作,其实通常的做法确实是建立一个额外的hash table,将原来的hash table中的数据在新的数据中进行重新输入,从而生成新

2014-11-27 15:31:09 2970

翻译 程序员可以在周末做的 8 件事

我希望,如果你是一个程序员,你的周末计划,可以说一下你的想法。1. 把时间给家人和朋友。在平日技术领域的程序员通常都很忙,所以周末的时间就留给你的家人和朋友。这也是其他领域的人该做的。2. 一天没有电脑(无电脑日)有些人曾试图没有科技,这意味着在白天不使用任何技术。电脑完全断开这可能是不现实的,但至少有一些是可以避免的。不接触电脑基本

2014-10-25 14:18:37 1183

原创 TinyXML:一个优秀的C++ XML解析器

/*读取和设置xml配置文件是最常用的操作,试用了几个C++的XML解析器,个人感觉TinyXML是使用起来最舒服的,因为它的API接口和Java的十分类似,面向对象性很好。TinyXML是一个开源的解析XML的解析库,能够用于C++,能够在Windows或Linux中编译。这个解析库的模型通过解析XML文件,然后在内存中生成DOM模型,从而让我们很方便的遍历这棵XML树。DOM模型即文档对

2014-10-25 12:06:05 708

原创 Dynamic Programming: From novice to advanced

Dynamic Programming: From novice to advancedAn important part of given problems can be solved with the help of dynamic programming (DP for short). Being able to tackle problems of this type wo

2014-10-25 11:27:30 851

原创 Linux并发模型

Linux并发模型  目前可以实现并发程序的方法有Apache模型(Process Per Connection,简称PPC),TPC(Thread PerConnection)模型,以及select模型和poll模型、Epoll模型。各种模型优缺点  Apache模型和TPC模型是最容易理解的,Apache模型在并发上是通过多进程实现的,而TPC模型是通过多线程实现的

2014-10-25 11:25:01 1155

原创 linux sort 命令 指定分隔符

linux下的sort命令可以对文本的某些字段进行排序,而字段之间的分隔符默认是空格,如果想换成别的,则需要加参数-t。但是对于tab分隔符,还是得稍微注意一下。比如下面的命令:$sort -t '\t' -k3,3n a.txt >a.sortsort: multi-character tab `\t'  (出错)这个不能按照tab分隔符进行字段排序,换成如下

2014-07-25 13:10:41 23598

原创 linux 同步IO:sync、fsync与fdatasync

传统的UNIX实现在内核中设有缓冲区高速缓存或页面高速缓存,大多数磁盘I/O都通过缓冲进行。当将数据写入文件时,内核通常先将该数据复制到其中一个缓冲区中,如果该缓冲区尚未写满,则并不将其排入输出队列,而是等待其写满或者当内核需要重用该缓冲区以便存放其他磁盘块数据时,再将该缓冲排入输出队列,然后待其到达队首时,才进行实际的I/O操作。这种输出方式被称为延迟写(delayed write)(Bach

2014-05-21 20:16:49 1224

原创 Redis 数据结构之ziplist

Redis中压缩链表ziplist数据结构与API相关文件是:ziplist.h, ziplist.c, t_zset.c。一、ziplist的构成是一个4字节无符号整数,用来存储整个ziplist占用的字节数;是一个4字节无符号整数,用来存储ziplist最后一个节点的相对于ziplist首地址偏移量;是一个2字节无符号整数,存储zipli

2014-05-15 19:17:20 2263

原创 Redis 数据结构之 zipmap 内存布局分析

Redis被称为key/value应用中的瑞士军刀,除了其丰富的数据结构支持,更重要的是高效的内存使用,分析源码可以发现作者使用每一个 byte都精打细算。在hashtable实现中,Redis引入了zipmap数据结构,保证在hashtable刚创建以及元素较少时,用更少的内存 来存储,同时对查询的效率也不会受太大的影响。下面就以源码和例子结合的方式来分析一下zipmap的内存布局。先来

2014-05-15 18:56:37 967

原创 redis数据结构之 intset

整数集合intset用于有序、无重复地保存多个整数值,根据集合中元素的值自动选择使用整数类型来保存元素,例如:如果intset中绝对值最大的整数可以用int32_t来保存,那么整个intset中所有元素都使用int32_t来保存。如果当前intset所使用的类型不能保存一个即将加入到该intset的新元素时候,需要对intset进行升级,比如新元素的类型是int64_t,而当前intset

2014-05-15 11:40:42 953

原创 用python查看和更改系统默认编码

python在安装时,默认的编码是ascii,当程序中出现非ascii编码时,python的处理常常会报这样的错UnicodeDecodeError: 'ascii' codec can't decode byte 0x?? in position 1: ordinal not in range(128),python没办法处理非ascii编码的,此时需要自己设置将python的默认编码,一般设置

2014-05-13 12:01:30 1389

原创 GBK与UTF8编码互转的C++版

下面是GBK与UTF8互转的C++实现,

2014-05-09 16:42:18 5668 1

原创 Hadoop Streaming 使用介绍

Hadoop StreamingHadoop streaming is a utility that comes with the Hadoop distribution. The utility allows you to create and run Map/Reduce jobs with any executable or script as the mapper and/or t

2014-05-09 15:29:13 891

原创 Python里的string 和 unicode --2

先说一下,前面提到,print(string)的时候,如果string是按当前环境编码方式编码的,可以正常输出,不会乱码;如果string不是当前编码的,就会乱码。而print(unicode)是不会乱码的。why?应为print(unicode)的时候,会把unicode先转成当前编码,然后再输出。我没看过print的源码,不过估计是这样的。string转unicode或者unicode

2014-05-09 15:19:45 756

原创 Python里的string 和 unicode

在python里,string object和unicode object是两种不同的类型。string object是由characters组成的sequence,而unicode object是Unicode code units组成的sequence。string里的character是有多种编码方式的,比如单字节的ASCII,双字节的GB2312等等,再比如UTF-8。很明

2014-05-09 15:19:05 720

原创 Linux进程间通信

一、进程间通信概述进程通信有如下一些目的:A、数据传输:一个进程需要将它的数据发送给另一个进程,发送的数据量在一个字节到几M字节之间B、共享数据:多个进程想要操作共享数据,一个进程对共享数据的修改,别的进程应该立刻看到。C、通知事件:一个进程需要向另一个或一组进程发送消息,通知它(它们)发生了某种事件(如进程终止时要通知父进程)。D、资源共享:多个进程之间共享同样的资源。为了作

2014-04-30 19:25:26 781

原创 Redis安装部署

1       概要Redis服务器环境的安装。指导系统部署和维护使用,以64位Linux环境下安装使用2       缩略语和术语缩略语/术语全  称说  明append only file(aof)全持久化模式 

2014-04-30 19:23:10 795

原创 redis设计思想

不同于nginx的精雕细琢,redis代码的风格趋向于简洁实用。简洁启事,下面所述不再列举任何源码,不拼凑任何外来资料。去除末枝,下面直入redis主题,尽可能简洁地描述redis的设计思想。 整体模型:单进程单线程事件驱动模式。Redis在主处理流程中,采用了单进程接受各种client请求并返回结果,整体处理流程采用事件驱动的方式进行。通过其IO复用的方式监听aeEven

2014-04-30 19:18:31 995

原创 The architecture of REDIS

REDIS is an open source, advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets. Redis works with an in-memo

2014-04-30 19:17:50 1705

原创 Redis源码解析—源码目录介绍

概念      redis是一个key-value存储系统。和Memcached类似,它支持存储的value类型相对更多,包括string(字符串)、list(链表)、set(集合)和zset(有序集合)。这些数据类型都支持push/pop、add/remove及取交集并集和差集及更丰富的操作,而且这些操作都是原子性的。在此基础上,redis支持各种不同方式的排序。与memcached一样

2014-04-30 19:17:00 684

原创 typedef 函数指针的用法

进入正文: 代码简化, 促进跨平台开发的目的. typedef 行为有点像 #define 宏,用其实际类型替代同义字。 不同点:typedef 在编译时被解释,因此让编译器来应付超越预处理器能力的文本替换。用法一:typedef int (*MYFUN)(int, int); 这种用法一般用在给函数定义别名的时候上面的例子定义MYFUN 是一个函数

2014-04-30 19:13:42 540

原创 Redis源码简要分析

在文章的开头我们把所有服务端文件列出来,并且标示出其作用:adlist.c //双向链表ae.c //事件驱动ae_epoll.c //epoll接口, linux用ae_kqueue.c //kqueue接口, freebsd用ae_select.c //select接口, windows用anet.c //网络处理aof.c //处理AOF文件config.c

2014-04-30 19:10:58 663

原创 Redis运行流程源码解析

概述  Redis通过定义一个 struct redisServer 类型的全局变量server 来保存服务器的相关信息(比如:配置信息,统计信息,服务器状态等等)。启动时通过读取配置文件里边的信息对server进行初始化(如果没有指定配置文件,将使用默认值对sever进行初始化),初始化的内容有:起监听端口,绑定有新连接时的回调函数,绑定服务器的定时函数,虚拟内存初始化,log初始化等等

2014-04-30 19:06:56 776

原创 一个“轻量级” C 语言协程库

协程(coroutine)顾名思义就是“协作的例程”(co-operative routines)。跟具有操作系统概念的线程不一样,协程是在用户空间利用程序语言的语法语义就能实现逻辑上类似多任务的编程技巧。实际上协程的概念比线程还要早,按照 Knuth 的说法“子例程是协程的特例”,一个子例程就是一次子函数调用,那么实际上协程就是类函数一样的程序组件,你可以在一个线程里面轻松创建数十万个协程,就像

2014-01-28 14:47:32 2281

原创 memcached源码剖析系列之内存存储机制(三)

在memcached内存存储机制剖析的前两篇中,已分析过memcached的内存管理器初始化机制及slab的管理分配机制。接下来我们就来探讨下对象item的分配管理及LRU机制。1 item关键数据结构(1)item结构体原型typedef struct _stritem { struct _stritem *next; struct _strite

2014-01-27 15:36:17 893

原创 memcached源码剖析系列之内存存储机制(二)

在上一节中已经分析了memcached的内存分配管理初始化机制,在这节中我们将详细分析memcached中slab的管理与分配机制。slabclass[MAX_NUMBER_OF_SLAB_CLASSES]数组是slab管理器(类型见上节),是memcached内存管理的核心数据结构,起着非常重要的作用。slabclass[i]的内存示意图如下图所示: (1

2014-01-27 15:33:50 1027

原创 Memcached源码剖析系列之内存存储机制(一)

一 内存分配管理机制    memcached是一个高性能的,分布式内存对象缓存系统,用于在动态系统中减少数据库负载,提升性能。memcached有一个很有特色的内存管理方式,为了提高效率,默认情况下采用了名为Slab Allocator的机制分配管理内存空间。       memcached文档中关于slab allocator有这么一段话:    the primary

2014-01-27 15:32:00 1118

原创 memcached源码分析之线程池机制(二)

在上一篇中已分析了memcached线程池的创建流程,由于上篇篇幅较长,因此将memcached线程池中线程的调度流程另立一篇。先让我们把目光转到主函数中,主线程在调用thread_init函数创建好线程池后,就开始创建监听套接字,memcached支持TCP,UDP,UNIX域套接字,因此相应的要创建三种监听套接字这里我们只分析TCP listening socket的创建(UD

2014-01-27 15:31:04 732

原创 memcached源码分析之线程池机制(一)

已经个把月没有写长篇博文了,最近抽了点时间,将memcached源码分析系列文章的线程机制篇给整出来,在分析源码的过程中参考了网上的一些资源。该文主要集中于两个问题:(1)memcached线程池是如何创建的,(2)线程池中的线程又是如何进行调度的。一切从源码中找答案。memcached的线程池模型采用较典型的Master-Worker模型:(1)主线程负责监听客户端的建立

2014-01-27 15:29:57 788

原创 SecureCRT右键粘贴的设置

1、习惯用putty的朋友,一般都习惯鼠标右键自动粘贴的功能,对于SecureCRT6.0.2 ,这个功能也已经是默认配置了。  老版本的SecureCRT其实也有这个功能,只是不是默认设置,很多人不知道罢了。    菜单:  Options->Global Options ...->Terminal    里面有个Mouse的选项块。  Copy on Select 

2014-01-07 20:10:14 2016

原创 shell 中判断值是否已经在数组中

1.echo "${array[@]}" | grep -wq "$var" &&  echo "Yes" || echo "No"2.for i in ${array[@]}do   [ "$i" == "$var" ] && echo "yes"done3.test_array (){y_n=$1arr

2013-07-29 21:32:29 19408

原创 查看 linux 命令源代码的方法

用linux一段时间了,有时候想看看ls、cat、more等命令的源代码,在下载的内核源码中用cscope没能找到,在网上搜索了一下,将方 法总结如下:查看源代码主要有两种方式:基于debian的:以搜索ls命令源码为例,先搜索命令所在包,命令如下:lpj@lpj-linux:~$ which ls/bin/ls用命令搜索该软件所在包,代码如下:lpj@lpj-linu

2013-07-05 14:50:02 2980

原创 /proc详解--linux man page

proc(5) - Linux man pageNameproc - process information pseudo-file systemDescriptionThe proc file system is a pseudo-file system which is used as an interface to kernel data structures. It is

2013-07-05 10:12:38 5055

原创 使用shell 脚本对 Linux 系统进程的CPU使用率与内存资源进行监控

Shell 简介Shell 语言对于接触 LINUX 的人来说都比较熟悉,它是系统的用户界面,提供了用户与内核进行交互操作的一种接口。它接收用户输入的命令并把它送入内核去执行。实际上 Shell 是一个命令解释器,它解释由用户输入的命令并且把它们送到内核。它没有一般编程语言的“编译 - 链接 - 运行”过程。不仅如此,Shell 有自己的编程语言用于对命令的编辑,它允许用户编写由 shell 

2013-07-05 10:10:19 10691

原创 About size_t and ptrdiff_t

AbstractIntroductionsize_t typeptrdiff_t typePortability of size_t and ptrdiff_tSafety of ptrdiff_t and size_t types in address arithmeticPerformance of code using ptrdiff_t and size_tCo

2013-06-27 16:25:17 1089

原创 scanf函数的缓冲区问题

用户输入中多余的数据会丢失吗?scanf函数执行时是否每次都暂停程序的执行以等待用户的输入?答:用户的输入会存储输入缓冲区,而scanf函数只会到输入缓冲区中读取数据。输入缓冲区连接了用户和scanf函数。如何理解“当用户一次输入多个数据时,数据之间常用空格或回车分隔”?答:当遇到空格符或回车符时,scanf函数的处理分二种情况。第一种情况发生在数据匹配正在进行时,即已经有成功

2013-06-21 13:21:15 1659

原创 mysql update完root用户密码后,再登陆报错”Access denied for user 'root'@'localhost' (using password: YES)“的解决方法

1.mysql 更改root用户密码后,再重新登陆系统时会产生如下的错误:Access denied for user 'root'@'localhost' (using password: YES),这是由于更改用户密码后没有给予权限造成的。同时,在修改密码后用新密码登陆时,提示如下的错误:Access denied for user ''@'localhost' (usin

2013-05-17 11:42:07 1693

与TensorFlow第一次接触

Tensorflow入门经典小书,翻译自英文原版,适合工程师快速入门学习

2018-03-23

深入理解C++11:C++11新特性解析与应用 高清pdf

《深入理解C++11:C++11新特性解析与应用》内容简介:国内首本全面深入解读C++11新标准的专著,由C++标准委员会代表和IBM XL编译器中国开发团队共同撰写。不仅详细阐述了C++11标准的设计原则,而且系统地讲解了C++11新标准中的所有新语言特性、新标准库特性、对原有特性的改进,以及如何应用所有这些新特性。

2016-06-28

lua源码欣赏--云风 高清pdf

lua源码欣赏 云风写的,高清pdf,值的学习,分析lua源码的好资料

2015-05-14

linux命令源代码

linux命令源代码,具有很高的参考价值,可以学习C/SHELL的编程技巧,懂的朋友可以下了看看

2013-07-05

Doom3 源代码 毁灭战士

Doom3 源代码 毁灭战士 《毁灭战士3》(Doom 3)由id Software开发,计算机版于2004年8月3日由Activision发行,是一款杂恐怖与科幻于一身的第一人称射击游戏。游戏故事除了英文名称外,并未有完全跟随《毁灭战士》的发展,并采用了全新的图像和游戏发动机。

2012-02-28

quake3-1.32b-source

这是quake 3的源代码,欢迎使用下载。非常好的学习资料-This is the quake 3 source code, please use the download. Very good learning materials

2012-02-28

王纯业版Python学习笔记

学习python的参考资料~~python的参考资料~~

2011-11-25

[高质量程序设计指南.C.C语言(第三版)].林锐.高清扫描版

真正的《高质量程序设计指南.C.C++语言(第三版)]》,pdf版 高清pdf

2011-10-17

Google C++ Style Guide(Google C++编程规范)高清PDF

Table of Contents Header Files The #define Guard Header File Dependencies Inline Functions The -inl.h Files Function Parameter Ordering Names and Order of Includes Scoping Namespaces Nested Classes Nonmember, Static Member, and Global Functions Local Variables Static and Global Variables Classes Doing Work in Constructors Default Constructors Explicit Constructors Copy Constructors Structs vs. Classes Inheritance Multiple Inheritance Interfaces Operator Overloading Access Control Declaration Order Write Short Functions Google-Specific Magic Smart Pointers cpplint Other C++ Features Reference Arguments Function Overloading Default Arguments Variable-Length Arrays and alloca() Friends Exceptions Run-Time Type Information (RTTI) Casting Streams Preincrement and Predecrement Use of const Integer Types 64-bit Portability Preprocessor Macros 0 and NULL sizeof Boost C++0x Naming General Naming Rules File Names Type Names Variable Names Constant Names Function Names Namespace Names Enumerator Names Macro Names Exceptions to Naming Rules Comments Comment Style File Comments Class Comments Function Comments Variable Comments Implementation Comments Punctuation, Spelling and Grammar TODO Comments Deprecation Comments Formatting Line Length Non-ASCII Characters Spaces vs. Tabs Function Declarations and Definitions Function Calls Conditionals Loops and Switch Statements Pointer and Reference Expressions Boolean Expressions Return Values Variable and Array Initialization Preprocessor Directives Class Format Constructor Initializer Lists Namespace Formatting Horizontal Whitespace Vertical Whitespace Exceptions to the Rules Existing Non-conformant Code Windows Code Important Note Displaying Hidden Details in this Guide link ▶This style guide contains many details that are initially hidden from view. They are marked by the triangle icon, which you see here on your left. Click it now. You should see "Hooray" appear below. Hooray! Now you know you can expand points to get more details. Alternatively, there's an "expand all" at the top of this document. Background C++ is the main development language used by many of Google's open-source projects. As every C++ programmer knows, the language has many powerful features, but this power brings with it complexity, which in turn can make code more bug-prone and harder to read and maintain. The goal of this guide is to manage this complexity by describing in detail the dos and don'ts of writing C++ code. These rules exist to keep the code base manageable while still allowing coders to use C++ language features productively. Style, also known as readability, is what we call the conventions that govern our C++ code. The term Style is a bit of a misnomer, since these conventions cover far more than just source file formatting. One way in which we keep the code base manageable is by enforcing consistency. It is very important that any programmer be able to look at another's code and quickly understand it. Maintaining a uniform style and following conventions means that we can more easily use "pattern-matching" to infer what various symbols are and what invariants are true about them. Creating common, required idioms and patterns makes code much easier to understand. In some cases there might be good arguments for changing certain style rules, but we nonetheless keep things as they are in order to preserve consistency. Another issue this guide addresses is that of C++ feature bloat. C++ is a huge language with many advanced features. In some cases we constrain, or even ban, use of certain features. We do this to keep code simple and to avoid the various common errors and problems that these features can cause. This guide lists these features and explains why their use is restricted. Open-source projects developed by Google conform to the requirements in this guide. Note that this guide is not a C++ tutorial: we assume that the reader is familiar with the language. Header Files In general, every .cc file should have an associated .h file. There are some common exceptions, such as unittests and small .cc files containing just a main() function. Correct use of header files can make a huge difference to the readability, size and performance of your code. The following rules will guide you through the various pitfalls of using header files. The #define Guard link ▶All header files should have #define guards to prevent multiple inclusion. The format of the symbol name should be ___H_. To guarantee uniqueness, they should be based on the full path in a project's source tree. For example, the file foo/src/bar/baz.h in project foo should have the following guard: #ifndef FOO_BAR_BAZ_H_ #define FOO_BAR_BAZ_H_ ... #endif // FOO_BAR_BAZ_H_ Header File Dependencies link ▶Don't use an #include when a forward declaration would suffice. When you include a header file you introduce a dependency that will cause your code to be recompiled whenever the header file changes. If your header file includes other header files, any change to those files will cause any code that includes your header to be recompiled. Therefore, we prefer to minimize includes, particularly includes of header files in other header files. You can significantly minimize the number of header files you need to include in your own header files by using forward declarations. For example, if your header file uses the File class in ways that do not require access to the declaration of the File class, your header file can just forward declare class File; instead of having to #include "file/base/file.h". How can we use a class Foo in a header file without access to its definition? We can declare data members of type Foo* or Foo&. We can declare (but not define) functions with arguments, and/or return values, of type Foo. (One exception is if an argument Foo or const Foo& has a non-explicit, one-argument constructor, in which case we need the full definition to support automatic type conversion.) We can declare static data members of type Foo. This is because static data members are defined outside the class definition. On the other hand, you must include the header file for Foo if your class subclasses Foo or has a data member of type Foo. Sometimes it makes sense to have pointer (or better, scoped_ptr) members instead of object members. However, this complicates code readability and imposes a performance penalty, so avoid doing this transformation if the only purpose is to minimize includes in header files. Of course, .cc files typically do require the definitions of the classes they use, and usually have to include several header files. Note: If you use a symbol Foo in your source file, you should bring in a definition for Foo yourself, either via an #include or via a forward declaration. Do not depend on the symbol being brought in transitively via headers not directly included. One exception is if Foo is used in myfile.cc, it's ok to #include (or forward-declare) Foo in myfile.h, instead of myfile.cc. Inline Functions link ▶Define functions inline only when they are small, say, 10 lines or less. Definition: You can declare functions in a way that allows the compiler to expand them inline rather than calling them through the usual function call mechanism. Pros: Inlining a function can generate more efficient object code, as long as the inlined function is small. Feel free to inline accessors and mutators, and other short, performance-critical functions. Cons: Overuse of inlining can actually make programs slower. Depending on a function's size, inlining it can cause the code size to increase or decrease. Inlining a very small accessor function will usually decrease code size while inlining a very large function can dramatically increase code size. On modern processors smaller code usually runs faster due to better use of the instruction cache. Decision: A decent rule of thumb is to not inline a function if it is more than 10 lines long. Beware of destructors, which are often longer than they appear because of implicit member- and base-destructor calls! Another useful rule of thumb: it's typically not cost effective to inline functions with loops or switch statements (unless, in the common case, the loop or switch statement is never executed). It is important to know that functions are not always inlined even if they are declared as such; for example, virtual and recursive functions are not normally inlined. Usually recursive functions should not be inline. The main reason for making a virtual function inline is to place its definition in the class, either for convenience or to document its behavior, e.g., for accessors and mutators. The -inl.h Files link ▶You may use file names with a -inl.h suffix to define complex inline functions when needed. The definition of an inline function needs to be in a header file, so that the compiler has the definition available for inlining at the call sites. However, implementation code properly belongs in .cc files, and we do not like to have much actual code in .h files unless there is a readability or performance advantage. If an inline function definition is short, with very little, if any, logic in it, you should put the code in your .h file. For example, accessors and mutators should certainly be inside a class definition. More complex inline functions may also be put in a .h file for the convenience of the implementer and callers, though if this makes the .h file too unwieldy you can instead put that code in a separate -inl.h file. This separates the implementation from the class definition, while still allowing the implementation to be included where necessary. Another use of -inl.h files is for definitions of function templates. This can be used to keep your template definitions easy to read. Do not forget that a -inl.h file requires a #define guard just like any other header file. Function Parameter Ordering link ▶When defining a function, parameter order is: inputs, then outputs. Parameters to C/C++ functions are either input to the function, output from the function, or both. Input parameters are usually values or const references, while output and input/output parameters will be non-const pointers. When ordering function parameters, put all input-only parameters before any output parameters. In particular, do not add new parameters to the end of the function just because they are new; place new input-only parameters before the output parameters. This is not a hard-and-fast rule. Parameters that are both input and output (often classes/structs) muddy the waters, and, as always, consistency with related functions may require you to bend the rule. Names and Order of Includes link ▶Use standard order for readability and to avoid hidden dependencies: C library, C++ library, other libraries' .h, your project's .h. All of a project's header files should be listed as descentants of the project's source directory without use of UNIX directory shortcuts . (the current directory) or .. (the parent directory). For example, google-awesome-project/src/base/logging.h should be included as #include "base/logging.h" In dir/foo.cc, whose main purpose is to implement or test the stuff in dir2/foo2.h, order your includes as follows: dir2/foo2.h (preferred location — see details below). C system files. C++ system files. Other libraries' .h files. Your project's .h files. The preferred ordering reduces hidden dependencies. We want every header file to be compilable on its own. The easiest way to achieve this is to make sure that every one of them is the first .h file #included in some .cc. dir/foo.cc and dir2/foo2.h are often in the same directory (e.g. base/basictypes_test.cc and base/basictypes.h), but can be in different directories too. Within each section it is nice to order the includes alphabetically. For example, the includes in google-awesome-project/src/foo/internal/fooserver.cc might look like this: #include "foo/public/fooserver.h" // Preferred location. #include #include #include #include #include "base/basictypes.h" #include "base/commandlineflags.h" #include "foo/public/bar.h" Scoping Namespaces link ▶Unnamed namespaces in .cc files are encouraged. With named namespaces, choose the name based on the project, and possibly its path. Do not use a using-directive. Definition: Namespaces subdivide the global scope into distinct, named scopes, and so are useful for preventing name collisions in the global scope. Pros: Namespaces provide a (hierarchical) axis of naming, in addition to the (also hierarchical) name axis provided by classes. For example, if two different projects have a class Foo in the global scope, these symbols may collide at compile time or at runtime. If each project places their code in a namespace, project1::Foo and project2::Foo are now distinct symbols that do not collide. Cons: Namespaces can be confusing, because they provide an additional (hierarchical) axis of naming, in addition to the (also hierarchical) name axis provided by classes. Use of unnamed spaces in header files can easily cause violations of the C++ One Definition Rule (ODR). Decision: Use namespaces according to the policy described below. Unnamed Namespaces Unnamed namespaces are allowed and even encouraged in .cc files, to avoid runtime naming conflicts: namespace { // This is in a .cc file. // The content of a namespace is not indented enum { kUnused, kEOF, kError }; // Commonly used tokens. bool AtEof() { return pos_ == kEOF; } // Uses our namespace's EOF. } // namespace However, file-scope declarations that are associated with a particular class may be declared in that class as types, static data members or static member functions rather than as members of an unnamed namespace. Terminate the unnamed namespace as shown, with a comment // namespace. Do not use unnamed namespaces in .h files. Named Namespaces Named namespaces should be used as follows: Namespaces wrap the entire source file after includes, gflags definitions/declarations, and forward declarations of classes from other namespaces: // In the .h file namespace mynamespace { // All declarations are within the namespace scope. // Notice the lack of indentation. class MyClass { public: ... void Foo(); }; } // namespace mynamespace // In the .cc file namespace mynamespace { // Definition of functions is within scope of the namespace. void MyClass::Foo() { ... } } // namespace mynamespace The typical .cc file might have more complex detail, including the need to reference classes in other namespaces. #include "a.h" DEFINE_bool(someflag, false, "dummy flag"); class C; // Forward declaration of class C in the global namespace. namespace a { class A; } // Forward declaration of a::A. namespace b { ...code for b... // Code goes against the left margin. } // namespace b Do not declare anything in namespace std, not even forward declarations of standard library classes. Declaring entities in namespace std is undefined behavior, i.e., not portable. To declare entities from the standard library, include the appropriate header file. You may not use a using-directive to make all names from a namespace available. // Forbidden -- This pollutes the namespace. using namespace foo; You may use a using-declaration anywhere in a .cc file, and in functions, methods or classes in .h files. // OK in .cc files. // Must be in a function, method or class in .h files. using ::foo::bar; Namespace aliases are allowed anywhere in a .cc file, anywhere inside the named namespace that wraps an entire .h file, and in functions and methods. // Shorten access to some commonly used names in .cc files. namespace fbz = ::foo::bar::baz; // Shorten access to some commonly used names (in a .h file). namespace librarian { // The following alias is available to all files including // this header (in namespace librarian): // alias names should therefore be chosen consistently // within a project. namespace pd_s = ::pipeline_diagnostics::sidetable; inline void my_inline_function() { // namespace alias local to a function (or method). namespace fbz = ::foo::bar::baz; ... } } // namespace librarian Note that an alias in a .h file is visible to everyone #including that file, so public headers (those available outside a project) and headers transitively #included by them, should avoid defining aliases, as part of the general goal of keeping public APIs as small as possible. Nested Classes link ▶Although you may use public nested classes when they are part of an interface, consider a namespace to keep declarations out of the global scope. Definition: A class can define another class within it; this is also called a member class. class Foo { private: // Bar is a member class, nested within Foo. class Bar { ... }; }; Pros: This is useful when the nested (or member) class is only used by the enclosing class; making it a member puts it in the enclosing class scope rather than polluting the outer scope with the class name. Nested classes can be forward declared within the enclosing class and then defined in the .cc file to avoid including the nested class definition in the enclosing class declaration, since the nested class definition is usually only relevant to the implementation. Cons: Nested classes can be forward-declared only within the definition of the enclosing class. Thus, any header file manipulating a Foo::Bar* pointer will have to include the full class declaration for Foo. Decision: Do not make nested classes public unless they are actually part of the interface, e.g., a class that holds a set of options for some method. Nonmember, Static Member, and Global Functions link ▶Prefer nonmember functions within a namespace or static member functions to global functions; use completely global functions rarely. Pros: Nonmember and static member functions can be useful in some situations. Putting nonmember functions in a namespace avoids polluting the global namespace. Cons: Nonmember and static member functions may make more sense as members of a new class, especially if they access external resources or have significant dependencies. Decision: Sometimes it is useful, or even necessary, to define a function not bound to a class instance. Such a function can be either a static member or a nonmember function. Nonmember functions should not depend on external variables, and should nearly always exist in a namespace. Rather than creating classes only to group static member functions which do not share static data, use namespaces instead. Functions defined in the same compilation unit as production classes may introduce unnecessary coupling and link-time dependencies when directly called from other compilation units; static member functions are particularly susceptible to this. Consider extracting a new class, or placing the functions in a namespace possibly in a separate library. If you must define a nonmember function and it is only needed in its .cc file, use an unnamed namespace or static linkage (eg static int Foo() {...}) to limit its scope. Local Variables link ▶Place a function's variables in the narrowest scope possible, and initialize variables in the declaration. C++ allows you to declare variables anywhere in a function. We encourage you to declare them in as local a scope as possible, and as close to the first use as possible. This makes it easier for the reader to find the declaration and see what type the variable is and what it was initialized to. In particular, initialization should be used instead of declaration and assignment, e.g. int i; i = f(); // Bad -- initialization separate from declaration. int j = g(); // Good -- declaration has initialization. Note that gcc implements for (int i = 0; i < 10; ++i) correctly (the scope of i is only the scope of the for loop), so you can then reuse i in another for loop in the same scope. It also correctly scopes declarations in if and while statements, e.g. while (const char* p = strchr(str, '/')) str = p + 1; There is one caveat: if the variable is an object, its constructor is invoked every time it enters scope and is created, and its destructor is invoked every time it goes out of scope. // Inefficient implementation: for (int i = 0; i < 1000000; ++i) { Foo f; // My ctor and dtor get called 1000000 times each. f.DoSomething(i); } It may be more efficient to declare such a variable used in a loop outside that loop: Foo f; // My ctor and dtor get called once each. for (int i = 0; i < 1000000; ++i) { f.DoSomething(i); } Static and Global Variables link ▶Static or global variables of class type are forbidden: they cause hard-to-find bugs due to indeterminate order of construction and destruction. Objects with static storage duration, including global variables, static variables, static class member variables, and function static variables, must be Plain Old Data (POD): only ints, chars, floats, or pointers, or arrays/structs of POD. The order in which class constructors and initializers for static variables are called is only partially specified in C++ and can even change from build to build, which can cause bugs that are difficult to find. Therefore in addition to banning globals of class type, we do not allow static POD variables to be initialized with the result of a function, unless that function (such as getenv(), or getpid()) does not itself depend on any other globals. Likewise, the order in which destructors are called is defined to be the reverse of the order in which the constructors were called. Since constructor order is indeterminate, so is destructor order. For example, at program-end time a static variable might have been destroyed, but code still running -- perhaps in another thread -- tries to access it and fails. Or the destructor for a static 'string' variable might be run prior to the destructor for another variable that contains a reference to that string. As a result we only allow static variables to contain POD data. This rule completely disallows vector (use C arrays instead), or string (use const char []). If you need a static or global variable of a class type, consider initializing a pointer (which will never be freed), from either your main() function or from pthread_once(). Note that this must be a raw pointer, not a "smart" pointer, since the smart pointer's destructor will have the order-of-destructor issue that we are trying to avoid. Classes Classes are the fundamental unit of code in C++. Naturally, we use them extensively. This section lists the main dos and don'ts you should follow when writing a class. Doing Work in Constructors link ▶In general, constructors should merely set member variables to their initial values. Any complex initialization should go in an explicit Init() method. Definition: It is possible to perform initialization in the body of the constructor. Pros: Convenience in typing. No need to worry about whether the class has been initialized or not. Cons: The problems with doing work in constructors are: There is no easy way for constructors to signal errors, short of using exceptions (which are forbidden). If the work fails, we now have an object whose initialization code failed, so it may be an indeterminate state. If the work calls virtual functions, these calls will not get dispatched to the subclass implementations. Future modification to your class can quietly introduce this problem even if your class is not currently subclassed, causing much confusion. If someone creates a global variable of this type (which is against the rules, but still), the constructor code will be called before main(), possibly breaking some implicit assumptions in the constructor code. For instance, gflags will not yet have been initialized. Decision: If your object requires non-trivial initialization, consider having an explicit Init() method. In particular, constructors should not call virtual functions, attempt to raise errors, access potentially uninitialized global variables, etc. Default Constructors link ▶You must define a default constructor if your class defines member variables and has no other constructors. Otherwise the compiler will do it for you, badly. Definition: The default constructor is called when we new a class object with no arguments. It is always called when calling new[] (for arrays). Pros: Initializing structures by default, to hold "impossible" values, makes debugging much easier. Cons: Extra work for you, the code writer. Decision: If your class defines member variables and has no other constructors you must define a default constructor (one that takes no arguments). It should preferably initialize the object in such a way that its internal state is consistent and valid. The reason for this is that if you have no other constructors and do not define a default constructor, the compiler will generate one for you. This compiler generated constructor may not initialize your object sensibly. If your class inherits from an existing class but you add no new member variables, you are not required to have a default constructor. Explicit Constructors link ▶Use the C++ keyword explicit for constructors with one argument. Definition: Normally, if a constructor takes one argument, it can be used as a conversion. For instance, if you define Foo::Foo(string name) and then pass a string to a function that expects a Foo, the constructor will be called to convert the string into a Foo and will pass the Foo to your function for you. This can be convenient but is also a source of trouble when things get converted and new objects created without you meaning them to. Declaring a constructor explicit prevents it from being invoked implicitly as a conversion. Pros: Avoids undesirable conversions. Cons: None. Decision: We require all single argument constructors to be explicit. Always put explicit in front of one-argument constructors in the class definition: explicit Foo(string name); The exception is copy constructors, which, in the rare cases when we allow them, should probably not be explicit. Classes that are intended to be transparent wrappers around other classes are also exceptions. Such exceptions should be clearly marked with comments. Copy Constructors link ▶Provide a copy constructor and assignment operator only when necessary. Otherwise, disable them with DISALLOW_COPY_AND_ASSIGN. Definition: The copy constructor and assignment operator are used to create copies of objects. The copy constructor is implicitly invoked by the compiler in some situations, e.g. passing objects by value. Pros: Copy constructors make it easy to copy objects. STL containers require that all contents be copyable and assignable. Copy constructors can be more efficient than CopyFrom()-style workarounds because they combine construction with copying, the compiler can elide them in some contexts, and they make it easier to avoid heap allocation. Cons: Implicit copying of objects in C++ is a rich source of bugs and of performance problems. It also reduces readability, as it becomes hard to track which objects are being passed around by value as opposed to by reference, and therefore where changes to an object are reflected. Decision: Few classes need to be copyable. Most should have neither a copy constructor nor an assignment operator. In many situations, a pointer or reference will work just as well as a copied value, with better performance. For example, you can pass function parameters by reference or pointer instead of by value, and you can store pointers rather than objects in an STL container. If your class needs to be copyable, prefer providing a copy method, such as CopyFrom() or Clone(), rather than a copy constructor, because such methods cannot be invoked implicitly. If a copy method is insufficient in your situation (e.g. for performance reasons, or because your class needs to be stored by value in an STL container), provide both a copy constructor and assignment operator. If your class does not need a copy constructor or assignment operator, you must explicitly disable them. To do so, add dummy declarations for the copy constructor and assignment operator in the private: section of your class, but do not provide any corresponding definition (so that any attempt to use them results in a link error). For convenience, a DISALLOW_COPY_AND_ASSIGN macro can be used: // A macro to disallow the copy constructor and operator= functions // This should be used in the private: declarations for a class #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ TypeName(const TypeName&); \ void operator=(const TypeName&) Then, in class Foo: class Foo { public: Foo(int f); ~Foo(); private: DISALLOW_COPY_AND_ASSIGN(Foo); }; Structs vs. Classes link ▶Use a struct only for passive objects that carry data; everything else is a class. The struct and class keywords behave almost identically in C++. We add our own semantic meanings to each keyword, so you should use the appropriate keyword for the data-type you're defining. structs should be used for passive objects that carry data, and may have associated constants, but lack any functionality other than access/setting the data members. The accessing/setting of fields is done by directly accessing the fields rather than through method invocations. Methods should not provide behavior but should only be used to set up the data members, e.g., constructor, destructor, Initialize(), Reset(), Validate(). If more functionality is required, a class is more appropriate. If in doubt, make it a class. For consistency with STL, you can use struct instead of class for functors and traits. Note that member variables in structs and classes have different naming rules. Inheritance link ▶Composition is often more appropriate than inheritance. When using inheritance, make it public. Definition: When a sub-class inherits from a base class, it includes the definitions of all the data and operations that the parent base class defines. In practice, inheritance is used in two major ways in C++: implementation inheritance, in which actual code is inherited by the child, and interface inheritance, in which only method names are inherited. Pros: Implementation inheritance reduces code size by re-using the base class code as it specializes an existing type. Because inheritance is a compile-time declaration, you and the compiler can understand the operation and detect errors. Interface inheritance can be used to programmatically enforce that a class expose a particular API. Again, the compiler can detect errors, in this case, when a class does not define a necessary method of the API. Cons: For implementation inheritance, because the code implementing a sub-class is spread between the base and the sub-class, it can be more difficult to understand an implementation. The sub-class cannot override functions that are not virtual, so the sub-class cannot change implementation. The base class may also define some data members, so that specifies physical layout of the base class. Decision: All inheritance should be public. If you want to do private inheritance, you should be including an instance of the base class as a member instead. Do not overuse implementation inheritance. Composition is often more appropriate. Try to restrict use of inheritance to the "is-a" case: Bar subclasses Foo if it can reasonably be said that Bar "is a kind of" Foo. Make your destructor virtual if necessary. If your class has virtual methods, its destructor should be virtual. Limit the use of protected to those member functions that might need to be accessed from subclasses. Note that data members should be private. When redefining an inherited virtual function, explicitly declare it virtual in the declaration of the derived class. Rationale: If virtual is omitted, the reader has to check all ancestors of the class in question to determine if the function is virtual or not. Multiple Inheritance link ▶Only very rarely is multiple implementation inheritance actually useful. We allow multiple inheritance only when at most one of the base classes has an implementation; all other base classes must be pure interface classes tagged with the Interface suffix. Definition: Multiple inheritance allows a sub-class to have more than one base class. We distinguish between base classes that are pure interfaces and those that have an implementation. Pros: Multiple implementation inheritance may let you re-use even more code than single inheritance (see Inheritance). Cons: Only very rarely is multiple implementation inheritance actually useful. When multiple implementation inheritance seems like the solution, you can usually find a different, more explicit, and cleaner solution. Decision: Multiple inheritance is allowed only when all superclasses, with the possible exception of the first one, are pure interfaces. In order to ensure that they remain pure interfaces, they must end with the Interface suffix. Note: There is an exception to this rule on Windows. Interfaces link ▶Classes that satisfy certain conditions are allowed, but not required, to end with an Interface suffix. Definition: A class is a pure interface if it meets the following requirements: It has only public pure virtual ("= 0") methods and static methods (but see below for destructor). It may not have non-static data members. It need not have any constructors defined. If a constructor is provided, it must take no arguments and it must be protected. If it is a subclass, it may only be derived from classes that satisfy these conditions and are tagged with the Interface suffix. An interface class can never be directly instantiated because of the pure virtual method(s) it declares. To make sure all implementations of the interface can be destroyed correctly, they must also declare a virtual destructor (in an exception to the first rule, this should not be pure). See Stroustrup, The C++ Programming Language, 3rd edition, section 12.4 for details. Pros: Tagging a class with the Interface suffix lets others know that they must not add implemented methods or non static data members. This is particularly important in the case of multiple inheritance. Additionally, the interface concept is already well-understood by Java programmers. Cons: The Interface suffix lengthens the class name, which can make it harder to read and understand. Also, the interface property may be considered an implementation detail that shouldn't be exposed to clients. Decision: A class may end with Interface only if it meets the above requirements. We do not require the converse, however: classes that meet the above requirements are not required to end with Interface. Operator Overloading link ▶Do not overload operators except in rare, special circumstances. Definition: A class can define that operators such as + and / operate on the class as if it were a built-in type. Pros: Can make code appear more intuitive because a class will behave in the same way as built-in types (such as int). Overloaded operators are more playful names for functions that are less-colorfully named, such as Equals() or Add(). For some template functions to work correctly, you may need to define operators. Cons: While operator overloading can make code more intuitive, it has several drawbacks: It can fool our intuition into thinking that expensive operations are cheap, built-in operations. It is much harder to find the call sites for overloaded operators. Searching for Equals() is much easier than searching for relevant invocations of ==. Some operators work on pointers too, making it easy to introduce bugs. Foo + 4 may do one thing, while &Foo + 4 does something totally different. The compiler does not complain for either of these, making this very hard to debug. Overloading also has surprising ramifications. For instance, if a class overloads unary operator&, it cannot safely be forward-declared. Decision: In general, do not overload operators. The assignment operator (operator=), in particular, is insidious and should be avoided. You can define functions like Equals() and CopyFrom() if you need them. Likewise, avoid the dangerous unary operator& at all costs, if there's any possibility the class might be forward-declared. However, there may be rare cases where you need to overload an operator to interoperate with templates or "standard" C++ classes (such as operator<<(ostream&, const T&) for logging). These are acceptable if fully justified, but you should try to avoid these whenever possible. In particular, do not overload operator== or operator< just so that your class can be used as a key in an STL container; instead, you should create equality and comparison functor types when declaring the container. Some of the STL algorithms do require you to overload operator==, and you may do so in these cases, provided you document why. See also Copy Constructors and Function Overloading. Access Control link ▶Make data members private, and provide access to them through accessor functions as needed (for technical reasons, we allow data members of a test fixture class to be protected when using Google Test). Typically a variable would be called foo_ and the accessor function foo(). You may also want a mutator function set_foo(). Exception: static const data members (typically called kFoo) need not be private. The definitions of accessors are usually inlined in the header file. See also Inheritance and Function Names. Declaration Order link ▶Use the specified order of declarations within a class: public: before private:, methods before data members (variables), etc. Your class definition should start with its public: section, followed by its protected: section and then its private: section. If any of these sections are empty, omit them. Within each section, the declarations generally should be in the following order: Typedefs and Enums Constants (static const data members) Constructors Destructor Methods, including static methods Data Members (except static const data members) Friend declarations should always be in the private section, and the DISALLOW_COPY_AND_ASSIGN macro invocation should be at the end of the private: section. It should be the last thing in the class. See Copy Constructors. Method definitions in the corresponding .cc file should be the same as the declaration order, as much as possible. Do not put large method definitions inline in the class definition. Usually, only trivial or performance-critical, and very short, methods may be defined inline. See Inline Functions for more details. Write Short Functions link ▶Prefer small and focused functions. We recognize that long functions are sometimes appropriate, so no hard limit is placed on functions length. If a function exceeds about 40 lines, think about whether it can be broken up without harming the structure of the program. Even if your long function works perfectly now, someone modifying it in a few months may add new behavior. This could result in bugs that are hard to find. Keeping your functions short and simple makes it easier for other people to read and modify your code. You could find long and complicated functions when working with some code. Do not be intimidated by modifying existing code: if working with such a function proves to be difficult, you find that errors are hard to debug, or you want to use a piece of it in several different contexts, consider breaking up the function into smaller and more manageable pieces. Google-Specific Magic There are various tricks and utilities that we use to make C++ code more robust, and various ways we use C++ that may differ from what you see elsewhere. Smart Pointers link ▶If you actually need pointer semantics, scoped_ptr is great. You should only use std::tr1::shared_ptr under very specific conditions, such as when objects need to be held by STL containers. You should never use auto_ptr. "Smart" pointers are objects that act like pointers but have added semantics. When a scoped_ptr is destroyed, for instance, it deletes the object it's pointing to. shared_ptr is the same way, but implements reference-counting so only the last pointer to an object deletes it. Generally speaking, we prefer that we design code with clear object ownership. The clearest object ownership is obtained by using an object directly as a field or local variable, without using pointers at all. On the other extreme, by their very definition, reference counted pointers are owned by nobody. The problem with this design is that it is easy to create circular references or other strange conditions that cause an object to never be deleted. It is also slow to perform atomic operations every time a value is copied or assigned. Although they are not recommended, reference counted pointers are sometimes the simplest and most elegant way to solve a problem. cpplint link ▶Use cpplint.py to detect style errors. cpplint.py is a tool that reads a source file and identifies many style errors. It is not perfect, and has both false positives and false negatives, but it is still a valuable tool. False positives can be ignored by putting // NOLINT at the end of the line. Some projects have instructions on how to run cpplint.py from their project tools. If the project you are contributing to does not, you can download cpplint.py separately. Other C++ Features Reference Arguments link ▶All parameters passed by reference must be labeled const. Definition: In C, if a function needs to modify a variable, the parameter must use a pointer, eg int foo(int *pval). In C++, the function can alternatively declare a reference parameter: int foo(int &val). Pros: Defining a parameter as reference avoids ugly code like (*pval)++. Necessary for some applications like copy constructors. Makes it clear, unlike with pointers, that NULL is not a possible value. Cons: References can be confusing, as they have value syntax but pointer semantics. Decision: Within function parameter lists all references must be const: void Foo(const string &in, string *out); In fact it is a very strong convention in Google code that input arguments are values or const references while output arguments are pointers. Input parameters may be const pointers, but we never allow non-const reference parameters. One case when you might want an input parameter to be a const pointer is if you want to emphasize that the argument is not copied, so it must exist for the lifetime of the object; it is usually best to document this in comments as well. STL adapters such as bind2nd and mem_fun do not permit reference parameters, so you must declare functions with pointer parameters in these cases, too. Function Overloading link ▶Use overloaded functions (including constructors) only if a reader looking at a call site can get a good idea of what is happening without having to first figure out exactly which overload is being called. Definition: You may write a function that takes a const string& and overload it with another that takes const char*. class MyClass { public: void Analyze(const string &text); void Analyze(const char *text, size_t textlen); }; Pros: Overloading can make code more intuitive by allowing an identically-named function to take different arguments. It may be necessary for templatized code, and it can be convenient for Visitors. Cons: If a function is overloaded by the argument types alone, a reader may have to understand C++'s complex matching rules in order to tell what's going on. Also many people are confused by the semantics of inheritance if a derived class overrides only some of the variants of a function. Decision: If you want to overload a function, consider qualifying the name with some information about the arguments, e.g., AppendString(), AppendInt() rather than just Append(). Default Arguments link ▶We do not allow default function parameters, except in a few uncommon situations explained below. Pros: Often you have a function that uses lots of default values, but occasionally you want to override the defaults. Default parameters allow an easy way to do this without having to define many functions for the rare exceptions. Cons: People often figure out how to use an API by looking at existing code that uses it. Default parameters are more difficult to maintain because copy-and-paste from previous code may not reveal all the parameters. Copy-and-pasting of code segments can cause major problems when the default arguments are not appropriate for the new code. Decision: Except as described below, we require all arguments to be explicitly specified, to force programmers to consider the API and the values they are passing for each argument rather than silently accepting defaults they may not be aware of. One specific exception is when default arguments are used to simulate variable-length argument lists. // Support up to 4 params by using a default empty AlphaNum. string StrCat(const AlphaNum &a, const AlphaNum &b = gEmptyAlphaNum, const AlphaNum &c = gEmptyAlphaNum, const AlphaNum &d = gEmptyAlphaNum); Variable-Length Arrays and alloca() link ▶We do not allow variable-length arrays or alloca(). Pros: Variable-length arrays have natural-looking syntax. Both variable-length arrays and alloca() are very efficient. Cons: Variable-length arrays and alloca are not part of Standard C++. More importantly, they allocate a data-dependent amount of stack space that can trigger difficult-to-find memory overwriting bugs: "It ran fine on my machine, but dies mysteriously in production". Decision: Use a safe allocator instead, such as scoped_ptr/scoped_array. Friends link ▶We allow use of friend classes and functions, within reason. Friends should usually be defined in the same file so that the reader does not have to look in another file to find uses of the private members of a class. A common use of friend is to have a FooBuilder class be a friend of Foo so that it can construct the inner state of Foo correctly, without exposing this state to the world. In some cases it may be useful to make a unittest class a friend of the class it tests. Friends extend, but do not break, the encapsulation boundary of a class. In some cases this is better than making a member public when you want to give only one other class access to it. However, most classes should interact with other classes solely through their public members. Exceptions link ▶We do not use C++ exceptions. Pros: Exceptions allow higher levels of an application to decide how to handle "can't happen" failures in deeply nested functions, without the obscuring and error-prone bookkeeping of error codes. Exceptions are used by most other modern languages. Using them in C++ would make it more consistent with Python, Java, and the C++ that others are familiar with. Some third-party C++ libraries use exceptions, and turning them off internally makes it harder to integrate with those libraries. Exceptions are the only way for a constructor to fail. We can simulate this with a factory function or an Init() method, but these require heap allocation or a new "invalid" state, respectively. Exceptions are really handy in testing frameworks. Cons: When you add a throw statement to an existing function, you must examine all of its transitive callers. Either they must make at least the basic exception safety guarantee, or they must never catch the exception and be happy with the program terminating as a result. For instance, if f() calls g() calls h(), and h throws an exception that f catches, g has to be careful or it may not clean up properly. More generally, exceptions make the control flow of programs difficult to evaluate by looking at code: functions may return in places you don't expect. This causes maintainability and debugging difficulties. You can minimize this cost via some rules on how and where exceptions can be used, but at the cost of more that a developer needs to know and understand. Exception safety requires both RAII and different coding practices. Lots of supporting machinery is needed to make writing correct exception-safe code easy. Further, to avoid requiring readers to understand the entire call graph, exception-safe code must isolate logic that writes to persistent state into a "commit" phase. This will have both benefits and costs (perhaps where you're forced to obfuscate code to isolate the commit). Allowing exceptions would force us to always pay those costs even when they're not worth it. Turning on exceptions adds data to each binary produced, increasing compile time (probably slightly) and possibly increasing address space pressure. The availability of exceptions may encourage developers to throw them when they are not appropriate or recover from them when it's not safe to do so. For example, invalid user input should not cause exceptions to be thrown. We would need to make the style guide even longer to document these restrictions! Decision: On their face, the benefits of using exceptions outweigh the costs, especially in new projects. However, for existing code, the introduction of exceptions has implications on all dependent code. If exceptions can be propagated beyond a new project, it also becomes problematic to integrate the new project into existing exception-free code. Because most existing C++ code at Google is not prepared to deal with exceptions, it is comparatively difficult to adopt new code that generates exceptions. Given that Google's existing code is not exception-tolerant, the costs of using exceptions are somewhat greater than the costs in a new project. The conversion process would be slow and error-prone. We don't believe that the available alternatives to exceptions, such as error codes and assertions, introduce a significant burden. Our advice against using exceptions is not predicated on philosophical or moral grounds, but practical ones. Because we'd like to use our open-source projects at Google and it's difficult to do so if those projects use exceptions, we need to advise against exceptions in Google open-source projects as well. Things would probably be different if we had to do it all over again from scratch. There is an exception to this rule (no pun intended) for Windows code. Run-Time Type Information (RTTI) link ▶We do not use Run Time Type Information (RTTI). Definition: RTTI allows a programmer to query the C++ class of an object at run time. Pros: It is useful in some unittests. For example, it is useful in tests of factory classes where the test has to verify that a newly created object has the expected dynamic type. In rare circumstances, it is useful even outside of tests. Cons: A query of type during run-time typically means a design problem. If you need to know the type of an object at runtime, that is often an indication that you should reconsider the design of your class. Decision: Do not use RTTI, except in unittests. If you find yourself in need of writing code that behaves differently based on the class of an object, consider one of the alternatives to querying the type. Virtual methods are the preferred way of executing different code paths depending on a specific subclass type. This puts the work within the object itself. If the work belongs outside the object and instead in some processing code, consider a double-dispatch solution, such as the Visitor design pattern. This allows a facility outside the object itself to determine the type of class using the built-in type system. If you think you truly cannot use those ideas, you may use RTTI. But think twice about it. :-) Then think twice again. Do not hand-implement an RTTI-like workaround. The arguments against RTTI apply just as much to workarounds like class hierarchies with type tags. Casting link ▶Use C++ casts like static_cast(). Do not use other cast formats like int y = (int)x; or int y = int(x);. Definition: C++ introduced a different cast system from C that distinguishes the types of cast operations. Pros: The problem with C casts is the ambiguity of the operation; sometimes you are doing a conversion (e.g., (int)3.5) and sometimes you are doing a cast (e.g., (int)"hello"); C++ casts avoid this. Additionally C++ casts are more visible when searching for them. Cons: The syntax is nasty. Decision: Do not use C-style casts. Instead, use these C++-style casts. Use static_cast as the equivalent of a C-style cast that does value conversion, or when you need to explicitly up-cast a pointer from a class to its superclass. Use const_cast to remove the const qualifier (see const). Use reinterpret_cast to do unsafe conversions of pointer types to and from integer and other pointer types. Use this only if you know what you are doing and you understand the aliasing issues. Do not use dynamic_cast except in test code. If you need to know type information at runtime in this way outside of a unittest, you probably have a design flaw. Streams link ▶Use streams only for logging. Definition: Streams are a replacement for printf() and scanf(). Pros: With streams, you do not need to know the type of the object you are printing. You do not have problems with format strings not matching the argument list. (Though with gcc, you do not have that problem with printf either.) Streams have automatic constructors and destructors that open and close the relevant files. Cons: Streams make it difficult to do functionality like pread(). Some formatting (particularly the common format string idiom %.*s) is difficult if not impossible to do efficiently using streams without using printf-like hacks. Streams do not support operator reordering (the %1s directive), which is helpful for internationalization. Decision: Do not use streams, except where required by a logging interface. Use printf-like routines instead. There are various pros and cons to using streams, but in this case, as in many other cases, consistency trumps the debate. Do not use streams in your code. Extended Discussion There has been debate on this issue, so this explains the reasoning in greater depth. Recall the Only One Way guiding principle: we want to make sure that whenever we do a certain type of I/O, the code looks the same in all those places. Because of this, we do not want to allow users to decide between using streams or using printf plus Read/Write/etc. Instead, we should settle on one or the other. We made an exception for logging because it is a pretty specialized application, and for historical reasons. Proponents of streams have argued that streams are the obvious choice of the two, but the issue is not actually so clear. For every advantage of streams they point out, there is an equivalent disadvantage. The biggest advantage is that you do not need to know the type of the object to be printing. This is a fair point. But, there is a downside: you can easily use the wrong type, and the compiler will not warn you. It is easy to make this kind of mistake without knowing when using streams. cout << this; // Prints the address cout << *this; // Prints the contents The compiler does not generate an error because << has been overloaded. We discourage overloading for just this reason. Some say printf formatting is ugly and hard to read, but streams are often no better. Consider the following two fragments, both with the same typo. Which is easier to discover? cerr << "Error connecting to '" <bar()->hostname.first << ":" <bar()->hostname.second << ": " <bar()->hostname.first, foo->bar()->hostname.second, strerror(errno)); And so on and so forth for any issue you might bring up. (You could argue, "Things would be better with the right wrappers," but if it is true for one scheme, is it not also true for the other? Also, remember the goal is to make the language smaller, not add yet more machinery that someone has to learn.) Either path would yield different advantages and disadvantages, and there is not a clearly superior solution. The simplicity doctrine mandates we settle on one of them though, and the majority decision was on printf + read/write. Preincrement and Predecrement link ▶Use prefix form (++i) of the increment and decrement operators with iterators and other template objects. Definition: When a variable is incremented (++i or i++) or decremented (--i or i--) and the value of the expression is not used, one must decide whether to preincrement (decrement) or postincrement (decrement). Pros: When the return value is ignored, the "pre" form (++i) is never less efficient than the "post" form (i++), and is often more efficient. This is because post-increment (or decrement) requires a copy of i to be made, which is the value of the expression. If i is an iterator or other non-scalar type, copying i could be expensive. Since the two types of increment behave the same when the value is ignored, why not just always pre-increment? Cons: The tradition developed, in C, of using post-increment when the expression value is not used, especially in for loops. Some find post-increment easier to read, since the "subject" (i) precedes the "verb" (++), just like in English. Decision: For simple scalar (non-object) values there is no reason to prefer one form and we allow either. For iterators and other template types, use pre-increment. Use of const link ▶We strongly recommend that you use const whenever it makes sense to do so. Definition: Declared variables and parameters can be preceded by the keyword const to indicate the variables are not changed (e.g., const int foo). Class functions can have the const qualifier to indicate the function does not change the state of the class member variables (e.g., class Foo { int Bar(char c) const; };). Pros: Easier for people to understand how variables are being used. Allows the compiler to do better type checking, and, conceivably, generate better code. Helps people convince themselves of program correctness because they know the functions they call are limited in how they can modify your variables. Helps people know what functions are safe to use without locks in multi-threaded programs. Cons: const is viral: if you pass a const variable to a function, that function must have const in its prototype (or the variable will need a const_cast). This can be a particular problem when calling library functions. Decision: const variables, data members, methods and arguments add a level of compile-time type checking; it is better to detect errors as soon as possible. Therefore we strongly recommend that you use const whenever it makes sense to do so: If a function does not modify an argument passed by reference or by pointer, that argument should be const. Declare methods to be const whenever possible. Accessors should almost always be const. Other methods should be const if they do not modify any data members, do not call any non-const methods, and do not return a non-const pointer or non-const reference to a data member. Consider making data members const whenever they do not need to be modified after construction. However, do not go crazy with const. Something like const int * const * const x; is likely overkill, even if it accurately describes how const x is. Focus on what's really useful to know: in this case, const int** x is probably sufficient. The mutable keyword is allowed but is unsafe when used with threads, so thread safety should be carefully considered first. Where to put the const Some people favor the form int const *foo to const int* foo. They argue that this is more readable because it's more consistent: it keeps the rule that const always follows the object it's describing. However, this consistency argument doesn't apply in this case, because the "don't go crazy" dictum eliminates most of the uses you'd have to be consistent with. Putting the const first is arguably more readable, since it follows English in putting the "adjective" (const) before the "noun" (int). That said, while we encourage putting const first, we do not require it. But be consistent with the code around you! Integer Types link ▶Of the built-in C++ integer types, the only one used is int. If a program needs a variable of a different size, use a precise-width integer type from , such as int16_t. Definition: C++ does not specify the sizes of its integer types. Typically people assume that short is 16 bits, int is 32 bits, long is 32 bits and long long is 64 bits. Pros: Uniformity of declaration. Cons: The sizes of integral types in C++ can vary based on compiler and architecture. Decision: defines types like int16_t, uint32_t, int64_t, etc. You should always use those in preference to short, unsigned long long and the like, when you need a guarantee on the size of an integer. Of the C integer types, only int should be used. When appropriate, you are welcome to use standard types like size_t and ptrdiff_t. We use int very often, for integers we know are not going to be too big, e.g., loop counters. Use plain old int for such things. You should assume that an int is at least 32 bits, but don't assume that it has more than 32 bits. If you need a 64-bit integer type, use int64_t or uint64_t. For integers we know can be "big", use int64_t. You should not use the unsigned integer types such as uint32_t, unless the quantity you are representing is really a bit pattern rather than a number, or unless you need defined twos-complement overflow. In particular, do not use unsigned types to say a number will never be negative. Instead, use assertions for this. On Unsigned Integers Some people, including some textbook authors, recommend using unsigned types to represent numbers that are never negative. This is intended as a form of self-documentation. However, in C, the advantages of such documentation are outweighed by the real bugs it can introduce. Consider: for (unsigned int i = foo.Length()-1; i >= 0; --i) ... This code will never terminate! Sometimes gcc will notice this bug and warn you, but often it will not. Equally bad bugs can occur when comparing signed and unsigned variables. Basically, C's type-promotion scheme causes unsigned types to behave differently than one might expect. So, document that a variable is non-negative using assertions. Don't use an unsigned type. 64-bit Portability link ▶Code should be 64-bit and 32-bit friendly. Bear in mind problems of printing, comparisons, and structure alignment. printf() specifiers for some types are not cleanly portable between 32-bit and 64-bit systems. C99 defines some portable format specifiers. Unfortunately, MSVC 7.1 does not understand some of these specifiers and the standard is missing a few, so we have to define our own ugly versions in some cases (in the style of the standard include file inttypes.h): // printf macros for size_t, in the style of inttypes.h #ifdef _LP64 #define __PRIS_PREFIX "z" #else #define __PRIS_PREFIX #endif // Use these macros after a % in a printf format string // to get correct 32/64 bit behavior, like this: // size_t size = records.size(); // printf("%"PRIuS"\n", size); #define PRIdS __PRIS_PREFIX "d" #define PRIxS __PRIS_PREFIX "x" #define PRIuS __PRIS_PREFIX "u" #define PRIXS __PRIS_PREFIX "X" #define PRIoS __PRIS_PREFIX "o" Type DO NOT use DO use Notes void * (or any pointer) %lx %p int64_t %qd, %lld %"PRId64" uint64_t %qu, %llu, %llx %"PRIu64", %"PRIx64" size_t %u %"PRIuS", %"PRIxS" C99 specifies %zu ptrdiff_t %d %"PRIdS" C99 specifies %zd Note that the PRI* macros expand to independent strings which are concatenated by the compiler. Hence if you are using a non-constant format string, you need to insert the value of the macro into the format, rather than the name. It is still possible, as usual, to include length specifiers, etc., after the % when using the PRI* macros. So, e.g. printf("x = %30"PRIuS"\n", x) would expand on 32-bit Linux to printf("x = %30" "u" "\n", x), which the compiler will treat as printf("x = %30u\n", x). Remember that sizeof(void *) != sizeof(int). Use intptr_t if you want a pointer-sized integer. You may need to be careful with structure alignments, particularly for structures being stored on disk. Any class/structure with a int64_t/uint64_t member will by default end up being 8-byte aligned on a 64-bit system. If you have such structures being shared on disk between 32-bit and 64-bit code, you will need to ensure that they are packed the same on both architectures. Most compilers offer a way to alter structure alignment. For gcc, you can use __attribute__((packed)). MSVC offers #pragma pack() and __declspec(align()). Use the LL or ULL suffixes a

2011-03-08

软件加密技术.part7

软件加密技术内幕电子书 第1章 PE文件格式深入研究 第2章 PE分析工具编写 第3章 Win32 调试API 第4章 Windows下的异常处理 第5章 软件加密技术 第6章 加壳软件编写 第7章 如何让壳与程序融为一体 第8章 Visual Basic 6 逆向工程 附录A 在Visual C++中使用内联汇编 附录B 在Visual Basic中使用汇编

2011-03-06

软件加密技术.part6

软件加密技术内幕电子书 第1章 PE文件格式深入研究 第2章 PE分析工具编写 第3章 Win32 调试API 第4章 Windows下的异常处理 第5章 软件加密技术 第6章 加壳软件编写 第7章 如何让壳与程序融为一体 第8章 Visual Basic 6 逆向工程 附录A 在Visual C++中使用内联汇编 附录B 在Visual Basic中使用汇编

2011-03-06

软件加密技术.part5

软件加密技术内幕电子书 第1章 PE文件格式深入研究 第2章 PE分析工具编写 第3章 Win32 调试API 第4章 Windows下的异常处理 第5章 软件加密技术 第6章 加壳软件编写 第7章 如何让壳与程序融为一体 第8章 Visual Basic 6 逆向工程 附录A 在Visual C++中使用内联汇编 附录B 在Visual Basic中使用汇编

2011-03-06

软件加密技术.part4

软件加密技术内幕电子书 第1章 PE文件格式深入研究 第2章 PE分析工具编写 第3章 Win32 调试API 第4章 Windows下的异常处理 第5章 软件加密技术 第6章 加壳软件编写 第7章 如何让壳与程序融为一体 第8章 Visual Basic 6 逆向工程 附录A 在Visual C++中使用内联汇编 附录B 在Visual Basic中使用汇编

2011-03-06

软件加密技术.part3

软件加密技术内幕电子书 第1章 PE文件格式深入研究 第2章 PE分析工具编写 第3章 Win32 调试API 第4章 Windows下的异常处理 第5章 软件加密技术 第6章 加壳软件编写 第7章 如何让壳与程序融为一体 第8章 Visual Basic 6 逆向工程 附录A 在Visual C++中使用内联汇编 附录B 在Visual Basic中使用汇编

2011-03-06

软件加密技术.part2

软件加密技术内幕电子书 第1章 PE文件格式深入研究 第2章 PE分析工具编写 第3章 Win32 调试API 第4章 Windows下的异常处理 第5章 软件加密技术 第6章 加壳软件编写 第7章 如何让壳与程序融为一体 第8章 Visual Basic 6 逆向工程 附录A 在Visual C++中使用内联汇编 附录B 在Visual Basic中使用汇编

2011-03-06

软件加密技术.part1

软件加密技术内幕电子书 第1章 PE文件格式深入研究 第2章 PE分析工具编写 第3章 Win32 调试API 第4章 Windows下的异常处理 第5章 软件加密技术 第6章 加壳软件编写 第7章 如何让壳与程序融为一体 第8章 Visual Basic 6 逆向工程 附录A 在Visual C++中使用内联汇编 附录B 在Visual Basic中使用汇编

2011-03-06

寒江独钓-Windows内核安全编程(高清完整版).part7

http://wangfaqiang.download.csdn.net/ 上面这个网址就可以看到所有7个的下载链接 内容简介   本书从Windows内核编程出发,全面系统地介绍了串口、键盘、磁盘、文件系统、网络等相关的Windows内核模块的编程技术,以及基于这些技术实现的密码保护、防毒引擎、文件加密、网络嗅探、网络防火墙等信息安全软件的核心组件的具体编程。主要知识重点包括:Windows串口与键盘过滤驱动、Windows虚拟存储设备与存储设备过滤驱动、Windows文件系统过滤驱动、文件系统透明加密/解密驱动、Windows各类网络驱动(包括TDI过滤驱动及三类NDIS驱动),以及最新的WDF驱动开发模型。有助于读者熟悉Windows内核驱动的体系结构,并精通信息安全类的内核编程技术。本书的大部分代码具有广泛的兼容性,适合从Windows 2000 一直到目前最新的Windows 7 Beta 版。   本书适合大专院校计算机系的学生、普通Windows程序员、Windows内核程序员、信息安全行业的程序员,以及希望了解Windows系统底层知识的计算机编程爱好者使用。阅读本书,需要读者有C语言、数据结构、操作系统和计算机网络的基础知识。 目录: 封面 -25 扉页 -24 内容简介 -23 序 -22 关于本书作者和贡献者 -20 前言 -18 阅读注意 -16 目录 -12 正文 1 第1章 内核上机指导 1 1.1 下载和使用WDK 2 1.1.1 下载安装WDK 2 1.1.2 编写第一个C文件 3 1.1.3 编译一个工程 5 1.2 安装与运行 6 1.2.1 下载一个安装工具 6 1.2.2 运行与查看输出信息 7 1.2.3 在虚拟机中运行 9 1.3 调试内核模块 9 1.3.1 下载和安装WinDbg 9 1.3.2 设置Windows XP 调试执行 10 1.3.3 设置Vista调试执行 11 1.3.4 设置VMWare的管道虚拟串口 11 1.3.5 设置Windows内核符号表 13 1.3.6 实战调试first 14 练习题 16 第2章 内核编程环境及其特殊性 17 2.1 内核编程的环境 18 2.1.1 隔离的应用程序 18 2.1.2 共享的内核空间 19 2.1.3 无处不在的内核模块 20 2.2 数据类型 21 2.2.1 基本数据类型 21 2.2.2 返回状态 22 2.2.3 字符串 23 2.3 重要的数据结构 23 2.3.1 驱动对象 23 2.3.2 设备对象 25 2.3.3 请求 26 2.4 函数调用 28 2.4.1 查阅帮助 28 2.4.2 帮助中有的几类函数 30 2.4.3 帮助中没有的函数 32 2.5 Windows的驱动开发模型 32 2.6 WDK编程中的特殊点 33 2.6.1 内核编程的主要调用源 33 2.6.2 函数的多线程安全性 34 2.6.3 代码的中断级 36 2.6.4 WDK中出现的特殊代码 37 练习题 38 第3章 串口的过滤 40 3.1 过滤的概念 41 3.1.1 设备绑定的内核API之一 41 3.1.2 设备绑定的内核API之二 43 3.1.3 生成过滤设备并绑定 43 3.1.4 从名字获得设备对象 45 3.1.5 绑定所有串口 46 3.2 获得实际数据 47 3.2.1 请求的区分 47 3.2.2 请求的结局 48 3.2.3 写请求的数据 49 3.3 完整的代码 50 3.3.1 完整的分发函数 50 3.3.2 如何动态卸载 52 3.3.3 完整的代码 53 本章的示例代码 53 练习题 54 第4章 键盘的过滤 56 4.1 技术原理 57 4.1.1 预备知识 57 4.1.2 Windows中从击键到内核 58 4.1.3 键盘硬件原理 60 4.2 键盘过滤的框架 61 4.2.1 找到所有的键盘设备 61 4.2.2 应用设备扩展 64 4.2.3 键盘过滤模块的DriverEntry 65 4.2.4 键盘过滤模块的动态加载 66 4.3 键盘过滤的请求处理 68 4.3.1 通常的处理 68 4.3.2 PNP的处理 69 4.3.3 读的处理 70 4.3.4 读完成的处理 71 4.4 从请求中打印出按键信息 72 4.4.1 从缓冲区中获得KEYBOARD_INPUT_DATA 72 4.4.2 从KEYBOARD_INPUT_DATA中得到键 73 4.4.3 从MakeCode到实际字符 74 4.5 Hook分发函数 75 4.5.1 获得类驱动对象 76 4.5.2 修改类驱动的分发函数指针 77 4.5.3 类驱动之下的端口驱动 78 4.5

2011-01-04

寒江独钓-Windows内核安全编程(高清完整版).part6

http://wangfaqiang.download.csdn.net/ 上面这个网址就可以看到所有7个的下载链接 内容简介   本书从Windows内核编程出发,全面系统地介绍了串口、键盘、磁盘、文件系统、网络等相关的Windows内核模块的编程技术,以及基于这些技术实现的密码保护、防毒引擎、文件加密、网络嗅探、网络防火墙等信息安全软件的核心组件的具体编程。主要知识重点包括:Windows串口与键盘过滤驱动、Windows虚拟存储设备与存储设备过滤驱动、Windows文件系统过滤驱动、文件系统透明加密/解密驱动、Windows各类网络驱动(包括TDI过滤驱动及三类NDIS驱动),以及最新的WDF驱动开发模型。有助于读者熟悉Windows内核驱动的体系结构,并精通信息安全类的内核编程技术。本书的大部分代码具有广泛的兼容性,适合从Windows 2000 一直到目前最新的Windows 7 Beta 版。   本书适合大专院校计算机系的学生、普通Windows程序员、Windows内核程序员、信息安全行业的程序员,以及希望了解Windows系统底层知识的计算机编程爱好者使用。阅读本书,需要读者有C语言、数据结构、操作系统和计算机网络的基础知识。 目录: 封面 -25 扉页 -24 内容简介 -23 序 -22 关于本书作者和贡献者 -20 前言 -18 阅读注意 -16 目录 -12 正文 1 第1章 内核上机指导 1 1.1 下载和使用WDK 2 1.1.1 下载安装WDK 2 1.1.2 编写第一个C文件 3 1.1.3 编译一个工程 5 1.2 安装与运行 6 1.2.1 下载一个安装工具 6 1.2.2 运行与查看输出信息 7 1.2.3 在虚拟机中运行 9 1.3 调试内核模块 9 1.3.1 下载和安装WinDbg 9 1.3.2 设置Windows XP 调试执行 10 1.3.3 设置Vista调试执行 11 1.3.4 设置VMWare的管道虚拟串口 11 1.3.5 设置Windows内核符号表 13 1.3.6 实战调试first 14 练习题 16 第2章 内核编程环境及其特殊性 17 2.1 内核编程的环境 18 2.1.1 隔离的应用程序 18 2.1.2 共享的内核空间 19 2.1.3 无处不在的内核模块 20 2.2 数据类型 21 2.2.1 基本数据类型 21 2.2.2 返回状态 22 2.2.3 字符串 23 2.3 重要的数据结构 23 2.3.1 驱动对象 23 2.3.2 设备对象 25 2.3.3 请求 26 2.4 函数调用 28 2.4.1 查阅帮助 28 2.4.2 帮助中有的几类函数 30 2.4.3 帮助中没有的函数 32 2.5 Windows的驱动开发模型 32 2.6 WDK编程中的特殊点 33 2.6.1 内核编程的主要调用源 33 2.6.2 函数的多线程安全性 34 2.6.3 代码的中断级 36 2.6.4 WDK中出现的特殊代码 37 练习题 38 第3章 串口的过滤 40 3.1 过滤的概念 41 3.1.1 设备绑定的内核API之一 41 3.1.2 设备绑定的内核API之二 43 3.1.3 生成过滤设备并绑定 43 3.1.4 从名字获得设备对象 45 3.1.5 绑定所有串口 46 3.2 获得实际数据 47 3.2.1 请求的区分 47 3.2.2 请求的结局 48 3.2.3 写请求的数据 49 3.3 完整的代码 50 3.3.1 完整的分发函数 50 3.3.2 如何动态卸载 52 3.3.3 完整的代码 53 本章的示例代码 53 练习题 54 第4章 键盘的过滤 56 4.1 技术原理 57 4.1.1 预备知识 57 4.1.2 Windows中从击键到内核 58 4.1.3 键盘硬件原理 60 4.2 键盘过滤的框架 61 4.2.1 找到所有的键盘设备 61 4.2.2 应用设备扩展 64 4.2.3 键盘过滤模块的DriverEntry 65 4.2.4 键盘过滤模块的动态加载 66 4.3 键盘过滤的请求处理 68 4.3.1 通常的处理 68 4.3.2 PNP的处理 69 4.3.3 读的处理 70 4.3.4 读完成的处理 71 4.4 从请求中打印出按键信息 72 4.4.1 从缓冲区中获得KEYBOARD_INPUT_DATA 72 4.4.2 从KEYBOARD_INPUT_DATA中得到键 73 4.4.3 从MakeCode到实际字符 74 4.5 Hook分发函数 75 4.5.1 获得类驱动对象 76 4.5.2 修改类驱动的分发函数指针 77 4.5.3 类驱动之下的端口驱动 78 4.5.4 端口驱动和驱动之间的协作机制 79 4.5.5 找到关键的回调函数的条件 80 4.5.6 定义常数和数据结构 80 4.5.7 打开两种键盘端口驱动寻找设备 81 4.5.8 搜索在kbdClass类驱动中的地址 83 4.6 Hook键盘中断反过滤 86 4.6.1 中断:IRQ和INT 86 4.6.2 如何修改IDT 87 4.6.3 替换IDT中的跳转地址 88 4.6.4 QQ的PS/2反过滤措施 90 4.7 利用IOAPIC重定位中断处理函数 90 4.7.1 什么是IOAPIC 90 4.7.2 如何访问IOAPIC 91 4.7.3 编程修改IOAPIC重定位表 92 4.7.4 插入新的中断处理 93 4.7.5 驱动入口和卸载的实现 95 4.8 直接用端口操作键盘 96 4.8.1 读取键盘数据和命令端口 96 4.8.2 p2cUserFilter的最终实现 97 本章的示例代码 98 练习题 99 第5章 磁盘的虚拟 100 5.1 虚拟的磁盘 101 5.2 一个具体的例子 101 5.3 入口函数 102 5.3.1 入口函数的定义 102 5.3.2 Ramdisk驱动的入口函数 103 5.4 EvtDriverDeviceAdd函数 104 5.4.1 EvtDriverDeviceAdd的定义 104 5.4.2 局部变量的声明 105 5.4.3 磁盘设备的创建 105 5.4.4 如何处理发往设备的请求 107 5.4.5 用户配置的初始化 108 5.4.6 链接给应用程序 110 5.4.7 小结 111 5.5 FAT12/16磁盘卷初始化 111 5.5.1 磁盘卷结构简介 111 5.5.2 Ramdisk对磁盘的初始化 113 5.6 驱动中的请求处理 119 5.6.1 请求的处理 119 5.6.2 读/写请求 120 5.6.3 DeviceIoControl请求 122 5.7 Ramdisk的编译和安装 124 5.7.1 编译 124 5.7.2 安装 125 5.7.3 对安装的深入研究 125 练习题 126 第6章 磁盘过滤 127 6.1 磁盘过滤驱动的概念 128 6.1.1 设备过滤和类过滤 128 6.1.2 磁盘设备和磁盘卷设备过滤驱动 128 6.1.3 注册表和磁盘卷设备过滤驱动 129 6.2 具有还原功能的磁盘卷过滤驱动 129 6.2.1 简介 129 6.2.2 基本思想 130 6.3 驱动分析 130 6.3.1 DriverEntry函数 130 6.3.2 AddDevice函数 132 6.3.3 PnP请求的处理 136 6.3.4 Power请求的处理 140 6.3.5 DeviceIoControl请求的处理 140 6.3.6 bitmap的作用和分析 144 6.3.7 boot驱动完成回调函数和稀疏文件 150 6.3.8 读/写请求的处理 152 本章的示例代码 160 练习题 161 第7章 文件系统的过滤与监控 162 7.1 文件系统的设备对象 163 7.1.1 控制设备与卷设备 163 7.1.2 生成自己的一个控制设备 165 7.2 文件系统的分发函数 166 7.2.1 普通的分发函数 166 7.2.2 文件过滤的快速IO分发函数 167 7.2.3 快速IO分发函数的一个实现 169 7.2.4 快速IO分发函数逐个简介 170 7.3 设备的绑定前期工作 172 7.3.1 动态地选择绑定函数 172 7.3.2 注册文件系统变动回调 173 7.3.3 文件系统变动回调的一个实现 175 7.3.4 文件系统识别器 176 7.4 文件系统控制设备的绑定 177 7.4.1 生成文件系统控制设备的过滤设备 177 7.4.2 绑定文件系统控制设备 178 7.4.3 利用文件系统控制请求 180 7.5 文件系统卷设备的绑定 183 7.5.1 从IRP中获得VPB指针 183 7.5.2 设置完成函数并等待IRP完成 184 7.5.3 卷挂载IRP完成后的工作 187 7.5.4 完成函数的相应实现 190 7.5.5 绑定卷的实现 191 7.6 读/写操作的过滤 193 7.6.1 设置一个读处理函数 193 7.6.2 设备对象的区分处理 194 7.6.3 解析读请求中的文件信息 195 7.6.4 读请求的完成 198 7.7 其他操作的过滤 202 7.7.1 文件对象的生存周期 202 7.7.2 文件的打开与关闭 203 7.7.3 文件的删除 205 7.8 路径过滤的实现 206 7.8.1 取得文件路径的三种情况 206 7.8.2 打开成功后获取路径 207 7.8.3 在其他时刻获得文件路径 209 7.8.4 在打开请求完成之前获得路径 209 7.8.5 把短名转换为长名 211 7.9 把sfilter编译成静态库 212 7.9.1 如何方便地使用sfilter 212 7.9.2 初始化回调、卸载回调和绑定回调 213 7.9.3 绑定与回调 215 7.9.4 插入请求回调 216 7.9.5 如何利用sfilter.lib 218 本章的示例代码 221 练习题 221 第8章 文件系统透明加密 223 8.1 文件透明加密的应用 224 8.1.1 防止企业信息泄密 224 8.1.2 文件透明加密防止企业信息泄密 224 8.1.3 文件透明加密软件的例子 225 8.2 区分进程 226 8.2.1 机密进程与普通进程 226 8.2.2 找到进程名字的位置 227 8.2.3 得到当前进程的名字 228 8.3 内存映射与文件缓冲 229 8.3.1 记事本的内存映射文件 229 8.3.2 Windows的文件缓冲 230 8.3.3 文件缓冲:明文还是密文的选择 232 8.3.4 清除文件缓冲 233 8.4 加密标识 236 8.4.1 保存在文件外、文件头还是文件尾 236 8.4.2 隐藏文件头的大小 237 8.4.3 隐藏文件头的设置偏移 239 8.4.4 隐藏文件头的读/写偏移 240 8.5 文件加密表 241 8.5.1 何时进行加密操作 241 8.5.2 文件控制块与文件对象 242 8.5.3 文件加密表的数据结构与初始化 243 8.5.4 文件加密表的操作:查询 244 8.5.5 文件加密表的操作:添加 245 8.5.6 文件加密表的操作:删除 246 8.6 文件打开处理 248 8.6.1 直接发送IRP进行查询与设置操作 248 8.6.2 直接发送IRP进行读/写操作 250 8.6.3 文件的非重入打开 252 8.6.4 文件的打开预处理 255 8.7 读写加密/解密 260 8.7.1 在读取时进行解密 260 8.7.2 分配与释放MDL 261 8.7.3 写请求加密 262 8.8 crypt_file的组装 265 8.8.1 crypt_file的初始化 265 8.8.2 crypt_file的IRP预处理 266 8.8.3 crypt_file的IRP后处理 269 本章的示例代码 272 练习题 272 第9章 文件系统微过滤驱动 273 9.1 文件系统微过滤驱动简介 274 9.1.1 文件系统微过滤驱动的由来 274 9.1.2 Minifilter的优点与不足 275 9.2 Minifilter的编程框架 275 9.2.1 微文件系统过滤的注册 276 9.2.2 微过滤器的数据结构 277 9.2.3 卸载回调函数 280 9.2.4 预操作回调函数 281 9.2.5 后操作回调函数 284 9.2.6 其他回调函数 285 9.3 Minifilter如何与应用程序通信 288 9.3.1 建立通信端口的方法 288 9.3.2 在用户态通过DLL使用通信端口的范例 290 9.4 Minifilter的安装与加载 292 9.4.1 安装Minifilter的INF文件 293 9.4.2 启动安装完成的Minifilter 294 本章的示例代码 295 练习题 295 第10章 网络传输层过滤 296 10.1 TDI概要 297 10.1.1 为何选择TDI 297 10.1.2 从socket到Windows内核 297 10.1.3 TDI过滤的代码例子 299 10.2 TDI的过滤框架 299 10.2.1 绑定TDI的设备 299 10.2.2 唯一的分发函数 300 10.2.3 过滤框架的实现 302 10.2.4 主要过滤的请求类型 304 10.3 生成请求:获取地址 305 10.3.1 过滤生成请求 305 10.3.2 准备解析IP地址与端口 307 10.3.3 获取生成的IP地址和端口 308 10.3.4 连接终端的生成与相关信息的保存 310 10.4 控制请求 311 10.4.1 TDI_ASSOCIATE_ADDRESS的过滤 311 10.4.2 TDI_CONNECT的过滤 313 10.4.3 其他的次功能号 314 10.4.4 设置事件的过滤 316 10.4.5 TDI_EVENT_CONNECT类型的设置事件的过滤 318 10.4.6 直接获取发送函数的过滤 320 10.4.7 清理请求的过滤 322 10.5 本书例子tdifw.lib的应用 323 10.5.1 tdifw库的 回调接口 323 10.5.2 tdifw库德使用例子 325 本章的示例代码 326 练习题 327 第11章 NDIS协议驱动 328 11.1 以太网包和网络驱动架构 329 11.1.1 以太网包和协议驱动 329 11.1.2 NDIS网络驱动 330 11.2 协议驱动的DriverEntry 331 11.2.1 生成控制设备 331 11.2.2 注册协议 333 11.3 协议与网卡的绑定 335 11.3.1 协议与网卡的绑定概念 335 11.3.2 绑定回调处理的实现 335 11.3.3 协议绑定网卡的API 338 11.3.4 解决绑定竞争问题 339 11.3.5 分配接收和发送的包池与缓冲池 340 11.3.6 OID请求的发送和请求完成回调 342 11.3.7 ndisprotCreateBinding的最终实现 345 11.4 绑定的解除 351 11.4.1 解除绑定使用的API 351 11.4.2 ndisportShutdownBinding的实现 353 11.5 在用户态操作协议驱动 356 11.5.1 协议的收包与发包 356 11.5.2 在用户态编程打开设备 357 11.5.3 用DeviceIoControl发送控制请求 358 11.5.4 用WriteFile发送数据包 360 11.5.5 用ReadFile发送数据包 362 11.6 在内核态完成功能的实现 363 11.6.1 请求的分发与实现 363 11.6.2 等待设备绑定完成与指定设备名 364 11.6.3 指派设备的完成 365 11.6.4 处理读请求 368 11.6.5 处理写请求 370 11.7 协议驱动的接收问题 374 11.7.1 和接收包有关的回调函数 374 11.7.2 ReceiveHandler的实现 376 11.7.3 TransferDataCompleteHandler的实现 380 11.7.4 ReceivePacketHandler的实现 381 11.7.5 接收数据包的入队 383 11.7.6 接收数据包的出队和读请求的完成 385 本章的示例代码 388 练习题 389 第12章 NDIS小端口驱动 390 12.1 小端口驱动的应用与概述 391 12.1.1 小端口驱动的应用 391 12.1.2 小端口驱动的实例 392 12.1.3 小端口驱动的运作与编程概述 393 12.2 小端口驱动的初始化 393 12.2.1 小端口驱动的DriverEntry 393 12.2.2 小端口驱动的适配器结构 396 12.2.3 配置信息的读取 397 12.2.4 设置小端口适配器上下文 398 12.2.5 MPInitialize的实现 399 12.2.6 MPHalt的实现 402 12.3 打开ndisprot设置 403 12.3.1 I/O目标 403 12.3.2 给IO目标发送DeviceIoControl请求 404 12.3.3 打开ndisprot接口并完成配置设备 406 12.4 使用ndisprot发送包 409 12.4.1 小端口驱动的发包接口 409 12.4.2 发送控制块(TCB) 409 12.4.3 遍历包组并填写TCB 412 12.4.4 写请求的构建与发送 415 12.5 使用ndisproot接收包 417 12.5.1 提交数据包的内核API 417 12.5.2 从接收控制块(RCB)提交包 418 12.5.3 对ndisprot读请求的完成函数 420 12.5.4 读请求的发送 422 12.5.5 用于读包的WDF工作任务 424 12.5.6 ndisedge读工作任务的生成与入列 426 12.6 其他的特征回调函数的实现 428 12.6.1 包的归还 428 12.6.2 OID查询处理的直接完成 429 12.6.3 OID设置处理 432 本章的示例代码 433 练习题 434 第13章 NDIS中间层驱动 435 13.1 NDIS中间层驱动概述 436 13.1.1 Windows网络架构总结 436 13.1.2 NDIS中间层驱动简介 437 13.1.3 NDIS中间层驱动的应用 438 13.1.4 NDIS包描述符结构深究 439 13.2 中间层驱动的入口与绑定 442 13.2.1 中间层驱动的入口函数 442 13.2.2 动态绑定NIC设备 443 13.2.3 小端口初始化(MpInitialize) 445 13.3 中间层驱动发送数据包 447 13.3.1 发送数据包原理 447 13.3.2 包描述符“重利用” 448 13.3.3 包描述符“重申请” 451 13.3.4 发送数据包的异步完成 453 13.4 中间层驱动接收数据包 455 13.4.1 接收数据包概述 455 13.4.2 用PtReceive接收数据包 456 13.4.3 用PtReceivePacket接收 461 13.4.4 对包进行过滤 463 13.5 中间层驱动程序查询和设置 466 13.5.1 查询请求的处理 466 13.5.2 设置请求的处理 468 13.6 NDIS句柄 470 13.6.1 不可见的结构指针 470 13.6.2 常见的NDIS句柄 471 13.6.3 NDIS句柄误用问题 473 13.6.4 一种解决方案 475 13.7 生成普通控制设备 476 13.7.1 在中间层驱动中添加普通设备 476 13.7.2 使用传统方法来生成控制设备 478 本章的示例代码 483 练习题 483 附录A 如何使用本书的源码光盘 485 精品图书免费试读 488 封底 489

2011-01-04

寒江独钓-Windows内核安全编程(高清完整版).part5

http://wangfaqiang.download.csdn.net/ 上面这个网址就可以看到所有8个的下载链接 内容简介   本书从Windows内核编程出发,全面系统地介绍了串口、键盘、磁盘、文件系统、网络等相关的Windows内核模块的编程技术,以及基于这些技术实现的密码保护、防毒引擎、文件加密、网络嗅探、网络防火墙等信息安全软件的核心组件的具体编程。主要知识重点包括:Windows串口与键盘过滤驱动、Windows虚拟存储设备与存储设备过滤驱动、Windows文件系统过滤驱动、文件系统透明加密/解密驱动、Windows各类网络驱动(包括TDI过滤驱动及三类NDIS驱动),以及最新的WDF驱动开发模型。有助于读者熟悉Windows内核驱动的体系结构,并精通信息安全类的内核编程技术。本书的大部分代码具有广泛的兼容性,适合从Windows 2000 一直到目前最新的Windows 7 Beta 版。   本书适合大专院校计算机系的学生、普通Windows程序员、Windows内核程序员、信息安全行业的程序员,以及希望了解Windows系统底层知识的计算机编程爱好者使用。阅读本书,需要读者有C语言、数据结构、操作系统和计算机网络的基础知识。 目录: 封面 -25 扉页 -24 内容简介 -23 序 -22 关于本书作者和贡献者 -20 前言 -18 阅读注意 -16 目录 -12 正文 1 第1章 内核上机指导 1 1.1 下载和使用WDK 2 1.1.1 下载安装WDK 2 1.1.2 编写第一个C文件 3 1.1.3 编译一个工程 5 1.2 安装与运行 6 1.2.1 下载一个安装工具 6 1.2.2 运行与查看输出信息 7 1.2.3 在虚拟机中运行 9 1.3 调试内核模块 9 1.3.1 下载和安装WinDbg 9 1.3.2 设置Windows XP 调试执行 10 1.3.3 设置Vista调试执行 11 1.3.4 设置VMWare的管道虚拟串口 11 1.3.5 设置Windows内核符号表 13 1.3.6 实战调试first 14 练习题 16 第2章 内核编程环境及其特殊性 17 2.1 内核编程的环境 18 2.1.1 隔离的应用程序 18 2.1.2 共享的内核空间 19 2.1.3 无处不在的内核模块 20 2.2 数据类型 21 2.2.1 基本数据类型 21 2.2.2 返回状态 22 2.2.3 字符串 23 2.3 重要的数据结构 23 2.3.1 驱动对象 23 2.3.2 设备对象 25 2.3.3 请求 26 2.4 函数调用 28 2.4.1 查阅帮助 28 2.4.2 帮助中有的几类函数 30 2.4.3 帮助中没有的函数 32 2.5 Windows的驱动开发模型 32 2.6 WDK编程中的特殊点 33 2.6.1 内核编程的主要调用源 33 2.6.2 函数的多线程安全性 34 2.6.3 代码的中断级 36 2.6.4 WDK中出现的特殊代码 37 练习题 38 第3章 串口的过滤 40 3.1 过滤的概念 41 3.1.1 设备绑定的内核API之一 41 3.1.2 设备绑定的内核API之二 43 3.1.3 生成过滤设备并绑定 43 3.1.4 从名字获得设备对象 45 3.1.5 绑定所有串口 46 3.2 获得实际数据 47 3.2.1 请求的区分 47 3.2.2 请求的结局 48 3.2.3 写请求的数据 49 3.3 完整的代码 50 3.3.1 完整的分发函数 50 3.3.2 如何动态卸载 52 3.3.3 完整的代码 53 本章的示例代码 53 练习题 54 第4章 键盘的过滤 56 4.1 技术原理 57 4.1.1 预备知识 57 4.1.2 Windows中从击键到内核 58 4.1.3 键盘硬件原理 60 4.2 键盘过滤的框架 61 4.2.1 找到所有的键盘设备 61 4.2.2 应用设备扩展 64 4.2.3 键盘过滤模块的DriverEntry 65 4.2.4 键盘过滤模块的动态加载 66 4.3 键盘过滤的请求处理 68 4.3.1 通常的处理 68 4.3.2 PNP的处理 69 4.3.3 读的处理 70 4.3.4 读完成的处理 71 4.4 从请求中打印出按键信息 72 4.4.1 从缓冲区中获得KEYBOARD_INPUT_DATA 72 4.4.2 从KEYBOARD_INPUT_DATA中得到键 73 4.4.3 从MakeCode到实际字符 74 4.5 Hook分发函数 75 4.5.1 获得类驱动对象 76 4.5.2 修改类驱动的分发函数指针 77 4.5.3 类驱动之下的端口驱动 78 4.5

2011-01-04

寒江独钓-Windows内核安全编程(高清完整版).part4

http://wangfaqiang.download.csdn.net/ 上面这个网址就可以看到所有8个的下载链接 内容简介   本书从Windows内核编程出发,全面系统地介绍了串口、键盘、磁盘、文件系统、网络等相关的Windows内核模块的编程技术,以及基于这些技术实现的密码保护、防毒引擎、文件加密、网络嗅探、网络防火墙等信息安全软件的核心组件的具体编程。主要知识重点包括:Windows串口与键盘过滤驱动、Windows虚拟存储设备与存储设备过滤驱动、Windows文件系统过滤驱动、文件系统透明加密/解密驱动、Windows各类网络驱动(包括TDI过滤驱动及三类NDIS驱动),以及最新的WDF驱动开发模型。有助于读者熟悉Windows内核驱动的体系结构,并精通信息安全类的内核编程技术。本书的大部分代码具有广泛的兼容性,适合从Windows 2000 一直到目前最新的Windows 7 Beta 版。   本书适合大专院校计算机系的学生、普通Windows程序员、Windows内核程序员、信息安全行业的程序员,以及希望了解Windows系统底层知识的计算机编程爱好者使用。阅读本书,需要读者有C语言、数据结构、操作系统和计算机网络的基础知识。 目录: 封面 -25 扉页 -24 内容简介 -23 序 -22 关于本书作者和贡献者 -20 前言 -18 阅读注意 -16 目录 -12 正文 1 第1章 内核上机指导 1 1.1 下载和使用WDK 2 1.1.1 下载安装WDK 2 1.1.2 编写第一个C文件 3 1.1.3 编译一个工程 5 1.2 安装与运行 6 1.2.1 下载一个安装工具 6 1.2.2 运行与查看输出信息 7 1.2.3 在虚拟机中运行 9 1.3 调试内核模块 9 1.3.1 下载和安装WinDbg 9 1.3.2 设置Windows XP 调试执行 10 1.3.3 设置Vista调试执行 11 1.3.4 设置VMWare的管道虚拟串口 11 1.3.5 设置Windows内核符号表 13 1.3.6 实战调试first 14 练习题 16 第2章 内核编程环境及其特殊性 17 2.1 内核编程的环境 18 2.1.1 隔离的应用程序 18 2.1.2 共享的内核空间 19 2.1.3 无处不在的内核模块 20 2.2 数据类型 21 2.2.1 基本数据类型 21 2.2.2 返回状态 22 2.2.3 字符串 23 2.3 重要的数据结构 23 2.3.1 驱动对象 23 2.3.2 设备对象 25 2.3.3 请求 26 2.4 函数调用 28 2.4.1 查阅帮助 28 2.4.2 帮助中有的几类函数 30 2.4.3 帮助中没有的函数 32 2.5 Windows的驱动开发模型 32 2.6 WDK编程中的特殊点 33 2.6.1 内核编程的主要调用源 33 2.6.2 函数的多线程安全性 34 2.6.3 代码的中断级 36 2.6.4 WDK中出现的特殊代码 37 练习题 38 第3章 串口的过滤 40 3.1 过滤的概念 41 3.1.1 设备绑定的内核API之一 41 3.1.2 设备绑定的内核API之二 43 3.1.3 生成过滤设备并绑定 43 3.1.4 从名字获得设备对象 45 3.1.5 绑定所有串口 46 3.2 获得实际数据 47 3.2.1 请求的区分 47 3.2.2 请求的结局 48 3.2.3 写请求的数据 49 3.3 完整的代码 50 3.3.1 完整的分发函数 50 3.3.2 如何动态卸载 52 3.3.3 完整的代码 53 本章的示例代码 53 练习题 54 第4章 键盘的过滤 56 4.1 技术原理 57 4.1.1 预备知识 57 4.1.2 Windows中从击键到内核 58 4.1.3 键盘硬件原理 60 4.2 键盘过滤的框架 61 4.2.1 找到所有的键盘设备 61 4.2.2 应用设备扩展 64 4.2.3 键盘过滤模块的DriverEntry 65 4.2.4 键盘过滤模块的动态加载 66 4.3 键盘过滤的请求处理 68 4.3.1 通常的处理 68 4.3.2 PNP的处理 69 4.3.3 读的处理 70 4.3.4 读完成的处理 71 4.4 从请求中打印出按键信息 72 4.4.1 从缓冲区中获得KEYBOARD_INPUT_DATA 72 4.4.2 从KEYBOARD_INPUT_DATA中得到键 73 4.4.3 从MakeCode到实际字符 74 4.5 Hook分发函数 75 4.5.1 获得类驱动对象 76 4.5.2 修改类驱动的分发函数指针 77 4.5.3 类驱动之下的端口驱动 78 4.5.4 端口驱动和驱动之间的协作机制 79 4.5.5 找到关键的回调函数的条件 80 4.5.6 定义常数和数据结构 80 4.5.7 打开两种键盘端口驱动寻找设备 81 4.5.8 搜索在kbdClass类驱动中的地址 83 4.6 Hook键盘中断反过滤 86 4.6.1 中断:IRQ和INT 86 4.6.2 如何修改IDT 87 4.6.3 替换IDT中的跳转地址 88 4.6.4 QQ的PS/2反过滤措施 90 4.7 利用IOAPIC重定位中断处理函数 90 4.7.1 什么是IOAPIC 90 4.7.2 如何访问IOAPIC 91 4.7.3 编程修改IOAPIC重定位表 92 4.7.4 插入新的中断处理 93 4.7.5 驱动入口和卸载的实现 95 4.8 直接用端口操作键盘 96 4.8.1 读取键盘数据和命令端口 96 4.8.2 p2cUserFilter的最终实现 97 本章的示例代码 98 练习题 99 第5章 磁盘的虚拟 100 5.1 虚拟的磁盘 101 5.2 一个具体的例子 101 5.3 入口函数 102 5.3.1 入口函数的定义 102 5.3.2 Ramdisk驱动的入口函数 103 5.4 EvtDriverDeviceAdd函数 104 5.4.1 EvtDriverDeviceAdd的定义 104 5.4.2 局部变量的声明 105 5.4.3 磁盘设备的创建 105 5.4.4 如何处理发往设备的请求 107 5.4.5 用户配置的初始化 108 5.4.6 链接给应用程序 110 5.4.7 小结 111 5.5 FAT12/16磁盘卷初始化 111 5.5.1 磁盘卷结构简介 111 5.5.2 Ramdisk对磁盘的初始化 113 5.6 驱动中的请求处理 119 5.6.1 请求的处理 119 5.6.2 读/写请求 120 5.6.3 DeviceIoControl请求 122 5.7 Ramdisk的编译和安装 124 5.7.1 编译 124 5.7.2 安装 125 5.7.3 对安装的深入研究 125 练习题 126 第6章 磁盘过滤 127 6.1 磁盘过滤驱动的概念 128 6.1.1 设备过滤和类过滤 128 6.1.2 磁盘设备和磁盘卷设备过滤驱动 128 6.1.3 注册表和磁盘卷设备过滤驱动 129 6.2 具有还原功能的磁盘卷过滤驱动 129 6.2.1 简介 129 6.2.2 基本思想 130 6.3 驱动分析 130 6.3.1 DriverEntry函数 130 6.3.2 AddDevice函数 132 6.3.3 PnP请求的处理 136 6.3.4 Power请求的处理 140 6.3.5 DeviceIoControl请求的处理 140 6.3.6 bitmap的作用和分析 144 6.3.7 boot驱动完成回调函数和稀疏文件 150 6.3.8 读/写请求的处理 152 本章的示例代码 160 练习题 161 第7章 文件系统的过滤与监控 162 7.1 文件系统的设备对象 163 7.1.1 控制设备与卷设备 163 7.1.2 生成自己的一个控制设备 165 7.2 文件系统的分发函数 166 7.2.1 普通的分发函数 166 7.2.2 文件过滤的快速IO分发函数 167 7.2.3 快速IO分发函数的一个实现 169 7.2.4 快速IO分发函数逐个简介 170 7.3 设备的绑定前期工作 172 7.3.1 动态地选择绑定函数 172 7.3.2 注册文件系统变动回调 173 7.3.3 文件系统变动回调的一个实现 175 7.3.4 文件系统识别器 176 7.4 文件系统控制设备的绑定 177 7.4.1 生成文件系统控制设备的过滤设备 177 7.4.2 绑定文件系统控制设备 178 7.4.3 利用文件系统控制请求 180 7.5 文件系统卷设备的绑定 183 7.5.1 从IRP中获得VPB指针 183 7.5.2 设置完成函数并等待IRP完成 184 7.5.3 卷挂载IRP完成后的工作 187 7.5.4 完成函数的相应实现 190 7.5.5 绑定卷的实现 191 7.6 读/写操作的过滤 193 7.6.1 设置一个读处理函数 193 7.6.2 设备对象的区分处理 194 7.6.3 解析读请求中的文件信息 195 7.6.4 读请求的完成 198 7.7 其他操作的过滤 202 7.7.1 文件对象的生存周期 202 7.7.2 文件的打开与关闭 203 7.7.3 文件的删除 205 7.8 路径过滤的实现 206 7.8.1 取得文件路径的三种情况 206 7.8.2 打开成功后获取路径 207 7.8.3 在其他时刻获得文件路径 209 7.8.4 在打开请求完成之前获得路径 209 7.8.5 把短名转换为长名 211 7.9 把sfilter编译成静态库 212 7.9.1 如何方便地使用sfilter 212 7.9.2 初始化回调、卸载回调和绑定回调 213 7.9.3 绑定与回调 215 7.9.4 插入请求回调 216 7.9.5 如何利用sfilter.lib 218 本章的示例代码 221 练习题 221 第8章 文件系统透明加密 223 8.1 文件透明加密的应用 224 8.1.1 防止企业信息泄密 224 8.1.2 文件透明加密防止企业信息泄密 224 8.1.3 文件透明加密软件的例子 225 8.2 区分进程 226 8.2.1 机密进程与普通进程 226 8.2.2 找到进程名字的位置 227 8.2.3 得到当前进程的名字 228 8.3 内存映射与文件缓冲 229 8.3.1 记事本的内存映射文件 229 8.3.2 Windows的文件缓冲 230 8.3.3 文件缓冲:明文还是密文的选择 232 8.3.4 清除文件缓冲 233 8.4 加密标识 236 8.4.1 保存在文件外、文件头还是文件尾 236 8.4.2 隐藏文件头的大小 237 8.4.3 隐藏文件头的设置偏移 239 8.4.4 隐藏文件头的读/写偏移 240 8.5 文件加密表 241 8.5.1 何时进行加密操作 241 8.5.2 文件控制块与文件对象 242 8.5.3 文件加密表的数据结构与初始化 243 8.5.4 文件加密表的操作:查询 244 8.5.5 文件加密表的操作:添加 245 8.5.6 文件加密表的操作:删除 246 8.6 文件打开处理 248 8.6.1 直接发送IRP进行查询与设置操作 248 8.6.2 直接发送IRP进行读/写操作 250 8.6.3 文件的非重入打开 252 8.6.4 文件的打开预处理 255 8.7 读写加密/解密 260 8.7.1 在读取时进行解密 260 8.7.2 分配与释放MDL 261 8.7.3 写请求加密 262 8.8 crypt_file的组装 265 8.8.1 crypt_file的初始化 265 8.8.2 crypt_file的IRP预处理 266 8.8.3 crypt_file的IRP后处理 269 本章的示例代码 272 练习题 272 第9章 文件系统微过滤驱动 273 9.1 文件系统微过滤驱动简介 274 9.1.1 文件系统微过滤驱动的由来 274 9.1.2 Minifilter的优点与不足 275 9.2 Minifilter的编程框架 275 9.2.1 微文件系统过滤的注册 276 9.2.2 微过滤器的数据结构 277 9.2.3 卸载回调函数 280 9.2.4 预操作回调函数 281 9.2.5 后操作回调函数 284 9.2.6 其他回调函数 285 9.3 Minifilter如何与应用程序通信 288 9.3.1 建立通信端口的方法 288 9.3.2 在用户态通过DLL使用通信端口的范例 290 9.4 Minifilter的安装与加载 292 9.4.1 安装Minifilter的INF文件 293 9.4.2 启动安装完成的Minifilter 294 本章的示例代码 295 练习题 295 第10章 网络传输层过滤 296 10.1 TDI概要 297 10.1.1 为何选择TDI 297 10.1.2 从socket到Windows内核 297 10.1.3 TDI过滤的代码例子 299 10.2 TDI的过滤框架 299 10.2.1 绑定TDI的设备 299 10.2.2 唯一的分发函数 300 10.2.3 过滤框架的实现 302 10.2.4 主要过滤的请求类型 304 10.3 生成请求:获取地址 305 10.3.1 过滤生成请求 305 10.3.2 准备解析IP地址与端口 307 10.3.3 获取生成的IP地址和端口 308 10.3.4 连接终端的生成与相关信息的保存 310 10.4 控制请求 311 10.4.1 TDI_ASSOCIATE_ADDRESS的过滤 311 10.4.2 TDI_CONNECT的过滤 313 10.4.3 其他的次功能号 314 10.4.4 设置事件的过滤 316 10.4.5 TDI_EVENT_CONNECT类型的设置事件的过滤 318 10.4.6 直接获取发送函数的过滤 320 10.4.7 清理请求的过滤 322 10.5 本书例子tdifw.lib的应用 323 10.5.1 tdifw库的 回调接口 323 10.5.2 tdifw库德使用例子 325 本章的示例代码 326 练习题 327 第11章 NDIS协议驱动 328 11.1 以太网包和网络驱动架构 329 11.1.1 以太网包和协议驱动 329 11.1.2 NDIS网络驱动 330 11.2 协议驱动的DriverEntry 331 11.2.1 生成控制设备 331 11.2.2 注册协议 333 11.3 协议与网卡的绑定 335 11.3.1 协议与网卡的绑定概念 335 11.3.2 绑定回调处理的实现 335 11.3.3 协议绑定网卡的API 338 11.3.4 解决绑定竞争问题 339 11.3.5 分配接收和发送的包池与缓冲池 340 11.3.6 OID请求的发送和请求完成回调 342 11.3.7 ndisprotCreateBinding的最终实现 345 11.4 绑定的解除 351 11.4.1 解除绑定使用的API 351 11.4.2 ndisportShutdownBinding的实现 353 11.5 在用户态操作协议驱动 356 11.5.1 协议的收包与发包 356 11.5.2 在用户态编程打开设备 357 11.5.3 用DeviceIoControl发送控制请求 358 11.5.4 用WriteFile发送数据包 360 11.5.5 用ReadFile发送数据包 362 11.6 在内核态完成功能的实现 363 11.6.1 请求的分发与实现 363 11.6.2 等待设备绑定完成与指定设备名 364 11.6.3 指派设备的完成 365 11.6.4 处理读请求 368 11.6.5 处理写请求 370 11.7 协议驱动的接收问题 374 11.7.1 和接收包有关的回调函数 374 11.7.2 ReceiveHandler的实现 376 11.7.3 TransferDataCompleteHandler的实现 380 11.7.4 ReceivePacketHandler的实现 381 11.7.5 接收数据包的入队 383 11.7.6 接收数据包的出队和读请求的完成 385 本章的示例代码 388 练习题 389 第12章 NDIS小端口驱动 390 12.1 小端口驱动的应用与概述 391 12.1.1 小端口驱动的应用 391 12.1.2 小端口驱动的实例 392 12.1.3 小端口驱动的运作与编程概述 393 12.2 小端口驱动的初始化 393 12.2.1 小端口驱动的DriverEntry 393 12.2.2 小端口驱动的适配器结构 396 12.2.3 配置信息的读取 397 12.2.4 设置小端口适配器上下文 398 12.2.5 MPInitialize的实现 399 12.2.6 MPHalt的实现 402 12.3 打开ndisprot设置 403 12.3.1 I/O目标 403 12.3.2 给IO目标发送DeviceIoControl请求 404 12.3.3 打开ndisprot接口并完成配置设备 406 12.4 使用ndisprot发送包 409 12.4.1 小端口驱动的发包接口 409 12.4.2 发送控制块(TCB) 409 12.4.3 遍历包组并填写TCB 412 12.4.4 写请求的构建与发送 415 12.5 使用ndisproot接收包 417 12.5.1 提交数据包的内核API 417 12.5.2 从接收控制块(RCB)提交包 418 12.5.3 对ndisprot读请求的完成函数 420 12.5.4 读请求的发送 422 12.5.5 用于读包的WDF工作任务 424 12.5.6 ndisedge读工作任务的生成与入列 426 12.6 其他的特征回调函数的实现 428 12.6.1 包的归还 428 12.6.2 OID查询处理的直接完成 429 12.6.3 OID设置处理 432 本章的示例代码 433 练习题 434 第13章 NDIS中间层驱动 435 13.1 NDIS中间层驱动概述 436 13.1.1 Windows网络架构总结 436 13.1.2 NDIS中间层驱动简介 437 13.1.3 NDIS中间层驱动的应用 438 13.1.4 NDIS包描述符结构深究 439 13.2 中间层驱动的入口与绑定 442 13.2.1 中间层驱动的入口函数 442 13.2.2 动态绑定NIC设备 443 13.2.3 小端口初始化(MpInitialize) 445 13.3 中间层驱动发送数据包 447 13.3.1 发送数据包原理 447 13.3.2 包描述符“重利用” 448 13.3.3 包描述符“重申请” 451 13.3.4 发送数据包的异步完成 453 13.4 中间层驱动接收数据包 455 13.4.1 接收数据包概述 455 13.4.2 用PtReceive接收数据包 456 13.4.3 用PtReceivePacket接收 461 13.4.4 对包进行过滤 463 13.5 中间层驱动程序查询和设置 466 13.5.1 查询请求的处理 466 13.5.2 设置请求的处理 468 13.6 NDIS句柄 470 13.6.1 不可见的结构指针 470 13.6.2 常见的NDIS句柄 471 13.6.3 NDIS句柄误用问题 473 13.6.4 一种解决方案 475 13.7 生成普通控制设备 476 13.7.1 在中间层驱动中添加普通设备 476 13.7.2 使用传统方法来生成控制设备 478 本章的示例代码 483 练习题 483 附录A 如何使用本书的源码光盘 485 精品图书免费试读 488 封底 489

2011-01-04

寒江独钓-Windows内核安全编程(高清完整版).part3

http://wangfaqiang.download.csdn.net/ 上面这个网址就可以看到所有8个的下载链接 内容简介   本书从Windows内核编程出发,全面系统地介绍了串口、键盘、磁盘、文件系统、网络等相关的Windows内核模块的编程技术,以及基于这些技术实现的密码保护、防毒引擎、文件加密、网络嗅探、网络防火墙等信息安全软件的核心组件的具体编程。主要知识重点包括:Windows串口与键盘过滤驱动、Windows虚拟存储设备与存储设备过滤驱动、Windows文件系统过滤驱动、文件系统透明加密/解密驱动、Windows各类网络驱动(包括TDI过滤驱动及三类NDIS驱动),以及最新

2011-01-04

寒江独钓-Windows内核安全编程(高清完整版).part2

内容简介   本书从Windows内核编程出发,全面系统地介绍了串口、键盘、磁盘、文件系统、网络等相关的Windows内核模块的编程技术,以及基于这些技术实现的密码保护、防毒引擎、文件加密、网络嗅探、网络防火墙等信息安全软件的核心组件的具体编程。主要知识重点包括:Windows串口与键盘过滤驱动、Windows虚拟存储设备与存储设备过滤驱动、Windows文件系统过滤驱动、文件系统透明加密/解密驱动、Windows各类网络驱动(包括TDI过滤驱动及三类NDIS驱动),以及最新的WDF驱动开发模型。有助于读者熟悉Windows内核驱动的体系结构,并精通信息安全类的内核编程技术。本书的大部分代码具有广泛的兼容性,适合从Windows 2000 一直到目前最新的Windows 7 Beta 版。   本书适合大专院校计算机系的学生、普通Windows程序员、Windows内核程序员、信息安全行业的程序员,以及希望了解Windows系统底层知识的计算机编程爱好者使用。阅读本书,需要读者有C语言、数据结构、操作系统和计算机网络的基础知识。 目录: 封面 -25 扉页 -24 内容简介 -23 序 -22 关于本书作者和贡献者 -20 前言 -18 阅读注意 -16 目录 -12 正文 1 第1章 内核上机指导 1 1.1 下载和使用WDK 2 1.1.1 下载安装WDK 2 1.1.2 编写第一个C文件 3 1.1.3 编译一个工程 5 1.2 安装与运行 6 1.2.1 下载一个安装工具 6 1.2.2 运行与查看输出信息 7 1.2.3 在虚拟机中运行 9 1.3 调试内核模块 9 1.3.1 下载和安装WinDbg 9 1.3.2 设置Windows XP 调试执行 10 1.3.3 设置Vista调试执行 11 1.3.4 设置VMWare的管道虚拟串口 11 1.3.5 设置Windows内核符号表 13 1.3.6 实战调试first 14 练习题 16 第2章 内核编程环境及其特殊性 17 2.1 内核编程的环境 18 2.1.1 隔离的应用程序 18 2.1.2 共享的内核空间 19 2.1.3 无处不在的内核模块 20 2.2 数据类型 21 2.2.1 基本数据类型 21 2.2.2 返回状态 22 2.2.3 字符串 23 2.3 重要的数据结构 23 2.3.1 驱动对象 23 2.3.2 设备对象 25 2.3.3 请求 26 2.4 函数调用 28 2.4.1 查阅帮助 28 2.4.2 帮助中有的几类函数 30 2.4.3 帮助中没有的函数 32 2.5 Windows的驱动开发模型 32 2.6 WDK编程中的特殊点 33 2.6.1 内核编程的主要调用源 33 2.6.2 函数的多线程安全性 34 2.6.3 代码的中断级 36 2.6.4 WDK中出现的特殊代码 37 练习题 38 第3章 串口的过滤 40 3.1 过滤的概念 41 3.1.1 设备绑定的内核API之一 41 3.1.2 设备绑定的内核API之二 43 3.1.3 生成过滤设备并绑定 43 3.1.4 从名字获得设备对象 45 3.1.5 绑定所有串口 46 3.2 获得实际数据 47 3.2.1 请求的区分 47 3.2.2 请求的结局 48 3.2.3 写请求的数据 49 3.3 完整的代码 50 3.3.1 完整的分发函数 50 3.3.2 如何动态卸载 52 3.3.3 完整的代码 53 本章的示例代码 53 练习题 54 第4章 键盘的过滤 56 4.1 技术原理 57 4.1.1 预备知识 57 4.1.2 Windows中从击键到内核 58 4.1.3 键盘硬件原理 60 4.2 键盘过滤的框架 61 4.2.1 找到所有的键盘设备 61 4.2.2 应用设备扩展 64 4.2.3 键盘过滤模块的DriverEntry 65 4.2.4 键盘过滤模块的动态加载 66 4.3 键盘过滤的请求处理 68 4.3.1 通常的处理 68 4.3.2 PNP的处理 69 4.3.3 读的处理 70 4.3.4 读完成的处理 71 4.4 从请求中打印出按键信息 72 4.4.1 从缓冲区中获得KEYBOARD_INPUT_DATA 72 4.4.2 从KEYBOARD_INPUT_DATA中得到键 73 4.4.3 从MakeCode到实际字符 74 4.5 Hook分发函数 75 4.5.1 获得类驱动对象 76 4.5.2 修改类驱动的分发函数指针 77 4.5.3 类驱动之下的端口驱动 78 4.5.4 端口驱动和驱动之间的协作机制 79 4.5.5 找到关键的回调函数的条件 80 4.5.6 定义常数和数据结构 80 4.5.7 打开两种键盘端口驱动寻找设备 81 4.5.8 搜索在kbdClass类驱动中的地址 83 4.6 Hook键盘中断反过滤 86 4.6.1 中断:IRQ和INT 86 4.6.2 如何修改IDT 87 4.6.3 替换IDT中的跳转地址 88 4.6.4 QQ的PS/2反过滤措施 90 4.7 利用IOAPIC重定位中断处理函数 90 4.7.1 什么是IOAPIC 90 4.7.2 如何访问IOAPIC 91 4.7.3 编程修改IOAPIC重定位表 92 4.7.4 插入新的中断处理 93 4.7.5 驱动入口和卸载的实现 95 4.8 直接用端口操作键盘 96 4.8.1 读取键盘数据和命令端口 96 4.8.2 p2cUserFilter的最终实现 97 本章的示例代码 98 练习题 99 第5章 磁盘的虚拟 100 5.1 虚拟的磁盘 101 5.2 一个具体的例子 101 5.3 入口函数 102 5.3.1 入口函数的定义 102 5.3.2 Ramdisk驱动的入口函数 103 5.4 EvtDriverDeviceAdd函数 104 5.4.1 EvtDriverDeviceAdd的定义 104 5.4.2 局部变量的声明 105 5.4.3 磁盘设备的创建 105 5.4.4 如何处理发往设备的请求 107 5.4.5 用户配置的初始化 108 5.4.6 链接给应用程序 110 5.4.7 小结 111 5.5 FAT12/16磁盘卷初始化 111 5.5.1 磁盘卷结构简介 111 5.5.2 Ramdisk对磁盘的初始化 113 5.6 驱动中的请求处理 119 5.6.1 请求的处理 119 5.6.2 读/写请求 120 5.6.3 DeviceIoControl请求 122 5.7 Ramdisk的编译和安装 124 5.7.1 编译 124 5.7.2 安装 125 5.7.3 对安装的深入研究 125 练习题 126 第6章 磁盘过滤 127 6.1 磁盘过滤驱动的概念 128 6.1.1 设备过滤和类过滤 128 6.1.2 磁盘设备和磁盘卷设备过滤驱动 128 6.1.3 注册表和磁盘卷设备过滤驱动 129 6.2 具有还原功能的磁盘卷过滤驱动 129 6.2.1 简介 129 6.2.2 基本思想 130 6.3 驱动分析 130 6.3.1 DriverEntry函数 130 6.3.2 AddDevice函数 132 6.3.3 PnP请求的处理 136 6.3.4 Power请求的处理 140 6.3.5 DeviceIoControl请求的处理 140 6.3.6 bitmap的作用和分析 144 6.3.7 boot驱动完成回调函数和稀疏文件 150 6.3.8 读/写请求的处理 152 本章的示例代码 160 练习题 161 第7章 文件系统的过滤与监控 162 7.1 文件系统的设备对象 163 7.1.1 控制设备与卷设备 163 7.1.2 生成自己的一个控制设备 165 7.2 文件系统的分发函数 166 7.2.1 普通的分发函数 166 7.2.2 文件过滤的快速IO分发函数 167 7.2.3 快速IO分发函数的一个实现 169 7.2.4 快速IO分发函数逐个简介 170 7.3 设备的绑定前期工作 172 7.3.1 动态地选择绑定函数 172 7.3.2 注册文件系统变动回调 173 7.3.3 文件系统变动回调的一个实现 175 7.3.4 文件系统识别器 176 7.4 文件系统控制设备的绑定 177 7.4.1 生成文件系统控制设备的过滤设备 177 7.4.2 绑定文件系统控制设备 178 7.4.3 利用文件系统控制请求 180 7.5 文件系统卷设备的绑定 183 7.5.1 从IRP中获得VPB指针 183 7.5.2 设置完成函数并等待IRP完成 184 7.5.3 卷挂载IRP完成后的工作 187 7.5.4 完成函数的相应实现 190 7.5.5 绑定卷的实现 191 7.6 读/写操作的过滤 193 7.6.1 设置一个读处理函数 193 7.6.2 设备对象的区分处理 194 7.6.3 解析读请求中的文件信息 195 7.6.4 读请求的完成 198 7.7 其他操作的过滤 202 7.7.1 文件对象的生存周期 202 7.7.2 文件的打开与关闭 203 7.7.3 文件的删除 205 7.8 路径过滤的实现 206 7.8.1 取得文件路径的三种情况 206 7.8.2 打开成功后获取路径 207 7.8.3 在其他时刻获得文件路径 209 7.8.4 在打开请求完成之前获得路径 209 7.8.5 把短名转换为长名 211 7.9 把sfilter编译成静态库 212 7.9.1 如何方便地使用sfilter 212 7.9.2 初始化回调、卸载回调和绑定回调 213 7.9.3 绑定与回调 215 7.9.4 插入请求回调 216 7.9.5 如何利用sfilter.lib 218 本章的示例代码 221 练习题 221 第8章 文件系统透明加密 223 8.1 文件透明加密的应用 224 8.1.1 防止企业信息泄密 224 8.1.2 文件透明加密防止企业信息泄密 224 8.1.3 文件透明加密软件的例子 225 8.2 区分进程 226 8.2.1 机密进程与普通进程 226 8.2.2 找到进程名字的位置 227 8.2.3 得到当前进程的名字 228 8.3 内存映射与文件缓冲 229 8.3.1 记事本的内存映射文件 229 8.3.2 Windows的文件缓冲 230 8.3.3 文件缓冲:明文还是密文的选择 232 8.3.4 清除文件缓冲 233 8.4 加密标识 236 8.4.1 保存在文件外、文件头还是文件尾 236 8.4.2 隐藏文件头的大小 237 8.4.3 隐藏文件头的设置偏移 239 8.4.4 隐藏文件头的读/写偏移 240 8.5 文件加密表 241 8.5.1 何时进行加密操作 241 8.5.2 文件控制块与文件对象 242 8.5.3 文件加密表的数据结构与初始化 243 8.5.4 文件加密表的操作:查询 244 8.5.5 文件加密表的操作:添加 245 8.5.6 文件加密表的操作:删除 246 8.6 文件打开处理 248 8.6.1 直接发送IRP进行查询与设置操作 248 8.6.2 直接发送IRP进行读/写操作 250 8.6.3 文件的非重入打开 252 8.6.4 文件的打开预处理 255 8.7 读写加密/解密 260 8.7.1 在读取时进行解密 260 8.7.2 分配与释放MDL 261 8.7.3 写请求加密 262 8.8 crypt_file的组装 265 8.8.1 crypt_file的初始化 265 8.8.2 crypt_file的IRP预处理 266 8.8.3 crypt_file的IRP后处理 269 本章的示例代码 272 练习题 272 第9章 文件系统微过滤驱动 273 9.1 文件系统微过滤驱动简介 274 9.1.1 文件系统微过滤驱动的由来 274 9.1.2 Minifilter的优点与不足 275 9.2 Minifilter的编程框架 275 9.2.1 微文件系统过滤的注册 276 9.2.2 微过滤器的数据结构 277 9.2.3 卸载回调函数 280 9.2.4 预操作回调函数 281 9.2.5 后操作回调函数 284 9.2.6 其他回调函数 285 9.3 Minifilter如何与应用程序通信 288 9.3.1 建立通信端口的方法 288 9.3.2 在用户态通过DLL使用通信端口的范例 290 9.4 Minifilter的安装与加载 292 9.4.1 安装Minifilter的INF文件 293 9.4.2 启动安装完成的Minifilter 294 本章的示例代码 295 练习题 295 第10章 网络传输层过滤 296 10.1 TDI概要 297 10.1.1 为何选择TDI 297 10.1.2 从socket到Windows内核 297 10.1.3 TDI过滤的代码例子 299 10.2 TDI的过滤框架 299 10.2.1 绑定TDI的设备 299 10.2.2 唯一的分发函数 300 10.2.3 过滤框架的实现 302 10.2.4 主要过滤的请求类型 304 10.3 生成请求:获取地址 305 10.3.1 过滤生成请求 305 10.3.2 准备解析IP地址与端口 307 10.3.3 获取生成的IP地址和端口 308 10.3.4 连接终端的生成与相关信息的保存 310 10.4 控制请求 311 10.4.1 TDI_ASSOCIATE_ADDRESS的过滤 311 10.4.2 TDI_CONNECT的过滤 313 10.4.3 其他的次功能号 314 10.4.4 设置事件的过滤 316 10.4.5 TDI_EVENT_CONNECT类型的设置事件的过滤 318 10.4.6 直接获取发送函数的过滤 320 10.4.7 清理请求的过滤 322 10.5 本书例子tdifw.lib的应用 323 10.5.1 tdifw库的 回调接口 323 10.5.2 tdifw库德使用例子 325 本章的示例代码 326 练习题 327 第11章 NDIS协议驱动 328 11.1 以太网包和网络驱动架构 329 11.1.1 以太网包和协议驱动 329 11.1.2 NDIS网络驱动 330 11.2 协议驱动的DriverEntry 331 11.2.1 生成控制设备 331 11.2.2 注册协议 333 11.3 协议与网卡的绑定 335 11.3.1 协议与网卡的绑定概念 335 11.3.2 绑定回调处理的实现 335 11.3.3 协议绑定网卡的API 338 11.3.4 解决绑定竞争问题 339 11.3.5 分配接收和发送的包池与缓冲池 340 11.3.6 OID请求的发送和请求完成回调 342 11.3.7 ndisprotCreateBinding的最终实现 345 11.4 绑定的解除 351 11.4.1 解除绑定使用的API 351 11.4.2 ndisportShutdownBinding的实现 353 11.5 在用户态操作协议驱动 356 11.5.1 协议的收包与发包 356 11.5.2 在用户态编程打开设备 357 11.5.3 用DeviceIoControl发送控制请求 358 11.5.4 用WriteFile发送数据包 360 11.5.5 用ReadFile发送数据包 362 11.6 在内核态完成功能的实现 363 11.6.1 请求的分发与实现 363 11.6.2 等待设备绑定完成与指定设备名 364 11.6.3 指派设备的完成 365 11.6.4 处理读请求 368 11.6.5 处理写请求 370 11.7 协议驱动的接收问题 374 11.7.1 和接收包有关的回调函数 374 11.7.2 ReceiveHandler的实现 376 11.7.3 TransferDataCompleteHandler的实现 380 11.7.4 ReceivePacketHandler的实现 381 11.7.5 接收数据包的入队 383 11.7.6 接收数据包的出队和读请求的完成 385 本章的示例代码 388 练习题 389 第12章 NDIS小端口驱动 390 12.1 小端口驱动的应用与概述 391 12.1.1 小端口驱动的应用 391 12.1.2 小端口驱动的实例 392 12.1.3 小端口驱动的运作与编程概述 393 12.2 小端口驱动的初始化 393 12.2.1 小端口驱动的DriverEntry 393 12.2.2 小端口驱动的适配器结构 396 12.2.3 配置信息的读取 397 12.2.4 设置小端口适配器上下文 398 12.2.5 MPInitialize的实现 399 12.2.6 MPHalt的实现 402 12.3 打开ndisprot设置 403 12.3.1 I/O目标 403 12.3.2 给IO目标发送DeviceIoControl请求 404 12.3.3 打开ndisprot接口并完成配置设备 406 12.4 使用ndisprot发送包 409 12.4.1 小端口驱动的发包接口 409 12.4.2 发送控制块(TCB) 409 12.4.3 遍历包组并填写TCB 412 12.4.4 写请求的构建与发送 415 12.5 使用ndisproot接收包 417 12.5.1 提交数据包的内核API 417 12.5.2 从接收控制块(RCB)提交包 418 12.5.3 对ndisprot读请求的完成函数 420 12.5.4 读请求的发送 422 12.5.5 用于读包的WDF工作任务 424 12.5.6 ndisedge读工作任务的生成与入列 426 12.6 其他的特征回调函数的实现 428 12.6.1 包的归还 428 12.6.2 OID查询处理的直接完成 429 12.6.3 OID设置处理 432 本章的示例代码 433 练习题 434 第13章 NDIS中间层驱动 435 13.1 NDIS中间层驱动概述 436 13.1.1 Windows网络架构总结 436 13.1.2 NDIS中间层驱动简介 437 13.1.3 NDIS中间层驱动的应用 438 13.1.4 NDIS包描述符结构深究 439 13.2 中间层驱动的入口与绑定 442 13.2.1 中间层驱动的入口函数 442 13.2.2 动态绑定NIC设备 443 13.2.3 小端口初始化(MpInitialize) 445 13.3 中间层驱动发送数据包 447 13.3.1 发送数据包原理 447 13.3.2 包描述符“重利用” 448 13.3.3 包描述符“重申请” 451 13.3.4 发送数据包的异步完成 453 13.4 中间层驱动接收数据包 455 13.4.1 接收数据包概述 455 13.4.2 用PtReceive接收数据包 456 13.4.3 用PtReceivePacket接收 461 13.4.4 对包进行过滤 463 13.5 中间层驱动程序查询和设置 466 13.5.1 查询请求的处理 466 13.5.2 设置请求的处理 468 13.6 NDIS句柄 470 13.6.1 不可见的结构指针 470 13.6.2 常见的NDIS句柄 471 13.6.3 NDIS句柄误用问题 473 13.6.4 一种解决方案 475 13.7 生成普通控制设备 476 13.7.1 在中间层驱动中添加普通设备 476 13.7.2 使用传统方法来生成控制设备 478 本章的示例代码 483 练习题 483 附录A 如何使用本书的源码光盘 485 精品图书免费试读 488 封底 489

2011-01-04

寒江独钓-Windows内核安全编程(高清完整版).part1

内容简介   本书从Windows内核编程出发,全面系统地介绍了串口、键盘、磁盘、文件系统、网络等相关的Windows内核模块的编程技术,以及基于这些技术实现的密码保护、防毒引擎、文件加密、网络嗅探、网络防火墙等信息安全软件的核心组件的具体编程。主要知识重点包括:Windows串口与键盘过滤驱动、Windows虚拟存储设备与存储设备过滤驱动、Windows文件系统过滤驱动、文件系统透明加密/解密驱动、Windows各类网络驱动(包括TDI过滤驱动及三类NDIS驱动),以及最新的WDF驱动开发模型。有助于读者熟悉Windows内核驱动的体系结构,并精通信息安全类的内核编程技术。本书的大部分代码具有广泛的兼容性,适合从Windows 2000 一直到目前最新的Windows 7 Beta 版。   本书适合大专院校计算机系的学生、普通Windows程序员、Windows内核程序员、信息安全行业的程序员,以及希望了解Windows系统底层知识的计算机编程爱好者使用。阅读本书,需要读者有C语言、数据结构、操作系统和计算机网络的基础知识。 目录: 封面 -25 扉页 -24 内容简介 -23 序 -22 关于本书作者和贡献者 -20 前言 -18 阅读注意 -16 目录 -12 正文 1 第1章 内核上机指导 1 1.1 下载和使用WDK 2 1.1.1 下载安装WDK 2 1.1.2 编写第一个C文件 3 1.1.3 编译一个工程 5 1.2 安装与运行 6 1.2.1 下载一个安装工具 6 1.2.2 运行与查看输出信息 7 1.2.3 在虚拟机中运行 9 1.3 调试内核模块 9 1.3.1 下载和安装WinDbg 9 1.3.2 设置Windows XP 调试执行 10 1.3.3 设置Vista调试执行 11 1.3.4 设置VMWare的管道虚拟串口 11 1.3.5 设置Windows内核符号表 13 1.3.6 实战调试first 14 练习题 16 第2章 内核编程环境及其特殊性 17 2.1 内核编程的环境 18 2.1.1 隔离的应用程序 18 2.1.2 共享的内核空间 19 2.1.3 无处不在的内核模块 20 2.2 数据类型 21 2.2.1 基本数据类型 21 2.2.2 返回状态 22 2.2.3 字符串 23 2.3 重要的数据结构 23 2.3.1 驱动对象 23 2.3.2 设备对象 25 2.3.3 请求 26 2.4 函数调用 28 2.4.1 查阅帮助 28 2.4.2 帮助中有的几类函数 30 2.4.3 帮助中没有的函数 32 2.5 Windows的驱动开发模型 32 2.6 WDK编程中的特殊点 33 2.6.1 内核编程的主要调用源 33 2.6.2 函数的多线程安全性 34 2.6.3 代码的中断级 36 2.6.4 WDK中出现的特殊代码 37 练习题 38 第3章 串口的过滤 40 3.1 过滤的概念 41 3.1.1 设备绑定的内核API之一 41 3.1.2 设备绑定的内核API之二 43 3.1.3 生成过滤设备并绑定 43 3.1.4 从名字获得设备对象 45 3.1.5 绑定所有串口 46 3.2 获得实际数据 47 3.2.1 请求的区分 47 3.2.2 请求的结局 48 3.2.3 写请求的数据 49 3.3 完整的代码 50 3.3.1 完整的分发函数 50 3.3.2 如何动态卸载 52 3.3.3 完整的代码 53 本章的示例代码 53 练习题 54 第4章 键盘的过滤 56 4.1 技术原理 57 4.1.1 预备知识 57 4.1.2 Windows中从击键到内核 58 4.1.3 键盘硬件原理 60 4.2 键盘过滤的框架 61 4.2.1 找到所有的键盘设备 61 4.2.2 应用设备扩展 64 4.2.3 键盘过滤模块的DriverEntry 65 4.2.4 键盘过滤模块的动态加载 66 4.3 键盘过滤的请求处理 68 4.3.1 通常的处理 68 4.3.2 PNP的处理 69 4.3.3 读的处理 70 4.3.4 读完成的处理 71 4.4 从请求中打印出按键信息 72 4.4.1 从缓冲区中获得KEYBOARD_INPUT_DATA 72 4.4.2 从KEYBOARD_INPUT_DATA中得到键 73 4.4.3 从MakeCode到实际字符 74 4.5 Hook分发函数 75 4.5.1 获得类驱动对象 76 4.5.2 修改类驱动的分发函数指针 77 4.5.3 类驱动之下的端口驱动 78 4.5.4 端口驱动和驱动之间的协作机制 79 4.5.5 找到关键的回调函数的条件 80 4.5.6 定义常数和数据结构

2011-01-04

全球DEMO大赛的一等奖集锦

这个是用汇编做的 所以只有64K的大小 却可以播放绚丽的画面好几分钟 如果用CG动画的话 估计得几个G呢 64K做出这样的DEMO 真的很厉害很厉害呀 带上耳机欣赏吧 (附件rar解压后就是demo了,exe文件 直接双击播放 不是病毒哦) 这里主要介绍的DEMO并非指的商业性的DEMO,而是在国际比赛,有个参赛团体专门为DEMO比赛而制作的DEMO。这些DEMO主要目的是:带给欣赏者趣味并且发挥电脑在秽土与音乐上的亲历。也就是说DEMO结合另人看到目瞪口呆的CG与音乐,在加上DEMO制作者的编程技巧与功力,展现出许多高难度的表演。有人说DEMO就是:“亲爱的,我把PC变成SGI了。”得奖的DEMO在设计时一般进行程序最优化,充分发挥PC的硬件潜力,产生惊人的效果,包括:多变的音乐,即时运算产生的RENER图形,FRACTRL,透明,PLASMA,3D VECTOR SPACE,VIRTUAL REALITY,MORPH等。 为了达到这些效果,这些DEMO通常有下面四个特性: 1。使用汇编语言,要产生一个简单的DEMO,用高级语言可以很轻松的写出来,但因为一些限制速度很不理想。运用汇编语言最优化,可以充分发挥与控制软硬件饿威力。 2。多声道的音乐。 3。突破传统的绘图能力:在PC上标准VGA在320X200的解析度只能显示256色,很少有记忆页,造成很多限制。而DEMO往往使用特殊的模式,通常称做X MODE,在这些模式下能达到320X200 256色多记忆页。 4。即时运算:在这些DEMO里大多有3D向量空间,虚拟真实的部分,或是有许多的电脑上色效果,还有变形等。由于即时运算的关系,尽管一个DEMO不大,也可以播10-20分钟。 DEMO界的大集会 “International Demo Competi-tions”国际DEMO大赛,通常由组织较为庞大的DEMO团队来主办,比赛项目包括DEMO,INTRO(小于64Kb的DEMO),muisc及GRAPHICS。 通常会为不同机种举行不同比赛。由投票产生名次,获奖者可获得奖金或赞助商的奖品。 之一:幽灵古堡 这个是oday组织自制的demo ,完全用源代码编写,是用来炫耀本组织技术的。看完了这个DEMO,我们能相信它只有65K吗? 之二:第七天堂 这又是一个超级COOL的DEMO,也许我们还不能体会到作者的思想内涵,但是其画面和音质之佳,还是让我们目眩。而最重要的是,它仍旧只有——65K。    之三:火域幻境 这个版本是作者在得奖之后再进行改进的作品,虽然是73K,却比原来得奖的版本要多了很多功能。我们还是不能想象这个小小的73K作品居然是那么的COOL!    之四:爱之记忆 这个DEMO讲述了作者真实的爱情故事,充满了哀思和爱意,整个色调也处理得相当完美。可能更值得我们注意的是,它只有39K!    之五:死亡阴影 这个DEMO最出色的地方不是因为他的华丽外表,而实际上它一点也不华丽,但是它所表现出的创造力以及气氛营造能力,绝对会让一个出色的广告设计师佩服。当然,它还是64K!    之六:金属迷城 我们只需要知道一点——它只有6K!

2011-01-04

WINDOWS编程循序渐进.part05

http://wangfaqiang.download.csdn.net/ 上面这个网址就可以看到所有8个的下载链接 看雪论坛主力成员张静盛所编著。为高清晰完整版PDF电子书,是学习Windows编程很好的书籍。作者简介:张静盛,目前在盛大网络从事技术研发工作。自2005至今在看雪软件安全论坛担任“Win32/Win64编程”版版主(网名:北极星2003)。曾获第31届ACM/ICPC国际大学生程序设计竞赛亚洲赛区(上海)银奖。他追求专业技术的精纯,常为工作、为兴趣废寝忘食。 本书设计了大量的实例演示Windows应用程序开发过程中的相关技术,分为3篇。 软件设计基础篇 ·第1章,软件开发起步:编写第一个软件,熟悉MFC应用程序框架。 ·第2章,对话框应用程序:熟悉模态、非模态对话框以及通常对话框的原理与使用方法。 ·第3章,基本控件:介绍按钮、编辑框、列表框等基本控件的使用方法。 ·第4章,文档与视图:介绍文档与视图的基本原理。 ·第5章,GDI绘图技术:介绍GDI绘图技术的基本的GDI对象。 ·第6章,键盘与鼠标消息:介绍键盘、鼠标消息的处理与模拟。 软件设计综合应用篇 第7章,网络通信基础:介绍网络模型、协议以及套接字编程和LSP的实现。 第8章,密码学算法:介绍常见的密码学算法及其实现。 第9章,多媒体技术:介绍几种多媒体控件的使用方式和屏幕截图、录像的实现。 第10章,数据库技术:介绍MFC ODBC和DAO基本使用方法。 第11章,综合实例开发:实现多个具有趣味性的实例。 Windows系统程序设计篇 第12章,进程与线程:介绍进程与线程的原理及其基本应用。 第13章,内存管理:介绍虚拟内存与内存映射两种内存管理机制。 .第14章,进程间通信:介绍共享内存、管道等进程间通信方式的原理与实现方法。.. 第15章,线程同步:介绍多种线程同步技术,包括使用内核对象实现线程同步。 第16章,动态链接库:介绍DLL的基本原理,包括TLS机制。 第17章,结构化异常处理:介绍结构化异常处理机制,及其在VC++环境下的特性。 第18章,可执行文件格式:介绍PE文件格式及其基本应用。 第19章,模块注入与函数挂接技术:介绍模块注入及函数挂接技术及其防御。

2011-01-03

Microsoft Win32 Programmers Reference(windows win32 程序员参考手册)附WIN7安装使用办法

这是一个关于win32 API的帮助文件,会编程的人不会不知道它,它就好像DOS时代的《中断大全》,这里有详尽的API信息,绝对不比MSDN差!

2011-01-03

WINDOWS编程循序渐进.part06

http://wangfaqiang.download.csdn.net/ 上面这个网址就可以看到所有8个的下载链接 看雪论坛主力成员张静盛所编著。为高清晰完整版PDF电子书,是学习Windows编程很好的书籍。作者简介:张静盛,目前在盛大网络从事技术研发工作。自2005至今在看雪软件安全论坛担任“Win32/Win64编程”版版主(网名:北极星2003)。曾获第31届ACM/ICPC国际大学生程序设计竞赛亚洲赛区(上海)银奖。他追求专业技术的精纯,常为工作、为兴趣废寝忘食。 本书设计了大量的实例演示Windows应用程序开发过程中的相关技术,分为3篇。 软件设计基础篇 ·第1章,软件开发起步:编写第一个软件,熟悉MFC应用程序框架。 ·第2章,对话框应用程序:熟悉模态、非模态对话框以及通常对话框的原理与使用方法。 ·第3章,基本控件:介绍按钮、编辑框、列表框等基本控件的使用方法。 ·第4章,文档与视图:介绍文档与视图的基本原理。 ·第5章,GDI绘图技术:介绍GDI绘图技术的基本的GDI对象。 ·第6章,键盘与鼠标消息:介绍键盘、鼠标消息的处理与模拟。 软件设计综合应用篇 第7章,网络通信基础:介绍网络模型、协议以及套接字编程和LSP的实现。 第8章,密码学算法:介绍常见的密码学算法及其实现。 第9章,多媒体技术:介绍几种多媒体控件的使用方式和屏幕截图、录像的实现。 第10章,数据库技术:介绍MFC ODBC和DAO基本使用方法。 第11章,综合实例开发:实现多个具有趣味性的实例。 Windows系统程序设计篇 第12章,进程与线程:介绍进程与线程的原理及其基本应用。 第13章,内存管理:介绍虚拟内存与内存映射两种内存管理机制。 .第14章,进程间通信:介绍共享内存、管道等进程间通信方式的原理与实现方法。.. 第15章,线程同步:介绍多种线程同步技术,包括使用内核对象实现线程同步。 第16章,动态链接库:介绍DLL的基本原理,包括TLS机制。 第17章,结构化异常处理:介绍结构化异常处理机制,及其在VC++环境下的特性。 第18章,可执行文件格式:介绍PE文件格式及其基本应用。 第19章,模块注入与函数挂接技术:介绍模块注入及函数挂接技术及其防御。

2011-01-03

WINDOWS编程循序渐进.part07

http://wangfaqiang.download.csdn.net/ 上面这个网址就可以看到所有8个的下载链接 看雪论坛主力成员张静盛所编著。为高清晰完整版PDF电子书,是学习Windows编程很好的书籍。作者简介:张静盛,目前在盛大网络从事技术研发工作。自2005至今在看雪软件安全论坛担任“Win32/Win64编程”版版主(网名:北极星2003)。曾获第31届ACM/ICPC国际大学生程序设计竞赛亚洲赛区(上海)银奖。他追求专业技术的精纯,常为工作、为兴趣废寝忘食。 本书设计了大量的实例演示Windows应用程序开发过程中的相关技术,分为3篇。 软件设计基础篇 ·第1章,软件开发起步:编写第一个软件,熟悉MFC应用程序框架。 ·第2章,对话框应用程序:熟悉模态、非模态对话框以及通常对话框的原理与使用方法。 ·第3章,基本控件:介绍按钮、编辑框、列表框等基本控件的使用方法。 ·第4章,文档与视图:介绍文档与视图的基本原理。 ·第5章,GDI绘图技术:介绍GDI绘图技术的基本的GDI对象。 ·第6章,键盘与鼠标消息:介绍键盘、鼠标消息的处理与模拟。 软件设计综合应用篇 第7章,网络通信基础:介绍网络模型、协议以及套接字编程和LSP的实现。 第8章,密码学算法:介绍常见的密码学算法及其实现。 第9章,多媒体技术:介绍几种多媒体控件的使用方式和屏幕截图、录像的实现。 第10章,数据库技术:介绍MFC ODBC和DAO基本使用方法。 第11章,综合实例开发:实现多个具有趣味性的实例。 Windows系统程序设计篇 第12章,进程与线程:介绍进程与线程的原理及其基本应用。 第13章,内存管理:介绍虚拟内存与内存映射两种内存管理机制。 .第14章,进程间通信:介绍共享内存、管道等进程间通信方式的原理与实现方法。.. 第15章,线程同步:介绍多种线程同步技术,包括使用内核对象实现线程同步。 第16章,动态链接库:介绍DLL的基本原理,包括TLS机制。 第17章,结构化异常处理:介绍结构化异常处理机制,及其在VC++环境下的特性。 第18章,可执行文件格式:介绍PE文件格式及其基本应用。 第19章,模块注入与函数挂接技术:介绍模块注入及函数挂接技术及其防御。

2011-01-03

WINDOWS编程循序渐进.part08

http://wangfaqiang.download.csdn.net/ 上面这个网址就可以看到所有8个的下载链接 看雪论坛主力成员张静盛所编著。为高清晰完整版PDF电子书,是学习Windows编程很好的书籍。作者简介:张静盛,目前在盛大网络从事技术研发工作。自2005至今在看雪软件安全论坛担任“Win32/Win64编程”版版主(网名:北极星2003)。曾获第31届ACM/ICPC国际大学生程序设计竞赛亚洲赛区(上海)银奖。他追求专业技术的精纯,常为工作、为兴趣废寝忘食。 本书设计了大量的实例演示Windows应用程序开发过程中的相关技术,分为3篇。 软件设计基础篇 ·第1章,软件开发起步:编写第一个软件,熟悉MFC应用程序框架。 ·第2章,对话框应用程序:熟悉模态、非模态对话框以及通常对话框的原理与使用方法。 ·第3章,基本控件:介绍按钮、编辑框、列表框等基本控件的使用方法。 ·第4章,文档与视图:介绍文档与视图的基本原理。 ·第5章,GDI绘图技术:介绍GDI绘图技术的基本的GDI对象。 ·第6章,键盘与鼠标消息:介绍键盘、鼠标消息的处理与模拟。 软件设计综合应用篇 第7章,网络通信基础:介绍网络模型、协议以及套接字编程和LSP的实现。 第8章,密码学算法:介绍常见的密码学算法及其实现。 第9章,多媒体技术:介绍几种多媒体控件的使用方式和屏幕截图、录像的实现。 第10章,数据库技术:介绍MFC ODBC和DAO基本使用方法。 第11章,综合实例开发:实现多个具有趣味性的实例。 Windows系统程序设计篇 第12章,进程与线程:介绍进程与线程的原理及其基本应用。 第13章,内存管理:介绍虚拟内存与内存映射两种内存管理机制。 .第14章,进程间通信:介绍共享内存、管道等进程间通信方式的原理与实现方法。.. 第15章,线程同步:介绍多种线程同步技术,包括使用内核对象实现线程同步。 第16章,动态链接库:介绍DLL的基本原理,包括TLS机制。 第17章,结构化异常处理:介绍结构化异常处理机制,及其在VC++环境下的特性。 第18章,可执行文件格式:介绍PE文件格式及其基本应用。 第19章,模块注入与函数挂接技术:介绍模块注入及函数挂接技术及其防御。

2011-01-03

WINDOWS编程循序渐进.part04(8部分)

http://wangfaqiang.download.csdn.net/ 上面这个网址就可以看到所有8个的下载链接 看雪论坛主力成员张静盛所编著。为高清晰完整版PDF电子书,是学习Windows编程很好的书籍。作者简介:张静盛,目前在盛大网络从事技术研发工作。自2005至今在看雪软件安全论坛担任“Win32/Win64编程”版版主(网名:北极星2003)。曾获第31届ACM/ICPC国际大学生程序设计竞赛亚洲赛区(上海)银奖。他追求专业技术的精纯,常为工作、为兴趣废寝忘食。 本书设计了大量的实例演示Windows应用程序开发过程中的相关技术,分为3篇。 软件设计基础篇 ·第1章,软件开发起步:编写第一个软件,熟悉MFC应用程序框架。 ·第2章,对话框应用程序:熟悉模态、非模态对话框以及通常对话框的原理与使用方法。 ·第3章,基本控件:介绍按钮、编辑框、列表框等基本控件的使用方法。 ·第4章,文档与视图:介绍文档与视图的基本原理。 ·第5章,GDI绘图技术:介绍GDI绘图技术的基本的GDI对象。 ·第6章,键盘与鼠标消息:介绍键盘、鼠标消息的处理与模拟。 软件设计综合应用篇 第7章,网络通信基础:介绍网络模型、协议以及套接字编程和LSP的实现。 第8章,密码学算法:介绍常见的密码学算法及其实现。 第9章,多媒体技术:介绍几种多媒体控件的使用方式和屏幕截图、录像的实现。 第10章,数据库技术:介绍MFC ODBC和DAO基本使用方法。 第11章,综合实例开发:实现多个具有趣味性的实例。 Windows系统程序设计篇 第12章,进程与线程:介绍进程与线程的原理及其基本应用。 第13章,内存管理:介绍虚拟内存与内存映射两种内存管理机制。 .第14章,进程间通信:介绍共享内存、管道等进程间通信方式的原理与实现方法。.. 第15章,线程同步:介绍多种线程同步技术,包括使用内核对象实现线程同步。 第16章,动态链接库:介绍DLL的基本原理,包括TLS机制。 第17章,结构化异常处理:介绍结构化异常处理机制,及其在VC++环境下的特性。 第18章,可执行文件格式:介绍PE文件格式及其基本应用。 第19章,模块注入与函数挂接技术:介绍模块注入及函数挂接技术及其防御。

2011-01-03

WINDOWS编程循序渐进.part03(8部分)

http://wangfaqiang.download.csdn.net/ 上面这个网址就可以看到所有8个的下载链接 看雪论坛主力成员张静盛所编著。为高清晰完整版PDF电子书,是学习Windows编程很好的书籍。作者简介:张静盛,目前在盛大网络从事技术研发工作。自2005至今在看雪软件安全论坛担任“Win32/Win64编程”版版主(网名:北极星2003)。曾获第31届ACM/ICPC国际大学生程序设计竞赛亚洲赛区(上海)银奖。他追求专业技术的精纯,常为工作、为兴趣废寝忘食。 本书设计了大量的实例演示Windows应用程序开发过程中的相关技术,分为3篇。 软件设计基础篇 ·第1章,软件开发起步:编写第一个软件,熟悉MFC应用程序框架。 ·第2章,对话框应用程序:熟悉模态、非模态对话框以及通常对话框的原理与使用方法。 ·第3章,基本控件:介绍按钮、编辑框、列表框等基本控件的使用方法。 ·第4章,文档与视图:介绍文档与视图的基本原理。 ·第5章,GDI绘图技术:介绍GDI绘图技术的基本的GDI对象。 ·第6章,键盘与鼠标消息:介绍键盘、鼠标消息的处理与模拟。 软件设计综合应用篇 第7章,网络通信基础:介绍网络模型、协议以及套接字编程和LSP的实现。 第8章,密码学算法:介绍常见的密码学算法及其实现。 第9章,多媒体技术:介绍几种多媒体控件的使用方式和屏幕截图、录像的实现。 第10章,数据库技术:介绍MFC ODBC和DAO基本使用方法。 第11章,综合实例开发:实现多个具有趣味性的实例。 Windows系统程序设计篇 第12章,进程与线程:介绍进程与线程的原理及其基本应用。 第13章,内存管理:介绍虚拟内存与内存映射两种内存管理机制。 .第14章,进程间通信:介绍共享内存、管道等进程间通信方式的原理与实现方法。.. 第15章,线程同步:介绍多种线程同步技术,包括使用内核对象实现线程同步。 第16章,动态链接库:介绍DLL的基本原理,包括TLS机制。 第17章,结构化异常处理:介绍结构化异常处理机制,及其在VC++环境下的特性。 第18章,可执行文件格式:介绍PE文件格式及其基本应用。 第19章,模块注入与函数挂接技术:介绍模块注入及函数挂接技术及其防御。

2011-01-03

WINDOWS编程循序渐进.part02(8部分)

http://wangfaqiang.download.csdn.net/ 上面这个网址就可以看到所有8个的下载链接 看雪论坛主力成员张静盛所编著。为高清晰完整版PDF电子书,是学习Windows编程很好的书籍。作者简介:张静盛,目前在盛大网络从事技术研发工作。自2005至今在看雪软件安全论坛担任“Win32/Win64编程”版版主(网名:北极星2003)。曾获第31届ACM/ICPC国际大学生程序设计竞赛亚洲赛区(上海)银奖。他追求专业技术的精纯,常为工作、为兴趣废寝忘食。 本书设计了大量的实例演示Windows应用程序开发过程中的相关技术,分为3篇。 软件设计基础篇 ·第1章,软件开发起步:编写第一个软件,熟悉MFC应用程序框架。 ·第2章,对话框应用程序:熟悉模态、非模态对话框以及通常对话框的原理与使用方法。 ·第3章,基本控件:介绍按钮、编辑框、列表框等基本控件的使用方法。 ·第4章,文档与视图:介绍文档与视图的基本原理。 ·第5章,GDI绘图技术:介绍GDI绘图技术的基本的GDI对象。 ·第6章,键盘与鼠标消息:介绍键盘、鼠标消息的处理与模拟。 软件设计综合应用篇 第7章,网络通信基础:介绍网络模型、协议以及套接字编程和LSP的实现。 第8章,密码学算法:介绍常见的密码学算法及其实现。 第9章,多媒体技术:介绍几种多媒体控件的使用方式和屏幕截图、录像的实现。 第10章,数据库技术:介绍MFC ODBC和DAO基本使用方法。 第11章,综合实例开发:实现多个具有趣味性的实例。 Windows系统程序设计篇 第12章,进程与线程:介绍进程与线程的原理及其基本应用。 第13章,内存管理:介绍虚拟内存与内存映射两种内存管理机制。 .第14章,进程间通信:介绍共享内存、管道等进程间通信方式的原理与实现方法。.. 第15章,线程同步:介绍多种线程同步技术,包括使用内核对象实现线程同步。 第16章,动态链接库:介绍DLL的基本原理,包括TLS机制。 第17章,结构化异常处理:介绍结构化异常处理机制,及其在VC++环境下的特性。 第18章,可执行文件格式:介绍PE文件格式及其基本应用。 第19章,模块注入与函数挂接技术:介绍模块注入及函数挂接技术及其防御。

2011-01-03

WINDOWS编程循序渐进高清完整PDF.part01(8部分)

http://wangfaqiang.download.csdn.net/ 上面这个网址就可以看到所有8个的下载链接 看雪论坛主力成员张静盛所编著。为高清晰完整版PDF电子书,是学习Windows编程很好的书籍。作者简介:张静盛,目前在盛大网络从事技术研发工作。自2005至今在看雪软件安全论坛担任“Win32/Win64编程”版版主(网名:北极星2003)。曾获第31届ACM/ICPC国际大学生程序设计竞赛亚洲赛区(上海)银奖。他追求专业技术的精纯,常为工作、为兴趣废寝忘食。 本书设计了大量的实例演示Windows应用程序开发过程中的相关技术,分为3篇。 软件设计基础篇 ·第1章,软件开发起步:编写第一个软件,熟悉MFC应用程序框架。 ·第2章,对话框应用程序:熟悉模态、非模态对话框以及通常对话框的原理与使用方法。 ·第3章,基本控件:介绍按钮、编辑框、列表框等基本控件的使用方法。 ·第4章,文档与视图:介绍文档与视图的基本原理。 ·第5章,GDI绘图技术:介绍GDI绘图技术的基本的GDI对象。 ·第6章,键盘与鼠标消息:介绍键盘、鼠标消息的处理与模拟。 软件设计综合应用篇 第7章,网络通信基础:介绍网络模型、协议以及套接字编程和LSP的实现。 第8章,密码学算法:介绍常见的密码学算法及其实现。 第9章,多媒体技术:介绍几种多媒体控件的使用方式和屏幕截图、录像的实现。 第10章,数据库技术:介绍MFC ODBC和DAO基本使用方法。 第11章,综合实例开发:实现多个具有趣味性的实例。 Windows系统程序设计篇 第12章,进程与线程:介绍进程与线程的原理及其基本应用。 第13章,内存管理:介绍虚拟内存与内存映射两种内存管理机制。 .第14章,进程间通信:介绍共享内存、管道等进程间通信方式的原理与实现方法。.. 第15章,线程同步:介绍多种线程同步技术,包括使用内核对象实现线程同步。 第16章,动态链接库:介绍DLL的基本原理,包括TLS机制。 第17章,结构化异常处理:介绍结构化异常处理机制,及其在VC++环境下的特性。 第18章,可执行文件格式:介绍PE文件格式及其基本应用。 第19章,模块注入与函数挂接技术:介绍模块注入及函数挂接技术及其防御。

2011-01-03

Linux 专业人员编程 Professional Linux Programming( linux高级程序设计)

Jon Masters is a 25-year-old British-born Linux kernel engineer, embedded systems specialist, and author who lives and works in the United States for Red Hat. Jon made UK history by becoming one of the youngest University students the country had ever seen, at the tender age of just 13. Having been

2010-12-06

C程序设计语言(第2版·新版)非扫描版&详细书签版

全球最经典的C语言教材,高清版,绝对是学习C语言必备的书籍。

2010-12-05

VIM7.2+VIM7.2gdb 把VIM变成Linux下程序开发IDE

这是最新的VIM版本+VIMgdb版本,通过这两个程序 可以把VIM7.2打行造成LINUX下程序开发的IDE,真是大家的福音.我们在VIM中就可以调试程序,功能十分强大 现在相应版本的VIM不好找,希望大家喜欢用

2010-11-30

flashfxp 3.6的完美注册机 完美使用

flashfxp 3.6的完美注册机 完美使用。破解后完美使用,不再看到烦人的提示框。

2010-11-28

C#写的记事本程序源代码

用C#写的记事本,实现了记事本的所有功能,与WINDOWS自带的记事完全一样,适合初学者学习参考。

2010-11-28

ASP.NET网站用户管理模块功能实现

ASP.NET网站用户管理模块功能实现,利用asp.net实现的网站用户的维护管理,添加、删除、修改资料等常用功能。可以用来参考学习

2010-11-21

Microsoft_Visual_Studio_C++_2010入门教程(修订版)

Microsoft_Visual_Studio_C++_2010入门教程(修订版),官方权威,详细介绍vs2010下c++的开发方法,让你快速学会vs2010下c++开发

2010-11-21

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除