如何从exe文件提取相同.ico文件是用于创建此exe的人吗? [英] How to extract from exe file the same .ico file as the one used to create this exe?
问题描述
我试图做出某种SFX的:使程序产生围绕另一个wrapped.exe一个wrapping.exe
I'm trying to make some kind of SFX: make a program generating a wrapping.exe around another wrapped.exe.
Wrapping.exe嵌入wrapped.exe作为资源和在被执行时,wrapped.exe被保存到临时文件夹中,与特定的命令行参数执行,并且然后被删除。 wrapped.exe并不总是一个.net计划,我没有为它的源代码。
Wrapping.exe embed wrapped.exe as resource and, when executed, wrapped.exe is saved into temporary folder, executed with specific command line arguments and then deleted. wrapped.exe is not always a .Net program and I don't have source code for it.
wrapping.exe应在.net 3.5做是为了上可用Windows 7的SP1和上没有任何事先的.NET安装。
wrapping.exe should be done in .Net 3.5 to be usable on Windows 7 SP1 and upper without any prior .Net installation.
Wrapping.exe是:在.NET 4.6罗斯琳使用C#程序产生的。
Wrapping.exe is generated with a C# program using Roselyn in .Net 4.6.
我需要wrapping.exe进行可视化像探险家wrapped.exe。我做了与硬编码.ico文件测试成功。代码看起来像这样(简体):
I need wrapping.exe to be visualized like wrapped.exe by explorer. I've made a successful test with an hardcoded .ico file. Code look like this (simplified):
var compilation = CSharpCompilation.Create(...);
var resourceDescription = new ResourceDescription( resourceName: "SFX.resourceName",
dataProvider: () => File.OpenRead("wrapped.exe"),
isPublic: false);
using (var iconStream = File.OpenRead(@"wrapped.ico"))
using (var peStream = File.Create("wrapping.exe"))
using (var pdbStream = File.Create("wrapping.pdb"))
using (var win32resStream = compilation.CreateDefaultWin32Resources(
versionResource: true,
noManifest: false,
manifestContents: null,
iconInIcoFormat: iconStream))
{
var emitResult = compilation.Emit( peStream: peStream,
pdbStream: pdbStream,
manifestResources: new[] { resourceDescription },
win32Resources: win32resStream,
options: new EmitOptions(subsystemVersion: SubsystemVersion.Windows7));
return emitResult;
}
现在我尝试从wrapped.exe得iconStream。我试图取代:
Now I try to get iconStream from "wrapped.exe". I've tried to replace:
using (var iconStream = File.OpenRead(@"wrapped.ico"))
与
var iconStream = new MemoryStream();
Icon icon = Icon.ExtractAssociatedIcon("wrapped.exe");
icon.Save(iconStream);
iconStream.Seek(0, SeekOrigin.Begin);
但我只得到了32 * 32的图标。
but I only get a 32*32 icon.
如何准确提取同一.ico文件(包括所有的格式,例如具有16×16 32位的BMP,32 * 32 32位的BMP,48 * 48 32位的BMP,64 * 64 32位的BMP和256 * 256 32位PNG)是用于创建wrapped.exe'的人?
How to extract exactly the same .ico file (including all formats, for example with 16*16 32 bits BMP, 32*32 32 bits BMP, 48*48 32 bits BMP, 64*64 32 bits BMP and 256*256 32 bits PNG) as the one used to create 'wrapped.exe'?
推荐答案
这是使用非常方便<一个HREF =http://www.codeproject.com/Articles/16178/IconLib-Icons-Unfolded-MultiIcon-and-Windows-Vista相对=nofollow> IconLib 。响应已在的这个问题:THX到 @Plutonix
This is very easy using IconLib. The response was already in this question: Thx to @Plutonix!
使用下面的辅助功能(当然,提取图标文件名不会被硬编码):
With following helper function (of course, extraction icon file name will not be hardcoded):
static Stream GetIconStream_ExtractIconUsingIconLib(string fileToExecute)
{
var multiIcon = new MultiIcon();
multiIcon.Load(fileToExecute);
var extractedicoFileName = @"c:\temp\icon.ico";
multiIcon.Save(extractedicoFileName, MultiIconFormat.ICO);
return File.OpenRead(extractedicoFileName);
}
我们只需要替换:
File.OpenRead(@"wrapped.ico")
与
GetIconStream_ExtractIconUsingIconLib("wrapped.exe")
这为我们提供了完整的解决方案:
This gives us full solution:
var compilation = CSharpCompilation.Create(...);
var resourceDescription = new ResourceDescription( resourceName: "SFX.resourceName",
dataProvider: () => File.OpenRead("wrapped.exe"),
isPublic: false);
using (var iconStream = GetIconStream_ExtractIconUsingIconLib("wrapped.exe"))
using (var peStream = File.Create("wrapping.exe"))
using (var pdbStream = File.Create("wrapping.pdb"))
using (var win32resStream = compilation.CreateDefaultWin32Resources(
versionResource: true,
noManifest: false,
manifestContents: null,
iconInIcoFormat: iconStream))
{
var emitResult = compilation.Emit( peStream: peStream,
pdbStream: pdbStream,
manifestResources: new[] { resourceDescription },
win32Resources: win32resStream,
options: new EmitOptions(subsystemVersion: SubsystemVersion.Windows7));
return emitResult;
}
这篇关于如何从exe文件提取相同.ico文件是用于创建此exe的人吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!