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

8
ILSpy/TreeNodes/ResourceNodes/ResourceEntryNode.cs

@ -68,9 +68,13 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -68,9 +68,13 @@ namespace ICSharpCode.ILSpy.TreeNodes
foreach (var factory in App.CompositionContainer.GetExportedValues<IResourceNodeFactory>()) {
result = factory.CreateNode(key, data);
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)

77
ILSpy/TreeNodes/ResourceNodes/ResourcesFileTreeNode.cs

@ -48,10 +48,11 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -48,10 +48,11 @@ namespace ICSharpCode.ILSpy.TreeNodes
return null;
}
}
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)
: base(er)
@ -78,30 +79,68 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -78,30 +79,68 @@ namespace ICSharpCode.ILSpy.TreeNodes
return;
}
foreach (DictionaryEntry entry in reader.Cast<DictionaryEntry>().OrderBy(e => e.Key.ToString())) {
if (entry.Value is String)
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));
ProcessResourceEntry(entry);
}
}
}
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)
{
EnsureLazyChildren();
base.Decompile(language, output, options);
if (filteredEntries.Count == 0)
return;
ISmartTextOutput smartOutput = output as ISmartTextOutput;
if (null != smartOutput) {
smartOutput.AddUIElement(
delegate {
return new ResourceStringTable(filteredEntries);
}
);
if (stringTableEntries.Count != 0) {
ISmartTextOutput smartOutput = output as ISmartTextOutput;
if (null != smartOutput) {
smartOutput.AddUIElement(
delegate {
return new ResourceStringTable(stringTableEntries,
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