走进Windows 2000 内部(一)

走进Windows 2000 内部()

       --Windows 源代码解读与发现

       拿到Windows2000的源代码有些日子了,业余时间就看看,总结出了一些东西.我先发表一些比较有实用价值的,希望能对大家的学习与工作有所帮助.如果大家觉得有必要,我会陆陆续续发表解读出来的一些东西与大家共同进步.

       这一次主要讲讲user32模块里的一些东西.

       首先,我们需要一个能访问内核内存的工具函数库.令我感到奇怪的是,user32大量的代码在Kernel Mode下运行.不过那是MS的事,先说说这个工具函数库.我用DDK构建的它.很简单.有两个功能地:,写内核内存.

       为了不偏离主题,只列出最后的函数原形

BOOL WriteSysMemroy(PVOID pAddr , PVOID pBuff , DWORD dwLen);

BOOL ReadSysMemroy(PVOID pBuff , PVOID pAddr , DWORD dwLen);

 

1 关于THREADINFO

先列出这个结构的原形

 

// 大部分都有注释,它们的意意慢慢说

 

typedef struct tagTHREADINFO

{

       //W32THREAD;

    //PTL             ptl;                // Listhead for thread lock list

// W32THREAD PTL 是我所不知道的结构,通过SoftICE的帮助,我知道了它们的大小,

//于是我弄了个东东来填充它

       PADDING(padding1 , 0x2c);                    

    PVOID               ppi;                // process info struct for this thread

                                                                      // type is PPROCESSINFO

       PVOID                  rpdesk;                            // type is PDESKTOP

    PDESKTOPINFO     pDeskInfo;          // Desktop info visible to client

                                                                      // type is PDESKTOPINFO

    PCLIENTINFO           pClientInfo;       // Client info stored in TEB

                                                                      // type is PCLIENTINFO

       DWORD           TIF_flags;          // TIF_ flags go here.

       PUNICODE_STRING pstrAppName;        // Application module name.

       PVOID           psmsSent;           // Most recent SMS this thread has sent

                                                                      // type is PSMS

    PVOID           psmsCurrent;        // Received SMS this thread is currently processing

                                                                      // type is PSMS

 

    PVOID           psmsReceiveList;    // SMSs to be processed

                                                                      // type is PSMS

       LONG            timeLast;           // Time, position, and ID of last message

    ULONG_PTR       idLast;

       int             cQuit;

    int             exitCode;

       HDESK           hdesk;              // Desktop handle

                                                                      // HDESK

    int             cPaintsReady;

    UINT            cTimersReady;

       PVOID                 pMenuState;                     // type is PMENUSTATE

       union {

        PVOID            ptdb;          // Win16Task Schedule data for WOW thread

                                                                      // type is PTDB

        PVOID                  pwinsta;        // Window station for SYSTEM thread

// type is PWINDOWSTATION

    };

       PVOID                         psiiList;       // thread DDEML instance list

                                                                      // type is PSVR_INSTANCE_INFO

    DWORD           dwExpWinVer;

    DWORD           dwCompatFlags;      // The Win 3.1 Compat flags

    DWORD           dwCompatFlags2;     // new DWORD to extend compat flags for NT5+ features

       PVOID           pqAttach;           // calculation variabled used in

                                                                      // type is PQ

       // zzzAttachThreadInput()

      

    PTHREADINFO     ptiSibling;         // pointer to sibling thread info

      

    PVOID               pmsd;                            // type is PMOVESIZEDATA

      

    DWORD           fsHooks;            // WHF_ Flags for which hooks are installed

                                                                     

    PHOOK           sphkCurrent;        // Hook this thread is currently processing

                                                                      // type is PHOOK

      

    PVOID                  pSBTrack;                     // type is PSBTRACK

      

    HANDLE          hEventQueueClient;

    PVOID            pEventQueueServer;  // type is PKEVENT

 

    PVOID                 PtiLink;            // Link to other threads on desktop

                                                                      // type is LIST_ENTRY

    int             iCursorLevel;       // keep track of each thread's level

   

       PADDING(padding2 , 4);

 

       POINT           ptLast;

      

    PWND            spwndDefaultIme;            // Default IME Window for this thread

                                                                      // type is PWND

 

    PVOID           spDefaultImc;                      // Default input context for this thread

                                                                      // type is PIMC

 

    HANDLE          hklPrev;                       // Previous active keyboard layout

// type is HKL

 

    int             cEnterCount;

      

    MLIST           mlPost;             // posted message list.

    USHORT          fsChangeBitsRemoved;// Bits removed during PeekMessage

    WCHAR           wchInjected;        // character from last VK_PACKET

    DWORD           fsReserveKeys;      // Keys that must be sent to the active

       // active console window.

    PVOID                  *apEvent;           // Wait array for xxxPollAndWaitForSingleObject

                                                                      // type is PKEVENT

    ACCESS_MASK     amdesk;             // Granted desktop access

 

    UINT            cWindows;           // Number of windows owned by this thread

    UINT            cVisWindows;        // Number of visible windows on this thread

      

    PHOOK           aphkStart[CWINHOOKS];   // Hooks registered for this thread

                                                                             // type is PHOOK

    BYTE                    cti;                        // Use this when no desktop is available

                                                                      // type is CLIENTTHREADINFO

      

       }THREADINFO ,* PTHREADINFO;

