Basic debugging & tips using NTSD

听故事学语言 · 数据结构篇 · 第 12 章 树的工业应用 数据结构篇第十二章,树的工业应用。第一站文件树:打开一条路径就是从树根逐层查找,每一层都是一次小小的顺序查找,目录项是目录里的一行,NTFS 的目录在磁盘上用 B 树来管。第二站人造的两棵树:DOM 是网页内容的树,开标签压栈闭标签弹栈,弹出来的就是爸爸,一对标签一条线段,层次就是盖住你的线段条数;Git 提交一次给整棵目录树拍快照,没变的子树新旧快照直接共用,每份内容一枚按内容算出来的号。第三站字典树:一层一个字母,查一个词看词长不看词库大小,联想词先序收子树,天然字典序。第四站磁盘上的树讲矮胖:页 16 阅读详情

http://www.opferman.net/Text/ntsd.txt

Basic debugging & tips using NTSD

By Toby Opferman (AKA Scrat/_Secret)
http://www.opferman.com
http;//www.opferman.net
toby@opferman.com


NOTE:  This tutorial is without warrenty.  Use at your own risk. I am
not in any way responsible for any damages caused by use of this tutorial.



	NTSD is a debugger for WinNT & Win2K that can be used to debug
application bugs and traps.  To set NTSD to be launched when an application
traps, you need to set the following registry key:

HKEY_LOCAL_MACHINE/Software/Microsoft/WindowsNT/CurrentVersion/AeDebugger

Set the value "Debugger" to
"ntsd -p %ld -e %ld -g"
or just "ntsd -p %ld -e %ld"  
or just "ntsd -p %ld"

You can do ntsd /?  and check out the options you like.  The -g does is when
it traps to the debugger, it does "auto go".


Set the value "Auto" to
1

This is if you want to change to NTSD.  If you have devstudio installed,
this value may be set to devstudio, or it could be set to Dr. Watson.
If it is set to Dr. Watson, I would suggest setting it to NTSD instead,
since Dr. Watson just gives a stack trace and a small assembly listing.


	When an application traps, if the trap is not handled, NTSD should
catch and break into the process where it trapped.  To start using NTSD on
an application, when it is set as your default debugger you can right click
on the process in task manager and click "Debug Process".  You can also
get the PID of the process in Task Manager or by running qprocess and 
doing NTSD -P <PID>.


	Some of the basic commands that you would want to know are:
kb - Stack Dump
dd - Dump Dwords
da - Dump ANSI String
du - Dump UNICODE String
~* - List Threads
~<number><command> - Perform <command> on Thread <number> 
                     (Such as ~1kb Stack Dump Thread 1)
u - Unassemble
!reload - Reload Symbols
g - Go
p - Step 1 instruction, but do not trace into function calls
t - Trace into, and step 1 instruction
bp - Set Breakpoint
bc - Clear Breakpoint

	Before we start on NTSD, let us look at symbols.  Now, when using
a debug build, symbols along with other debug information are embedded
into the executable and the assembly is not optimized.  This makes it
easier to debug.

	However, when you want to release you would like to build a retail
build.  Synchronization, timing and memory may show up more in a retail
build and you would have a hard time debugging them.  What we want to be
able to do, is debug our applications without recompiling and throwing
in 100 print statements.  On that note, if this bug is not that reproducable
or the steps to reproduce it are long and not very easy, we would like to
be able to find out what the problem is from it's crashed state.  

Let's take a look at something.  I have a small source file that I wrote
when I was working on an OS to remove the binary headers from executables.

Compiling with optimizations and linking this source like so:

cl /Ox /c rmhdr.c
link /SUBSYSTEM:CONSOLE /OUT:rmhdr.exe rmhdr.obj 

Produces:
RMHDR    EXE        32,768

Now, there are no symbols or memory mappings of what the binary contains.
So, if we compile with debug information, all we really need are the symbols.

cl /Ox /Zi /c rmhdr.c
link /SUBSYSTEM:CONSOLE /OUT:rmhdr.exe rmhdr.obj -pdb:rmhdr.pdb -debugtype:both -debug

Produces:
RMHDR    EXE        53,506

53k Executable.  Now, this file can be used to debug directly and you would have
symbols for the function calls which make it easier to debug.   However, Would
you want to release a file with debug information?  On the other hand, if you
release a file without debug information and it crashes on someone's machine
and you want to be able to debug this machine easily, you would want the debug
information.  So, what should we do?


rebase -b 0x00400000 -x ./ -a rmhdr.exe

When we run the rebase utility, we now have 2 files.
RMHDR    DBG        16,876  12-13-00  8:53p rmhdr.dbg
RMHDR    EXE        37,136  12-13-00  8:53p rmhdr.exe

