Browse Source

Decompile contents of resource file nodes + non-Stream resources

pull/226/head
Ronny Klier 14 years ago
parent
commit
77c2411b6d
  1. 6
      ILSpy.BamlDecompiler/BamlResourceNodeFactory.cs
  2. 8
      ILSpy.sln
  3. 15
      ILSpy/TreeNodes/ResourceNodes/CursorResourceEntryNode.cs
  4. 2
      ILSpy/TreeNodes/ResourceNodes/IResourceNodeFactory.cs
  5. 18
      ILSpy/TreeNodes/ResourceNodes/ImageResourceEntryNode.cs
  6. 4
      ILSpy/TreeNodes/ResourceNodes/ResourceEntryNode.cs
  7. 10
      ILSpy/TreeNodes/ResourceNodes/ResourcesFileTreeNode.cs
  8. 6
      ILSpy/TreeNodes/ResourceNodes/XamlResourceNode.cs
  9. 10
      ILSpy/TreeNodes/ResourceNodes/XmlResourceNode.cs

6
ILSpy.BamlDecompiler/BamlResourceNodeFactory.cs

@ -18,10 +18,10 @@ namespace ILSpy.BamlDecompiler
return null; return null;
} }
public ILSpyTreeNode CreateNode(string key, Stream data) public ILSpyTreeNode CreateNode(string key, object data)
{ {
if (key.EndsWith(".baml", StringComparison.OrdinalIgnoreCase)) if (key.EndsWith(".baml", StringComparison.OrdinalIgnoreCase) && data is Stream)
return new BamlResourceEntryNode(key, data); return new BamlResourceEntryNode(key, (Stream)data);
else else
return null; return null;
} }

8
ILSpy.sln

@ -1,7 +1,7 @@
 
