Imported Upstream version 5.10.0.47

Former-commit-id: d0813289fa2d35e1f8ed77530acb4fb1df441bc0
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2018-01-24 17:04:36 +00:00
parent 88ff76fe28
commit e46a49ecf1
5927 changed files with 226314 additions and 129848 deletions

View File

@ -40,6 +40,7 @@ public class Program
public bool ShowHelp { get; set; }
public bool Verbose { get; set; }
public List<string> 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<string> extra;
@ -100,6 +103,24 @@ public class Program
static void RewriteAssembly (string assemblyLocation, Dictionary<string, string> resourcesStrings, CmdOptions options)
{
var methods = new Dictionary<string, MethodBody> (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;