WinDbg Cheatsheet


[:  :]

References

Display Bytes

CommandDescription
db espDisplay bytes from address in ESP as bytes with ASCII chars on the side (hex dump)
db kernel32!WriteFileDisplay bytes in a function
dw espDisplay bytes from address in ESP as words (2 bytes)
dW espDisplay bytes from address in ESP as words with ASCII chars on the side like in db
dd espDisplay bytes from address in ESP as double words (4 bytes)
dd 771bab89Display bytes from address 0x771bab89 as double words (4 bytes)
dc espDisplay bytes from address in ESP as dobule words with ASCII chars on the side like in db
dq 00faf974Display bytes from address in ESP as quad words (8 bytes)
da espDisplay bytes from address in ESP as ASCII (This is ASCII with no hex dump)
dd poi(esp)Display dwords from the pointer that the address ESP points to.
dW KERNELBASE+0x40Display dwords with ASCII chars at KERNELBASE + 0x40
dd esp L4Display 4 double words from address in ESP
dW KERNELBASE L2Display 2 words with ASCII chars from KERNELBASE
db KERNELBASE L2Display 2 bytes with ASCII chars from KERNELBASE

Program Control

https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/controlling-the-target

CommandDescription
gGo. Continues execution
guExecute until function is complete.
pStep. Step Over. If a function call it just keeps going. F10
paStep to Address.
pcStep to Next Call.
pctStep to Next Call or Return.
phStep to Next Branching Instruction. Any branches, calls, rets, or syscalls
ptStep to Next Return. Go to the end of the function
tTrace. Step Into. If a function call it steps into it. F8, F11
taTrace to address. See docs for full info on this.

Breakpoints

CommandDescription
blList breakpoints
bd 1Disable breakpoint 1
bc 2Clear breakpoint 2
bp wsock32!recvBreak on wsock32!recv
bp WS2_32!recvBreak on WS2_32!recv
br 0xbaf000Break on reading address 0xbaf000
bw 0xbaf000Break on writing to address 0xbaf000
be 0xbaf000Break on executing address 0xbaf000

Hardware Breakpoints

ba e 1 kernel32!WriteFile – Set a hardware breakpoint when kernel32!WriteFile executes

Symbols

CommandDescription
.reload /fReload symbols
x WS2_32!recvSearch for symbol. Displays address.
x WS2_32!rec*Search for symbol with wildcard. Will show recv and recvfrom.
!drvobj nameFind driver
!devobj nameFind device object
!devhandles handleFind app using driver

Examine Code

CommandDescription
u 761ae7b2Unassemble at address 0x761ae7b2
u kernel32!GetCurrentThreadUnassemble kernel32!GetCurrentThread
u kernel32!GetCurrentThread+0x2Unassemble kernel32!GetCurrentThread+0x2
u kernel32!GetCurrentThread+0x2 L2Unassemble kernel32!GetCurrentThread+0x2 and display 2 lines

Dump Structures

CommandDescription
kDump Call Stack
lmShow loaded modules
lm m kernel*Show loaded modules beginning with “kernel”
lmDva 0x724a0000Get info on the module at address 0x724a0000
ln 77c94d10Show the closest symbol to the address 0x77C94D10
rDump all registers
r ecxDump value in ECX
r ecx=41414141Write 0x41414141 to ECX
!tebDump Thread Environment Block
!pebDump Process Environment Block
!vadumpDump memory pages/info
!heapDump heap info

Display Type (dt)

https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/dt--display-type-

CommandDescription
dt ntdll!_TEBdump the Thread Env Block
dt -r ntdll!_TEB @$teb-r is recursively dumping structs, @$teb is a pseudo register that represents $teb
?? sizeof(ntdll!_TEB)Get the size of a structure

Display specific fields:

dt ntdll!_TEB @$teb ThreadLocalStoragePointer

Writing to Memory

Write ascii with ea, write unicode with eu

CommandDescription
dd esp L1Show dword at esp
ed esp 41414141Write 0x41414141 to pointer in ESP
dd esp L1Show dword at esp
ea esp “Haha”Write “Haha” to the pointer at ESP
da espShow ASCII from bytes at ESP
eu esp “Ha”Write “Ha” UTF-16, which is also 4 bytes
da espShow ASCII from bytes at ESP

Searching Memory Space

See reference for way more info https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/s--search-memory-

Four parameters

CommandDescription
ed esp 41414141Write 0x41414141 to pointer in ESP
s -d 0 L?80000000 41414141Search process image for dword 0x41414141
s -d 77a40000 77d00000 41414141Search address range for dword 0x41414141
s 77a40000 77a60000 41 41 41 41Search address range for 0x41414141 as bytes

Examples:

Search for DOS header:

s -a 0 L?80000000 "This program cannot be run in DOS mode"

Search for the string “SCADA” as unicode:

s -u 0 L?80000000 "SCADA"
- Example Output: 53 00 43 00 41 00 44 00 41 00 00 00

Expressions

The default representation of numbers in Windbg is hex.

See all the formats of a hex number with .formats

0:000> .formats 41414141
Evaluate expression:
  Hex:     41414141
  Decimal: 1094795585
  Octal:   10120240501
  Binary:  01000001 01000001 01000001 01000001
  Chars:   AAAA
  Time:    Fri Sep 10 01:53:05 2004
  Float:   low 12.0784 high 0
  Double:  5.40901e-315

? evaluates an expression.

0:000> ? 77269bc0 - 77231430
Evaluate expression: 231312 = 00038790
0:000> ? 77269bc0 >> 18
Evaluate expression: 119 = 00000077

Doing the same thing in decimal needs 0n as the prefix.

0:007> ? 0n1000 - 0n250
Evaluate expression: 750 = 000002ee

Binary needs 0y prefix. This is 0x41 + 0x41

0:007> ? 0y01000001 + 0y01000001
Evaluate expression: 130 = 00000082

User defined psuedo registers $t0 to $t19. Useful in scripts.

r@$t0 = 41414141  -- Assign value to $t0
r $t0             -- Examine value in $t0