In a C# .Net application, is BinaryFormatter used to deserialize resource image data embedded in the application via .resx files and Resource Explorer?
I've been handed a .Net application and the task of eliminating the use of BinaryFormatter due to the security concerns inherent to BinaryFormatter. The original author used Visual Studio Resource Explorer to create .resx files and to embed bitmap image data (images for the GUI, etc..) into a library (dll), and that dll gets linked into the final application, a stand alone exe.
Inside the .resx file, the images are embedded like this:
<data name="MyImage" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\images\MyImage.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=1234567890ABCEF0</value>
</data>
Inside the auto-generated ResourcesDesigner.cs file, the images are extracted like this:
public static System.Drawing.Bitmap Captured {
get {
object obj = ResourceManager.GetObject("MyImage", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
Looking at the compiler output, this .resx file gets converted to a .resources file by CoreResGen, then that .resources file is embedded in the dll, which must be embedded in the exe because the exe is all by itself. My understanding is BinaryFormatter is not used when extracting this embedded resources data from the exe at runtime. Can anyone confirm that this is correct or not?
TypeConverterthat is able to convert the corresponding type tostringorbyte[], thenResourceManager(well, in factResXDataNodeunder the hood) uses the type converter rather than a formatter. ForBitmapinstances the parentImageclass specifies theImageConverterclass that can convert to and frombyte[].