WinDbg 笔记
设置符号:Settings -> Debugging Settings -> Default symbol path 修改为
srv*C:\symbols*https://msdl.microsoft.com/download/symbols
加载任意进程,执行 .reload -f
常用命令
-
查看汇编指令
u kernel32!GetCurrentThread # 查看
- 查看内存
r (显示寄存器信息)
db esp (以 byte 格式查看栈信息)
dw esp L20 (以 word 格式查看 20 个字节的栈信息)
dd 00ddff44 (以 double word 格式查看 0x00ddff44 的信息)
dc KERNELBASE (以 ascii 格式查看基址内存信息)
dW KERNELBASE + 40 (以显示字符格式查看基址偏移 40 字节的内存信息)
dd poi(esp-4) (查看以 esp-4
地址上的数据作为的地址的内存信息)
dt ntdll!_TEB (查看线程环境框数据结构信息)
dt -r ntdll!_TEB (递归查看)
?? sizeof(ntdll!_TEB) (查看对应大小与类型)
- 编辑内存
ed esp 41414141 (向 esp 地址写入 41414141)
db esp + 4 4242 (向 esp+4 地址写入 4141)
- 查看内存
s -d 0 L?2000 41414141 (查询从 0 开始 2000 个double word范围中存储 41414141 数据的内存地址)
# s: 搜索 -d 以 double word 格式查询
Getting Help 寻求帮助
– .help : Display a list of all meta-commands. – .help :显示所有元命令的列表。 – .hh command : Open help file index for the specified command. – .hh 命令:打开指定命令的帮助文件索引。 – ! [ExtensionDLL.]help : Display help text that describes the extension commands exported from ExtensionDLL or from the extension dll at the top of the chain. –! [ExtensionDLL.]help :显示描述从 ExtensionDLL 或链顶部的扩展 dll 导出的扩展命令的帮助文本。
Sources 来源
– .srcpath : Display the source search path. – .srcpath :显示源搜索路径。 – .srcpath+ path : Append path to the current source file search path. – .srcpath+ path :将路径附加到当前源文件搜索路径。
– .srcnoisy : Display the current status of noisy source loading. – .srcnoisy :显示噪声源加载的当前状态。 – .srcnoisy {0 | 1 | 2 | 3} : control the verbosity level for source file loading. – .srcnoisy {0 | 1 | 2 | 3} :控制源文件加载的详细级别。
– .cls : Clear the Debugger Command window display. – .cls:清除调试器命令窗口显示。
– lsf FileName : Load the source file FileName. – lsf FileName :加载源文件FileName。 – lsf- : Unload the source file FileName. – lsf- :卸载源文件FileName。
– ls first, count : Display count lines starting from first line from the current source file. – ls first, count :显示当前源文件从第一行开始的计数行。 – lsp Leading Trailing : Specify Leading and Trailing lines to show before and after the current line. – lspleading Trailing :指定在当前行之前和之后显示的前导行和尾随行。
– lsc : Display the current source file name and line number. –lsc :显示当前源文件名和行号。 – lse : Open an editor for the current source file. – lse :打开当前源文件的编辑器。
– l+l / l-l : Show/turn of source line numbers at the command prompt. – l+l / l-l :在命令提示符下显示/显示源行号。 – l+s / l-s : Display/hide source lines and source line numbers at the command prompt. – l+s / l-s :在命令提示符下显示/隐藏源代码行和源代码行号。 – l+t / l-t : Start source mode / set the debugger is in assembly mode. – l+t / l-t :启动源代码模式/设置调试器处于汇编模式。
– .lines [-e | -d | -t] : Toggle source-line information support [enable | disable | toggle]. – .lines [-e | -d | -t]:切换源行信息支持[启用|禁用|切换]。
Symbols 符号
– x ! : List all modules. - X ! :列出所有模块。 – x module! : List all symbols loaded from module. – x module! : 列出从模块加载的所有符号。 – x /t /v module!* : List all symbol in module with data type, symbol type and size. – x /t /v module!* : 列出模块中的所有符号,包括数据类型、符号类型和大小。 – x module!pattern* : show me all the symbols loaded from module that begin with pattern. – x module!pattern* :显示从模块加载的所有以模式开头的符号。 – x module!pattern : Finds all of the symbols in module that contain the string pattern. – x module!pattern :查找模块中包含字符串模式的所有符号。
– .sympath+ path : Add symbols located in path. – .sympath+ path :添加位于路径中的符号。 – !sym noisy : Activate noisy symbol loading. – !sym嘈杂:激活嘈杂的符号加载。
– .reload /f driver.sys : Force the debugger to immediately reload symbols for driver.sys. – .reload /f driver.sys :强制调试器立即重新加载 driver.sys 的符号。 – .reload /u driver.sys : Unload driver.sys and all its symbols. – .reload /u driver.sys :卸载 driver.sys 及其所有符号。
Loaded modules 加载的模块
– lm : Display all loaded and unloaded modules. – lm :显示所有加载和卸载的模块。 – lm f : List loaded modules with full path. – lm f :列出已加载的模块及其完整路径。 – lm t : List loaded modules with last modified timestamp. – lm t :列出已加载的模块以及最后修改的时间戳。 – lm v m module : Display all possible information for module. – lm v m module :显示模块的所有可能信息。
– !dlls -v -c ntdll : Display table entries and version information for ntdll.dll, including Loadcount. – !dlls -v -c ntdll :显示 ntdll.dll 的表条目和版本信息,包括 Loadcount。
– !lmi driver.sys : Display detailed information about driver.sys, including symbol information. – !lmi driver.sys :显示有关 driver.sys 的详细信息,包括符号信息。 – !dh ndis : Display file headers for ndis.sys. – !dh ndis :显示 ndis.sys 的文件头。
Processes 流程
– |* : Print status of all processes being debugged. – |* : 打印所有正在调试的进程的状态。 – |. : Print status of the current process. –|。 :打印当前进程的状态。
– .tlist : Lists all processes running on the system. – .tlist :列出系统上运行的所有进程。 – !peb : Display formatted view of the process’s environment block (PEB). – !peb:显示进程环境块(PEB)的格式化视图。
– !process 0 0 : List all active processes with basic details. – !process 0 0 :列出所有活动进程及其基本详细信息。 – !process 0 7 process : Display full details for process. – !process 0 7 process : 显示进程的完整详细信息。
Threads 线程数
– ~ : Display status for all threads in the current process. –~ :显示当前进程中所有线程的状态。
– ~* k : Call stack for all threads. – ~* k :所有线程的调用堆栈。 – ~number n : Suspend thread whose ordinal is number. – ~number n :挂起序数为 number 的线程。 – ~number m : Resume thread whose ordinal is number. – ~number m :恢复序数为 number 的线程。 – ~number f : Freeze thread whose ordinal is number. – ~number f :冻结序数为 number 的线程。 – ~number u : Unfreeze thread whose ordinal is number. – ~number u :解冻序数为 number 的线程。 – ~number s : Switch to thread whose ordinal is number. – ~number s :切换到序号为number的线程。
– ~# f : Freeze the thread causing the current exception. – ~# f :冻结导致当前异常的线程。
– !thread : Display current thread on the target system. – !thread :显示目标系统上的当前线程。 – !thread -t ThreadID : Dump thread which ID is ThreadID. – !thread -t ThreadID : 转储 ID 为 ThreadID 的线程。 – !ready : Display summary information about each thread in the system in a READY state. – !ready :显示系统中处于 READY 状态的每个线程的摘要信息。
– !analyse -v : Display verbose information about the current exception or bug check. – !analysis -v :显示有关当前异常或错误检查的详细信息。 – !analyze -show BugCheckCode : Display information about BugCheckCode bug check code. – !analyze -show BugCheckCode :显示有关 BugCheckCode 错误检查代码的信息。
Breakpoints 断点
– bl – List existing breakpoints. Each breakpoint listed has a number in the list. – bl – 列出现有断点。列出的每个断点在列表中都有一个编号。 – bc * : Clear all breakpoints. – bc * :清除所有断点。 – bc number : Clear breakpoint identified by number. – bc number :清除由编号标识的断点。 – be number : Enable breakpoint identified by number. – be number :启用由数字标识的断点。 – bd number : Disable breakpoint identified by number. – bd number :禁用由数字标识的断点。
– bp module!source.c:20 : Set breakpoint at source.c line 20 in module.
– bp module!source.c:20 :在模块中的 source.c 第 20 行设置断点。
– bm module!pattern* : Set a breakpoint on symbols starting with pattern in module.
– bm module!pattern* :在模块中以模式开头的符号上设置断点。
– bu module!function : Set a breakpoint on function as soon as module is loaded.
– bu module!function :加载模块后立即在函数上设置断点。
– ba r4 variable : Set a breakpoint for read access on 4 bytes of variable. – bar4 变量:设置断点以对 4 字节变量进行读取访问。 – ba w4 address : Set a breakpoint for write access on 4 bytes at address. – ba w4 地址:在地址处的 4 个字节上设置写访问断点。 – bp @@(class::method) : Break on method defined in class. Useful if the same method is overloaded and thus present on several addresses. – bp @@(class::method) :中断类中定义的方法。如果相同的方法被重载并因此出现在多个地址上,则很有用。
– bp module!function /1 : Trigger only once a breakpoint at function in module. – bp module!function /1 :仅在模块中的函数处触发一次断点。 – bp module!function k : Hit breakpoint at function in module after k-1 passes. – bp module!function k :在 k-1 通过后在模块中的函数处命中断点。
– ba w4 address “k;g” : Display call stack every write access on 4 bytes at address. – ba w4 地址“k;g”:显示地址处 4 个字节的每次写访问的调用堆栈。 – bu module!function “.dump C:\Dump.dmp; g” : Create a dump in C:\Dump.dmp every time breakpoint at function in module is hit. – bu module!function “.dump C:\Dump.dmp; g”:每次在模块中的函数处遇到断点时,都会在 C:\Dump.dmp 中创建转储。
– bp /t thread : Set a kernel mode breakpoint that only triggers when hit in the context of the associated thread. – bp /t thread :设置一个内核模式断点,仅在关联线程的上下文中命中时触发。 – bp /p process : Set a kernel mode breakpoint that only triggers when hit in the context of the associated process. – bp /p process :设置一个内核模式断点,仅在关联进程的上下文中命中时触发。
-.logopen FilePath; .bpcmds; .logclose : Save breakpoints to FilePath. -.logopen 文件路径; .bpcmds; .logclose :将断点保存到 FilePath。 – $<FilePath : Reload breakpoints from FilePath. – $
Tracing and stepping 追踪和步进
– g : Start executing the given process or thread.
-g :开始执行给定的进程或线程。
– g :number; ? poi(variable); g : Executes the current program to source line number, print the value of variable then resume execution.
– g :数字; ? poi(变量); g :执行当前程序到源代码行号,打印变量的值然后恢复执行。
– gc : Resume execution from a conditional breakpoint.
– gc :从条件断点恢复执行。
– gu : Execute until the current function is complete.
–gu :执行直到当前函数完成。
– gh : Go with Exception Handled.
– gh :进行异常处理。
– gn,: Go with Exception Not Handled.
– gn,: 继续处理未处理的异常。
– p : Step over.
-p:跨过去。
– t : Step in.
–t:介入。
– pr : Toggle displaying of registers.
– pr :切换寄存器的显示。
– p count “kb” : Step through count source lines then execute “kb”.
-p count“kb”:单步执行 count 源代码行,然后执行“kb”。
– pc : Step to next CALL instruction.
– pc : 进入下一条 CALL 指令。
– pt – Steps through until the next return instruction.
– pt – 逐步执行直到下一个返回指令。
– pa address : Step until address is reached.
– pa 地址:步进直至到达地址。
– wt : Trace and watch the execution flow of a function and its sub-functions.
– wt :跟踪和观察函数及其子函数的执行流程。
– wt -l Depth -oR : Trace sub-functions to Depth and display their return values.
– wt -l Depth -oR :跟踪子函数到 Depth 并显示其返回值。
Call stack 调用栈
– k : Display call stack. -k:显示调用堆栈。 – kn : Display call stack with frame numbers. – kn :显示带有帧编号的调用堆栈。 – kb : Display call stack with first three parameters passed to each function. – kb :显示传递给每个函数的前三个参数的调用堆栈。 – kb FrameCount : Display first FrameCount frames only. – kb FrameCount :仅显示第一个 FrameCount 帧。 – kp : Display all of the parameters for each function that is called in the stack trace. – kp :显示堆栈跟踪中调用的每个函数的所有参数。 – kn : Display frame numbers. - kn:显示帧编号。
– !findstack symbol 2 : Display all stacks that contain symbol. – !findstack symbol 2 : 显示包含symbol的所有堆栈。
– .frame : Show current frame. – .frame :显示当前帧。 – .frame FrameNumber : Set frame FrameNumber for the local context. – .frame FrameNumber :设置本地上下文的帧 FrameNumber。 – .frame /r FrameNumber : Display registers in frame FrameNumber. – .frame /r FrameNumber : 显示帧 FrameNumber 中的寄存器。
– !running -ti : Dump the stacks of each thread that is running on all processors. – !running -ti :转储所有处理器上运行的每个线程的堆栈。 – !stacks : Give a brief summary of the state of every thread. – !stacks :给出每个线程状态的简短摘要。
Registers 寄存器
– rm ? : Show possible Mask bits. - R M ? :显示可能的掩码位。 – rm 1 : Enable integer registers only. – rm 1:仅启用整数寄存器。 – r : Display the integer registers. –r:显示整数寄存器。 – r eax, edx : Display only eax and edx. – r eax, edx :仅显示 eax 和 edx。 – r eax=5, edx=6 : Assign new values to eax and edx. – r eax=5, edx=6 :为 eax 和 edx 分配新值。 – r eax:1ub : Display only the first byte from eax. – r eax:1ub :仅显示 eax 中的第一个字节。 – rF : Display the floating-point register. – rF :显示浮点寄存器。
Variables 变量
– dv /t /i /V : Dump local variables with type information, addresses and EBP offsets and classify them into categories. – dv /t /i /V :转储带有类型信息、地址和 EBP 偏移量的局部变量,并将它们分类。 – dt module!pattern* -v -s Length : List with verbose output all variables that begin with pattern in module that have Length bytes size. – dt module!pattern* -v -s Length :以详细输出列出模块中以 Length 字节大小的模式开头的所有变量。
– dt ntdll!_PEB : Dump _PEB structure. – dt ntdll!_PEB :转储 _PEB 结构。 – dt module!struct : Show fields of the structure struct defined in module with their offsets and types. – dt module!struct :显示模块中定义的结构体 struct 的字段及其偏移量和类型。 – dt module!struct -rCount : Dump fields of the structure struct defined in module recursively for Count levels. – dt module!struct -rCount :转储模块中为 Count 级别递归定义的结构体 struct 的字段。
– dt module!struct var. : Dump var defined in strcut in module and expand its subfields. – dt 模块!结构变量。 :转储模块中 strcut 中定义的 var 并展开其子字段。 – dt module!struct var.. : Expand subfields of var defined in strcut in module for 2 levels. – dt module!struct var.. :将 module 中 strcut 中定义的 var 子字段展开 2 级。
Memory 记忆
– dd address : Display double-words at address. – dd 地址:显示地址处的双字。 – dd address LLength: Display Length double-words at address. – dd 地址 LLength:显示地址处双字的长度。 – du address : Display unicode chars at address. – du 地址:显示地址处的 unicode 字符。 – du address LLength : Display Length unicode chars at address. – du 地址 LLength :显示地址处 unicode 字符的长度。 – !mapped_file address : Display name of file that contains address. – !mapped_file 地址:显示包含地址的文件名称。 – !address : Show all memory regions of our process. – !address :显示我们进程的所有内存区域。 – !address address : Retreive inforamation about a region of memory at address. – !address 地址:检索有关地址处内存区域的信息。
– eb address value : Set byte at address to value. – eb 地址值:将地址处的字节设置为值。 – ew address value : Set word at address to value. – ew 地址值:将地址处的字设置为值。 – ed address value : Set double-word at address to value. –ed 地址值:将地址处的双字设置为值。
– ds /c width address : Display width chars at address. – ds /c 宽度地址:显示地址处的宽度字符。 – dS /c width address : Display width unicode chars at address. – dS /c 宽度地址:显示地址处的宽度 unicode 字符。
– c address1 LLength address2 : Compare Length bytes at address1 with address2. – c address1 LLength address2 :比较地址 1 和地址 2 处的长度字节。 – m address1 LLength address2 : Move Length bytes at address1 to address2. – m 地址1 LLength 地址2 :将地址1 处的长度字节移至地址2。 – f address LLength ‘A’ ‘B’ ‘C’ – Fill memory location from address to address + Length – 1 with the pattern “ABC”, repeated as many times as necessary. – f 地址 LLength ‘A’ ‘B’ ‘C’ – 使用模式“ABC”填充从地址到地址 + Length – 1 的内存位置,根据需要重复多次。
– s -a address LLength “pattern” : Search memory location from address to address + Length – 1 for pattern. – s -a 地址 LLength “pattern” :从地址到地址 + Length – 1 搜索模式的内存位置。 – s -wa address LLength “pattern” : Search only writable memory from address to address + Length – 1 for pattern. – s -wa 地址 LLength “pattern” :仅搜索从地址到地址 + Length – 1 的可写内存的模式。
– !poolused : Display memory use summaries, based on the tag used for each pool allocation. – !poolused :根据每个池分配使用的标签显示内存使用摘要。 – !vm : Display summary information about virtual memory use statistics on the target system. – !vm :显示有关目标系统上虚拟内存使用统计信息的摘要信息。
– u address : Unassemble code at address. -u 地址:地址处的反汇编代码。
Heap 堆
– dt ntdll!_HEAP : Dump _HEAP structure. – dt ntdll!_HEAP :转储 _HEAP 结构。 – !heap : List all heaps with index and Heap address. – !heap : 列出所有堆及其索引和堆地址。 – !heap -h : List all of the current process heap with start and end addresses. – !heap -h :列出当前进程的所有堆及其起始地址和结束地址。 – !heap -h HeapIndex : Display detailed heap information for heap with index HeapIndex. – !heap -h HeapIndex :显示索引为 HeapIndex 的堆的详细堆信息。 – !heap -s 0 : Display summary for all heaps including reserved and committed memory … – !heap -s 0 : 显示所有堆的摘要,包括保留和提交的内存… – !heap -flt s 0x50 : Display all of the allocations of size 0x50. – !heap -flt s 0x50 :显示大小为 0x50 的所有分配。 – !heap -stat -h address : Display heap usage statistics for HeapHandle is equal to address. – !heap -stat -h 地址:显示HeapHandle 的堆使用统计信息等于地址。 – !heap -b alloc tag HeapIndex : Breakpoint in heap with index HeapIndex on HeapAlloc calls with TAG equal to tag. – !heap -b alloc tag HeapIndex :在 TAG 等于 tag 的 HeapAlloc 调用上使用索引 HeapIndex 的堆中断点。 – !heap -p -all : Display details of all allocations in all heaps in the process. – !heap -p -all :显示进程中所有堆中所有分配的详细信息。 – !heap -l : Make the debugger detect leaked heap blocks. – !heap -l :使调试器检测泄漏的堆块。
Memory dump 内存转储
– .dump FileName : Dump small memory image into FileName. – .dump FileName : 将小内存映像转储到 FileName 中。 – .dump /ma FileName : Dump complete memory image into FileName. – .dump /ma FileName :将完整的内存映像转储到 FileName 中。
Locks 锁具
– !locks : Display all kernel mode locks held on resources by threads. – !locks :显示线程在资源上持有的所有内核模式锁。 – !qlocks : Display the state of all queued spin locks. – !qlocks :显示所有排队的自旋锁的状态。
Extension DLLs 扩展 DLL
– .load ExtensionDLL : Load the extension DLL ExtensionDLL into the debugger. – .load ExtensionDLL :将扩展 DLL ExtensionDLL 加载到调试器中。 – .unload ExtensionDLL : Unload the extension DLL ExtensionDLL. – .unload ExtensionDLL :卸载扩展 DLL ExtensionDLL。
– .chain : List all extensions that the debugger has loaded. – .chain :列出调试器已加载的所有扩展。 – .unloadall : Unload all extension DLLs from the debugger. – .unloadall :从调试器中卸载所有扩展 DLL。 – .setdll ExtensionDLL : Change the default extension DLL to ExtensionDLL for the debugger – .setdll ExtensionDLL :将调试器的默认扩展 DLL 更改为 ExtensionDLL
Application Verifier 应用验证器
– !avrf : Display a variety of output produced by Application Verifier. If a Stop has occurred, reveal the its nature and what caused it. – !avrf:显示应用程序验证器生成的各种输出。如果发生停止,请揭示其性质以及导致其发生的原因。 – !verifier 0xf : Display the status of Driver Verifier and its actions. – !verifier 0xf :显示 Driver Verifier 的状态及其操作。 – !verifier 0x80 address : Display log associated with the specified address within the kernel pool Allocate and Free operations. – !verifier 0x80 地址:显示与内核池分配和释放操作中指定地址相关的日志。 – !verifier 0x100 address : Display log associated with the IRP at address. – !verifier 0x100 地址:显示与地址处的 IRP 关联的日志。
