Hi all,
I'm newbie with CIL. I tried to:
- Read a DLL file.
- Iterate all instructions
  + if program encounters add operator, it will change to sub and then save 
to a new dll (Add.dll)
  + if program encounters sub operator, it will change to add and then save 
to a new dll.(Sub.dll)
My problem is:
 - After I run my code, Sub.dll is modified from Add.dll, instead of 
original code.
*I. Result I've got :*
1. Original code
    public int add(int a,int b) {return a+b;}
    public int subtract(int a,int b) {return a-b;}
2. Add.dll
   public int add(int a,int b) {return a-b;}
   public int subtract (int a,int b) {return a-b;}
3. Subtract.dll
   public int add(int a,int b)*{return a-b;} //instead of a+b*
   public int subtract(int a,int b){return a+b;}


*II. My code*
 
var _module = ModuleDefinition.ReadModule(sourceFile);
            
                foreach (TypeDefinition type in  _module.Types)
                {
                    if (type.Name != "<Module>")
                    {
                        foreach (MethodDefinition method in type.Methods)
                        {
                             //omit constructor
                             if (method.Name != ".ctor")
                            {
                                //iterate all instructions in each method
                                foreach (var instruction in 
method.Body.Instructions)
                                {
                                    if (instruction.OpCode == OpCodes.Add)
                                    {
                                        instruction.OpCode = OpCodes.Sub;
                                        _module.Write("Add.dll");
                                    }
                                    else if (instruction.OpCode == 
OpCodes.Sub)
                                    {
                                        instruction.OpCode = OpCodes.Add;
                                        _module.Write(Sub.dll");
                                    }
                              

Thanks for your time !


-- 
-- 
--
mono-cecil
--- 
You received this message because you are subscribed to the Google Groups 
"mono-cecil" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to