When I searched on Google, I found a useful class that allowed us to change the icon of any .exe using the following line of code:
WindowsFormsApplication1.IconInjector.InjectIcon("myfile.exe", "myicon.ico", 200, 1);
If 200 and 1 correspond to the GroupID icon and the BaseID icon, which I can determine with the Resource Hacker. In this case, the file icon changes successfully without damaging the file.
So, I planned to use this class in my program, which is the defender of SFX / Software, the output file always does not have an icon, everything that I can see in the resource hacker is below:

I can not see the identifier of the group of identifiers and the identifier of the base, in any case (I do not know what to put instead of 200 and 1 in this case). Therefore, I tried to change the icon using the same line of code as above, I used the following line of code (same as above):
WindowsFormsApplication1.IconInjector.InjectIcon("myfile.exe", "myicon.ico", 200, 1);
The file icon was successfully changed, but the file no longer works!
When I tried to open the file using ResourceHacker, I found the following:

It seems that icon resources have been successfully added, but I can’t understand why the file no longer works, it seems to be damaged.

Any help would be appreciated.
Note. I tried to use this class with an unprotected file, and it works like a charm!
The class I'm using is below:
// IconInjector.cs using System; using System.Runtime.InteropServices; using System.Diagnostics; namespace WindowsFormsApplication1 { /// <summary> /// IconInjectorクラスの定義/// </summary> public class IconInjector { [DllImport("kernel32.dll", SetLastError = true)] //static extern bool UpdateResource(IntPtr hUpdate, string lpType, string lpName, ushort wLanguage, IntPtr lpData, uint cbData); static extern int UpdateResource(IntPtr hUpdate, uint lpType, uint lpName, ushort wLanguage, byte[] lpData, uint cbData); [DllImport("kernel32.dll", SetLastError = true)] static extern IntPtr BeginUpdateResource(string pFileName, [MarshalAs(UnmanagedType.Bool)]bool bDeleteExistingResources); [DllImport("kernel32.dll", SetLastError = true)] static extern bool EndUpdateResource(IntPtr hUpdate, bool fDiscard); /// <summary> /// アプリケーションのメイン エントリ ポイントです。 /// </summary> [STAThread] public static void InjectIcon(string execFileName, string iconFileName, uint iconGroupID, uint iconBaseID) { const uint RT_ICON = 3; const uint RT_GROUP_ICON = 14; // アイコンファイルの読み込みIconFile iconFile = new IconFile(); iconFile.Load(iconFileName); // リソースの更新開始IntPtr hUpdate = BeginUpdateResource(execFileName, false); Debug.Assert(hUpdate != IntPtr.Zero); // RT_GROUP_ICON 書き込みbyte[] data = iconFile.CreateIconGroupData(iconBaseID); UpdateResource(hUpdate, RT_GROUP_ICON, iconGroupID, 0, data, (uint)data.Length); // RT_ICON書き込みfor (int i = 0; i < iconFile.GetImageCount(); i++) { byte[] image = iconFile.GetImageData(i); UpdateResource(hUpdate, RT_ICON, (uint)(iconBaseID + i), 0, image, (uint)image.Length); } // リソースの更新終了EndUpdateResource(hUpdate, false); } } }
Any help or suggestion on adding an icon to a protected file without corrupting it?