Monday, May 09, 2011

Windbg - Lệnh poi

Hix, cái lệnh khó hiểu này, tìm ra rồi thì mới thấy nó đơn giản.

Đọc manual của nó chẳng hiểu là gì :D
poi: Pointer-sized data from the specified address. The pointer size is 32 bits or 64 bits. In kernel debugging, this size is based on the processor of the target computer. In user-mode debugging on an Itanium-based computer, this size is 32 bits or 64 bits, depending on the target application. Therefore, poi is the best operator to use if you want pointer-sized data.

Thì ra nó là một con trỏ hihi. Ví dụ bạn có địa chỉ xxx trong bộ nhớ, thì poi(xxx) chính là giá trị tại địa chỉ xxx, hix thế thôi mà mò hoài hổng hiểu hihihi

Ví dụ:
Tôi muốn xem nội dung của một biến kiểu string, tôi gõ lệnh:

0:008> !do 01aaaa38
Name: System.String
MethodTable: 6e530b70
EEClass: 6e2ed66c
Size: 32(0x20) bytes
(C:\Windows\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll)
String: chunked
Fields:
MT Field Offset Type VT Attr Value Name
6e532dbc 4000096 4 System.Int32 1 instance 8 m_arrayLength
6e532dbc 4000097 8 System.Int32 1 instance 7 m_stringLength
6e531850 4000098 c System.Char 1 instance 63 m_firstChar
6e530b70 4000099 10 System.String 0 shared static Empty
>> Domain:Value 00336430:01981198 0484b680:01981198 <<
6e5317a0 400009a 14 System.Char[] 0 shared static WhitespaceChars
>> Domain:Value 00336430:019817b4 0484b680:019d4e5c <<

Ok, chúng ta chú ý cột Offset và cột Value nhé, thì thấy là tương ứng với offset thì sẽ có giá trị. Như vậy nếu tôi gõ lệnh poi(base+offset) thì sẽ bằng Value. Ví dụ tại offset 4 thì có Value là 8, để kiểm tra bằng lệnh poi, tôi gõ như sau:

0:008> ?poi(01aaaa38+0x4)
Evaluate expression: 8 = 00000008

Voila, thấy chưa! Nếu ta không có cột Value thì poi sẽ rất hữu ích đúng ko nào. Yeah.


No comments: