2015-11-26 55 views
2

我的布爾變量可以使用語法如何更改託管變量的值?

MPrime.exe Spirit.MPrimeComServerManager._isComServerReady 

我已經使用語法

?? MPrime.exe Spirit.MPrimeComServerManager._isComServerReady=1 

試圖引用,我不知道如何使用e*命令使用託管代碼。

這是!DumpObj輸出:

00007fff81a6d6e8 4000198 169 System.Boolean 1 static 0 _isComServerReady 

回答

3

讓我們寫這個例子程序,看看如何布爾在.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; } 
    } 
} 

步驟來調試:

  1. 將其編譯爲調試模式
  2. 運行該應用程序。
  3. 連接WinDbg
  4. 修復符號.symfix;.reload
  5. 負載的.NET擴展.loadby sos clr
  6. 找到相關的對象!dumpheap -short -type BooleanHolder
  7. 轉儲對象!do <address>
  8. 轉儲存儲器中的原始值dd <address>+<offset> L1

    我們會看到true == 1

  9. 編輯的原始值ed <address>+<offset> 0
  10. 繼續運行程序g
  11. 在控制檯上看到輸出
  12. 輸入

    它已經切換到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 

enter image description here

+0

不錯的演練會這將是巨大的,如果你能展示如何用C++/C#修改?表達式? FOO :: booleanxxx :: BOOL; ed foo:boolean :: xxx而不是ed @@ masm(地址)無論如何upvoted – blabb

+0

@blabb:嗯,我從來沒有這樣做過。應該有可能嗎?我會嘗試 –

+0

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