Hi,

I need to read file content and check something for update my application 
modules and save something to file again , i wrote sample code :

            AssemblyDefinition asm = AssemblyDefinition.ReadAssembly(@
"D:\1.exe");


            var method = asm.MainModule.EntryPoint;


            var mbi = method.Body.Instructions;


            if (mbi[mbi.Count - 1].OpCode == OpCodes.Ret)
                mbi.Remove(mbi[mbi.Count - 1]);


            // Read text file buffer
            mbi.Add(Instruction.Create(OpCodes.Ldstr, @"D:\\1.txt"));
            mbi.Add(Instruction.Create(OpCodes.Call, asm.MainModule.Import(
typeof(File).GetMethod("ReadAllBytes", new Type[] { typeof(string) }))));


            // Write the buffer to file
            mbi.Add(Instruction.Create(OpCodes.Stloc_0));
            mbi.Add(Instruction.Create(OpCodes.Ldstr, @"D:\2.txt"));
            mbi.Add(Instruction.Create(OpCodes.Ldloc_0));
            mbi.Add(Instruction.Create(OpCodes.Call, asm.MainModule.Import(
typeof(File).GetMethod("WriteAllBytes", new Type[] { typeof(string), typeof(
byte[]) }))));


            asm.Write(@"D:\2.exe");
 
the problem is when i want to write the readed bytes to file again lose the 
readed byte array and using Stloc_0 & Ldloc_0 kill my app .
my question is how can i access the readed bytes when my "WriteAllBytes" 
method have 2 params and my stack gose to break ?

Thanks.

-- 
-- 
--
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