The Artima Developer Community
Sponsored Link

.NET Buzz Forum
GetILAsByteArray e l'opzione /bytes dell'ildasm

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Adrian Florea

Posts: 206
Nickname: adrian11
Registered: Jul, 2004

Adrian Florea is a .NET developer from Italy
GetILAsByteArray e l'opzione /bytes dell'ildasm Posted: Sep 20, 2005 6:50 AM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Adrian Florea.
Original Post: GetILAsByteArray e l'opzione /bytes dell'ildasm
Feed Title: Web Log di Adrian Florea
Feed URL: /error.aspx?aspxerrorpath=/adrian/Rss.aspx
Feed Description: "You know you've achieved perfection in design, not when you have nothing more to add, but when you have nothing more to take away." Antoine de Saint-Exupery
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Adrian Florea
Latest Posts From Web Log di Adrian Florea

Advertisement

Per vedere "the actual bytes (in hex) as instruction comments" nel codice IL, abbiamo l'opzione /bytes dell'ildasm. Per esempio, per il metodo Foo::Sum della classe:

class Foo
{
      public int Sum(int a, int b)
      {
            return a + b;
      }
}

otteniamo:

IL_0000:  /* 00   |                  */ nop
IL_0001:  /* 03   |                  */ ldarg.1
IL_0002:  /* 04   |                  */ ldarg.2
IL_0003:  /* 58   |                  */ add
IL_0004:  /* 0A   |                  */ stloc.0
IL_0005:  /* 2B   | 00               */ br.s       IL_0007
IL_0007:  /* 06   |                  */ ldloc.0
IL_0008:  /* 2A   |                  */ ret

dove con rosso sono scritti in esadecimale gli opcode (e i loro parametri! - vedi lo 00 nella colonna a destra) delle istruzioni IL corrispondenti (vedi ECMA-335, Partition III, 1.2.1 "Opcode encodings").

Ottenere questi byte per un metodo o per un costruttore è semplicissimo, basta utilizzare (in .NET 2.0) il metodo GetILAsByteArray: Per esempio, questo snippet:

foreach(byte b in typeof(Foo).GetMethod("Sum").GetMethodBody().GetILAsByteArray())
{
      Console.WriteLine(Convert.ToString(b, 16).PadLeft(2, '0').ToUpper());
}

stampa:

00
03
04
58
0A
2B
00
06
2A

cioè, esattamente i byte di sopra, in rosso.

Read: GetILAsByteArray e l'opzione /bytes dell'ildasm

Topic: IT Forum 2005 - win a ticket Previous Topic   Next Topic Topic: IE Developer Toolbar

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use