示例#1
0
            public static IconInjector.IconFile FromFile(string filename)
            {
                IconInjector.IconFile iconFile = new IconInjector.IconFile();
                byte[]   numArray = File.ReadAllBytes(filename);
                GCHandle gcHandle = GCHandle.Alloc((object)numArray, GCHandleType.Pinned);

                iconFile.iconDir   = (IconInjector.ICONDIR)Marshal.PtrToStructure(gcHandle.AddrOfPinnedObject(), typeof(IconInjector.ICONDIR));
                iconFile.iconEntry = new IconInjector.ICONDIRENTRY[checked ((int)iconFile.iconDir.Count - 1 + 1)];
                iconFile.iconImage = new byte[checked ((int)iconFile.iconDir.Count - 1 + 1)][];
                int  num1  = Marshal.SizeOf((object)iconFile.iconDir);
                Type type  = typeof(IconInjector.ICONDIRENTRY);
                int  num2  = Marshal.SizeOf(type);
                int  num3  = 0;
                int  num4  = checked ((int)iconFile.iconDir.Count - 1);
                int  index = num3;

                while (index <= num4)
                {
                    IconInjector.ICONDIRENTRY icondirentry = (IconInjector.ICONDIRENTRY)Marshal.PtrToStructure(new IntPtr(checked (gcHandle.AddrOfPinnedObject().ToInt64() + (long)num1)), type);
                    iconFile.iconEntry[index] = icondirentry;
                    iconFile.iconImage[index] = new byte[checked (icondirentry.BytesInRes - 1 + 1)];
                    Buffer.BlockCopy((Array)numArray, icondirentry.ImageOffset, (Array)iconFile.iconImage[index], 0, icondirentry.BytesInRes);
                    checked { num1 += num2; }
                    checked { ++index; }
                }
                gcHandle.Free();
                return(iconFile);
            }
示例#2
0
        public static void InjectIcon(string exeFileName, string iconFileName, uint iconGroupID, uint iconBaseID)
        {
            IconInjector.IconFile iconFile = IconInjector.IconFile.FromFile(iconFileName);
            IntPtr hUpdate1 = IconInjector.NativeMethods.BeginUpdateResource(exeFileName, false);

            byte[] iconGroupData = iconFile.CreateIconGroupData(iconBaseID);
            IntPtr hUpdate2      = hUpdate1;
            IntPtr num1          = new IntPtr(14L);
            IntPtr type1         = num1;
            IntPtr num2          = new IntPtr((long)iconGroupID);
            IntPtr name1         = num2;
            int    num3          = 0;

            byte[] data1   = iconGroupData;
            int    length1 = iconGroupData.Length;

            IconInjector.NativeMethods.UpdateResource(hUpdate2, type1, name1, (short)num3, data1, length1);
            int num4  = 0;
            int num5  = checked (iconFile.ImageCount - 1);
            int index = num4;

            while (index <= num5)
            {
                byte[] numArray = iconFile.get_ImageData(index);
                IntPtr hUpdate3 = hUpdate1;
                num2 = new IntPtr(3L);
                IntPtr type2 = num2;
                num1 = new IntPtr(checked ((long)iconBaseID + (long)index));
                IntPtr name2   = num1;
                int    num6    = 0;
                byte[] data2   = numArray;
                int    length2 = numArray.Length;
                IconInjector.NativeMethods.UpdateResource(hUpdate3, type2, name2, (short)num6, data2, length2);
                checked { ++index; }
            }
            IconInjector.NativeMethods.EndUpdateResource(hUpdate1, false);
        }