Today I started to learn how CIL code works.
I found List of CIL instructions
And now I'm trying to edit one function.
I'm using .NET Reflector with Reflexil
I want to edit this function:
.method family hidebysig instance void SomeFunction(float32 var1, float32 var2, class SomeClassComponent component, class SomeInstanceClassComponent instance, float32 var3) cil managed
{
}
It's starting with code:
IL_0000: ldarg.0
IL_0001: ldarg.3
IL_0002: ldarg.1
IL_0003: ldarg.2
I want to replace var1 with hard-written value.
Wikipedia says:
conv.r4
Convert to float32, pushing F on stack.
When I try do edit it, I get this:
Where's my mistake?
As Lucas Trzesniewski said in his comment, you first need to have a value on the stack which the conv.r4 instruction can use.
For a more in depth description about the operands, see this msdn link and here is the link for the conv.r4 operand which states that "The conv.r4 opcode converts the value on top of the stack to the type specified in the opcode" - meaning you have to make sure that there is already a value on the stack and it is the correct value that the conv.r4 instruction can use.
As some minor self advertisement at the end ;) I've written some tutorials about IL programming you can read here and here. I tried to use a hands on approach so you understand IL through programming, not just reading.