ioncodes / dnpatch

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

BuildMemberRef signature always returns void and always takes argument string #17

Closed ViRb3 closed 7 years ago

ViRb3 commented 7 years ago

Isn't this going to fail to match the original members with a different signature?

ioncodes commented 7 years ago

Example?

ViRb3 commented 7 years ago

Say I want to find a call to System.Console Read. I create an instruction to find like in your example project:

Instruction.Create(OpCodes.Call, p.BuildMemberRef("System", "Console", "Read", Patcher.MemberRefType.Static)),

BuildMemberRef() does this:

return new MemberRefUser(_module, "Read",
                    MethodSig.CreateStatic(_module.CorLibTypes.Void, _module.CorLibTypes.String),
                    typeRef);

So it creates a MemberRef with signature like this:

Parameters: String
Returns: Void

But the real signature is:

Parameters: None
Returns: String

Thus, I'm pretty confident it will fail in finding it. I don't have access to a VS environment so I haven't tested anything, I may be wrong.

ViRb3 commented 7 years ago

E.g. here: https://github.com/ioncodes/dnpatch/blob/master/dnpatch/PatchHelper.cs#L186

ioncodes commented 7 years ago

Thanks for the report, I will look into it ASAP!

SlowLogicBoy commented 7 years ago

this should be fixed with #13 since BuildMemberRef is supported only for Console.WriteLine() and similar signature methods

ioncodes commented 7 years ago

https://github.com/ioncodes/dnpatch/commit/efd3dbd83237e2c8229db25c60e12654a69453f1