37k is a little more than 32k, but you're already programming in C and
not assembly (Or C++ if that's the case)  so you're not too worried about
size that much, at least not to the point to complain about this or else
you'd be writing in assembly.

Now, you say you have this DBG file, but what can you do with it?  
There's a few things you can do with it, let me provide an example.

I purposely put a bug into this C program and will run it on Windows 98.

And now you get the "This program has performed an illegal operation and will be
shut down"  "If this problem persists, contact the program vendor"

It does ask you "Close", "Debug" or "Details"  Well, you can debug, (The best
debugger for Win98 would be like softice or even VC++), but I think that
we can get enough information just by hitting "Details".

This is what we get when we hit details:

RMHDR caused an invalid page fault in
module RMHDR.EXE at 0177:0040124b.
Registers:
EAX=3f3e3d3c CS=0177 EIP=0040124b EFLGS=00010246
EBX=00530000 SS=017f ESP=0063fcd4 EBP=0063fde4
ECX=004083c8 DS=017f ESI=81756014 FS=23f7
EDX=00000000 ES=017f EDI=00000000 GS=0000
Bytes at CS:EIP:
c7 00 0a 00 00 00 8b 8d f8 fe ff ff 83 c1 04 89 
Stack dump:
004083c8 004083e8 3f3e3d3c 00000000 47464544 
4b4a4948 0063fd20 816e8050 816edcdc cddb6b80 
0063fd20 bff7a0fe bff7b317 816e8000 00000000 
00000014 


Notice EIP = 0040124b, just using that number, we can narrow it down.

There is a utility that comes with VC++ called dumpbin, which is very useful.

dumpbin /symbols rmhdr.dbg > t.txt


We now have a mapping of all the symbols and their addresses.

We have to map 0040124b to the image.  We usually will just take
124b part, or will have to adjust the number to match the symbols (i.e.,
it could really be 10124b in the map, depends on where the EXE was loaded
into memory).  One way is to go into t.txt now, and look at the very last
entry.

235 00009F04 SECT3  notype       External     | __acmdln
236 0000A000 DEBUG  notype       External     | end

    0040124b
Are the very last entries.  Comparing the values, you can see that
0040124b is not an absolute 1-1 mapping to the symbols.  Notice also that
this is simple since we did not have to look at the stack and we know that
EIP is still inside RMHDR.EXE (I made sure of that when I put the bug in).
There are times when you may have to map the entire stack to find out the calling 
path.  

Well, let's try 124b.  Now remeber, we can't search on this number.  This number
will not exist in the mapping.  We need to find 2 functions where this number
would lie between.

0F7 0000114F SECT1  notype ()    External     | _RemoveHdr
0F8 00001295 SECT1  notype ()    External     | _atol

And here we found it.  124B is between _RemoveHdr and _atol in the source.
This means, that the function that crashed is _RemoveHdr.  

Now, if we would have dropped into a debugger, we could look at the stack
and even find out who called RemoveHdr, what the values on the parameters are,
and etc.  However, we didn't.  I also ran this in Win98. We could generate
a MAP file or COD file that would show the Asm with C with addresses and
we'd be able now to go directly to RemoveHdr and find the spot where it
crashed. (And I bet you never knew how useful those little GPF messages
were!)

However, this tutorial isn't just about debugging.  It's about
debugging with NTSD.

So, let's take it to Win2k with NTSD set to trap as our default debugger. 
(Remeber, we set our default debugger as NTSD eariler).

Now, I run the program and it traps into NTSD.

Microsoft(R) Windows 2000 Debugger
Version 5.00.2184.1
Copyright (C) Microsoft Corp. 1981-1999

CommandLine:
*** wait for debug event
Symbol search path is: C:/WINDOWS
NTSD ModLoad: 00400000 0040a000   rmhdr.exe
NTSD ModLoad: 77f80000 77ff9000   ntdll.dll
NTSD ModLoad: 77e80000 77f36000   KERNEL32.dll
NTSD: access violation
NTSD: !!! second chance !!!
eax=00000018 ebx=7ffdf000 ecx=004083c8 edx=00000000 esi=77e84ed2 edi=00008000
eip=0040124b esp=0012fe5c ebp=0012ff6c iopl=0         nv up ei pl zr na po nc
cs=001b  ss=0023  ds=0023  es=0023  fs=0038  gs=0000             efl=00000246
*** ERROR: Module load completed but symbols could not be loaded for rmhdr.exe
rmhdr+124b:
0040124b c7000a000000     mov   dword ptr [eax],0xa ds:0023:00000018=????????
0:000>

It traps into rmhdr.  Look at the line that says "symbols could not be loaded"

We need symbols!

0:000> u
rmhdr+124b:
0040124b c7000a000000     mov     dword ptr [eax],0xa
00401251 8b8df8feffff     mov     ecx,[ebp-0x108]
00401257 83c104           add     ecx,0x4
0040125a 898df8feffff     mov     [ebp-0x108],ecx
00401260 83bdfcfeffff00   cmp     dword ptr [ebp-0x104],0x0
00401267 7591             jnz     rmhdr+0x11fa (004011fa)
00401269 8b95f0feffff     mov     edx,[ebp-0x110]
0040126f 52               push    edx
0:000> kb
ChildEBP RetAddr  Args to Child
0012ff6c 0040107c 00300eca 00300ed6 0007a120 rmhdr+0x124b
0012ff80 004018de 00000004 00300eb0 00300e00 rmhdr+0x107c
0012ffc0 77e87903 00008000 77e84ed2 7ffdf000 rmhdr+0x18de
0012fff0 00000000 0040182a 00000000 000000c8 KERNEL32!SetUnhandledExceptionFilte
r+0x5c
0:000>

Nice, we have no idea how this function was called.  First, we have a
small buffer, so we want to go to the top left corner of the window,
go to "Properties -> Layout Tab"  then go to Buffer Height.  It is probably
300 on Win2k and 80 on NT.  Set it to 9999.  Now, we have room to work.

Looking at that, we could be anywhere.  Symbols are usually put into
C:/WINNT/Symbols/EXE & C:/WINNT/Symbols/Dll

So, we copy the rmhdr.dbg file into C:/WINNT/SYMBOLS/EXE if you have
the symbols environment variable set.  Or, to be simpler, you may
copy it to your environment path and NTSD will pick it up.


0:000> !reload
0:000> kb
ChildEBP RetAddr  Args to Child
0012ff6c 0040107c 00300eca 00300ed6 0007a120 rmhdr!RemoveHdr+0xfc
0012ff80 004018de 00000004 00300eb0 00300e00 rmhdr!main+0x7c
0012ffc0 77e87903 00008000 77e84ed2 7ffdf000 rmhdr!mainCRTStartup+0xb4
0012fff0 00000000 0040182a 00000000 000000c8 KERNEL32!SetUnhandledExceptionFi
r+0x5c
0:000> r
eax=00000018 ebx=7ffdf000 ecx=004083c8 edx=00000000 esi=77e84ed2 edi=00008000
eip=0040124b esp=0012fe5c ebp=0012ff6c iopl=0         nv up ei pl zr na po nc
cs=001b  ss=0023  ds=0023  es=0023  fs=0038  gs=0000             efl=00000246
rmhdr!RemoveHdr+fc:
0040124b c7000a000000     mov   dword ptr [eax],0xa ds:0023:00000018=????????
0:000> u
rmhdr!RemoveHdr+fc:
0040124b c7000a000000     mov     dword ptr [eax],0xa
00401251 8b8df8feffff     mov     ecx,[ebp-0x108]
00401257 83c104           add     ecx,0x4
0040125a 898df8feffff     mov     [ebp-0x108],ecx
00401260 83bdfcfeffff00   cmp     dword ptr [ebp-0x104],0x0
00401267 7591             jnz     rmhdr!RemoveHdr+0xab (004011fa)
00401269 8b95f0feffff     mov     edx,[ebp-0x110]
0040126f 52               push    edx
0:000>

We now have symbols!  We see that we are moving 10 into EAX, which
is set to 18h.  Well, let me show you some features of NTSD before
we figure out what the problem is.

If you look at the first "Return Address" on the stack, we can
dissassemble it and look at the calling code.

0:000> u 40107c
rmhdr!main+7c:
0040107c 83c40c           add     esp,0xc
0040107f 33c0             xor     eax,eax
00401081 5d               pop     ebp
00401082 c3               ret
rmhdr!DispatchMsg:
00401083 55               push    ebp
00401084 8bec             mov     ebp,esp
00401086 51               push    ecx
00401087 8b4508           mov     eax,[ebp+0x8]
0:000>

Doing this requires at least some assembly knowledge however.  

0:000> ~*
  0  id: 100.228   Suspend: 0 Teb 7ffde000 Unfrozen
  1  id: 100.310   Suspend: 0 Teb 7ffdd000 Unfrozen
0:000>

We see there are two threads.

0:000> ~1kb
ChildEBP RetAddr  Args to Child
0045ffb4 77e92ca8 00000000 00000200 0040fcbc ntdll!DbgBreakPoint+0x1
0045ffec 00000000 77eabe5a 00000000 00000000 KERNEL32!CreateFileA+0x11b
0:000> ~0kb
ChildEBP RetAddr  Args to Child
0012ff6c 0040107c 00300eca 00300ed6 0007a120 rmhdr!RemoveHdr+0xfc
0012ff80 004018de 00000004 00300eb0 00300e00 rmhdr!main+0x7c
0012ffc0 77e87903 00008000 77e84ed2 7ffdf000 rmhdr!mainCRTStartup+0xb4
0012fff0 00000000 0040182a 00000000 000000c8 KERNEL32!SetUnhandledExceptionFilte
r+0x5c
0:000>

However, this program is single threaded.  One of the threads could have been
created by an API we called (A lot of APIs create seperate threads). However,
"DbgBreakPoint" kind of makes it look to be a break point thread created by
NTSD to break into the thread.

We are only concerned with thread 0.
ChildEBP RetAddr  Args to Child
0012ff6c 0040107c 00300eca 00300ed6 0007a120 rmhdr!RemoveHdr+0xfc

Now, we know that the prototype of RemoveHdr is  

void RemoveHdr(char *InFileName, char *OutFileName, int Size)

Let's take a look at what is stored in the third parameter.  We also know
we called the function as so:

C:/>rmhdr tdconfig.td happy 500000
Stripping 500000 Bytes

And 50000 should have been passed to rmhdr as an integer.

0007a120 is what is listed as the third parameter.  Being passed
by value, this is the value in decimal 500000.

So, we know we're passing a correct parameter.  Next, we notice the 
first two parameters are ANSI strings.  

(Notice that just because it lists 3 parameters on all the functions, 
this is not nessecarily how many parameters the function has.)

0:000> da 300eca
00300eca  "tdconfig.td"
0:000> da 300ed6
00300ed6  "happy"
0:000>

(Notice, for Unicode strings, type "du <address>").

We notice we are passing down the correct parameters.  Parameter 1 is
the inputname we gave, and parameter 2 is the output name we gave.

We can do something else now.  We can find the address of RemoveHdr.

0:000> x rmhdr!RemoveHdr
0040114f  rmhdr!RemoveHdr
0:000>

Wild cards can be used as well, example:
0:000> x rmhdr!*   ; would list all the symbols for rmdhr.


Well, we now have the address.  But, we actually don't need
the address.  Because, you can referr to the function by its
symbol.  Let's unassemble.

0:000> u rmhdr!RemoveHdr
rmhdr!RemoveHdr:
0040114f 55               push    ebp
00401150 8bec             mov     ebp,esp
00401152 81ec10010000     sub     esp,0x110
00401158 681c814000       push    0x40811c
0040115d 8b4508           mov     eax,[ebp+0x8]
00401160 50               push    eax
00401161 e826030000       call    rmhdr!fopen (0040148c)
00401166 83c408           add     esp,0x8
0:000> u
rmhdr!RemoveHdr+1a:
00401169 8985f0feffff     mov     [ebp-0x110],eax
0040116f 83bdf0feffff00   cmp     dword ptr [ebp-0x110],0x0
00401176 750f             jnz     rmhdr!RemoveHdr+0x38 (00401187)
00401178 6a01             push    0x1
0040117a e804ffffff       call    rmhdr!DispatchMsg (00401083)
0040117f 83c404           add     esp,0x4
00401182 e90a010000       jmp     rmhdr!RemoveHdr+0x142 (00401291)
00401187 6820814000       push    0x408120
0:000> u
rmhdr!RemoveHdr+3d:
0040118c 8b4d0c           mov     ecx,[ebp+0xc]
0040118f 51               push    ecx
00401190 e8f7020000       call    rmhdr!fopen (0040148c)
00401195 83c408           add     esp,0x8
00401198 8985f4feffff     mov     [ebp-0x10c],eax
0040119e 83bdf4feffff00   cmp     dword ptr [ebp-0x10c],0x0
004011a5 751e             jnz     rmhdr!RemoveHdr+0x76 (004011c5)
004011a7 8b95f0feffff     mov     edx,[ebp-0x110]
0:000> u
rmhdr!RemoveHdr+5e:
004011ad 52               push    edx
004011ae e863020000       call    rmhdr!fclose (00401416)
004011b3 83c404           add     esp,0x4
004011b6 6a02             push    0x2
004011b8 e8c6feffff       call    rmhdr!DispatchMsg (00401083)
004011bd 83c404           add     esp,0x4
004011c0 e9cc000000       jmp     rmhdr!RemoveHdr+0x142 (00401291)
004011c5 6a00             push    0x0
0:000> r eip
eip=0040124b

 .....  we keep unassembling until we get to the crashed area.

0:000> u
rmhdr!RemoveHdr+ed:
0040123c 52               push    edx
0040123d e85d020000       call    rmhdr!fwrite (0040149f)
00401242 83c410           add     esp,0x10
00401245 8b85f8feffff     mov     eax,[ebp-0x108]
0040124b c7000a000000     mov     dword ptr [eax],0xa
00401251 8b8df8feffff     mov     ecx,[ebp-0x108]
00401257 83c104           add     ecx,0x4
0040125a 898df8feffff     mov     [ebp-0x108],ecx
0:000>

Now, we call fwrite before we move 10 into this variable.  Notice
EAX's address comes from EBP-0x108, which means it's a local variable.
We are assigning 10 to a local variable, infact, a pointer, since
we reference this address after we get it from the stack.  Right
after we call fwrite().  Should be easy to figure out.

(Also Note:

0:000> r
eax=00000018 ebx=7ffdf000 ecx=004083c8 edx=00000000 esi=77e84ed2 edi=00008000
eip=0040124b esp=0012fe5c ebp=0012ff6c iopl=0         nv up ei pl zr na po nc
cs=001b  ss=0023  ds=0023  es=0023  fs=0038  gs=0000             efl=00000246
rmhdr!RemoveHdr+fc:
0040124b c7000a000000     mov   dword ptr [eax],0xa ds:0023:00000018=????????
0:000>

Hitting r will display all registers and take you to the spot where
it crashed or asserted again.  Using u from here will start
dissassembling after the point where it faulted.
)



We lucked out.  There is only 1 fwrite in the function, so we don't even have to 
try to see how many calls happened or who called what before when. 

     if(BlockSize)
       fwrite(Buffer, 1, BlockSize, OutFile);
     
     *x = 10; 
     x++;

What do we see here!  A pointer being assigned the value 10.  Now, why would this
crash?  As we look further we find:
  int BlockSize, *x;

And no other reference to *x in the entire function.  x has not bee allocated,
it's tring to write randomly to memory.  We have solved the problem.  
(Also, thank god for small functions, please do not write 5000000000 line functions!
They are hard to debug!).

We found the problem without rerunning the program.  Once it trapped into NTSD,
we were able to use NTSD to determine where the program had crashed without tring
to put print statements in and recompiling (Which can sometimes change a binary
in a way to where the bug doesn't seem to show up anymore!).  We also got it
without rerunning and tring to step through the code.  This can save you time, 
depending on the problem, size of the program and where it crashes, rerunning
or recompiling may not be an option.  However, this was a very simple case.
You may find yourself with traps that could have corrupted the stack, wrong
version of a dbg so you get bad symbols! or heap corruption which make debugging
all the more nasty.  For those who do not know assembly that well, you can 
generate assembly map files, which shows the C source with the generated assembly
below the lines.  This may help some who are not so good with assembly to
debug traps.


Now I'm going to break into a program and show some of the things you can do
with NTSD.  When you break into a process, or hit "CONTROL + C" when in
NTSD while it's in a process, you end up stopping the program.  When you
break in, however, you will be in a new thread created by NTSD just to break in.
These threads won't show, however, if you set a break point in the program or
if you trap into the program.  This only happens when you force NTSD to break
into the program.  Now, let's break into CuteFTP.


I run CuteFTP and look for the process ID on task manager.
It's 740, so I break into it.

C:/>ntsd -p 740


Microsoft(R) Windows 2000 Debugger
Version 5.00.2184.1
Copyright (C) Microsoft Corp. 1981-1999

CommandLine:
*** wait for debug event
Symbol search path is: C:/WINDOWS
NTSD ModLoad: 00400000 004da000   CUTEFTP.EXE
NTSD ModLoad: 77f80000 77ff9000   ntdll.dll
NTSD ModLoad: 77570000 775a0000   WINMM.dll
NTSD ModLoad: 77e10000 77e75000   USER32.dll
NTSD ModLoad: 77e80000 77f36000   KERNEL32.dll
NTSD ModLoad: 77f40000 77f7c000   GDI32.dll
NTSD ModLoad: 77db0000 77e0a000   ADVAPI32.dll
NTSD ModLoad: 77d40000 77daf000   RPCRT4.dll
NTSD ModLoad: 75050000 75058000   WSOCK32.dll
NTSD ModLoad: 75030000 75044000   WS2_32.dll
NTSD ModLoad: 78000000 78046000   MSVCRT.dll
NTSD ModLoad: 75020000 75028000   WS2HELP.dll
NTSD ModLoad: 76b30000 76b6e000   comdlg32.dll
NTSD ModLoad: 77c70000 77cba000   SHLWAPI.dll
NTSD ModLoad: 77b50000 77bda000   COMCTL32.dll
NTSD ModLoad: 775a0000 777e0000   SHELL32.dll
NTSD ModLoad: 77800000 7781d000   WINSPOOL.DRV
NTSD ModLoad: 752f0000 7530f000   oledlg.dll
NTSD ModLoad: 77a50000 77b45000   ole32.dll
eax=00000000 ebx=00000000 ecx=00000101 edx=ffffffff esi=00000000 edi=00000200
eip=77f9f9df esp=00ddffa8 ebp=00ddffb4 iopl=0         nv up ei ng nz na po nc
cs=001b  ss=0023  ds=0023  es=0023  fs=0038  gs=0000             efl=00000286
ntdll!DbgBreakPoint:
77f9f9df cc               int     3
0:002> ~*
  0  id: 2e4.210   Suspend: 0 Teb 7ffde000 Unfrozen
  1  id: 2e4.2a8   Suspend: 0 Teb 7ffdd000 Unfrozen
  2  id: 2e4.228   Suspend: 0 Teb 7ffdc000 Unfrozen
0:002> ~0kb
*** ERROR: Module load completed but symbols could not be loaded for cuteftp.exe

ChildEBP RetAddr  Args to Child
0006fbbc 0044fad5 004939e0 00000000 00000000 USER32!DispatchMessageW+0x24b
004939e0 0000000f 00000000 00000000 00328f9c CUTEFTP+0x4fad5
0:002> ~1kb
ChildEBP RetAddr  Args to Child
00d8ff74 77d4b407 77d4b7bf 000b7658 00000000 ntdll!ZwReplyWaitReceivePortEx+0xb
00d8ffa8 77d4b771 000b65e8 00d8ffec 77e92ca8 RPCRT4!RpcBindingSetOption+0x18e
00d8ffb4 77e92ca8 000b77a0 00000000 400b7154 RPCRT4!RpcBindingSetOption+0x4f8
00d8ffec 00000000 77d4b759 000b77a0 00000000 KERNEL32!CreateFileA+0x11b
0:002> ~2kb
ChildEBP RetAddr  Args to Child
00ddffb4 77e92ca8 00000000 00000200 0040fcbc ntdll!DbgBreakPoint
00ddffec 00000000 77eabe5a 00000000 00000000 KERNEL32!CreateFileA+0x11b
0:002>

One of the threads is the breakpoint created by NTSD, that's thread
#3, the one we are in now.  Notice, CuteFTP has no symbols.

But, lets see some things we can do with NTSD.  First, let's set a break point.

0:002> ~0kb
ChildEBP RetAddr  Args to Child
0006fbbc 0044fad5 004939e0 00000000 00000000 USER32!DispatchMessageW+0x24b
004939e0 0000000f 00000000 00000000 00328f9c CUTEFTP+0x4fad5
0:002> ~0r
eax=0000000b ebx=77e1a57c ecx=0006f824 edx=00000000 esi=004939e0 edi=004939e0
eip=77e1414f esp=0006fb9c ebp=0006fbbc iopl=0         nv up ei pl zr na po nc
cs=001b  ss=0023  ds=0023  es=0023  fs=0038  gs=0000             efl=00000246
USER32!DispatchMessageW+24b:
77e1414f c21000           ret     0x10
0:002> bp 44fad5
0:002> g
eax=00000001 ebx=77e1a57c ecx=00000007 edx=ffffffff esi=004939b0 edi=004939e0
eip=0044fad5 esp=0006fbd4 ebp=004939e0 iopl=0         nv up ei pl zr na po nc
cs=001b  ss=0023  ds=0023  es=0023  fs=0038  gs=0000             efl=00000246
CUTEFTP+4fad5:
0044fad5 85c0             test    eax,eax
0:000>

We set a breakpoint on the return address of thread 0.  
We hit 'g' which tells the process to continue.  However, it will
stop if it hits an NTSD set break point or a hard coded int 3 breakpoint
or if the application traps.  However, this time, it hit our
NTSD defined break point.

This is obviously the message loop (DispatchMessageW, Gives that away)
We know the parameter to DispatchMessage is an address 
to an MSG structure.  We can dump this.

0:000> dd 4939e0
004939e0  000101a2 00000219 00000007 00000000
004939f0  0032cd1b 0000010b 00000198 00000000
00493a00  00000000 00464eb7 008b0a40 000001cb
00493a10  000001e9 00000200 00400000 00000000
00493a20  00082788 ffffffff 008b09e0 00000000
00493a30  008b1e20 00000000 008b09d0 008b0ae0
00493a40  008b0ab0 00000000 00000000 00000000
00493a50  00000000 00000000 00000000 00000000
0:000> ~*
  0  id: 2e4.210   Suspend: 0 Teb 7ffde000 Unfrozen
  1  id: 2e4.2a8   Suspend: 0 Teb 7ffdd000 Unfrozen
0:000>

Notice there are only 2 threads now.  These are both CuteFTP threads,
not NTSD breakpoint threads.



Now, I am going to teach you a trick.  Every thread has
an Information Block that stores information about itself.
You can look it up on MSDN, "TIB".  It's pretty much the
same structure for all Win32 platforms, as application programs
sometimes hard code using this data.  To get the locations of
what most of the structure means, search MSDN.  I will show you
one part of the TIB.  The TIB is pointed to by FS.  

Let's say you have this situtation.  You break into a program
you have, you set a breakpoint on a particular API you know is failing.
Then you set a break point on it's return.  Now, you see it failed,
but you would need to call GetLastError() to get the error number!
You would need to recompile this program and put in a print message
just to find one number!  What to do?


0:000> x KERNEL32!GetLastError
77e8668c  KERNEL32!GetLastError
0:000> u KERNEL32!GetLastError
KERNEL32!GetLastError:
77e8668c 64a118000000     mov     eax,fs:[00000018]
77e86692 8b4034           mov     eax,[eax+0x34]
77e86695 c3               ret
77e86696 85ff             test    edi,edi
77e86698 0f84053c0400     je      KERNEL32!VerLanguageNameA+0xef (77eca2a3)
77e8669e 8d8d58ffffff     lea     ecx,[ebp-0xa8]
77e866a4 6a00             push    0x0
77e866a6 51               push    ecx
0:000>

Well, what do you know?  GetLastError() is pretty simple.

Let's find out what the Last Error was!

0:000> dd fs:18
0038:00000018  7ffde000 00000000 000002e4 00000210
0038:00000028  00000000 00000000 7ffdf000 00000000
0038:00000038  00000000 00000000 e1fe9228 00000000
0038:00000048  00000000 00000000 00000000 00000000
0038:00000058  00000000 00000000 00000000 00000000
0038:00000068  00000000 00000000 00000000 00000000
0038:00000078  00000000 00000000 00000000 00000000
0038:00000088  00000000 00000000 00000000 00000000
0:000> dd 7ffde000+34
7ffde034  00000000 00000000 00000000 e1fe9228
7ffde044  00000000 00000000 00000000 00000000
7ffde054  00000000 00000000 00000000 00000000
7ffde064  00000000 00000000 00000000 00000000
7ffde074  00000000 00000000 00000000 00000000
7ffde084  00000000 00000000 00000000 00000000
7ffde094  00000000 00000000 00000000 00000000
7ffde0a4  00000000 00000000 00000000 00000000
0:000>

As you notice, the first DWORD listed is 0.  Now, when I did this,
there was no error.  But, you can see how this can be useful.

Remeber you can always clear and set breakpoints.  Use "T" and "P" to step
through and execute the code.  

That is all for now.  Hopefully, you will practice real debugging and
improve your debugging skills after reading this basic debuggin tutorial.


智勇三国架构设计总结书 本文总结智勇三国网络版三年开发经验,梳理其基于MFC的CS架构,涵盖服务端、客户端及通信机制,强调数据一致性与版本控制。因维护成本高,提出重构内核计划,暂不采用QT以规避体积与兼容风险。重点阐述物理、数据、运行与逻辑架构,明确各层依赖关系,为后续系统优化与重写提供指导。 阅读详情

相关推荐

6与win7的兼容问题

                                                                    出自何丹的论坛这个问题经常有人问,因为我没有win7,所以也无法测试。我可以确定的是少部分人确实可以在win7上跑VC6,大部人不行。我把一些人的解决方案理出来,欢迎大家补充。 -------- 持啊,我的Windows 7一直支持,从7100到7260都是支

闻缺陷则喜何志丹 2223

微软拼音输入卡顿:清理临时文件并设置自动清理

本文记录我遇到的一次微软拼音输入卡顿问题,解决方法参考微软问答,并已在自己的 Windows 10 主机上验证。

H'Senseiの工坊 192

【深度学习预测】项目介绍 Python实现基于BO-Transformer-LSTM贝叶斯优化算法(BO)优化Transformer-LSTM模型进行多变量时间序列预测(含模型描述及部分示例代码)

内容概要:本文详细介绍了一个基于BO-Transformer-LSTM的多变量时间序列预测项目,通过结合Transformer的全局自注意力机制与LSTM的局部时序建模能力,构建了适用于复杂业务场景的深度学习预测模型。模型输入采用多变量滑动窗口结构,并引入正弦余弦位置编码以保留时间顺序信息;Transformer编码器提取变量间长距离依赖关系,LSTM进一步捕捉动态演化特征,最终通过回归层输出预测值。为优化模型性能,采用贝叶斯优化算法(基于Tree-structured Parzen Estimator)自动搜索最优超参数组合,包括嵌入维度、注意力头数、学习率、窗口长度等,显著提升了调参效率与模型泛化能力。项目还设计了包含周期性、趋势性、均值回归、突发事件和异方差噪声的五因素模拟数据生成机制,确保数据贴近真实业务场景,并建立了从数据预处理、模型训练、验证评估到结果恢复的完整技术链路。; 适合人群:具备一定机器学习与深度学习基础,熟悉PyTorch框架,从事时间序列预测相关研究或工程应用的研发人员、数据科学家及研究生。; 使用场景及目标:①应用于能源负荷预测、设备状态监测、金融风控、供应链需求预测等多变量时间序列预测任务;②解决传统模型在长时依赖、非线性关系和高维特征下的预测瓶颈;③实现高效超参数优化,提升模型调优自动化水平与部署可行性。; 阅读建议:本文含核心模型结构与部分示例代码,建议结合完整项目代码(如GitHub或博客资源)进行复现实践,重点关注数据生成逻辑、模型前向传播流程及贝叶斯优化集成方式,同时可通过调整网络结构或优化策略进一步拓展至多步预测、概率输出与可视化分析等高级功能。

微软PL-300认证和CDA数据分析师考哪个?

🌈CDA 数据分析师认证:是国内推出的数据分析能力分级认证,共分 Level Ⅰ、Ⅱ、Ⅲ 三个等级且需逐级报考,Level Ⅰ 面向零基础和业务岗,考数据分析理论、Excel、SQL、统计基础、可视化与业务分析框架,Level Ⅱ 起加入 Python/R 编程和统计建模,Level Ⅲ 聚焦数据挖掘、机器学习与项目答辩;考试为线下上机,一级无报考门槛,它偏通用方法论和综合能力背书,在国内求职、转行和业务岗数字化提升场景中认知度较高,适合想系统补数据分析体系、或往统计建模方向发展的人。

2501_90496024的博客 194

城市生命线之长距离输水管线的监测与检测.pdf

城市生命线之长距离输水管线的监测与检测.pdf

电子技术——共栅和共源共栅放大器的高频响应

我们在之前学过无论是是CS放大器还是CE放大器,都可以看做是一个带通(IC低通)滤波器。在高频处的响应收到输入电容 $C_{in}$ 的限制(主要是米勒效应)。因此,若想扩大放大器的带宽,我们必须减小米勒效应,一种方案就是共栅放大器。

jiahonghao2002的博客 4201

微软技术日报 2026-11-23:Entra 接口被读 109 天、Win11 安全基线、M365 最终报告

这一天有四条线,落点各不一样。Entra Connect Health 这条,讲的是一个监控层接口的 109 天。它没有被分配 CVE,没有公告页,能留下的公开痕迹是一份发到租户控制台的通知和一篇报道。对做安全的人来说,这件事最实用的部分不是漏洞本身,是那份暴露字段清单,它准确描述了「一次身份层侦察能拿到什么」。Windows 11 基线保护这条,讲的是把分散的判定收成一处。八个开关一直都在,缺的一直是一个统一答案,让用户知道自己的机器到底算不算干净,让应用有一个不必自己实现八次检查的接口。

海盗Sharp的博客 699

企业数字化转型的 4A 架构指南:从概念解读到 TOGAF 阶段对应

4A企业架构是中国数字化转型实践中总结的简化框架,包含业务、应用、数据和技术四个架构层。它自上而下形成业务驱动应用的指导关系,自下而上构建技术支撑数据的实现路径,与国际标准TOGAF核心内容高度对应。该模型通过统一语言、战略对齐和系统梳理,有效连接业务需求与IT实施,已成为企业架构规划的实用工具。其分层结构清晰展示了从业务目标到技术落地的完整推导链,特别适合中国企业的数字化转型场景。

友莘居士的博客 2194

微软技术日报 11 月 26 日:VS Code 1.148 让智能体不再被休眠打断、SSMS 用 Copilot 读执行计划、NTLM 签名撞上第三方认证

11 月 25 日到 26 日这 24 小时,微软在四条线上各有动作:VS Code 发布 1.148 稳定版,把「智能体跑长任务时机器会不会睡过去」做成正式开关;SQL Server Management Studio 把查询性能调优塞进了 Copilot 的代理模式;十一月累积更新的 NTLM 签名第一阶段开始反噬部分第三方认证设备;Azure Local 的 2610/2611 更新则把边缘节点的 GPU 配置从脚本里搬进了门户。此外还有一条被漏发的 9.8 分 Visio 漏洞公告。

海盗Sharp的博客 371

OpenRA引擎实战:如何从零开始搭建一个经典RTS游戏模组(附资源包)

本文详细介绍了如何利用开源游戏引擎OpenRA从零开始搭建经典RTS游戏模组。内容涵盖开发环境配置、资源管线处理、YAML规则定义、地图编辑与Lua脚本编写等全流程实战指南,并提供了资源包,帮助开发者和爱好者快速创建属于自己的即时战略游戏世界。

silver的专栏 918

嵌入式Linux网络调试踩坑记:YT8531/YT8521 PHY驱动移植与设备树配置实战

本文深入解析嵌入式Linux系统中YT8531/YT8521 PHY驱动移植与设备树配置的实战经验。从网络不通的常见现象入手,详细介绍了驱动移植关键点、设备树配置详解及常见问题排查技巧,帮助开发者快速解决RGMII接口调试难题,提升嵌入式网络开发效率。

weixin_42525328的博客 459

微软技术日报 2026-11-27:Copilot 伴生应用因内存退役,APIM 密钥要自己换

四条消息拼在一起,指向同一件事的不同侧面。三款伴生应用退役,是微软给自己 2025 年那轮「把 Copilot 铺到每个角落」的做法做了减法。减法比加法难,因为它等于承认一个已经装到几百万台机器上的东西不划算。这类回收本周还有第二笔,就是 860MB 内存优化里属于 Defender、OneDrive、Purview 的那 500MB。APIM 那条说明云上的修复天然分两半。平台那半微软一天能做完,客户那半得一个密钥一个密钥地过,还得先知道自己有哪些实例。把这两半混为一谈,是这次事件里最容易犯的错误。

海盗Sharp的博客 437

QT6与QT5安装全攻略:从下载到环境配置一站式指南

本文提供了一份详尽的QT6与QT5安装教程,涵盖从版本选择、在线安装器使用到环境变量配置的全过程。针对新手常见痛点,重点对比了QT6与QT5的安装差异,并给出了MinGW与MSVC编译器的选择建议,旨在帮助开发者快速搭建稳定可用的QT开发环境,避免常见错误。

weixin_29216353的博客 321

深度 | 决策模型抢滩:OpenAI 微软同周下场,大模型从生成文本转向输出概率判断

微软发布决策模型 Microsoft-Decision-1,基于阿里 Qwen3.5-9B 后训练,专注判断任务,不生成文本。该模型以低至 0.042 美元/百万 token 的成本实现高精度、低延迟判断,推动“决策”从生成模型中独立出来,形成新品类。六周内,OpenAI、TypeSafe 等纷纷入局,问题类型趋同但接口标准分裂,适配层如 LiteLLM 正在统一方言。这一趋势标志着“概率”正成为可计价、可审计的原子能力,预示 AI 架构向更高效、可信赖的分层演进。

summerliyang的博客 356

Anaconda离线创建python环境

既然是离线创建python环境,就需要有一个已经创建好的python环境。所以我们有两台win10的机器,分别是A和B。两台机器都安装了anaconda。其中A可以连网,因此我们在A上创建好一个python2.7的环境py27,然后将py27移植(安装)到B上。B连不连网都无所谓。 一、机器上A上创建python2.7的环境py27 有两种方法: 方法1:使用Anaconda的图形界面。首先,点击Environments-&gt;Create,然后输入要创建的环境名称"py27",然后选择2.7,如图

FY_2018的博客 6792

uniapp: err = err.replace(this._UNI_INPUT_DIR_REG, ‘UNI_TypeError: err.replace is not a function问题修复

问题:uniapp的依赖包出现了问题,需要升级解决办法:升级uniapp依赖包,下载"semver"和”@dcloudio/uni-i18n“两个包,本地锁定postcss为7版本,就解决了。

py_boy的博客 1461

微软 365 全球中断最终复盘:一处锁竞争缺陷,如何借自动流量调度从北美扩散到全球

微软365于11月12日全球中断,最终复盘确认非网络攻击或AI工具所致,根因是网关服务器中潜伏三个月的锁竞争缺陷,在新款多核服务器上叠加容量缩减、Teams故障转移及美国日高峰流量后爆发。本用于保护系统的自动流量调度反而将故障扩散至全球,导致超80%北美服务器失效。恢复缓慢因“惊群效应”及定位困难,需逐单元修复。微软已回退变更、加强监控与冗余,并计划2027年前完成架构优化。企业应警惕自动转移的边界问题,避免“挪过去一起倒”。

2601_96080144的博客 575

Python量化入门:用pytdx获取800个交易日K线数据的完整指南(附代码)

本文为Python量化交易初学者提供了使用pytdx库免费获取股票日线级别K线数据的完整指南。文章详细介绍了从环境搭建、单只股票数据获取,到构建健壮的批量下载器、数据清洗与验证,再到基础分析与可视化的全流程,并附有可直接运行的代码示例,帮助读者快速建立本地股票数据库。

weixin_29050513的博客 1496

微软宣布 Windows 11 中的蓝牙 MTP、家庭安全桌面 App 将逐步移除

微软近期将蓝牙MTP文件传输与内置家庭安全应用列入弃用清单,二者将逐步淘汰。蓝牙MTP仅限无线浏览设备媒体文件,速度慢且使用少,日常小文件传输(OPP)不受影响;家庭安全App虽停更,但家庭管控功能仍可通过网页或移动端延续。推荐替代方案包括USB MTP连接、Phone Link及云盘。此举为清理低频老旧组件,多数用户无感,仅少数依赖者需提前迁移。

jianlu365的博客 187

vb 6.0并口开发操作实例

vb6并口开发,简体中文,试例内有inpout32.dll动态链接库

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

不买微软账号、不绑主域名:用 Entra ID B2B Direct Federation 打通 Google Workspace 访问 Azure

把本文方案与企业级“全域名联合”放在同一个工程坐标系下做对照,各自的适用边界非常清晰。查看下面这张多维对比表时,可以重点对比“域名与配置复杂度”与“微软账号与许可成本”两行:对于以 Google Workspace 为日常核心底座、仅将 Azure 作为部分业务或基础设施托管平台的技术团队而言,B2B Direct Federation 用极低的运维投入(一个自定义 SAML 应用加一条 DNS TXT 记录),同时拿到了。

十年运维开发经验的王义杰在此分享自己的知识和经验 248

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

C++ 跨语言交互实战:C++ 与 Python/Go 的 FFI 绑定与性能损耗控制

C++ 跨语言交互的本质是「用 C ABI 做稳定边界,用批量与零拷贝做性能优化」。

Ur8EGCBK5的博客 274

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

微软技术日报 2026-11-28:Agent Framework 包被投毒、应用目录权限收紧

11 月 17 日晚上 8 点半到 9 点半(UTC),微软开源项目 Microsoft Agent Framework 的 Python 包在 PyPI 上出现了两个不该出现的版本。1.26.1 与 1.26.2,一共在架上待了大约五十五分钟,期间任何一次不带版本锁的都可能装上它们。这两个包里有窃取凭据的代码。

海盗Sharp的博客 432

微软 Foundry 语音智能体 GA:从 API 调用到可运营的工程闭环

据微软公布的测试数据,在 τ-Voice 数据集超过 1000 通符合条件的通话中,Task Completion Audio 结合音频与工具调用数据时,任务完成判定准确率为 79.8%,两次运行判定一致率为 91.9%。客户侧,Landis Technologies 首席执行官 Matt Landis 表示,其为一家区域银行客户部署的语音智能体已能端到端处理约 30% 来电,并可在需要时转交人工——属于客户案例陈述,不作为普遍结论。成本:实时语音同时涉及识别、推理、工具调用、合成,成本结构比文本复杂。

Leinwin的博客 251

源码级拆解 OCI Python SDK:云原生 SDK 请求链路与异步架构设计

本文通过静态代码分析的方式,深入 OCI Python SDK 的底层实现逻辑,梳理其请求生命周期、安全签名生成与异步执行架构。结合实际后端与 AI Agent 网关的开发场景,说明为什么云厂商 SDK 要采用分层设计、如何处理敏感信息脱敏,以及同步与异步模式在 I/O 密集型任务中的性能差异。文章不提供官方文档复述,重点给出源码阅读路径、核心模块职责划分与二次开发时的注意事项。

2402_83344867的博客 397

操作系统实验7:文件系统管理——磁盘分区、格式化、挂载、fstab 与 U 盘自动挂载全流程(附踩坑实录)

本文通过KaliLinux虚拟机环境,系统演示了磁盘从分区到永久挂载的完整流程,并深入剖析六个典型错误背后的Linux设计原则:设备名不可靠(应使用UUID)、交互工具状态敏感、权限与占用机制、自毁防护、硬件兼容性限制及配置持久化。实验强调“报错即诊断”“保护机制是安全设计”的核心理念,结合快照回滚、fstab验证、udisks2自动挂载等实践,揭示了存储管理中稳定性、安全性与可维护性的根本逻辑。

2503_91800161的博客 754

AI前沿日报 · 2026-11-25:一句话生成演示视频、一门语言跑遍芯片与微软的红色代码

CTV 让 AI 只写分镜、Playwright 录制真实应用,本地 4B 模型即够;KlongPy v2 用 Rust 重写数组语言,一份代码从 GPU 跑到 FPGA 与微控制器;TrueForge 声称 agent 运行成本降 30%–75%;微软宕机 24 小时后启动 Code Red,可靠性升为最高优先级;GPT-6.2 设计蛋白,抗体环结合率 70%;Claude Ship 让三个 agent 站 PR 审批;三进制 Bonsai 2.5 27B 仅 5.9GB,SWE-bench 75.6。

johnsong2009的博客 706
上一篇: How To Debug
下一篇: Exploitation of Buffer Overflow Vulnerabilities Under Windows XP
iiprogram
博客等级 码龄25年 1068粉丝 1515原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址