메모장 입니다2

Windows] 드라이버 개발 - 3) windbg 기능, 커널 덤프 본문

Study/Programming

Windows] 드라이버 개발 - 3) windbg 기능, 커널 덤프

Wooum@n 2017. 2. 23. 23:40

1.심볼 파일


 -종류

>Public Symbol: MS에서 제공하는 심볼


>Private Symbol: 제조사가 제공하는 심볼



 -Windbg 설정

->심볼 경로 지정

`File> Symbol File Path`

"C:\sym; srv*c:\sym\websym*http://msdl.microsoft.com/download/symbols" 저장

[전체 심볼]       [웹에서 받아올 심볼]     [URL]

->심볼 업데이트

windbg 상에서 명령어 입력

kd> .reload /a




2.프로세스 전환


 -작업중인 프로세스 외에 다른 프로세스의 정보(쓰레드, 콜스텍 등)를 확인할 수 있다.

 -실습

1)프로세스 정보 확인

`!process`

:현재 active 쓰레드가 속한 프로세스 정보 출력


`!process 0 1`

:모든 프로세스 정보 출력


`!process 0 7`

:모든 프로세스에 대한 쓰레드와 콜스택 정보까지 얻어옴.




2)프로세스 전환

`.process [프로세스 주소]`


kd> .process 95be9040

Implicit process is now 95be9040

WARNING: .cache forcedecodeuser is not enabled



3)쓰레드 정보 출력

`!thread`


kd> !thread

THREAD 822e8480  Cid 0000.0000  Teb: 00000000 Win32Thread: 00000000 RUNNING on processor 0

Not impersonating

DeviceMap                 886067a8

Owning Process            822e8900       Image:         Idle

Attached Process          8714e340       Image:         System

Wait Start TickCount      11791          Ticks: 1 (0:00:00:00.015)

Context Switch Count      19421          IdealProcessor: 0             

UserTime                  00:00:00.000

KernelTime                00:02:31.125

Win32 Start Address nt!KiIdleLoop (0x821ab468)

Stack Init 83698ca0 Current 83698c00 Base 83699000 Limit 83696000 Call 00000000

Priority 0 BasePriority 0 PriorityDecrement 0 IoPriority 0 PagePriority 5

ChildEBP RetAddr  Args to Child              

83698800 821f951e 00000001 821c28b5 00000002 nt!RtlpBreakWithStatusInstruction (FPO: [1,0,0])

83698864 820b2812 00002e10 00000002 00000000 nt! ?? ::FNODOBFM::`string'+0x4a572

83698894 820b2676 836989c8 ffd10a30 00000002 nt!KiUpdateRunTime+0x42 (FPO: [Non-Fpo])

83698920 8201c8b3 8202e70b 00000001 83698b88 nt!KeClockInterruptNotify+0x206 (FPO: [Non-Fpo])

83698930 8202c81b 021a0202 000000d1 01fab043 hal!HalpTimerClockInterruptCommon+0x3f (FPO: [0,0,4])

83698930 8202e70b 021a0202 000000d1 01fab043 hal!HalpTimerClockInterrupt+0x1f7 (FPO: [0,2] TrapFrame @ 836989c8)

83698a38 8218d01a 820b3cc6 ffffffff 00000000 hal!HalProcessorIdle+0x7 (FPO: [0,0,0])

83698a3c 820b3cc6 ffffffff 00000000 871dab94 nt!PpmIdleDefaultExecute+0x6 (FPO: [3,0,0])

83698b88 820b3678 ffffffff 822e8400 1a1c0f10 nt!PpmIdleExecuteTransition+0x506 (FPO: [7,75,4])

83698c04 821ab475 00000000 00000000 00000000 nt!PoIdle+0x328 (FPO: [Non-Fpo])

83698c08 00000000 00000000 00000000 00000000 nt!KiIdleLoop+0xd (FPO: [0,0,0])



4)쓰레드 전환

`.thread [쓰레드 주소]`


kd> .thread 822e8480

Implicit thread is now 822e8480



5)현재 지정된 쓰레드의 콜스택 출력

`kM`

kd> kM

  *** Stack trace for last set context - .thread/.cxr resets it

 # ChildEBP RetAddr  

00 83698800 821f951e nt!RtlpBreakWithStatusInstruction

01 83698864 820b2812 nt! ?? ::FNODOBFM::`string'+0x4a572

02 83698894 820b2676 nt!KiUpdateRunTime+0x42

03 83698920 8201c8b3 nt!KeClockInterruptNotify+0x206

04 83698930 8202c81b hal!HalpTimerClockInterruptCommon+0x3f

05 83698930 8202e70b hal!HalpTimerClockInterrupt+0x1f7

06 83698a38 8218d01a hal!HalProcessorIdle+0x7

07 83698a3c 820b3cc6 nt!PpmIdleDefaultExecute+0x6

08 83698b88 820b3678 nt!PpmIdleExecuteTransition+0x506

