Log in

View Full Version : Useful WinDbg commands: .formats


Nynaeve
April 23rd, 2008, 10:01
One of the many things that you end up having to do while debugging a program is displaying data types. While you probably know many of the basic commands like db, da, du, and soforth, one perhaps little-used command is useful for displaying a four or eight byte quantity in a number of different data types: the “.formats” command. This command is useful for viewing various primative/built-in data types, where you cannot display as a structure via the “dt” command.

In particular, you can use .formats to translate a number of different data types into readable values, including floating point or various time formats (time_t if you provide a 32-bit value, or FILETIME if you give a 64-bit value). For instance:

Code:
0:001> .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
The command also supports 64-bit filetime quantities:

Code:
0:001> .formats 01010101`01010101
Evaluate expression:
Hex: 01010101`01010101
Decimal: 72340172838076673
Octal: 0004010020040100200401
Binary: 00000001 00000001 00000001 00000001
00000001 00000001 00000001 00000001
Chars: ........
Time: Sun Mar 28 21:14:43.807 1830 (GMT-4)
Float: low 2.36943e-038 high 2.36943e-038
Double: 7.7486e-304
.formats is primarily useful for saving you a bit of time poking around in a calculator to translate times, or convert perhaps an overwritten eip into text if you are examining a stack buffer string overflow. In conjunction with db and dt, you should be able to format most any data you’ll come across in a debugging session into a readable format (provided you have symbols, of course, in the case of complex user-defined data types).



http://www.nynaeve.net/?p=58