讓我們寫這個例子程序,看看如何布爾在.NET中工作,以及如何使用WinDbg更改值:
using System;
namespace ChangeValueOfBoolean
{
class Program
{
static void Main()
{
var h = new BooleanHolder();
h.BoolValue = true;
Console.WriteLine("Debug now. Boolean member has the value {0}", h.BoolValue);
Console.ReadLine();
Console.WriteLine("After debugging, boolean member has the value {0}", h.BoolValue);
h.BoolValue = true;
Console.ReadLine();
}
}
class BooleanHolder
{
public bool BoolValue { get; set; }
}
}
步驟來調試:
- 將其編譯爲調試模式
- 運行該應用程序。
- 連接WinDbg
- 修復符號
.symfix;.reload
- 負載的.NET擴展
.loadby sos clr
- 找到相關的對象
!dumpheap -short -type BooleanHolder
- 轉儲對象
!do <address>
轉儲存儲器中的原始值dd <address>+<offset> L1
我們會看到true == 1
- 編輯的原始值
ed <address>+<offset> 0
- 繼續運行程序
g
- 在控制檯上看到輸出
按輸入
它已經切換到false
完全攻略在WinDbg中:
0:004> .symfix;.reload
Reloading current modules
..........................
0:004> .loadby sos clr
0:004> !dumpheap -short -type BooleanHolder
025330c8
0:004> !do 025330c8
Name: ChangeValueOfBoolean.BooleanHolder
MethodTable: 00144d74
EEClass: 00141804
Size: 12(0xc) bytes
File: E:\Projekte\SVN\HelloWorlds\ChangeValueOfBoolean\bin\Debug\ChangeValueOfBoolean.exe
Fields:
MT Field Offset Type VT Attr Value Name
704bf3d8 4000001 4 System.Boolean 1 instance 1 <BoolValue>k__BackingField
0:004> dd 025330c8+4 L1
025330cc 00000001
0:004> ed 025330c8+4 0
0:004> g
不錯的演練會這將是巨大的,如果你能展示如何用C++/C#修改?表達式? FOO :: booleanxxx :: BOOL; ed foo:boolean :: xxx而不是ed @@ masm(地址)無論如何upvoted – blabb
@blabb:嗯,我從來沒有這樣做過。應該有可能嗎?我會嘗試 –
cdb -g booldoll.exe 1 <----- (a4.bac):Control-C exception - code 40010005(first chance) 0:001> ?? booooll!foo bool true 0:001> ed booldoll!foo 0 0:001> ?? booldoll!foo bool false 0:001> g 0 <-------------- type booldoll。cpp #include bool foo = true; int main(void){ char temp [10]; printf(「%x \ n」,foo); get_s(temp,sizeof(temp)); printf(「%x \ n」,foo); get_s(temp,sizeof(temp)); } –
blabb