Code Monkey home page Code Monkey logo

Comments (3)

 avatar commented on July 25, 2024

No, there's no method in dnlib that will tell you that.

You'll have to do what you wrote, check the current method's declaring type's interfaces and the base type. It's the base type that will complicate things because it's not always a TypeRef/TypeDef, it could be a TypeSpec. If so, you'd have to replace all generic parameters with the generic arguments on every method from then on.

Class1 : Class2<int, bool>

If Class2 has this method: T method1<T, U>(U u), you must first replace the generic params with the generic arguments and turn it into int method1<int, bool>(bool u) before comparing it with your method. The code would be very similar to what the Importer class already does.

To compare methods, use the SigComparer class.

from dnlib.

asdfgasdfsafgsdfa avatar asdfgasdfsafgsdfa commented on July 25, 2024

Thank you very much for the help.
I will look into it and report back when I got it working (or not).

Btw is there a trick you are aware of that I could use to restructure the Ld* instructions just before a call when the signature of the method being called has changed?

I have to modify the parameter order of some methods (only internal) and of course I have to update all callsites.
I already found out all locations where the method is called, changed the parameter order and updated all instructions in the method.
What's left is updating the callsites.

Most of the time the ld* (ldc, ldloc, ldarg) commands are all neatly packed next to each other just in front of the call. But sometimes a value is consumed by the call that has been pushed on the evaluation stack many instructions further up, or even below (with a jump back up).

Some values might not even be loaded from anywhere at all. For example results of add,sub,mul or call. The whole thing gets especially complicated when there is a call-chain with no load/store commands in between...

Since there is no msil instruction to swap two items on the evaluation stack, I thought the best way to reorder the values would be to add additional local variables pop them in and push them in the needed order...

Is there a way / method in dnlib or de4dot that does something like a cleanup on a methodbody?
So all ld*s are directly in front of the call?

I think there surely is a better way to do this. What would you do?

from dnlib.

 avatar commented on July 25, 2024

You could create a static method (set first argument to the 'this' instance) which uses the original parameter order which then calls the new method (be sure that you use the same call/callvirt instruction in this proxy method as the original code used).

Otherwise you'll just have to pop the args to temporary variables and then push them in the new order, like you said.

from dnlib.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.