View Single Post
  #6  
Old 02-27-2019, 16:09
deepzero's Avatar
deepzero deepzero is offline
VIP
 
Join Date: Mar 2010
Location: Germany
Posts: 300
Rept. Given: 111
Rept. Rcvd 64 Times in 42 Posts
Thanks Given: 178
Thanks Rcvd at 216 Times in 92 Posts
deepzero Reputation: 64
First.

Code:
    IL_0000: ldarg.1      // load a
    IL_0001: ldarg.2      // load b (which is a reference)
    IL_0002: ldind.i4      //dereference b (bc it is is reference: int&)
    IL_0003: call         BitConverter::ToUInt() //call and put result on stack
then

Code:
    IL_0008: ldarg.2      // load b on stack for later use
    IL_0009: ldarg.2      // load b
    IL_000a: ldind.i4      //dereference it
    IL_000b: ldc.i4.4      //load interger-constant "4" to stack
    IL_000c: add           //add the values of b and "4" and put the result on the stack
SO now the stack looks like this:


Code:
<value: result of b+4>
<reference: b> (was loaded at IL_0008)
<value: return value of the BitConverter call>

Then the last piece of the puzzle:

Code:
    IL_000d: stind.i4   //store the result of  "b+4" in b
There now is just one entry on the stack:

Code:
<value: return value of the BitConverter call>
and finally return that last entry:

Code:
    IL_000e: ret


So in conclusion the method does two things: 1) b += 4 and 2) return BitConverter(). So reflector is right and the others are wrong. You should file a bug report.


A more literal decompilation would be:


Code:
    private uint e(byte[] a, ref int b)
    {
        uint32 tmp = BitConverter.ToUInt32(a, b);
        b += 4;
        return tmp;
    }
But you can trivially optimize that by eliminating the tmp variable.
Reply With Quote
The Following 2 Users Say Thank You to deepzero For This Useful Post:
tonyweb (03-02-2019), WhoCares (02-27-2019)