X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Ftools%2Fcil-stringreplacer%2Fcil-stringreplacer.cs;h=9892827b2d79088e979acea2849bd0f7256a0b3f;hb=f0ce7bc289794b4f022f2b5939e45e2faf56ac87;hp=3226b3911d9b291093cc8d100a871014dc7f016a;hpb=6ac36d6c40a2dd0ab2800c23d08894856b193c2f;p=mono.git diff --git a/mcs/tools/cil-stringreplacer/cil-stringreplacer.cs b/mcs/tools/cil-stringreplacer/cil-stringreplacer.cs index 3226b3911d9..9892827b2d7 100644 --- a/mcs/tools/cil-stringreplacer/cil-stringreplacer.cs +++ b/mcs/tools/cil-stringreplacer/cil-stringreplacer.cs @@ -40,6 +40,7 @@ public class Program public bool ShowHelp { get; set; } public bool Verbose { get; set; } public List ResourcesStrings { get; } + public string ILFile { get; set; } public CmdOptions () { @@ -54,10 +55,12 @@ public class Program var p = new OptionSet () { { "r|resourcestrings=", "File with string resource in key=value format", v => options.ResourcesStrings.Add (v) }, - { "h|help", "Display available options", + { "h|help", "Display available options", v => options.ShowHelp = v != null }, - { "v|verbose", "Use verbose output", - v => options.Verbose = v != null }, + { "v|verbose", "Use verbose output", + v => options.Verbose = v != null }, + { "ilreplace=", "File with IL code to be used instead", + v => options.ILFile = v }, }; List extra; @@ -100,6 +103,24 @@ public class Program static void RewriteAssembly (string assemblyLocation, Dictionary resourcesStrings, CmdOptions options) { + var methods = new Dictionary (StringComparer.Ordinal); + if (options.ILFile != null) { + var rp = new ReaderParameters { + InMemory = true + }; + + using (var module = ModuleDefinition.ReadModule (options.ILFile,rp)) { + foreach (var type in module.GetTypes ()) { + foreach (var method in type.Methods) { + if (!method.HasBody) + continue; + + methods.Add (method.FullName, method.Body); + } + } + } + } + var readerParameters = new ReaderParameters { ReadSymbols = true, ReadWrite = true, @@ -113,6 +134,33 @@ public class Program if (!method.HasBody) continue; + MethodBody newBody; + if (methods.TryGetValue (method.FullName, out newBody)) { + var mbody = method.Body; + mbody.Instructions.Clear (); + foreach (var instr in newBody.Instructions) { + switch (instr.OpCode.OperandType) { + case OperandType.InlineType: + var tr = (TypeReference)instr.Operand; + foreach (var t in method.GenericParameters) { + if (tr.FullName == t.FullName) { + instr.Operand = t; + break; + } + } + + break; + } + + mbody.Instructions.Add (instr); + } + + method.Body.Variables.Clear (); + foreach (var variable in newBody.Variables) { + mbody.Variables.Add (variable); + } + } + foreach (var instr in method.Body.Instructions) { if (instr.OpCode != OpCodes.Ldstr) continue;