I\'m trying to make some kind of SFX: make a program generating a wrapping.exe around another wrapped.exe.
Wrapping.exe embed wrapped.exe as resource and, when executed,
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);
}
We just have to replace:
File.OpenRead(@"wrapped.ico")
with
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;
}
There is also online websites that do this job https://extracico.com/