Microsoft Visual Studio Solution File, Format Version 11.00 Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010 # Visual Studio 2010
# SharpDevelop 4.1.0.7590-alpha # SharpDevelop 4.0.1.7126
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "doc", "doc", "{F45DB999-7E72-4000-B5AD-3A7B485A0896}" Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "doc", "doc", "{F45DB999-7E72-4000-B5AD-3A7B485A0896}"
ProjectSection(SolutionItems) = postProject ProjectSection(SolutionItems) = postProject
doc\Command Line.txt = doc\Command Line.txt doc\Command Line.txt = doc\Command Line.txt
@ -11,10 +11,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Debugger", "Debugger", "{89
ProjectSection(SolutionItems) = postProject ProjectSection(SolutionItems) = postProject
EndProjectSection EndProjectSection
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ILSpy.Debugger", "Debugger\ILSpy.Debugger\ILSpy.Debugger.csproj", "{6D3D0F0D-348D-456A-A6ED-E9BD5EFABB6A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Debugger.Core", "Debugger\Debugger.Core\Debugger.Core.csproj", "{1D18D788-F7EE-4585-A23B-34DC8EC63CB8}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Debugger.Core", "Debugger\Debugger.Core\Debugger.Core.csproj", "{1D18D788-F7EE-4585-A23B-34DC8EC63CB8}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ILSpy.Debugger", "Debugger\ILSpy.Debugger\ILSpy.Debugger.csproj", "{6D3D0F0D-348D-456A-A6ED-E9BD5EFABB6A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ILSpy", "ILSpy\ILSpy.csproj", "{1E85EFF9-E370-4683-83E4-8A3D063FF791}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ILSpy", "ILSpy\ILSpy.csproj", "{1E85EFF9-E370-4683-83E4-8A3D063FF791}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.TreeView", "SharpTreeView\ICSharpCode.TreeView.csproj", "{DDE2A481-8271-4EAC-A330-8FA6A38D13D1}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.TreeView", "SharpTreeView\ICSharpCode.TreeView.csproj", "{DDE2A481-8271-4EAC-A330-8FA6A38D13D1}"
@ -146,7 +146,7 @@ Global
HideSolutionNode = FALSE HideSolutionNode = FALSE
EndGlobalSection EndGlobalSection
GlobalSection(NestedProjects) = preSolution GlobalSection(NestedProjects) = preSolution
{1D18D788-F7EE-4585-A23B-34DC8EC63CB8} = {89C4A682-2706-44A3-ADDC-BC273164C37E}
{6D3D0F0D-348D-456A-A6ED-E9BD5EFABB6A} = {89C4A682-2706-44A3-ADDC-BC273164C37E} {6D3D0F0D-348D-456A-A6ED-E9BD5EFABB6A} = {89C4A682-2706-44A3-ADDC-BC273164C37E}
{1D18D788-F7EE-4585-A23B-34DC8EC63CB8} = {89C4A682-2706-44A3-ADDC-BC273164C37E}
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal

15
ILSpy/TreeNodes/ResourceNodes/CursorResourceEntryNode.cs

@ -40,11 +40,13 @@ namespace ICSharpCode.ILSpy.TreeNodes
return null; return null;
} }
public ILSpyTreeNode CreateNode(string key, Stream data) public ILSpyTreeNode CreateNode(string key, object data)
{ {
if (!(data is Stream))
return null;
foreach (string fileExt in imageFileExtensions) { foreach (string fileExt in imageFileExtensions) {
if (key.EndsWith(fileExt, StringComparison.OrdinalIgnoreCase)) if (key.EndsWith(fileExt, StringComparison.OrdinalIgnoreCase))
return new CursorResourceEntryNode(key, data); return new CursorResourceEntryNode(key, (Stream)data);
} }
return null; return null;
} }
@ -71,7 +73,14 @@ namespace ICSharpCode.ILSpy.TreeNodes
//HACK: windows imaging does not understand that .cur files have the same layout as .ico //HACK: windows imaging does not understand that .cur files have the same layout as .ico
// so load to data, and modify the ResourceType in the header to make look like an icon... // so load to data, and modify the ResourceType in the header to make look like an icon...
byte[] curData = ((MemoryStream)Data).ToArray(); MemoryStream s = Data as MemoryStream;
if (null == s)
{
// data was stored in another stream type (e.g. PinnedBufferedMemoryStream)
s = new MemoryStream();
Data.CopyTo(s);
}
byte[] curData = s.ToArray();
curData[2] = 1; curData[2] = 1;
using (Stream stream = new MemoryStream(curData)) { using (Stream stream = new MemoryStream(curData)) {
image.BeginInit(); image.BeginInit();

2
ILSpy/TreeNodes/ResourceNodes/IResourceNodeFactory.cs

@ -28,6 +28,6 @@ namespace ICSharpCode.ILSpy.TreeNodes
public interface IResourceNodeFactory public interface IResourceNodeFactory
{ {
ILSpyTreeNode CreateNode(Resource resource); ILSpyTreeNode CreateNode(Resource resource);
ILSpyTreeNode CreateNode(string key, Stream data); ILSpyTreeNode CreateNode(string key, object data);
} }
} }

18
ILSpy/TreeNodes/ResourceNodes/ImageResourceEntryNode.cs

@ -40,11 +40,25 @@ namespace ICSharpCode.ILSpy.TreeNodes
return null; return null;
} }
public ILSpyTreeNode CreateNode(string key, Stream data) public ILSpyTreeNode CreateNode(string key, object data)
{ {
if (data is System.Drawing.Icon)
{
MemoryStream s = new MemoryStream();
((System.Drawing.Icon)data).Save(s);
return new ImageResourceEntryNode(key, s);
}
else if (data is System.Drawing.Image)
{
MemoryStream s = new MemoryStream();
((System.Drawing.Image)data).Save(s, System.Drawing.Imaging.ImageFormat.Bmp);
return new ImageResourceEntryNode(key, s);
}
if (!(data is Stream))
return null;
foreach (string fileExt in imageFileExtensions) { foreach (string fileExt in imageFileExtensions) {
if (key.EndsWith(fileExt, StringComparison.OrdinalIgnoreCase)) if (key.EndsWith(fileExt, StringComparison.OrdinalIgnoreCase))
return new ImageResourceEntryNode(key, data); return new ImageResourceEntryNode(key, (Stream)data);
} }
return null; return null;
} }

