Memory dump and bug

Frida实战:高效dump Android内存数据的完整指南 在移动安全与逆向工程领域,动态分析是理解应用运行时行为的关键技术。其核心原理在于通过注入技术,在目标进程执行时实时监控和修改其内存与逻辑,从而突破静态分析的局限。这项技术的核心价值在于能够捕获加密密钥、核心算法、动态加载模块等运行时数据,为安全评估、漏洞挖掘和算法还原提供直接依据。在Android平台,Frida作为一个强大的动态插桩框架,因其脚本化、非侵入式和跨平台特性,成为实现高效内存操作的首选工具。通过Frida的Memory和Process API,安全研究人员可以精准定位并提取特定内存区域的数据, 阅读详情

Introduction

Our software just published version 1.0 . My clients often encountered exceptions and blue screens that caused the program to terminate. Most of time, we can not reproduce the bug in our systems. So catching and analyzing a memory dump file is important. This article teaches you how to use hands-on tools to catch and read memory dump files.

The hands-on tools are :-

  • Dr. Watson, which is included by almost all the windows systems.
  • VC6 and VC7 compiler, we need to recompile the project to generate Map files and COM files for tracing the bug.
  • Dumpchk can check dump file, before you are going to send it.
  • Windbg and kd can give you detailed information about the spot when exception occurred. Symbol files are always necessary for debugging dump files.

Details

Before reproducing the bug, Dr. Watson must be installed and running for srwtsn32.log to be created. We also need to configure the project to generate debug information, MAPFILE and COD file, then recompile the project.

Configuring Dr. Watson

To start Dr. Watson and set it as default debugger, go to command line, type:

drwtsn32 –I

If you want to change the settings you can run drwtsn32 at command line any time. Default settings is ok. Then if a program crashes, Dr. Watson will write drwtsn32.log and dump memory into user.dmp.

Reconfiguring Project Settings in Visual C++ environment

You can prepare the source code to be ready for Dr. Watson and memory dump. You need to take three simple step as following:

  1. You need to Generate debug symbols for the Win32 Release version of your .EXE and/ or .DLL files in settings configuration for the project, for the linker, Open "Project Settings" window( click Settings item in Project menu), select Link tab, check Generate Mapfile, and check Generate debug info. For the compiler, check Debug Info: Program Database, under General in C/C++ tab.
  2. Creating and keeping a copy of your application's .MAP and .COD intermediate files for further reference. Under Link tab, in Project Options editbox, add switch "/mapinfo:exports" ( switch /mapinfo:exports causes the linker to describe the binary's exported functions.) Add switch "/mapinfo:lines" (The switch /mapinfo:lines will add line numbers in mapfile). A .COD file contains a mixture of source code, assembly code and memory addresses, and it will help you to locate the offending line of code within a function that has been identified via the .MAP file. Under General section in C/C++ tab, add switch "/FAcs" in project options.
  3. Specifying a fixed load base hexadecimal address for your .EXE and/or .DLL files. Under Output in the Link tab, input a hexadecimal address in Base address, such as 0x 602f 0000

Examples

Use the Visual C++ application wizard to create MFC win32 exe file names "MapDemo". Add following lines in InitInstance function in CMapDemoApp class.

 char * pch1 = 0;

 char * pch2 = 0;

 pch1 = (char *)malloc( 20 );

 pch2 = (char *)malloc( 20 );

 pch1 = pch2; free( pch1 );

 free( pch2 );

This code will eventually fail because the application will try to release the same block of memory twice. Run the program and it will crash. Open the file drwtsn32.log:

Collapse

*----> Module List <----*

