Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7815179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:26:17+00:00 2026-06-02T05:26:17+00:00

I’m playing with mutation testing at the moment. One of the mutations I’m looking

  • 0

I’m playing with mutation testing at the moment. One of the mutations I’m looking at involves swapping parameters, for which I may need to swap, for example Ldarg.0 and Ldarg_S with an operand indicating the index.

The operand type for this is an inline arg, which in Mono.Cecil I believe requires me to create a properly instantiated ParameterDefinition to store the 32-bit int index. Does anyone have enough experience with Cecil to point me in the right direction of an easy way to create an Instruction instance with OpCode of Ldarg_S and an Operand of the appropriate type?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T05:26:18+00:00Added an answer on June 2, 2026 at 5:26 am

    You have two kinds of opcodes here, ldarg.0, and ldarg (and its _s) variant.

    The first one is a “macro” opcode, meaning that it’s used to reduce the size of the code for typically used values.

    If you need to modify the parameters of a method, I suggest you firs transform all macro opcodes to a complete form, this is done using the SimplifyMacros() extension method on MethodBody from the helper library Mono.Cecil.Rocks:

    using Mono.Cecil;
    using Mono.Cecil.Cil;
    using Mono.Cecil.Rocks;
    
    // ..
    
    method.Body.SimplifyMacros();
    

    When this is done, an existing ldarg.0 instruction will now be ldarg with the correct operand, which is as you guessed, a ParameterDefinition.

    With that in place, you can re-order the parameters, and create new instructions:

    var il = method.Body.GetILProcessor();
    var instruction = il.Create(OpCodes.Ldarg, aParameterDefinition);
    il.InsertBefore(xxx, instruction);
    

    When you’re done, you can call the inverse of SimplifyMacros(), OptimizeMacros(), which will try to, well, optimize the opcodes into their macro form if possible.

    One thing you’ll have to take care of, is that the first argument of a instance method, the implicit “this”, is represented with the method.Body.ThisParameter special parameter which you won’t find in the .Parameters collection of the method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
In my XML file chapters tag has more chapter tag.i need to display chapters
I am doing a simple coin flipping experiment for class that involves flipping a
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.