4
ILSpy/TreeNodes/ResourceNodes/ResourceEntryNode.cs

@ -62,7 +62,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
this.data = data; this.data = data;
} }
public static ILSpyTreeNode Create(string key, Stream data) public static ILSpyTreeNode Create(string key, object data)
{ {
ILSpyTreeNode result = null; ILSpyTreeNode result = null;
foreach (var factory in App.CompositionContainer.GetExportedValues<IResourceNodeFactory>()) { foreach (var factory in App.CompositionContainer.GetExportedValues<IResourceNodeFactory>()) {
@ -70,7 +70,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
if (result != null) if (result != null)
break; break;
} }
return result ?? new ResourceEntryNode(key, data); return result ?? new ResourceEntryNode(key, data as Stream);
} }
public override void Decompile(Language language, ITextOutput output, DecompilationOptions options) public override void Decompile(Language language, ITextOutput output, DecompilationOptions options)

10
ILSpy/TreeNodes/ResourceNodes/ResourcesFileTreeNode.cs

@ -43,7 +43,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
return null; return null;
} }
public ILSpyTreeNode CreateNode(string key, Stream data) public ILSpyTreeNode CreateNode(string key, object data)
{ {
return null; return null;
} }
@ -78,12 +78,12 @@ 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 Stream) if (entry.Value is String)
Children.Add(ResourceEntryNode.Create(entry.Key.ToString(), (Stream)entry.Value)); filteredEntries.Add(new KeyValuePair<string, string>(entry.Key.ToString(), (string)entry.Value));
else if (entry.Value is byte[]) else if (entry.Value is byte[])
Children.Add(ResourceEntryNode.Create(entry.Key.ToString(), new MemoryStream((byte[])entry.Value))); Children.Add(ResourceEntryNode.Create(entry.Key.ToString(), new MemoryStream((byte[])entry.Value)));
else if (entry.Value is String) else
filteredEntries.Add(new KeyValuePair<string, string>(entry.Key.ToString(), (string)entry.Value)); Children.Add(ResourceEntryNode.Create(entry.Key.ToString(), entry.Value));
} }
} }
} }

6
ILSpy/TreeNodes/ResourceNodes/XamlResourceNode.cs

@ -35,10 +35,10 @@ namespace ICSharpCode.ILSpy.Xaml
return null; return null;
} }
public ILSpyTreeNode CreateNode(string key, Stream data) public ILSpyTreeNode CreateNode(string key, object data)
{ {
if (key.EndsWith(".xaml", StringComparison.OrdinalIgnoreCase)) if (key.EndsWith(".xaml", StringComparison.OrdinalIgnoreCase) && data is Stream)
return new XamlResourceEntryNode(key, data); return new XamlResourceEntryNode(key, (Stream)data);
else else
return null; return null;
} }

10
ILSpy/TreeNodes/ResourceNodes/XmlResourceNode.cs

@ -41,12 +41,16 @@ namespace ICSharpCode.ILSpy.Xaml
return null; return null;
} }
public ILSpyTreeNode CreateNode(string key, Stream data) public ILSpyTreeNode CreateNode(string key, object data)
{ {
if (!(data is Stream))
return null;
foreach (string fileExt in xmlFileExtensions) foreach (string fileExt in xmlFileExtensions)
{
if (key.EndsWith(fileExt, StringComparison.OrdinalIgnoreCase)) if (key.EndsWith(fileExt, StringComparison.OrdinalIgnoreCase))
return new XmlResourceEntryNode(key, data); return new XmlResourceEntryNode(key, (Stream)data);
return null; }
return null;
} }
} }

Loading…
Cancel
Save