(0000000000400000 - 000000000040b000:

    C:/WORK/CODEPROJ/MapDemo/Debug/MapDemo.exe

(0000000010200000 - 000000001026c 000: C:/WINDOWS/System32/MSVCRTD.dll

( 000000005f 400000 - 000000005f 4e5000: C:/WINDOWS/System32/MFC42D.DLL

(00000000605d0000 - 00000000605d8000: C:/WINDOWS/System32/mslbui.dll

( 0000000070a 70000 - 0000000070ad4000: C:/WINDOWS/system32/SHLWAPI.dll

(0000000074720000 - 0000000074764000: C:/WINDOWS/System32/MSCTF.dll

(0000000077120000 - 00000000771ab000: C:/WINDOWS/system32/OLEAUT32.DLL

(00000000771b0000 - 00000000772d1000: C:/WINDOWS/system32/OLE32.DLL

( 0000000077c 00000 - 0000000077c 07000: C:/WINDOWS/system32/VERSION.dll

( 0000000077c 10000 - 0000000077c 63000: C:/WINDOWS/system32/msvcrt.dll

( 0000000077c 70000 - 0000000077cb0000: C:/WINDOWS/system32/GDI32.dll

(0000000077d40000 - 0000000077dc6000: C:/WINDOWS/system32/USER32.dll

(0000000077dd0000 - 0000000077e5d000: C:/WINDOWS/system32/ADVAPI32.dll

(0000000077e60000 - 0000000077f 46000: C:/WINDOWS/system32/kernel32.dll

( 0000000077f 50000 - 0000000077ff7000: C:/WINDOWS/System32/ntdll.dll

(0000000078000000 - 000000007807f 000: C:/WINDOWS/system32/RPCRT4.dll

*----> State Dump for Thread Id 0x3274 <----*

eax=00000001 ebx=7ffdf000 ecx=10261558 edx=00010000

esi=0012febc edi=7ffdf000

eip=10213638 esp=0012fe 5c ebp=0012fe 6c iopl=0        

nv up ei pl zr na po nc

cs=001b  ss=0023  ds=0023  es=0023  fs=0038  gs=0000           

efl=00000246

Collapse

function: MSVCRTD!_free_dbg_lk

        10213616 7521             jnz     MSVCRTD!_free_dbg_lk+0xc9

                                          (10213639)

        10213618 6814732510       push    0x10257314

        1021361d 6a 00             push    0x0

        1021361f 6814040000       push    0x414

        10213624 68f 4712510       push    0x 102571f 4

        10213629 6a 02             push    0x2

        1021362b e810180000       call    MSVCRTD!_CrtDbgReport (10214e40)

        10213630 83c 414           add     esp,0x14

        10213633 83f 801           cmp     eax,0x1

        10213636 7501             jnz     MSVCRTD!_free_dbg_lk+0xc9

                                           (10213639)

FAULT ->;10213638 cc               int     3

        10213639 33c 0             xor     eax,eax

        1021363b 85c 0             test    eax,eax

        1021363d 75c 9             jnz     MSVCRTD!_free_dbg_lk+0x98

                                           (10213608)

        1021363f 8b4d08           mov     ecx,[ebp+0x8]

        10213642 83e920           sub     ecx,0x20

        10213645 894dfc           mov     [ebp-0x4],ecx

        10213648 8b55fc           mov     edx,[ebp-0x4]

        1021364b 8b4214           mov     eax,[edx+0x14]

        1021364e 25ffff0000       and     eax,0xffff

        10213653 83f 804           cmp     eax,0x4

Collapse

*----> Stack Back Trace <----*

*** WARNING: Unable to verify checksum for

  C:/WORK/CODEPROJ/MapDemo/Debug/MapDemo.exe

*** ERROR: Symbol file could not be found.  Defaulted to

  export symbols for C:/WINDOWS/system32/kernel32.dll -

WARNING: Stack unwind information not available. Following

  frames may be wrong.

ChildEBP RetAddr  Args to Child             

0012fe 6c 10213541 00324708 00000001 7ffdf000 MSVCRTD!_free_dbg_lk+0xc8

0012fea0 102134ce 00324708 00000001 0012fee8 MSVCRTD!_free_dbg+0x41

0012feb0 00401360 00324708 7ffde000 00324238 MSVCRTD!free+0xe

0012fee8 5f 4335c 3 7ffdf000 7ffde000 7ffdf000

    MapDemo!CMapDemoApp__InitInstance+0x132

0012ff08 00402248 00400000 00000000 001423ac MFC42D!AfxWinMain+0x83

0012ff20 00402153 00400000 00000000 001423ac MapDemo!WinMain+0x18

0012ffc0 77e 814c 7 7ffdf000 7ffde000 7ffdf000

    MapDemo!WinMainCRTStartup+0x1b3

0012fff0 00000000 00401fa0 00000000 78746341

    kernel32!GetCurrentDirectoryW+0x44

Because the code was fault in the memory free function "_free_dbg_lk", it is called by function Initinstance(), so we search the stack-track-back part, on the fourth line, it indicates that the sub function was called by InitInstance function at the offset 0x132.

So, look at the .COD intermediate file, "MapDemo.COD", search for the module "InitInstance()", the offset address at the beginning of the module is 0x00ae, add the address of (0x132+0xae = 0x01e0 ) , so we know the program was crashed at line 79 in source code file "MapDemo.cpp".


Another Example - How to trace fault into DLL file( in – process, and out – process DLL file).

Use Application Wizard in Visual Studio to generate a DLL library project MapDemoDll, create a export function DllSquareRoot(), and put a fault code in that function :-

 char* pChar = NULL;

 *pChar = 'a'; // This is fault line 70

The program will throw an exception that trying to access to a invalid memory address(0x0000). Use Application Wizard to generate an client program calling the DllSquareRoot function in MapDemoDll.dll. Before running the exe program with the DLL library, we need to set the MapDemoDll’s project’s settings. Generate MAP, COD file, specify the base address for loading at 0x 60f 20000. Compile the project and run the program.

Program crashed and screen displayed the message like that "DemoDllClient.exe has generated errors and will be closed by windows. You will need to restart the program." Following is the drwsnt32.log generated by Dr. Watson.

State Dump for Thread Id 0x7b0

eax=00000000 ebx=005e4b68 ecx=00135dd0 edx= 60f 35918

esi= 0012f 27c edi= 0012f 26c

eip= 60f 21320 esp= 0012f 204 ebp= 0012f 26c iopl=0        

nv up ei pl zr na po nc

cs=001b  ss=0023  ds=0023  es=0023  fs=0038  gs=0000          

efl=00000246

Collapse

function: DllSquareRoot

        60f 212f 9 8d7da4           lea     edi,[ebp+0xa4]        

                ss: 00c 8c 83e=????????

         60f 212fc b917000000       mov     ecx,0x17

        60f 21301 b8cccccccc       mov     eax,0xcccccccc

        60f 21306 f 3ab             rep     stosd                 

                es: 0012f 26c = 0012f 2cc

        60f 21308 e 8f 3020000       call    AfxGetStaticModuleState

                ( 60f 21600)

        60f 2130d 50               push    eax

        60f 2130e 8d4df8           lea     ecx,[ebp+0xf8]        

                ss: 00c 8c 83e=????????

        60f 21311 e 8a 4010000  call

                AFX_MAINTAIN_STATE2::AFX_MAINTAIN_STATE2 ( 60f 214ba)

        60f 21316 c 745f 400000000   mov   dword ptr [ebp+0xf4],0x0

                ss: 00c 8c 83e=????????

        60f 2131d 8b 45f 4           mov     eax,[ebp+0xf4]        

                ss: 00c 8c 83e=????????

FAULT ->; 60f 21320 c 60078           mov     byte ptr [eax],0x78         

                ds:00000000=??

        60f 21323 dd4508          fld qword ptr [ebp+0x8]

                ss: 00c 8c 83e=????????????????

        60f 21326 dc1d 4841f 360                           

                ds: 60f 34148=0000000000000000

                                  fcomp   qword ptr [_real ( 60f 34148)]

        60f 2132c dfe0             fstsw

        60f 2132e f 6c 401           test    ah,0x1

        60f 21331 7520             jnz     _enc$textbss$begin+0x 5f 43

               ( 60f 29e53)

        60f 21333 8b4d 0c            mov     ecx,[ebp+0xc]         

               ss: 00c 8c 83e=????????

        60f 21336 51               push    ecx

        60f 21337 8b5508           mov     edx,[ebp+0x8]         

               ss: 00c 8c 83e=????????

        60f 2133a 52               push    edx

        60f 2133b e848060000       call    sqrt ( 60f 21988)

        60f 21340 83c 408           add     esp,0x8

The program crashed at address 0x 60f 21230, here is part of the mapfile

Collapse

Address Publics by Value Rva+Base Lib:Object

 0001:00000050 ?_GetBaseMessageMap@CMapDemoDllApp@@KGPBUAFX_MSGMAP@@XZ

        60f 21050 f MapDemoDll.obj

 0001:00000080 ?GetMessageMap@CMapDemoDllApp@@MBEPBUAFX_MSGMAP@@XZ

        60f 21080 f MapDemoDll.obj

 0001: 000000c 0 ??0CMapDemoDllApp@@QAE@XZ 60f 210c 0 f MapDemoDll.obj

 0001:00000120 ??_GCMapDemoDllApp@@UAEPAXI@Z 60f 21120 f i MapDemoDll.obj

 0001:00000120 ??_ECMapDemoDllApp@@UAEPAXI@Z 60f 21120 f i MapDemoDll.obj

 0001:00000190 ??1CMapDemoDllApp@@UAE@XZ 60f 21190 f i MapDemoDll.obj

 0001: 000002f 0 _DllSquareRoot 60f 212f 0 f MapDemoDll.obj

 0001:000003b2 ?WinHelpA@CWinApp@@UAEXKI@Z 60f 213b2

      f mfc42d:MFC42D.DLL

 0001:000003b8 ?OnDDECommand@CWinApp@@UAEHPAD@Z 60f 213b8

      f mfc42d:MFC42D.DLL

 0001:000003be ?DoWaitCursor@CWinApp@@UAEXH@Z 60f 213be

      f mfc42d:MFC42D.DLL

 0001: 000003c 4 ?DoMessageBox@CWinApp@@UAEHPBDII@Z 60f 213c 4

      f mfc42d:MFC42D.DLL

 0001:000003ca ?SaveAllModified@CWinApp@@UAEHXZ 60f 213ca

      f mfc42d:MFC42D.DLL

 0001:000003d0 ?InitApplication@CWinApp@@UAEHXZ 60f 213d0

      f mfc42d:MFC42D.DLL

The biggest function address that just less than the crashing address 0x 60f 21320 is 0x 60f 212f 0, which belongs to DllSquareRoot function in MapDemoDll object. We also can follow that calculation: crash_address - preferred_load_address - 0x1000. Why do we need to subtract 0x1000, because the first part the binary is the Portable Executable (PE), which is 0x1000 bytes long. So the calculation is: 0x 60f 21320 – 0x 60f 20000 – 0x1000 = 0x320

Line numbers for ./Debug/MapDemoDll.obj

(D:/work/MapDemoDll/MapDemoDll.cpp) segment .text

    44 0001:00000050    44 0001:00000080   

    55 0001: 000000c 0    58 0001: 000000f 0

    63 0001:00000220    66 0001: 000002f 0   

    67 0001:00000308    69 0001:00000316

    70 0001:0000031d    72 0001:00000323   

    73 0001:00000333    74 0001:00000353

    75 0001:00000361    76 0001: 0000037a

Above is the information section of MAPFILE, like that: 44 0001:00000050, first number is line number, the second number is the offset from the beginning of the code section in which this line occurred. So we will know the program was crashed at line 70 in MapDemoDll.cpp. Which tried to write a number into an invalid address.

How to read and debug by memory dump file

  1. Get the symbol table or symbol server address. To prepare for debugging the dump file, you should get the Microsoft symbol server address or download the symbols from Microsoft (http://www.microsoft.com/whdc/ddk/debugging/symbolpkg.mspx#Windows%20symbol%20packages)
  2. Download the debugging tools for Windows. Those debugging tools can read the windows memory dump and simulate the original memory environment.
  3. Need to install the support tools from original installation CD. Before using memory dump to debug, we need to check if it is not corrupted by dumpchk.exe, which is in the windows installation CD. Go to command line and input: Dumpchk -a [dump file]
  4. If the memory dump file passes the check, now we can use windbg or kd to debug the memory dump. After the installation is complete, start a command prompt, change to the path where the debugging tools were installed. Use the one of following command to load the dump file into debugger. Windbg.exe is a windows-based debugger, kd.exe is a command line debugger.

windbg -y SymbolPath -i ImagePath -z DumpFilePath

kd -y SymbolPath -i ImagePath -z DumpFilePath

The SymbolPath is the path of symbols, it is either a local path where the symbol files were downloaded, or the server path which is an URL. ImagePath is the path of windows image files, which are contained in the /I386 folder on the WINDOWS. Installation CD-ROM. DumpPath is the path and file name for the dump that you are examining.

Example

kd -y SRV*f:/symbols*http://msdl.microsoft.com/download/symbols

   -i e:/i386 -z f:/dumps/minidump.dmp

kd -y f:/symbols -i e:/i386 -z "f:/my debug files/minidump.dmp"

windbg -y f:/symbols -i e:/i386 -z "f:/dumps/minidump.dmp"

Both of the debuggers accept commands which gather information from dump file, such as:

The !analyze -show command displays the Stop error code

    (also known as the bug check code) and its parameters.

The !analyze -v command displays verbose output.

The !drivers command displays a list of the drivers that

    were loaded on the computer when the problem occurred.

About Woodykk

 

I am a shameless software engineer and developer.
work-manic, sleepless animal, a crazy MCP, MCSE, MCDBA and SCJP.

Click here to view Woodykk's online profile.

 

Other popular Debug tips articles:

Explanation of the debugger pseudoregisters like @ERR, @TIB

Learn about the issues and differences between Debug and Release builds.

Finding crash information using the MAP file: how to create and read the file

A classic article on how to debug your release build applications

 

Introduction

Our software just published version 1.0 . My clients often encountered exceptions and blue screens that caused the program to terminate. Most of time, we can not reproduce the bug in our systems. So catching and analyzing a memory dump file is important. This article teaches you how to use hands-on tools to catch and read memory dump files.

The hands-on tools are :-

  • Dr. Watson, which is included by almost all the windows systems.
  • VC6 and VC7 compiler, we need to recompile the project to generate Map files and COM files for tracing the bug.
  • Dumpchk can check dump file, before you are going to send it.
  • Windbg and kd can give you detailed information about the spot when exception occurred. Symbol files are always necessary for debugging dump files.

Details

Before reproducing the bug, Dr. Watson must be installed and running for srwtsn32.log to be created. We also need to configure the project to generate debug information, MAPFILE and COD file, then recompile the project.

Configuring Dr. Watson

To start Dr. Watson and set it as default debugger, go to command line, type:

drwtsn32 –I

If you want to change the settings you can run drwtsn32 at command line any time. Default settings is ok. Then if a program crashes, Dr. Watson will write drwtsn32.log and dump memory into user.dmp.

Reconfiguring Project Settings in Visual C++ environment

You can prepare the source code to be ready for Dr. Watson and memory dump. You need to take three simple step as following:

  1. You need to Generate debug symbols for the Win32 Release version of your .EXE and/ or .DLL files in settings configuration for the project, for the linker, Open "Project Settings" window( click Settings item in Project menu), select Link tab, check Generate Mapfile, and check Generate debug info. For the compiler, check Debug Info: Program Database, under General in C/C++ tab.
  2. Creating and keeping a copy of your application's .MAP and .COD intermediate files for further reference. Under Link tab, in Project Options editbox, add switch "/mapinfo:exports" ( switch /mapinfo:exports causes the linker to describe the binary's exported functions.) Add switch "/mapinfo:lines" (The switch /mapinfo:lines will add line numbers in mapfile). A .COD file contains a mixture of source code, assembly code and memory addresses, and it will help you to locate the offending line of code within a function that has been identified via the .MAP file. Under General section in C/C++ tab, add switch "/FAcs" in project options.
  3. Specifying a fixed load base hexadecimal address for your .EXE and/or .DLL files. Under Output in the Link tab, input a hexadecimal address in Base address, such as 0x 602f 0000

Examples

Use the Visual C++ application wizard to create MFC win32 exe file names "MapDemo". Add following lines in InitInstance function in CMapDemoApp class.

 char * pch1 = 0;

 char * pch2 = 0;

 pch1 = (char *)malloc( 20 );

 pch2 = (char *)malloc( 20 );

 pch1 = pch2; free( pch1 );

 free( pch2 );

This code will eventually fail because the application will try to release the same block of memory twice. Run the program and it will crash. Open the file drwtsn32.log:

Collapse

*----> Module List <----*

(0000000000400000 - 000000000040b000:

    C:/WORK/CODEPROJ/MapDemo/Debug/MapDemo.exe

(0000000010200000 - 000000001026c 000: C:/WINDOWS/System32/MSVCRTD.dll

( 000000005f 400000 - 000000005f 4e5000: C:/WINDOWS/System32/MFC42D.DLL

(00000000605d0000 - 00000000605d8000: C:/WINDOWS/System32/mslbui.dll

( 0000000070a 70000 - 0000000070ad4000: C:/WINDOWS/system32/SHLWAPI.dll

(0000000074720000 - 0000000074764000: C:/WINDOWS/System32/MSCTF.dll

(0000000077120000 - 00000000771ab000: C:/WINDOWS/system32/OLEAUT32.DLL

(00000000771b0000 - 00000000772d1000: C:/WINDOWS/system32/OLE32.DLL

( 0000000077c 00000 - 0000000077c 07000: C:/WINDOWS/system32/VERSION.dll

( 0000000077c 10000 - 0000000077c 63000: C:/WINDOWS/system32/msvcrt.dll

( 0000000077c 70000 - 0000000077cb0000: C:/WINDOWS/system32/GDI32.dll

(0000000077d40000 - 0000000077dc6000: C:/WINDOWS/system32/USER32.dll

(0000000077dd0000 - 0000000077e5d000: C:/WINDOWS/system32/ADVAPI32.dll

(0000000077e60000 - 0000000077f 46000: C:/WINDOWS/system32/kernel32.dll

( 0000000077f 50000 - 0000000077ff7000: C:/WINDOWS/System32/ntdll.dll

(0000000078000000 - 000000007807f 000: C:/WINDOWS/system32/RPCRT4.dll

*----> State Dump for Thread Id 0x3274 <----*

eax=00000001 ebx=7ffdf000 ecx=10261558 edx=00010000

esi=0012febc edi=7ffdf000

eip=10213638 esp=0012fe 5c ebp=0012fe 6c iopl=0        

nv up ei pl zr na po nc

cs=001b  ss=0023  ds=0023  es=0023  fs=0038  gs=0000           

efl=00000246

Collapse

function: MSVCRTD!_free_dbg_lk

        10213616 7521             jnz     MSVCRTD!_free_dbg_lk+0xc9

                                          (10213639)

        10213618 6814732510       push    0x10257314

        1021361d 6a 00             push    0x0

        1021361f 6814040000       push    0x414

        10213624 68f 4712510       push    0x 102571f 4

        10213629 6a 02             push    0x2

        1021362b e810180000       call    MSVCRTD!_CrtDbgReport (10214e40)

        10213630 83c 414           add     esp,0x14

        10213633 83f 801           cmp     eax,0x1

        10213636 7501             jnz     MSVCRTD!_free_dbg_lk+0xc9

                                           (10213639)

FAULT ->;10213638 cc               int     3

        10213639 33c 0             xor     eax,eax

        1021363b 85c 0             test    eax,eax

        1021363d 75c 9             jnz     MSVCRTD!_free_dbg_lk+0x98

                                           (10213608)

        1021363f 8b4d08           mov     ecx,[ebp+0x8]

        10213642 83e920           sub     ecx,0x20

        10213645 894dfc           mov     [ebp-0x4],ecx

        10213648 8b55fc           mov     edx,[ebp-0x4]

        1021364b 8b4214           mov     eax,[edx+0x14]

        1021364e 25ffff0000       and     eax,0xffff

        10213653 83f 804           cmp     eax,0x4

Collapse

*----> Stack Back Trace <----*

*** WARNING: Unable to verify checksum for

  C:/WORK/CODEPROJ/MapDemo/Debug/MapDemo.exe

*** ERROR: Symbol file could not be found.  Defaulted to

  export symbols for C:/WINDOWS/system32/kernel32.dll -

WARNING: Stack unwind information not available. Following

  frames may be wrong.

ChildEBP RetAddr  Args to Child             

0012fe 6c 10213541 00324708 00000001 7ffdf000 MSVCRTD!_free_dbg_lk+0xc8

0012fea0 102134ce 00324708 00000001 0012fee8 MSVCRTD!_free_dbg+0x41

0012feb0 00401360 00324708 7ffde000 00324238 MSVCRTD!free+0xe

0012fee8 5f 4335c 3 7ffdf000 7ffde000 7ffdf000

    MapDemo!CMapDemoApp__InitInstance+0x132

0012ff08 00402248 00400000 00000000 001423ac MFC42D!AfxWinMain+0x83

0012ff20 00402153 00400000 00000000 001423ac MapDemo!WinMain+0x18

0012ffc0 77e 814c 7 7ffdf000 7ffde000 7ffdf000

    MapDemo!WinMainCRTStartup+0x1b3

0012fff0 00000000 00401fa0 00000000 78746341

    kernel32!GetCurrentDirectoryW+0x44

Because the code was fault in the memory free function "_free_dbg_lk", it is called by function Initinstance(), so we search the stack-track-back part, on the fourth line, it indicates that the sub function was called by InitInstance function at the offset 0x132.

So, look at the .COD intermediate file, "MapDemo.COD", search for the module "InitInstance()", the offset address at the beginning of the module is 0x00ae, add the address of (0x132+0xae = 0x01e0 ) , so we know the program was crashed at line 79 in source code file "MapDemo.cpp".


Another Example - How to trace fault into DLL file( in – process, and out – process DLL file).

Use Application Wizard in Visual Studio to generate a DLL library project MapDemoDll, create a export function DllSquareRoot(), and put a fault code in that function :-

 char* pChar = NULL;

 *pChar = 'a'; // This is fault line 70

The program will throw an exception that trying to access to a invalid memory address(0x0000). Use Application Wizard to generate an client program calling the DllSquareRoot function in MapDemoDll.dll. Before running the exe program with the DLL library, we need to set the MapDemoDll’s project’s settings. Generate MAP, COD file, specify the base address for loading at 0x 60f 20000. Compile the project and run the program.

Program crashed and screen displayed the message like that "DemoDllClient.exe has generated errors and will be closed by windows. You will need to restart the program." Following is the drwsnt32.log generated by Dr. Watson.

State Dump for Thread Id 0x7b0

eax=00000000 ebx=005e4b68 ecx=00135dd0 edx= 60f 35918

esi= 0012f 27c edi= 0012f 26c

eip= 60f 21320 esp= 0012f 204 ebp= 0012f 26c iopl=0        

nv up ei pl zr na po nc

cs=001b  ss=0023  ds=0023  es=0023  fs=0038  gs=0000          

efl=00000246

Collapse

function: DllSquareRoot

        60f 212f 9 8d7da4           lea     edi,[ebp+0xa4]        

                ss: 00c 8c 83e=????????

         60f 212fc b917000000       mov     ecx,0x17

        60f 21301 b8cccccccc       mov     eax,0xcccccccc

        60f 21306 f 3ab             rep     stosd                 

                es: 0012f 26c = 0012f 2cc

        60f 21308 e 8f 3020000       call    AfxGetStaticModuleState

                ( 60f 21600)

        60f 2130d 50               push    eax

        60f 2130e 8d4df8           lea     ecx,[ebp+0xf8]        

                ss: 00c 8c 83e=????????

        60f 21311 e 8a 4010000  call

                AFX_MAINTAIN_STATE2::AFX_MAINTAIN_STATE2 ( 60f 214ba)

        60f 21316 c 745f 400000000   mov   dword ptr [ebp+0xf4],0x0

                ss: 00c 8c 83e=????????

        60f 2131d 8b 45f 4           mov     eax,[ebp+0xf4]        

                ss: 00c 8c 83e=????????

FAULT ->; 60f 21320 c 60078           mov     byte ptr [eax],0x78         

                ds:00000000=??

        60f 21323 dd4508          fld qword ptr [ebp+0x8]

                ss: 00c 8c 83e=????????????????

        60f 21326 dc1d 4841f 360                           

                ds: 60f 34148=0000000000000000

                                  fcomp   qword ptr [_real ( 60f 34148)]

        60f 2132c dfe0             fstsw

        60f 2132e f 6c 401           test    ah,0x1

        60f 21331 7520             jnz     _enc$textbss$begin+0x 5f 43

               ( 60f 29e53)

        60f 21333 8b4d 0c            mov     ecx,[ebp+0xc]         

               ss: 00c 8c 83e=????????

        60f 21336 51               push    ecx

        60f 21337 8b5508           mov     edx,[ebp+0x8]         

               ss: 00c 8c 83e=????????

        60f 2133a 52               push    edx

        60f 2133b e848060000       call    sqrt ( 60f 21988)

        60f 21340 83c 408           add     esp,0x8

The program crashed at address 0x 60f 21230, here is part of the mapfile

Collapse

Address Publics by Value Rva+Base Lib:Object

 0001:00000050 ?_GetBaseMessageMap@CMapDemoDllApp@@KGPBUAFX_MSGMAP@@XZ

        60f 21050 f MapDemoDll.obj

 0001:00000080 ?GetMessageMap@CMapDemoDllApp@@MBEPBUAFX_MSGMAP@@XZ

        60f 21080 f MapDemoDll.obj

 0001: 000000c 0 ??0CMapDemoDllApp@@QAE@XZ 60f 210c 0 f MapDemoDll.obj

 0001:00000120 ??_GCMapDemoDllApp@@UAEPAXI@Z 60f 21120 f i MapDemoDll.obj

 0001:00000120 ??_ECMapDemoDllApp@@UAEPAXI@Z 60f 21120 f i MapDemoDll.obj

 0001:00000190 ??1CMapDemoDllApp@@UAE@XZ 60f 21190 f i MapDemoDll.obj

 0001: 000002f 0 _DllSquareRoot 60f 212f 0 f MapDemoDll.obj

 0001:000003b2 ?WinHelpA@CWinApp@@UAEXKI@Z 60f 213b2

      f mfc42d:MFC42D.DLL

 0001:000003b8 ?OnDDECommand@CWinApp@@UAEHPAD@Z 60f 213b8

      f mfc42d:MFC42D.DLL

 0001:000003be ?DoWaitCursor@CWinApp@@UAEXH@Z 60f 213be

      f mfc42d:MFC42D.DLL

 0001: 000003c 4 ?DoMessageBox@CWinApp@@UAEHPBDII@Z 60f 213c 4

      f mfc42d:MFC42D.DLL

 0001:000003ca ?SaveAllModified@CWinApp@@UAEHXZ 60f 213ca

      f mfc42d:MFC42D.DLL

 0001:000003d0 ?InitApplication@CWinApp@@UAEHXZ 60f 213d0

      f mfc42d:MFC42D.DLL

The biggest function address that just less than the crashing address 0x 60f 21320 is 0x 60f 212f 0, which belongs to DllSquareRoot function in MapDemoDll object. We also can follow that calculation: crash_address - preferred_load_address - 0x1000. Why do we need to subtract 0x1000, because the first part the binary is the Portable Executable (PE), which is 0x1000 bytes long. So the calculation is: 0x 60f 21320 – 0x 60f 20000 – 0x1000 = 0x320

Line numbers for ./Debug/MapDemoDll.obj

(D:/work/MapDemoDll/MapDemoDll.cpp) segment .text

    44 0001:00000050    44 0001:00000080   

    55 0001: 000000c 0    58 0001: 000000f 0

    63 0001:00000220    66 0001: 000002f 0   

    67 0001:00000308    69 0001:00000316

    70 0001:0000031d    72 0001:00000323   

    73 0001:00000333    74 0001:00000353

    75 0001:00000361    76 0001: 0000037a

Above is the information section of MAPFILE, like that: 44 0001:00000050, first number is line number, the second number is the offset from the beginning of the code section in which this line occurred. So we will know the program was crashed at line 70 in MapDemoDll.cpp. Which tried to write a number into an invalid address.

How to read and debug by memory dump file

  1. Get the symbol table or symbol server address. To prepare for debugging the dump file, you should get the Microsoft symbol server address or download the symbols from Microsoft (http://www.microsoft.com/whdc/ddk/debugging/symbolpkg.mspx#Windows%20symbol%20packages)
  2. Download the debugging tools for Windows. Those debugging tools can read the windows memory dump and simulate the original memory environment.
  3. Need to install the support tools from original installation CD. Before using memory dump to debug, we need to check if it is not corrupted by dumpchk.exe, which is in the windows installation CD. Go to command line and input: Dumpchk -a [dump file]
  4. If the memory dump file passes the check, now we can use windbg or kd to debug the memory dump. After the installation is complete, start a command prompt, change to the path where the debugging tools were installed. Use the one of following command to load the dump file into debugger. Windbg.exe is a windows-based debugger, kd.exe is a command line debugger.

windbg -y SymbolPath -i ImagePath -z DumpFilePath

kd -y SymbolPath -i ImagePath -z DumpFilePath

The SymbolPath is the path of symbols, it is either a local path where the symbol files were downloaded, or the server path which is an URL. ImagePath is the path of windows image files, which are contained in the /I386 folder on the WINDOWS. Installation CD-ROM. DumpPath is the path and file name for the dump that you are examining.

Example

kd -y SRV*f:/symbols*http://msdl.microsoft.com/download/symbols

   -i e:/i386 -z f:/dumps/minidump.dmp

kd -y f:/symbols -i e:/i386 -z "f:/my debug files/minidump.dmp"

windbg -y f:/symbols -i e:/i386 -z "f:/dumps/minidump.dmp"

Both of the debuggers accept commands which gather information from dump file, such as:

The !analyze -show command displays the Stop error code

    (also known as the bug check code) and its parameters.

The !analyze -v command displays verbose output.

The !drivers command displays a list of the drivers that

    were loaded on the computer when the problem occurred.

About Woodykk

 

I am a shameless software engineer and developer.
work-manic, sleepless animal, a crazy MCP, MCSE, MCDBA and SCJP.

Click here to view Woodykk's online profile.

 

Other popular Debug tips articles:

Explanation of the debugger pseudoregisters like @ERR, @TIB

Learn about the issues and differences between Debug and Release builds.

Finding crash information using the MAP file: how to create and read the file

A classic article on how to debug your release build applications

 

 
WinDbg分析蓝屏教程:常见Bug Check代码解读 深入讲解如何使用WinDbg分析蓝屏问题,解读常见的Bug Check代码,帮助开发者快速定位系统崩溃原因,掌握windbg分析蓝屏教程的核心技巧。 阅读详情

相关推荐

Windows蓝屏分析利器:Dump文件深度解析工具实战

你看,蓝屏并不可怕。它不是系统的失败,而是它在努力自救。只要我们学会倾听它的“遗言”,就能一次次让它变得更坚强。无论是个人用户还是企业运维,都应该建立起一套完整的“蓝屏响应机制”:合理配置Dump、熟练使用工具、规范分析流程、及时修复漏洞。毕竟,真正的稳定,不是从未崩溃,而是每次跌倒后都能爬起来,并且记得为什么摔倒。下次再见到那抹蓝色,别慌,微笑着打开WinDbg,说一句:“欢迎回来,老朋友。”💙本文还有配套的精品资源,点击获取。

weixin_35950531的博客 1654

Memory Dump利用实例

三好学生 · 2015/09/11 11:040x00 前言众所周知,procdump可以获得进程的内存dump文件 最常见的用法如下:1、使用procdump抓取lsass进程 2、获得LSASS进程内存dump文件 3、用mimikatz解析dump文件 4、获取主机明文密码 复制代码那么,我们是否可以大胆设想一下,能否使用procdump抓取其他进程内存文件,进而获得内存中的敏感信息呢?0x...

weixin_34356138的博客 4180

蓝屏分析器工具实战指南【dump文件分析与故障排除】

Windows蓝屏(Blue Screen of Death,简称BSOD)是Windows操作系统在遇到严重系统级错误时,为防止数据损坏而强制停止系统运行所展示的错误屏幕。蓝屏通常表现为全屏蓝色界面,伴随错误代码(如:0x0000007E)、错误描述(如:)以及涉及的驱动或模块名称。从系统行为来看,当Windows内核检测到无法恢复的硬件、驱动或系统软件错误时,会触发Bug Check机制,输出崩溃信息并终止所有进程。

weixin_36173034的博客 1471

[范例]从正在运行的Linux进程中dump出内存内容

参考: https://colin.guru/index.php?title=Dumping_Ram_From_Running_Linux_Processes先file一下,$ file ctf-bin ctf-bin: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs

公众号shadow sock7 3万+

C#调用Halcon程序三种方法

C#调用Halcon程序三种方法 1.halcon导出C#文件,在C#里面调用 2.在C#里面使用Halcon引擎调用Halcon程序 3.在C#里面使用Halcon引擎调用.hdev下本地函数或者.hdvp外部函数 Halcon引擎手册:C:/Program Files/MVTec/HALCON-21.11-Progress/doc_en_US/html/manuals/programmers_guide/programmers_guide_0120.html 1.导出C#(代码我只给出类,需要调用)

A541925504的博客 1万+

经典脉冲激光测距原理&雷达方程

脉冲激光测距机的工作过程如下:首先用瞄准光学系统瞄准目标,然后接通激光电源,储能电容器充电,产生触发闪光灯的触发脉冲,闪光灯点亮,激光器受激辐射,从输出反射镜发射出一个前沿陡峭、峰值功率高的激光脉冲,通过发射光学系统压缩光束发射角后射向目标。通过计算激光发射功率经介质传输的衰减,目标表面截获和反射的光功率,到达接收视场的光功率,以及接收光学系统接收到的光功率,就可以得到到达光电探测器的光功率,即接收功率。⑤光東路程上的折射率变化;),测量光脉冲到达目标并由目标返回到接收机的时间,由此计算出目标的距离。

weixin_46153372的博客 2532

查找内存泄漏的一个思路 ---- GDB调试汇编分析

使用GDB检测内存泄漏 https://blog.youkuaiyun.com/zoomdy/article/details/51594228 https://blog.youkuaiyun.com/yatusiter/article/details/51122757 利用gdb在汇编指令级调试C程序 https://blog.youkuaiyun.com/boyxiaolong/article/details/22761991 GDB调试汇编分析 https://www.cnblogs.com/20145205y/p..

happylzs2008的专栏 1333

保姆级教程:用安卓手机+IP摄像头App,5分钟搭建一个免费的RTSP监控测试环境

本文提供了一份详细的保姆级教程,教你如何利用安卓手机和IP摄像头App在5分钟内搭建免费的RTSP监控测试环境。通过零成本方案,开发者可以快速获取实时视频流,适用于计算机视觉、物联网开发等多种场景。教程涵盖工具选型、配置详解、电脑端测试及OpenCV集成,助你高效完成开发测试。

weixin_27419879的博客 277

VC应用程序中的SECTION(2): .textbss

快乐虾http://blog.youkuaiyun.com/lights_joy/lights@hb165.com 本文适用于Xp sp3 / Vs2008 欢迎转载,但请保留作者信息 1.1.1   节的基本信息使用dumpbin可以看到这一节的基本信息:SECTION HEADER #1

嵌云阁 3404

FFmpeg实战:5分钟搞定m3u8视频下载与ts文件合并(附完整命令)

本文详细介绍了如何使用FFmpeg快速下载m3u8视频并合并ts文件为mp4格式。通过简洁的命令行操作,读者可以轻松完成视频处理任务,包括环境准备、链接获取、下载合并及性能优化等实用技巧,特别适合需要高效处理流媒体内容的用户。

weixin_30836759的博客 221

Wireshark教程:解密HTTPS流量

Wireshark教程:如何解密HTTPS流量

nuan444979的博客 1万+

如何通过崩溃地址找到出错的代码行(转)

这是从“VC编程经验总结7”中转出来的 借花献佛——如何通过崩溃地址找到出错的代码行 作为程序员,我们平时最担心见到的事情是什么?是内存泄漏?是界面不好看?……错啦!我相信我的看法是不会有人反对的--那就是,程序发生了崩溃! “该 程序执行了非法操作,即将关闭。请与你的软件供应商联系。”,呵呵,这句 M$Content$nbsp;的“名言”,恐怕就是程序员最担心见到的东西了。有的时候,自...

weixin_33708432的博客 367

rk3399 hdmi HDCP key烧录

1.key转换 使用 hdcp\ProvisioningTool_20170526\KeyConverterV2.02 目录下的KeyConvertor.exe工具将1.4key进行转换 转换后得到 TX00000001.skf 文件,将 TX00000001.skf 文件烧录到开发板上,烧录方式: 打开文件 hdcp\ProvisioningTool_20170526\ProvisioningTool20170526\ProvisioningTool.exe 选择烧录方式与烧录路...

qq_32645109的博客 3860

c\c++出bug调试技巧 —— 如何利用windbg + dump + map分析程序异常 .

之前碰到论坛里有几个好友,说程序不时的崩溃,什么xxoo不能read的!  如果光要是这个内存地址,估计你会疯掉~~ 所以分享一下基本的调试技巧,需要准备的工具有WinDbg + VC6.0, 下面是自己整理的一份自动生成DUMP文件的源代码,只需要添加到工程即可,源代码如下: MiniDump.h MiniDump.cpp 1、在CXXDlg::OnIni

zmqarenas的专栏 1万+

Open3D点云数据处理(五):点云、mesh可视化(draw_geometries方法)

本文介绍了Open3D中的draw_geometries可视化方法,可以用于可视化点云和mesh。详细讲述了该方法的各个参数的作用,给出了代码示例。

孙悟空 3141

YOLOv8目标出入计数部署:讲解C#使用ONNX检测模型进行目标出入计数 可运行完整实例

代码、步骤、讲解完整,可一键运行,效果如下:车辆出入计数人员出入计数。

Limiiiing的博客 82

memory dump and Memory Leak

Memory Leak 定义 内存泄漏(Memory Leak)是指程序中已动态分配的堆内存由于某种原因程序未释放或无法释放,造成系统内存的浪费 ,导致程序运行速度减慢甚至系统崩溃等严重后果。 Memory Leak 特性 内存泄漏缺陷具有隐蔽性、积累性 的特征,比其他内存非法访问错误更难检测。因为内存泄漏的产生原因是内存块未被释放,属于遗漏型缺陷而不是过错型缺陷 。此外,内存泄漏通常不会直接产生可观察的错误症状,而是逐渐积累,降低系统整体性能,极端的情况下可能使系统崩溃。 静态变量 静态存储变量是指在程序

qinzheng_chen的博客 1936

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

恭喜你, core dump

何谓 core?      在使用半导体作为内存的材料前,人类是利用线圈当作内存的材料(发明 者为王安),线圈就叫作 core ,用线圈做的内存就叫作 core memory。如今 ,半导体工业澎勃发展,已经没有人用 core memory 了,不过,在许多情况下, 人们还是把记忆体叫作 core 。 何谓 core dump?      我们在开发(或使用)一个程序时,最怕的就是程序莫明其妙地当

aaaaatiger--寻路 809

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

windows蓝屏dump分析详解

Windows 蓝屏(BSOD,Blue Screen of Death)后生成的内存转储文件(Dump 文件)可以提供关于系统崩溃原因的重要信息。分析这些转储文件通常需要使用 Windows Debugging Tools (WinDbg),这是一套由微软提供的调试工具。

首席技术总监的专栏 4632

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

dump文件过大使用linux mat分析记录

java.lang.OutOfMemoryError: Java heap space的解决方法;dump文件过大使用linux mat分析记录;堆内存分析

yyp_abcd的博客 1647

使用Eclipse Memory Analyzer进行内存泄漏分析

一、准备工作 1)工具下载:http://www.eclipse.org/mat/downloads.php 可以选择eclipse插件的方式安装 http://download.eclipse.org/mat/1.3/update-site/ 2)分析较大的dump文件(2G以上的dump文件,可能mat会出现oom)需要调整虚拟机参数 ...

dgqvhtlwq472235338的博客 160

记一次生产环境的严重bug

在系统部署生产环境后, 在十天左右就会出现系统反应慢, 堆爆了,cpu占用百分百的情况。 在重启tomcat后情况就恢复了。 在经过详细的 跟踪, 线程dump, 堆dump 下来分析后, 线程没有问题,  发现有两个原因: 1: 通过memory  analyzer  分析 堆dump文件后,   有一个缓存对象无限增长,并保持活动, 导致回收不了, 堆爆掉。 2:由于后台 频繁gc, 导...

tang_jian_dong的博客 1万+

UNIX/C:core dump

何谓 core?在使用半导体作为内存的材料前,人类是利用线圈当作内存的材料(发明 者为王安),线圈就叫作 core ,用线圈做的内存就叫作 core memory。如今 ,半导体工业澎勃发展,已经没有人用 core memory 了,不过,在许多情况下, 人们还是把记忆体叫作 core 。 何谓 core dump?我们在开发(或使用)一个程序时,最怕的就是程序莫明其妙地当掉。虽然系 统没事,但我

prstat的专栏 899

半导体晶圆搬移上位机为何首选C#与WPF

工业上位机系统是连接产线设备与操作人员的关键枢纽,其核心在于实时性、协议兼容性与人机安全的协同实现。在半导体制造等高精度场景中,毫秒级响应、多源工业协议(如OPC UA、Modbus TCP、S7)统一接入、以及无尘室环境下防误触交互设计,共同构成技术选型的硬约束。C#凭借可控内存管理(如NoGCRegion)保障7×24小时确定性运行,WPF则依托DirectX渲染管线与数据绑定机制,在三维拓扑可视化、高频PLC数据刷新及物理建模驱动方面展现出不可替代的工程优势。本文聚焦晶圆盒(FOUP)与石墨岛(Gra

weixin_34151004的博客 568

linux程序开发之Core Dump

整理:Wilbur Lang何谓 core?在使用半导体作为内存的材料前,人类是利用线圈当作内存的材料(发明 者为王安),线圈就叫作 core ,用线圈做的内存就叫作 core memory。如今 ,半导体工业澎勃发展,已经没有人用 core memory 了,不过,在许多情况下, 人们还是把记忆体叫作 core 。 何谓 core dump? 我们在开发(或使用

技术资料库 1757

oracle 表空间 dump,PowerHA给Oracle新增表空间,遭遇memory croedump

PowerHA给Oracle新增表空间,遭遇memory croedump通过PowerHA给Oracle新增表空间,使用C-SPOC在线添加LV,开始给Datavg添加,很顺利,添加了10个很成功,在继续添加新的lv后,居然报错了. memory croedump.17032512370b098c3323ad2601.png1,内存不够用了吗.看了一下确实有点紧张hostA:1.pnghostB...

weixin_36051064的博客 217
上一篇: 今天编程的时候犯的两个错误
下一篇: AI,将去何处
knowBot
博客等级 码龄20年 0粉丝 10原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值