这个结构用来保存线程的一些信息,它怎么得到呢,请看下面的代码

PTHREADINFO WINAPI NtPtiCurrent(void)

{

      

       PTHREADINFO pti = NULL;

       __asm

       {

              mov eax,fs:[00000018h]

              mov eax,[eax+40h]

       mov pti , eax ; 现在pti 保存的就是当前线程的THREADINFO.

       }

       return  pti;

}

 

知道这个结构很重要,下面我就说一个这个结构的应用.

大家都知道Windows的消息Hook,下面这段代码可是让你的线程不被Hook,也就是让Hook失效

 

// 这个宏得到一个结构指针的成员地址

#define memaddr(p , s , m)          (PVOID) ( (DWORD ) p + offsetof(s , m) )

 

 

 

       PTHREADINFO pti = NtPtiCurrent();

      

       if (pti == NULL)

              return FALSE;

 

       DWORD TIF_flags;

 

       if (!ReadSysMemroy(

              &TIF_flags ,

              memaddr(pti , THREADINFO , TIF_flags) ,

              sizeof(TIF_flags))

              )

              return FALSE;

      

       TIF_flags |= 0x20000000;

 

       return WriteSysMemroy(

              memaddr(pti , THREADINFO , TIF_flags) ,

              &TIF_flags ,

              sizeof(TIF_flags)

              );

原理很简单,就是设了一个标志,告诉Windows Hook ,别来惹我

好了,先开个头,看看反响,如果可以的话,再接着说.

Windows 2000,原名Windows NT 5.0。它结合了Windows 98和Windows NT 4.0的很多优良的功能/性能与一身,超越了Windows NT的原来含义。   Windows 2000系列分成四个产品:Windows 2000 Professional, Windows 2000 Server, Windows 2000 Advanced Server, Windows 2000 Datacenter Server。 Windows 2000 Professional 是一个商业用户的桌面操作系统,也适合移动用户,是Windows NT Workstation 4.0的升级。Windows 2000 Server和Advanced Server分别是Windows NT Server 4.0及其企业版的升级产品。Windows 2000 Datacenter Server是一个新的品种,主要通过OEM的方式销售,是,支持32个以上的CPU和64GB的内存,以及4个节点的集群服务。 Windows 2000平台包括了Windows 2000 Professional 和Windows 2000 Server前后台的集成,下面仅从五个方面简要地介绍一下它的新特性和新功能。   一、活动目录   Windows 2000 Server在Windows NT Server 4.0的基础上,进一步发展了“活动目录(Active Directory)”。活动目录是从一个数据存储开始的。它采用了类似Exchange Server的数据存储,称为:Extensible Storage Service (ESS)。其特点是不需要事先定义数据库的参数,可以做到动态地增长,性能非常优良。这个数据存储之上已建立索引的,可以方便快速地搜索和定位。活动目录的分区是“域(Domain)”,一个域可以存储上百万的对象。域之间还有层次关系,可以建立域树和域森林,无限地扩展。   在数据存储之上,微软建立了一个对象模型,以构成活动目录。这一对象模型对LDAP有纯粹的支持,还可以管理和修改Schema。Schema包括了在活动目录中的计算机、用户和打印机等所有对象的定义,其本身也是活动目录的内容之一,在整个域森林中是唯一的。通过修改Schema的工具,用户或开发人员可以自己定义特殊的类和属性,来创建所需要的对象和对象属性。   活动目录包括两个方面:一个目录和与目录相关的服务。目录是存储各种对象的一个物理上的容器;而目录服务是使目录中所有信息和资源发挥作用的服务。活动目录是一个分布式的目录服务。信息可以分散在多台不同的计算机上,保证快速访问和容错;同时不管用户从何处访问或信息处在何处,都对用户提供统一的视图。 活动目录充分体现了微软产品的“ICE”,即集成性(Integration),深入性(Comprehensive),和易用性(Ease of Use)等优点。活动目录是一个完全可扩展,可伸缩的目录服务,既能满足商业ISP的需要,又能满足企业内部网和外联网的需要 最近在网上游荡的时候发现msdos和windows 2000的原代码 ,不敢独享,所以分享给大家
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值