• Windows内核--WRK和真实的Windows内核源代码差多少?(1.3)


            前面有提到WRK是微软官方公布的XP/Server 2003供学习和研究的内核源代码。WRK介绍关于source code如下:

    WRK源代码已经很完备

    WRK v1.2 includes most of the NTOS kernel sources from the latest released
    version of Windows, which supports the AMD64 architecture on the Desktop.
    The kernel sources excluded from the kit are primarily in the areas of
    plug-and-play, power management, the device verifier, kernel debugger
    interface, and virtual dos machine.  The primary modifications to WRK
    from the released kernel are related to cleanup and removal of server
    support, such as code related to the Intel IA64.

            由上可见,WRK1.2包含了绝大部分NTOS内核源代码,移除了PNP、电源管理、设备验证器、内核调试接口和虚拟DOS模拟器这些代码,另外关于服务器端相关的内核代码也有移除。

    (移除的代码对我们分析Windows Kernel已经无关紧要!)

    WRK Prebuilt Binary文件

    •     WS03SP1HALS\x86\...\halxxxx.dll
    •      bootvid.lib/hal.lib/kdcom.lib/ntosarch.lib/ntoswrk.lib/sdbapint.lib   

         

    Prebuilt Binary Makefile 

      最终会link如上这些binary(部分lib当作map文件).      

    1. WRK-v1.2\base\ntos\build\makefile:
    2. linklibpath = -LIBPATH:$(topobj) -LIBPATH:PREBUILT\$(targ)
    3. ntoswrklib = ntoswrk.lib
    4. ntosarchlib = ntosarch.lib
    5. bootlibs = bootvid.lib sdbapint.lib kdcom.lib
    6. fullkernel = EXE\$(kernel)
    7. # kernel link definitions
    8. LINKFLAGS = -IGNORE:4087,4001,4010,4037,4039,4065,4070,4078,4087,4089,4221,4198 -WX -NODEFAULTLIB -machine:$(machine) $(linklibpath)
    9. LINK = link.exe -nologo
    10. LINKEDIT = link.exe -edit -nologo
    11. LIB = $(LIB) $(linklibpath)
    12. !if "$(targ)" == "i386"
    13. archlinkopts = -safeseh -functionpadmin:5 -debugtype:cv,fixup -STACK:0x40000,0x2000 -align:0x1000
    14. hotpatch = -stub:PREBUILT\i386\stub512.com
    15. entrypoint = KiSystemStartup@4
    16. !else
    17. archlinkopts = -functionpadmin:6 -debugtype:cv,fixup,pdata -STACK:0x80000,0x2000
    18. hotpatch = PREBUILT\amd64\hotpatch.obj
    19. LINKFLAGS = -IGNORE:4108,4088,4218,4218,4235 $(LINKFLAGS)
    20. LIBFLAGS = -IGNORE:4108,4088,4218,4218,4235 $(LIBFLAGS)
    21. entrypoint = KiSystemStartup
    22. !endif
    23. ntosmerge = -merge:PAGECONST=PAGE -merge:INITCONST=INIT -merge:INITDATA=INIT -merge:PAGELKCONST=PAGELK \
    24. -merge:PAGEVRFY_CONST=PAGEVRFY -MERGE:_PAGE=PAGE -MERGE:_TEXT=.text -merge:.rdata=.text
    25. ntosversion = -release -version:5.2 -osversion:5.2 -subsystem:native,5.02
    26. ntoslinkopts = $(ntosversion) $(ntosmerge) -SECTION:INIT,d -OPT:REF -OPT:ICF -INCREMENTAL:NO \
    27. -FULLBUILD -debug $(archlinkopts) -opt:nowin98 -pdbcompress -driver
    28. kernelexp:
    29. copy ..\init\ntoskrnl.src+..\init\$(targ)def.src $(OBJ)\$(kernel).pp
    30. $(CC) $(CFLAGS0) -EP $(OBJ)\$(kernel).pp > $(fullkernel).def
    31. -del $(OBJ)\$(kernel).pp
    32. $(LIB) $(LIBFLAGS) -IGNORE:4001 $(OBJ)\*.lib $(ntoswrklib) -def:$(fullkernel).def -out:$(fullkernel).lib
    33. kernellib:
    34. $(LIB) $(fullkernel).lib $(ntosarchlib) -out:$(fullkernel).lib
    35. kernelexe:
    36. $(LINK) $(LINKFLAGS) $(ntoslinkopts) -out:$(fullkernel).exe -map:$(fullkernel).map -pdb:$(fullkernel).pdb -entry:$(entrypoint) \
    37. $(hotpatch) PREBUILT\$(targ)\ntoskrnl.res $(OBJ)\ntkrnlmp.obj $(OBJ)\*.lib $(ntoswrklib) hal.lib $(fullkernel).exp $(bootlibs)
    38. $(LINKEDIT) -section:.rsrc,!d $(fullkernel).exe

    WRK Source Code

            

    WRK目录介绍

    cache\  - cache manager (缓存管理器)
    config\ - registry implementation (注册表)
    dbgk\   - user-mode debugger support
    ex\     - executive functions (kernel heap, synchronization, time) (和rtl都是支援函数)
    fsrtl\  - file system run-time support
    io\     - I/O manager (驱动程序IO相关)
    ke\     - scheduler, CPU management, low-level synchronization (核心调度/同步机制)
    lpc\    - local procedure call implementation
    mm\     - virtual memory manager (申请/释放虚拟内存和物理内存等)
    ob\     - kernel object manager (创建/删除内核对象等,比如进程/线程对象)
    ps\     - process/thread support (进程/线程 创建/终止等)
    se\     - security functions  (安全相关)
    wmi\    - Windows Management Instrumentation

    inc\    - NTOS-only include files
    rtl\    - kernel run-time support (Runtime Library, 有点像kernel的"libc")
    init\   - kernel startup  (开机初始化)

    HAL

            微软没有提供HAL源代码,有提供DLL和PDB供使用和调试。

               以halmacpi为例:   

            

            HAL可以实现隔离掉硬件的差异,主要是硬件结构强相关部分,比如中断、Clock和处理器切换等.

    ntoskrnl和HAL

            

             wrkamd64.exe Imports依赖的函数如上,可以看到有HAL/KDCOM/BOOTVID等。以后会详细介绍。

  • 相关阅读:
    C++可以这么学----->类和对象(下)
    CP03大语言模型ChatGLM3-6B特性代码解读(1)
    ansible copy 模块
    java实现pdf转为word
    bash: nvcc: command not found
    性能测试分类
    Python数据科学实战教程
    【全】【ES集群安装+配置教程】装ElasticSearch到CentOS 8中liunx
    (Note)机器学习面试题
    读取多行,对字符串数组排序
  • 原文地址:https://blog.csdn.net/cxsjabcabc/article/details/127702843