09 83698c04 821ab475 nt!PoIdle+0x328

0a 83698c08 00000000 nt!KiIdleLoop+0xd



6)스텍프레임 전환

`.frame [인덱스 값]  //5번에서 출력된 인덱스 값

>프레임 변환시, 디스어셈블리 창의 내용이 해당 함수의 호출코드 변경되어 출력된다.

1)frame 1의 호출코드


2)frame 2의 호출코드





3.dt 명령어


 -형식

`dt  [구조체 원형]  [주소]


 -기능

1)특정 구조체 정보 출력

`dt  [구조체 원형]`


/* _ETHREAD 구조체 정보 출력 */

kd> dt _ETHREAD

dtx is unsupported for this scenario.  It only recognizes dtx [<type>] [<address>] with -a, -h, and -r.  Reverting to dt.

nt!_ETHREAD

   +0x000 Tcb              : _KTHREAD

   +0x348 CreateTime       : _LARGE_INTEGER

   +0x350 ExitTime         : _LARGE_INTEGER

   +0x350 KeyedWaitChain   : _LIST_ENTRY

   +0x358 ChargeOnlySession : Ptr32 Void

   +0x35c PostBlockList    : _LIST_ENTRY

   +0x35c ForwardLinkShadow : Ptr32 Void

   +0x360 StartAddress     : Ptr32 Void

   +0x364 TerminationPort  : Ptr32 _TERMINATION_PORT

   +0x364 ReaperLink       : Ptr32 _ETHREAD

   +0x364 KeyedWaitValue   : Ptr32 Void

   +0x368 ActiveTimerListLock : Uint4B

   +0x36c ActiveTimerListHead : _LIST_ENTRY

   +0x374 Cid              : _CLIENT_ID

   +0x37c KeyedWaitSemaphore : _KSEMAPHORE

   +0x37c AlpcWaitSemaphore : _KSEMAPHORE

   +0x390 ClientSecurity   : _PS_CLIENT_SECURITY_CONTEXT

   +0x394 IrpList          : _LIST_ENTRY

   +0x39c TopLevelIrp      : Uint4B

   +0x3a0 DeviceToVerify   : Ptr32 _DEVICE_OBJECT

   +0x3a4 Win32StartAddress : Ptr32 Void

   +0x3a8 LegacyPowerObject : Ptr32 Void

...........
...........
...........


2)특정 메모리 범위의 값을, 지정한 구조체의 형식에 맞춰 출력가능.

`dt  [구조체 원형]  [메모리 주소]`


/* 822e8480~의 값을 _ETHREAD 구조체 형식에 맞춰 출력 */

kd> dt _ETHREAD 822e8480

nt!_ETHREAD

   +0x000 Tcb              : _KTHREAD

   +0x348 CreateTime       : _LARGE_INTEGER 0x0

   +0x350 ExitTime         : _LARGE_INTEGER 0x0

   +0x350 KeyedWaitChain   : _LIST_ENTRY [ 0x0 - 0x0 ]

   +0x358 ChargeOnlySession : (null) 

   +0x35c PostBlockList    : _LIST_ENTRY [ 0x0 - 0x821ab468 ]

   +0x35c ForwardLinkShadow : (null) 

   +0x360 StartAddress     : 0x821ab468 Void

   +0x364 TerminationPort  : (null) 

   +0x364 ReaperLink       : (null) 

   +0x364 KeyedWaitValue   : (null) 

   +0x368 ActiveTimerListLock : 0

   +0x36c ActiveTimerListHead : _LIST_ENTRY [ 0x0 - 0x0 ]

   +0x374 Cid              : _CLIENT_ID

   +0x37c KeyedWaitSemaphore : _KSEMAPHORE

   +0x37c AlpcWaitSemaphore : _KSEMAPHORE

   +0x390 ClientSecurity   : _PS_CLIENT_SECURITY_CONTEXT

   +0x394 IrpList          : _LIST_ENTRY [ 0x0 - 0x0 ]

   +0x39c TopLevelIrp      : 0

   +0x3a0 DeviceToVerify   : (null) 

   +0x3a4 Win32StartAddress : 0x821ab468 Void

   +0x3a8 LegacyPowerObject : (null) 

   +0x3ac ThreadListEntry  : _LIST_ENTRY [ 0x822e8a94 - 0x822e8a94 ]

   +0x3b4 RundownProtect   : _EX_RUNDOWN_REF

   +0x3b8 ThreadLock       : _EX_PUSH_LOCK

   +0x3bc ReadClusterSize  : 0

   +0x3c0 MmLockOrdering   : 0n0

   +0x3c4 CmLockOrdering   : 0n0

   +0x3c8 CrossThreadFlags : 0x5000

   +0x3c8 Terminated       : 0y0

   +0x3c8 ThreadInserted   : 0y0


                     ->값이 구조체 멤버에 매칭되어 출력되었다.