Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7666965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:58:30+00:00 2026-05-31T14:58:30+00:00

When I was searching on Google I found a useful class which let us

  • 0

When I was searching on Google I found a useful class which let us change the icon of any .exe file using the following line of code :

WindowsFormsApplication1.IconInjector.InjectIcon("myfile.exe", "myicon.ico", 200, 1);

Where 200 and 1 are respectively icon GroupID and icon BaseID which I can determine using Resource Hacker. In this case the file’s icon changes successfully without corrupting the file.

So i planned to use this class on my program which is a SFX / Software protector, the output file always hasn’t an icon, all what I can see on Resource hacker is the below :

Resource Hacker view of PuTTY_Protected.exe prechange

i can’t see icon group id nor the base id, anyway, (I don’t know what to put instead of 200 and 1 in this case) So I tried to change the icon using the same line of code mentioned 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 doesn’t work anymore!

When I tried to reopen the file using ResourceHacker, I found the below:

Resource Hacker view of PuTTY_Protected.exe after change

It seems that the icon resources were successfully added, but i can’t figure out why the file doesn’t work anymore, it seems that is corrupted.

PuTTY_protected.exe has stopped working

Any help would be appreciated.

Note : I tried using this class with unprotected file and it works like a charm!

The class I am using is the 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 the icon to the protected file without corrupting it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T14:58:32+00:00Added an answer on May 31, 2026 at 2:58 pm

    It sounds like the protection application is verifying that the contents of the file haven’t been tampered with. Injecting an icon is definitely a form of tampering, and unless the protection software is updated to ignore it, it will always fail. Alternatively if you own the protection software you could update it to not strip the icons.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After some searching on Google and here, I still haven't found any answer to
I have been searching around using Google but I can't find an answer to
I am searching for a program like Google Analytics or Clicky which runs on
I was searching through google about Microsoft Component Object Model. Found only few normal
sorry, I did not find something useful when searching google. Very basic question, mainly
I want to use Ninject 2 on Castle Monorail. Searching on google, I found
I need to handle another windows application programatically, searching google I found a sample
i got a script after searching google for Edit Image FaceBook Style but found
i'm looking for implement datagrid with CI, better if using ajax. Searching on Google
I was searching Google and found some code that implements a jQuery lazy load

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.