From ee5ddb7695c1fd059c04f3df943b284f755a6ed1 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Fri, 18 Apr 2014 11:10:26 +0200 Subject: [PATCH] fix #206 - BAML decompiler - NotImplementedException: StaticResourceStart --- .../KeyMapping.cs | 5 +++-- .../KnownInfo.cs | 3 +++ .../XmlBamlReader.cs | 20 ++++++++++++++----- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/KeyMapping.cs b/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/KeyMapping.cs index abda8e317..a0c3a03fa 100644 --- a/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/KeyMapping.cs +++ b/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/KeyMapping.cs @@ -14,8 +14,9 @@ namespace Ricciolo.StylesExplorer.MarkupReflection get { return staticResources; } } - public bool HasStaticResources { - get { return staticResources != null && staticResources.Count > 0; } + public bool HasStaticResource(int identifier) + { + return staticResources != null && staticResources.Count > identifier; } public string KeyString { get; set; } diff --git a/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/KnownInfo.cs b/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/KnownInfo.cs index 76e4f56d1..2aa8f32b9 100644 --- a/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/KnownInfo.cs +++ b/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/KnownInfo.cs @@ -1175,6 +1175,9 @@ namespace Ricciolo.StylesExplorer.MarkupReflection KnownResourceTable.Add(0xda, new ResourceName("InternalSystemParametersEnd")); KnownResourceTable.Add(0x5e, new ResourceName("InternalSystemParametersStart")); KnownResourceTable.Add(0xe8, new ResourceName("InternalSystemThemeStylesEnd")); + KnownResourceTable.Add(0xe9, new ResourceName("InternalSystemColorsExtendedStart")); + KnownResourceTable.Add(0xea, new ResourceName("InactiveSelectionHighlightBrush")); + KnownResourceTable.Add(0xeb, new ResourceName("InactiveSelectionHighlightTextBrush")); KnownResourceTable.Add(0xd6, new ResourceName("InternalSystemThemeStylesStart")); KnownResourceTable.Add(0x95, new ResourceName("SystemParameters.IsImmEnabled")); KnownResourceTable.Add(150, new ResourceName("SystemParameters.IsMediaCenter")); diff --git a/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlReader.cs b/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlReader.cs index f45e9f4ab..f44011432 100644 --- a/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlReader.cs +++ b/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlReader.cs @@ -682,13 +682,21 @@ namespace Ricciolo.StylesExplorer.MarkupReflection return declaration; } else { identifier = (short)-identifier; - bool isNotKey = (identifier > 0xe8); - if (isNotKey) - identifier = (short)(identifier - 0xe8); + bool isKey = true; + if (identifier > 0xe8 && identifier < 0x1d0) { + isKey = false; + identifier -= 0xe8; + } else if (identifier > 0x1d0 && identifier < 0x1d3) { + identifier -= 0xe7; + } else if (identifier > 0x1d3 && identifier < 0x1d6) { + identifier -= 0xea; + isKey = false; + } ResourceName resource; if (!KnownInfo.KnownResourceTable.TryGetValue(identifier, out resource)) +// resource = new ResourceName("???Resource" + identifier + "???"); throw new ArgumentException("Cannot find resource name " + identifier); - if (!isNotKey) + if (isKey) return new ResourceName(resource.Name + "Key"); return resource; } @@ -1554,7 +1562,9 @@ namespace Ricciolo.StylesExplorer.MarkupReflection object GetStaticResource(short identifier) { int keyIndex = Math.Max(0, currentKey - 1); - while (keyIndex >= 0 && !keys[keyIndex].HasStaticResources) + while (keyIndex > keys.Count) + keyIndex--; + while (keyIndex >= 0 && !keys[keyIndex].HasStaticResource(identifier)) keyIndex--; if (keyIndex >= 0 && identifier < keys[keyIndex].StaticResources.Count) return keys[keyIndex].StaticResources[(int)identifier];