Start of Windbg script and expansion Tool

Source: Internet
Author: User

Start of Windbg script and expansion Tool

I haven't written any articles for a long time. Recently I have been busy with script and extension tools for the project's adjustable nature. In view of the strong power of windbg and the relatively small amount of information, I decided to write a series of articles on how to develop Windbg scripts and extended commands. Your support is my greatest motivation. I hope this series of articles will help you.

So what does a complete windbg script look like? First, let's look at the following example:

$ This script is used to list user processes and stacks.

R $ t0 = nt! PsActiveProcessHead
. For (r $ t1 = poi (@ $ t0); (@ $ t1! = 0) & (@ $ t1! = @ $ T0); r $ t1 = poi (@ $ t1 ))
{
R? $ T2 = # CONTAINING_RECORD (@ $ t1, nt! _ EPROCESS, ActiveProcessLinks );
. Process @ $ t2
. Reload
! Process @ $ t2
}

 

Compared with Windbg scripts, windbg extensions are complex and usually require more effort to write the same function. However, one benefit of Windbg extensions is that you can obtain more functions, you can even write a debugger using these extensions. What does a complete windbg extension look like? The extension dll prints the value of a global string.

Example of windbg extension written in C ++:

HRESULT CALLBACK
PrintPTR (PDEBUG_CLIENT pDebugClient, PCSTR args)
{
UNREFERENCED_PARAMETER (args );

IDebugSymbols * pDebugSymbols;
If (SUCCEEDED (pDebugClient-> QueryInterface (_ uuidof (IDebugSymbols), (void **) & pDebugSymbols )))
{// Resolve the symbol
ULONG64 ulAddress = 0;
If (SUCCEEDED (pDebugSymbols-> GetOffsetByName ("TestSTLMap! G_wString ", & ulAddress )))
{
IDebugDataSpaces * pDebugDataSpaces;
If (SUCCEEDED (pDebugClient-> QueryInterface (_ uuidof (IDebugDataSpaces), (void **) & pDebugDataSpaces )))
{// Read the value of the pointer from the target address space
ULONG64 ulPtr = 0;
If (SUCCEEDED (pDebugDataSpaces-> ReadPointersVirtual (1, ulAddress, & ulPtr )))
{
PDEBUG_CONTROL pDebugControl;
If (SUCCEEDED (pDebugClient-> QueryInterface (_ uuidof (IDebugControl), (void **) & pDebugControl )))
{// Output the values
PDebugControl-> Output (DEBUG_OUTPUT_NORMAL, "% p TestSTLMap! G_wString = 0x % p \ n ", ulAddress, ulPtr );
PDebugControl-> Output (DEBUG_OUTPUT_NORMAL, "% mu \ n", ulPtr );
PDebugControl-> Release ();
}
}
PDebugDataSpaces-> Release ();
}
PDebugSymbols-> Release ();
}
}
Return S_ OK;
}

 

Summary

Based on my research, I found that there are not many people doing relevant research in China. In fact, there are also a few cool people in the industry outside of China who do relatively better, but these tools are enough to shock you, start today. If you are interested, you can continue to pay attention to subsequent articles.

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.