Class IconExe


  • public class IconExe
    extends java.lang.Object
    Customize the icon of a Windows exe WARNING! This class is not part of SWT API. It is NOT API. It is an internal tool that may be changed or removed at anytime. Based on MSDN "An In-Depth Look into the Win32 Portable Executable File Format". Win x64 support (Bug #238001) based on MSDN "x64 Primer: Everything You Need To Know To Start Programming 64-Bit Windows Systems".
    • Constructor Detail

      • IconExe

        public IconExe()
    • Method Detail

      • main

        public static void main​(java.lang.String[] args)
                         throws java.lang.Exception
        Replace the Desktop icons provided in the Windows executable program with matching icons provided by the user. Takes 2 arguments argument 0: the Windows executable e.g c:/eclipse/eclipse.exe argument 1: The .ico file to write to the given executable e.g. c:/myApp.ico Note 1. Write access to the executable program is required. As a result, that program must not be currently running or edited elsewhere. Note 2. The Eclipse 3.4 launcher requires an .ico file with the following 7 images (in any order). 1. 48x48, 32 bit (RGB / Alpha Channel) 2. 32x32, 32 bit (RGB / Alpha Channel) 3. 16x16, 32 bit (RGB / Alpha Channel) 4. 48x48, 8 bit (256 colors) 5. 32x32, 8 bit (256 colors) 6. 24x24, 8 bit (256 colors) 7. 16x16, 8 bit (256 colors) A user icon matching exactly the width/height/depth of an executable icon will be written to the executable and will replace that executable icon. If an executable icon does not match a user icon, it is silently left as is. Note 3. This function modifies the content of the executable program and may cause its corruption.
        Throws:
        java.lang.Exception
      • loadIcons

        static IconExe.ImageData[] loadIcons​(java.lang.String program)
                                      throws java.io.FileNotFoundException,
                                             java.io.IOException
        Retrieve the Desktop icons provided in the Windows executable program. These icons are typically shown in various places of the Windows desktop. Note. The Eclipse 3.4 launcher returns the following 7 images (in any order). 1. 48x48, 32 bit (RGB / Alpha Channel) 2. 32x32, 32 bit (RGB / Alpha Channel) 3. 16x16, 32 bit (RGB / Alpha Channel) 4. 48x48, 8 bit (256 colors) 5. 32x32, 8 bit (256 colors) 6. 24x24, 8 bit (256 colors) 7. 16x16, 8 bit (256 colors)
        Parameters:
        program - the Windows executable e.g c:/eclipse/eclipse.exe
        Throws:
        java.io.FileNotFoundException
        java.io.IOException
      • unloadIcons

        static int unloadIcons​(java.lang.String program,
                               IconExe.ImageData[] icons)
                        throws java.io.FileNotFoundException,
                               java.io.IOException
        Replace the Desktop icons provided in the Windows executable program with icons provided by the user. Note 1. Write access to the executable program is required. As a result, that program must not be currently running or edited elsewhere. Note 2. Use loadIcons to determine which set of icons (width, height, depth) is required to replace the icons in the executable program. A user icon matching exactly the width/height/depth of an executable icon will be written to the executable and will replace that executable icon. If an executable icon does not match a user icon, it is left as is. Verify the return value matches the number of icons to write. Finally, use loadIcons after this operation to verify the icons have changed as expected. Note 3. The Eclipse 3.4 launcher requires the following 7 images (in any order). 1. 48x48, 32 bit (RGB / Alpha Channel) 2. 32x32, 32 bit (RGB / Alpha Channel) 3. 16x16, 32 bit (RGB / Alpha Channel) 4. 48x48, 8 bit (256 colors) 5. 32x32, 8 bit (256 colors) 6. 24x24, 8 bit (256 colors) 7. 16x16, 8 bit (256 colors) Note 4. This function modifies the content of the executable program and may cause its corruption.
        Parameters:
        program - the Windows executable e.g c:/eclipse/eclipse.exe
        icons - to write to the given executable
        Returns:
        the number of icons from the original program that were not successfully replaced (0 if success)
        Throws:
        java.io.FileNotFoundException
        java.io.IOException
      • getIcons

        IconExe.IconResInfo[] getIcons​(java.io.RandomAccessFile raf)
                                throws java.io.IOException
        Throws:
        java.io.IOException
      • dumpResourceDirectory

        void dumpResourceDirectory​(java.io.RandomAccessFile raf,
                                   int imageResourceDirectoryOffset,
                                   int resourceBase,
                                   int delta,
                                   int type,
                                   int level,
                                   boolean rt_icon_root)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • parseIcon

        static IconExe.ImageData parseIcon​(java.io.RandomAccessFile raf,
                                           int offset,
                                           int size)
                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • bitInvertData

        static byte[] bitInvertData​(byte[] data,
                                    int startIndex,
                                    int endIndex)
      • convertPad

        static final byte[] convertPad​(byte[] data,
                                       int width,
                                       int height,
                                       int depth,
                                       int pad,
                                       int newPad)
      • paletteFromBytes

        static IconExe.PaletteData paletteFromBytes​(byte[] bytes,
                                                    int numColors)
      • loadData

        static byte[] loadData​(IconExe.BITMAPINFOHEADER bih,
                               java.io.RandomAccessFile raf)
                        throws java.io.IOException
        Throws:
        java.io.IOException
      • flipScanLines

        static void flipScanLines​(byte[] data,
                                  int stride,
                                  int height)
      • loadData

        static byte[] loadData​(IconExe.BITMAPINFOHEADER bih,
                               java.io.RandomAccessFile raf,
                               int stride)
                        throws java.io.IOException
        Throws:
        java.io.IOException
      • unloadIcon

        static void unloadIcon​(java.io.RandomAccessFile raf,
                               IconExe.ImageData icon)
                        throws java.io.IOException
        Throws:
        java.io.IOException
      • unloadMaskData

        static void unloadMaskData​(java.io.RandomAccessFile raf,
                                   IconExe.ImageData icon)
      • unloadShapeData

        static void unloadShapeData​(java.io.RandomAccessFile raf,
                                    IconExe.ImageData icon)
      • readIconGroup

        static boolean readIconGroup​(java.io.RandomAccessFile raf,
                                     int offset,
                                     int size)
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • copyFile

        static void copyFile​(java.lang.String src,
                             java.lang.String dst)
                      throws java.io.FileNotFoundException,
                             java.io.IOException
        Throws:
        java.io.FileNotFoundException
        java.io.IOException
      • read

        static void read​(java.io.RandomAccessFile raf,
                         IconExe.BITMAPINFOHEADER bih)
                  throws java.io.IOException
        Throws:
        java.io.IOException
      • read

        static void read​(java.io.RandomAccessFile raf,
                         IconExe.BITMAPINFO bi)
                  throws java.io.IOException
        Throws:
        java.io.IOException
      • readU2

        static int readU2​(java.io.RandomAccessFile raf)
                   throws java.io.IOException
        Throws:
        java.io.IOException
      • read4

        static int read4​(java.io.RandomAccessFile raf)
                  throws java.io.IOException
        Throws:
        java.io.IOException
      • read8

        static long read8​(java.io.RandomAccessFile raf)
                   throws java.io.IOException
        Throws:
        java.io.IOException
      • write4

        static void write4​(java.io.RandomAccessFile raf,
                           int value)
                    throws java.io.IOException
        Throws:
        java.io.IOException
      • writeU2

        static void writeU2​(java.io.RandomAccessFile raf,
                            int value)
                     throws java.io.IOException
        Throws:
        java.io.IOException
      • read

        static void read​(java.io.RandomAccessFile raf,
                         IconExe.IMAGE_DOS_HEADER idh)
                  throws java.io.IOException
        Throws:
        java.io.IOException
      • read

        static void read​(java.io.RandomAccessFile raf,
                         IconExe.IMAGE_FILE_HEADER ifh)
                  throws java.io.IOException
        Throws:
        java.io.IOException
      • read

        static void read​(java.io.RandomAccessFile raf,
                         IconExe.IMAGE_DATA_DIRECTORY idd)
                  throws java.io.IOException
        Throws:
        java.io.IOException
      • read

        static void read​(java.io.RandomAccessFile raf,
                         IconExe.IMAGE_OPTIONAL_HEADER ioh)
                  throws java.io.IOException
        Throws:
        java.io.IOException
      • read

        static void read​(java.io.RandomAccessFile raf,
                         IconExe.IMAGE_NT_HEADERS inh)
                  throws java.io.IOException
        Throws:
        java.io.IOException
      • read

        static void read​(java.io.RandomAccessFile raf,
                         IconExe.IMAGE_SECTION_HEADER ish)
                  throws java.io.IOException
        Throws:
        java.io.IOException
      • read

        static void read​(java.io.RandomAccessFile raf,
                         IconExe.NEWHEADER nh)
                  throws java.io.IOException
        Throws:
        java.io.IOException
      • read

        static void read​(java.io.RandomAccessFile raf,
                         IconExe.ICONRESDIR i)
                  throws java.io.IOException
        Throws:
        java.io.IOException
      • read

        static void read​(java.io.RandomAccessFile raf,
                         IconExe.CURSORDIR c)
                  throws java.io.IOException
        Throws:
        java.io.IOException
      • read

        static void read​(java.io.RandomAccessFile raf,
                         IconExe.RESDIR rs)
                  throws java.io.IOException
        Throws:
        java.io.IOException