Browse Source

enhanced resource decompilation

pull/259/merge
Ed Harvey 14 years ago
parent
commit
b60dbc74af
  1. 6
      ILSpy/Controls/ResourceStringTable.xaml.cs
  2. 8
      ILSpy/TreeNodes/ResourceNodes/ResourceEntryNode.cs
  3. 77
      ILSpy/TreeNodes/ResourceNodes/ResourcesFileTreeNode.cs

6
ILSpy/Controls/ResourceStringTable.xaml.cs

@ -23,13 +23,13 @@ namespace ICSharpCode.ILSpy.Controls
/// </summary> /// </summary>
public partial class ResourceStringTable : UserControl public partial class ResourceStringTable : UserControl
{ {
public ResourceStringTable(IEnumerable strings) public ResourceStringTable(IEnumerable strings,Size maxSize)
{ {
InitializeComponent(); InitializeComponent();
// set size to fit decompiler window // set size to fit decompiler window
// TODO: there should be a more transparent way to do this // TODO: there should be a more transparent way to do this
MaxWidth = MainWindow.Instance.mainPane.ActualWidth-20; MaxWidth = maxSize.Width;
MaxHeight = MainWindow.Instance.mainPane.ActualHeight-100; MaxHeight = maxSize.Height;
resourceListView.ItemsSource = strings; resourceListView.ItemsSource = strings;
} }

8
ILSpy/TreeNodes/ResourceNodes/ResourceEntryNode.cs

@ -68,9 +68,13 @@ namespace ICSharpCode.ILSpy.TreeNodes
foreach (var factory in App.CompositionContainer.GetExportedValues<IResourceNodeFactory>()) { foreach (var factory in App.CompositionContainer.GetExportedValues<IResourceNodeFactory>()) {
result = factory.CreateNode(key, data); result = factory.CreateNode(key, data);
if (result != null) if (result != null)
break; return result;
} }
return result ?? new ResourceEntryNode(key, data as Stream); var streamData = data as Stream;
if(streamData !=null)
result = new ResourceEntryNode(key, data as Stream);
return result;
} }
public override void Decompile(Language language, ITextOutput output, DecompilationOptions options) public override void Decompile(Language language, ITextOutput output, DecompilationOptions options)

77
ILSpy/TreeNodes/ResourceNodes/ResourcesFileTreeNode.cs

@ -48,10 +48,11 @@ namespace ICSharpCode.ILSpy.TreeNodes
return null; return null;
} }
} }
sealed class ResourcesFileTreeNode : ResourceTreeNode sealed class ResourcesFileTreeNode : ResourceTreeNode
{ {
ICollection<KeyValuePair<string, string>> filteredEntries = new ObservableCollection<KeyValuePair<string, string>>(); ICollection<KeyValuePair<string, string>> stringTableEntries = new ObservableCollection<KeyValuePair<string, string>>();
ICollection<KeyValuePair<string, string>> otherEntries = new ObservableCollection<KeyValuePair<string, string>>();
public ResourcesFileTreeNode(EmbeddedResource er) public ResourcesFileTreeNode(EmbeddedResource er)
: base(er) : base(er)
@ -78,30 +79,68 @@ namespace ICSharpCode.ILSpy.TreeNodes
return; return;
} }
foreach (DictionaryEntry entry in reader.Cast<DictionaryEntry>().OrderBy(e => e.Key.ToString())) { foreach (DictionaryEntry entry in reader.Cast<DictionaryEntry>().OrderBy(e => e.Key.ToString())) {
if (entry.Value is String) ProcessResourceEntry(entry);
filteredEntries.Add(new KeyValuePair<string, string>(entry.Key.ToString(), (string)entry.Value));
else if (entry.Value is byte[])
Children.Add(ResourceEntryNode.Create(entry.Key.ToString(), new MemoryStream((byte[])entry.Value)));
else
Children.Add(ResourceEntryNode.Create(entry.Key.ToString(), entry.Value));
} }
} }
} }
private void ProcessResourceEntry(DictionaryEntry entry)
{
var keyString = entry.Key.ToString();
if (entry.Value is String) {
stringTableEntries.Add(new KeyValuePair<string, string>(keyString, (string)entry.Value));
return;
}
if (entry.Value is byte[]) {
Children.Add(ResourceEntryNode.Create(keyString, new MemoryStream((byte[])entry.Value)));
return;
}
var node = ResourceEntryNode.Create(keyString, entry.Value);
if (node != null) {
Children.Add(node);
return;
}
if (entry.Value is System.Globalization.CultureInfo) {
otherEntries.Add(new KeyValuePair<string, string>(keyString, ((System.Globalization.CultureInfo)entry.Value).DisplayName));
} else {
otherEntries.Add(new KeyValuePair<string, string>(keyString, entry.Value.ToString()));
}
}
public override void Decompile(Language language, ITextOutput output, DecompilationOptions options) public override void Decompile(Language language, ITextOutput output, DecompilationOptions options)
{ {
EnsureLazyChildren();
base.Decompile(language, output, options); base.Decompile(language, output, options);
if (filteredEntries.Count == 0) if (stringTableEntries.Count != 0) {
return; ISmartTextOutput smartOutput = output as ISmartTextOutput;
ISmartTextOutput smartOutput = output as ISmartTextOutput; if (null != smartOutput) {
if (null != smartOutput) { smartOutput.AddUIElement(
smartOutput.AddUIElement( delegate {
delegate { return new ResourceStringTable(stringTableEntries,
return new ResourceStringTable(filteredEntries); new System.Windows.Size(MainWindow.Instance.mainPane.ActualWidth - 40,
} MainWindow.Instance.mainPane.ActualHeight - 100));
); }
);
}
output.WriteLine();
}
if (otherEntries.Count != 0) {
ISmartTextOutput smartOutput = output as ISmartTextOutput;
if (null != smartOutput) {
smartOutput.AddUIElement(
delegate {
return new ResourceStringTable(otherEntries,
new System.Windows.Size(MainWindow.Instance.mainPane.ActualWidth - 40,
MainWindow.Instance.mainPane.ActualHeight - 100));
}
);
}
output.WriteLine();
} }
output.WriteLine();
} }
} }
} }

Loading…
Cancel
Save