Extract icon from executable file that is in memory

Does anyone know an API function to extract an icon resource from an executable file that is located in RAM (inside, say, a MemoryStream)?

All the icon highlighting features that I have seen so far depend on the executable file present on the disk. I would like to extract the icon without having to write exe to a temporary file and then load resources from it.

+3
source share
2 answers

This is never a real problem. Windows has a strict requirement that the executable file be a file on disk. You cannot start the process otherwise. Since you still have to write the file to disk, you will never have a problem retrieving resources from it using an API that requires a file path.

0
source

if we are talking about using the icon from an existing Reflector DLL function

http://www.red-gate.com/products/reflector/

to open the DLL and right-click on the icon with the right mouse button and click "Save As" this can also be done using code

Assembly myAssembly = Assembly.Load("SampleAssembly, Version=1.0.2004.0, Culture=neutral, PublicKeyToken=8744b20f8da049e3");
Stream myStream = myAssembly.GetManifestResourceStream( "MyNamespace.SubFolder.MyImage.bmp" );
Bitmap bmp = new Bitmap( myStream );

Best regards, Jordan

0
source

Source: https://habr.com/ru/post/1728930/


All Articles