ioncodes / dnpatch

.NET Patcher library using dnlib
MIT License
313 stars 48 forks source link

Added GetLdcI4Operand function to get ldc.i4 values #16

Closed andrewshulgin closed 7 years ago

andrewshulgin commented 7 years ago

Example:

Sample Program:

namespace Example
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = 1; // <- we want to get this value
            Console.WriteLine("a = {0}", a.ToString());
        }
    }
}

dnPatch Usage:

Patcher p = new Patcher("Example.exe");
Target target = new Target()
{
    Namespace = "Example",
    Class = "Program",
    Method = "Main",
    Index = 0
};
int a = p.GetLdcI4Operand(target);
Console.WriteLine("a = {0}", a.ToString());

dnSpy Screenshots:

1 2 3

SlowLogicBoy commented 7 years ago

How about making methodGetOperand<T>(target), p.GetOperand<int>(target); Another version could be GetOperand<T>(target) : where T : OpCode p.GetOperand<OpCode.LdcI4>(target); Or just object GetOperand(target); and you cast that object yourself?

Because current pull request only covers one case.

ioncodes commented 7 years ago

For now, I will merge the PR. Either make a new PR with @SlowLogicBoy 's recommendation or wait until I update it.