// Decompiled with JetBrains decompiler // Type: Server.Classes.ResourceModifier // Assembly: Raton, Version=0.4.0.0, Culture=neutral, PublicKeyToken=null // MVID: 36C4E416-7F8D-4D23-930F-B5CCB0D810E7 // Assembly location: C:\Users\user\Desktop\v3.8.0 Deluxe Plugins (v4.0.0) cracked\Raton.exe using System; using System.IO; using System.Runtime.InteropServices; using System.Security; #nullable disable namespace Server.Classes; public static class ResourceModifier { public static void ChangeIcon(string exeFileName, string iconFileName) { ResourceModifier.InjectIcon(exeFileName, iconFileName, 1U, 1U); } public static void InjectIcon( string exeFileName, string iconFileName, uint iconGroupID, uint iconBaseID) { ResourceModifier.IconFile iconFile = ResourceModifier.IconFile.FromFile(iconFileName); IntPtr hUpdate = ResourceModifier.NativeMethods.BeginUpdateResource(exeFileName, false); byte[] iconGroupData = iconFile.CreateIconGroupData(iconBaseID); ResourceModifier.NativeMethods.UpdateResource(hUpdate, new IntPtr(14L), new IntPtr((long) iconGroupID), (short) 0, iconGroupData, iconGroupData.Length); for (int index = 0; index <= iconFile.ImageCount - 1; ++index) { byte[] data = iconFile.ImageData(index); ResourceModifier.NativeMethods.UpdateResource(hUpdate, new IntPtr(3L), new IntPtr((long) iconBaseID + (long) index), (short) 0, data, data.Length); } ResourceModifier.NativeMethods.EndUpdateResource(hUpdate, false); } [SuppressUnmanagedCodeSecurity] private class NativeMethods { [DllImport("kernel32")] public static extern IntPtr BeginUpdateResource(string fileName, [MarshalAs(UnmanagedType.Bool)] bool deleteExistingResources); [DllImport("kernel32")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool UpdateResource( IntPtr hUpdate, IntPtr type, IntPtr name, short language, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 5)] byte[] data, int dataSize); [DllImport("kernel32")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool EndUpdateResource(IntPtr hUpdate, [MarshalAs(UnmanagedType.Bool)] bool discard); } private struct ICONDIR { public ushort Reserved; public ushort Type; public ushort Count; } private struct ICONDIRENTRY { public byte Width; public byte Height; public byte ColorCount; public byte Reserved; public ushort Planes; public ushort BitCount; public int BytesInRes; public int ImageOffset; } private struct BITMAPINFOHEADER { public uint Size; public int Width; public int Height; public ushort Planes; public ushort BitCount; public uint Compression; public uint SizeImage; public int XPelsPerMeter; public int YPelsPerMeter; public uint ClrUsed; public uint ClrImportant; } [StructLayout(LayoutKind.Sequential, Pack = 2)] private struct GRPICONDIRENTRY { public byte Width; public byte Height; public byte ColorCount; public byte Reserved; public ushort Planes; public ushort BitCount; public int BytesInRes; public ushort ID; } private class IconFile { private ResourceModifier.ICONDIR iconDir; private ResourceModifier.ICONDIRENTRY[] iconEntry; private byte[][] iconImage; public int ImageCount => (int) this.iconDir.Count; public byte[] ImageData(int index) => this.iconImage[index]; public static ResourceModifier.IconFile FromFile(string filename) { ResourceModifier.IconFile iconFile = new ResourceModifier.IconFile(); byte[] src = File.ReadAllBytes(filename); GCHandle gcHandle = GCHandle.Alloc((object) src, GCHandleType.Pinned); iconFile.iconDir = (ResourceModifier.ICONDIR) Marshal.PtrToStructure(gcHandle.AddrOfPinnedObject(), typeof (ResourceModifier.ICONDIR)); iconFile.iconEntry = new ResourceModifier.ICONDIRENTRY[(int) iconFile.iconDir.Count]; iconFile.iconImage = new byte[(int) iconFile.iconDir.Count][]; int num1 = Marshal.SizeOf(iconFile.iconDir); Type type = typeof (ResourceModifier.ICONDIRENTRY); int num2 = Marshal.SizeOf(type); for (int index = 0; index <= (int) iconFile.iconDir.Count - 1; ++index) { ResourceModifier.ICONDIRENTRY structure = (ResourceModifier.ICONDIRENTRY) Marshal.PtrToStructure(new IntPtr(gcHandle.AddrOfPinnedObject().ToInt64() + (long) num1), type); iconFile.iconEntry[index] = structure; iconFile.iconImage[index] = new byte[structure.BytesInRes]; Buffer.BlockCopy((Array) src, structure.ImageOffset, (Array) iconFile.iconImage[index], 0, structure.BytesInRes); num1 += num2; } gcHandle.Free(); return iconFile; } public byte[] CreateIconGroupData(uint iconBaseID) { byte[] iconGroupData = new byte[Marshal.SizeOf(typeof (ResourceModifier.ICONDIR)) + Marshal.SizeOf(typeof (ResourceModifier.GRPICONDIRENTRY)) * this.ImageCount]; GCHandle gcHandle1 = GCHandle.Alloc((object) iconGroupData, GCHandleType.Pinned); Marshal.StructureToPtr(this.iconDir, gcHandle1.AddrOfPinnedObject(), false); int num = Marshal.SizeOf(this.iconDir); for (int index = 0; index <= this.ImageCount - 1; ++index) { ResourceModifier.GRPICONDIRENTRY structure = new ResourceModifier.GRPICONDIRENTRY(); ResourceModifier.BITMAPINFOHEADER bitmapinfoheader = new ResourceModifier.BITMAPINFOHEADER(); GCHandle gcHandle2 = GCHandle.Alloc((object) bitmapinfoheader, GCHandleType.Pinned); Marshal.Copy(this.ImageData(index), 0, gcHandle2.AddrOfPinnedObject(), Marshal.SizeOf(typeof (ResourceModifier.BITMAPINFOHEADER))); gcHandle2.Free(); structure.Width = this.iconEntry[index].Width; structure.Height = this.iconEntry[index].Height; structure.ColorCount = this.iconEntry[index].ColorCount; structure.Reserved = this.iconEntry[index].Reserved; structure.Planes = bitmapinfoheader.Planes; structure.BitCount = bitmapinfoheader.BitCount; structure.BytesInRes = this.iconEntry[index].BytesInRes; structure.ID = Convert.ToUInt16((long) iconBaseID + (long) index); Marshal.StructureToPtr(structure, new IntPtr(gcHandle1.AddrOfPinnedObject().ToInt64() + (long) num), false); num += Marshal.SizeOf(typeof (ResourceModifier.GRPICONDIRENTRY)); } gcHandle1.Free(); return iconGroupData; } } }