Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSIL - How does call opcode know what method to call given just an integer

Tags:

c#

clr

cil

I'm trying to figure out how MSIL is able to represent a call to a static function by only storing an integer.

For example, if you add a call to Interlocked.Increment(ref someVariable), your IL will contain the following:

0x28 | 0x12, 0x0, 0x0, 0xA

The pipe operator is my addition, essentially 0x28 is the call instruction and 012, 0x0, 0x0, 0xA is the "Interlocked.Increment" method.

Who decided that value? When you disassemble using ildasm, it pretty prints the name, but is there a table it looks up?

Where is this table defined?

like image 942
halivingston Avatar asked Sep 08 '15 20:09

halivingston


1 Answers

According to ECMA-335, 0x0A000012 is a metadata token. Metadata token is basically a number that uniquely identifies a type, method, field etc. in the local module. 0x0A represents the MemberRef table in the module, and 0x12 is the index of the method in the table.

The table contains the the name and signature of the method (like its parameters and return type).

like image 57
IS4 Avatar answered Oct 22 '22 15:10

IS4