Browse Source

ConnectMethodDecompiler: Adapt to new switch transformation.

pull/887/head
Siegfried Pammer 8 years ago
parent
commit
5399b93df7
  1. 10
      ILSpy.BamlDecompiler/BamlResourceEntryNode.cs
  2. 10
      ILSpy.BamlDecompiler/ConnectMethodDecompiler.cs

10
ILSpy.BamlDecompiler/BamlResourceEntryNode.cs

@ -10,6 +10,7 @@ using System.Threading.Tasks; @@ -10,6 +10,7 @@ using System.Threading.Tasks;
using System.Xml.Linq;
using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.Decompiler.Util;
using ICSharpCode.ILSpy;
using ICSharpCode.ILSpy.TextView;
using ICSharpCode.ILSpy.TreeNodes;
@ -135,7 +136,7 @@ namespace ILSpy.BamlDecompiler @@ -135,7 +136,7 @@ namespace ILSpy.BamlDecompiler
}
}
static void RemoveConnectionIds(XElement element, Dictionary<long, EventRegistration[]> eventMappings)
static void RemoveConnectionIds(XElement element, List<(LongSet key, EventRegistration[] value)> eventMappings)
{
foreach (var child in element.Elements())
RemoveConnectionIds(child, eventMappings);
@ -143,10 +144,9 @@ namespace ILSpy.BamlDecompiler @@ -143,10 +144,9 @@ namespace ILSpy.BamlDecompiler
var removableAttrs = new List<XAttribute>();
var addableAttrs = new List<XAttribute>();
foreach (var attr in element.Attributes(XName.Get("ConnectionId", XmlBamlReader.XWPFNamespace))) {
int id;
if (int.TryParse(attr.Value, out id) && eventMappings.ContainsKey(id)) {
var map = eventMappings[id];
foreach (var entry in map) {
int id, index;
if (int.TryParse(attr.Value, out id) && (index = eventMappings.FindIndex(item => item.key.Contains(id))) > -1) {
foreach (var entry in eventMappings[index].value) {
string xmlns = ""; // TODO : implement xmlns resolver!
addableAttrs.Add(new XAttribute(xmlns + entry.EventName, entry.MethodName));
}

10
ILSpy.BamlDecompiler/ConnectMethodDecompiler.cs

@ -10,6 +10,7 @@ using ICSharpCode.Decompiler.CSharp; @@ -10,6 +10,7 @@ using ICSharpCode.Decompiler.CSharp;
using ICSharpCode.Decompiler.IL;
using ICSharpCode.Decompiler.IL.Transforms;
using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.Decompiler.Util;
using Mono.Cecil;
namespace ILSpy.BamlDecompiler
@ -34,9 +35,9 @@ namespace ILSpy.BamlDecompiler @@ -34,9 +35,9 @@ namespace ILSpy.BamlDecompiler
this.assembly = assembly;
}
public Dictionary<long, EventRegistration[]> DecompileEventMappings(string fullTypeName, CancellationToken cancellationToken)
public List<(LongSet, EventRegistration[])> DecompileEventMappings(string fullTypeName, CancellationToken cancellationToken)
{
var result = new Dictionary<long, EventRegistration[]>();
var result = new List<(LongSet, EventRegistration[])>();
TypeDefinition type = this.assembly.MainModule.GetType(fullTypeName);
if (type == null)
@ -70,8 +71,7 @@ namespace ILSpy.BamlDecompiler @@ -70,8 +71,7 @@ namespace ILSpy.BamlDecompiler
if (ilSwitch != null) {
foreach (var section in ilSwitch.Sections) {
var events = FindEvents(section.Body);
foreach (long id in section.Labels.Values)
result.Add(id, events);
result.Add((section.Labels, events));
}
} else {
foreach (var ifInst in function.Descendants.OfType<IfInstruction>()) {
@ -82,7 +82,7 @@ namespace ILSpy.BamlDecompiler @@ -82,7 +82,7 @@ namespace ILSpy.BamlDecompiler
if (!comp.Right.MatchLdcI4(out id))
continue;
var events = FindEvents(comp.Kind == ComparisonKind.Inequality ? ifInst.FalseInst : ifInst.TrueInst);
result.Add(id, events);
result.Add((new LongSet(id), events));
}
}
return result;

Loading…
Cancel
Save