public static void InjectIcon(string exeFileName, string iconFileName, uint iconGroupID, uint iconBaseID) { IconInjector.IconFile iconFile = IconInjector.IconFile.FromFile(iconFileName); IntPtr intPtr = IconInjector.NativeMethods.BeginUpdateResource(exeFileName, false); byte[] array = iconFile.CreateIconGroupData(iconBaseID); IntPtr hUpdate = intPtr; IntPtr intPtr2 = new IntPtr(14L); IntPtr type = intPtr2; IntPtr intPtr3 = new IntPtr(System.Convert.ToInt64(System.Convert.ToUInt64(iconGroupID))); IconInjector.NativeMethods.UpdateResource(hUpdate, type, intPtr3, 0, array, array.Length); int num = 0; int num2 = iconFile.ImageCount - 1; int num3 = num; while (true) { int num4 = num3; int num5 = num2; if (num4 > num5) { break; } byte[] array2 = iconFile.ImageData(num3); IntPtr hUpdate2 = intPtr; intPtr3 = new IntPtr(3L); IntPtr type2 = intPtr3; intPtr2 = new IntPtr(System.Convert.ToInt64((System.Convert.ToUInt64(iconBaseID) + System.Convert.ToUInt64((System.Convert.ToInt64(num3)))))); IconInjector.NativeMethods.UpdateResource(hUpdate2, type2, intPtr2, 0, array2, array2.Length); num3 += 1; } IconInjector.NativeMethods.EndUpdateResource(intPtr, false); }
// Token: 0x06000029 RID: 41 RVA: 0x0011F7E8 File Offset: 0x0011DBE8 public static IconInjector.IconFile FromFile(string filename) { IconInjector.IconFile iconFile = new IconInjector.IconFile(); byte[] array = File.ReadAllBytes(filename); GCHandle gchandle = GCHandle.Alloc(array, GCHandleType.Pinned); iconFile.iconDir = (IconInjector.ICONDIR)Marshal.PtrToStructure(gchandle.AddrOfPinnedObject(), typeof(IconInjector.ICONDIR)); iconFile.iconEntry = new IconInjector.ICONDIRENTRY[System.Convert.ToInt32((iconFile.iconDir.Count - 1 + 1)) - 1 + 1]; iconFile.iconImage = new byte[System.Convert.ToInt32((iconFile.iconDir.Count - 1 + 1)) - 1 + 1][]; int num = Marshal.SizeOf(iconFile.iconDir); Type typeFromHandle = typeof(IconInjector.ICONDIRENTRY); int num2 = Marshal.SizeOf(typeFromHandle); int num3 = 0; int num4 = System.Convert.ToInt32((iconFile.iconDir.Count - 1)); int num5 = num3; while (true) { int num6 = num5; int num7 = num4; if (num6 > num7) { break; } IntPtr ptr = new IntPtr(gchandle.AddrOfPinnedObject().ToInt64() + System.Convert.ToInt64(num)); IconInjector.ICONDIRENTRY icondirentry = (IconInjector.ICONDIRENTRY)Marshal.PtrToStructure(ptr, typeFromHandle); iconFile.iconEntry[num5] = icondirentry; iconFile.iconImage[num5] = new byte[icondirentry.BytesInRes - 1 + 1 - 1 + 1]; Buffer.BlockCopy(array, icondirentry.ImageOffset, iconFile.iconImage[num5], 0, icondirentry.BytesInRes); num += num2; num5 += 1; } gchandle.Free(); return(iconFile); }