Class IconExe
- java.lang.Object
-
- org.eclipse.pde.internal.swt.tools.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".
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
IconExe.BITMAPINFO
static class
IconExe.BITMAPINFOHEADER
static class
IconExe.CURSORDIR
static class
IconExe.FileFormat
static class
IconExe.ICONRESDIR
static class
IconExe.IconResInfo
static class
IconExe.IMAGE_DATA_DIRECTORY
static class
IconExe.IMAGE_DOS_HEADER
static class
IconExe.IMAGE_FILE_HEADER
static class
IconExe.IMAGE_NT_HEADERS
static class
IconExe.IMAGE_OPTIONAL_HEADER
static class
IconExe.IMAGE_RESOURCE_DATA_ENTRY
static class
IconExe.IMAGE_RESOURCE_DIRECTORY
static class
IconExe.IMAGE_RESOURCE_DIRECTORY_ENTRY
static class
IconExe.IMAGE_SECTION_HEADER
(package private) static class
IconExe.ImageData
(package private) static class
IconExe.ImageLoader
(package private) static class
IconExe.LEDataInputStream
static class
IconExe.NEWHEADER
(package private) static class
IconExe.PaletteData
static class
IconExe.RESDIR
(package private) static class
IconExe.RGB
(package private) static class
IconExe.RGBQUAD
(package private) static class
IconExe.SWT
(package private) static class
IconExe.WinBMPFileFormat
(package private) static class
IconExe.WinICOFileFormat
-
Field Summary
Fields Modifier and Type Field Description (package private) static int
BMPHeaderFixedSize
(package private) static boolean
DEBUG
(package private) int
iconCnt
(package private) IconExe.IconResInfo[]
iconInfo
(package private) static int
IMAGE_DIRECTORY_ENTRY_RESOURCE
(package private) static int
IMAGE_DOS_SIGNATURE
(package private) static int
IMAGE_NT_OPTIONAL_HDR32_MAGIC
(package private) static int
IMAGE_NT_OPTIONAL_HDR64_MAGIC
(package private) static int
IMAGE_NT_SIGNATURE
(package private) static int
RES_ICON
(package private) static int
RT_GROUP_ICON
(package private) static int
RT_ICON
static java.lang.String
VERSION
-
Constructor Summary
Constructors Constructor Description IconExe()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) static byte[]
bitInvertData(byte[] data, int startIndex, int endIndex)
(package private) static byte[]
convertPad(byte[] data, int width, int height, int depth, int pad, int newPad)
(package private) static void
copyFile(java.lang.String src, java.lang.String dst)
(package private) void
dumpResourceDirectory(java.io.RandomAccessFile raf, int imageResourceDirectoryOffset, int resourceBase, int delta, int type, int level, boolean rt_icon_root)
(package private) static void
flipScanLines(byte[] data, int stride, int height)
(package private) IconExe.IconResInfo[]
getIcons(java.io.RandomAccessFile raf)
(package private) static byte[]
loadData(IconExe.BITMAPINFOHEADER bih, java.io.RandomAccessFile raf)
(package private) static byte[]
loadData(IconExe.BITMAPINFOHEADER bih, java.io.RandomAccessFile raf, int stride)
(package private) static IconExe.ImageData[]
loadIcons(java.lang.String program)
Retrieve the Desktop icons provided in the Windows executable program.(package private) static IconExe.PaletteData
loadPalette(IconExe.BITMAPINFOHEADER bih, java.io.RandomAccessFile raf)
static void
main(java.lang.String[] args)
Replace the Desktop icons provided in the Windows executable program with matching icons provided by the user.(package private) static IconExe.PaletteData
paletteFromBytes(byte[] bytes, int numColors)
(package private) static byte[]
paletteToBytes(IconExe.PaletteData pal)
(package private) static IconExe.ImageData
parseIcon(java.io.RandomAccessFile raf, int offset, int size)
(package private) static void
read(java.io.RandomAccessFile raf, IconExe.BITMAPINFO bi)
(package private) static void
read(java.io.RandomAccessFile raf, IconExe.BITMAPINFOHEADER bih)
(package private) static void
read(java.io.RandomAccessFile raf, IconExe.CURSORDIR c)
(package private) static void
read(java.io.RandomAccessFile raf, IconExe.ICONRESDIR i)
(package private) static void
read(java.io.RandomAccessFile raf, IconExe.IMAGE_DATA_DIRECTORY idd)
(package private) static void
read(java.io.RandomAccessFile raf, IconExe.IMAGE_DOS_HEADER idh)
(package private) static void
read(java.io.RandomAccessFile raf, IconExe.IMAGE_FILE_HEADER ifh)
(package private) static void
read(java.io.RandomAccessFile raf, IconExe.IMAGE_NT_HEADERS inh)
(package private) static void
read(java.io.RandomAccessFile raf, IconExe.IMAGE_OPTIONAL_HEADER ioh)
(package private) static void
read(java.io.RandomAccessFile raf, IconExe.IMAGE_RESOURCE_DATA_ENTRY irde)
(package private) static void
read(java.io.RandomAccessFile raf, IconExe.IMAGE_RESOURCE_DIRECTORY ird)
(package private) static void
read(java.io.RandomAccessFile raf, IconExe.IMAGE_RESOURCE_DIRECTORY_ENTRY irde)
(package private) static void
read(java.io.RandomAccessFile raf, IconExe.IMAGE_SECTION_HEADER ish)
(package private) static void
read(java.io.RandomAccessFile raf, IconExe.NEWHEADER nh)
(package private) static void
read(java.io.RandomAccessFile raf, IconExe.RESDIR rs)
(package private) static int
read4(java.io.RandomAccessFile raf)
(package private) static long
read8(java.io.RandomAccessFile raf)
(package private) static boolean
readIconGroup(java.io.RandomAccessFile raf, int offset, int size)
(package private) static int
readU2(java.io.RandomAccessFile raf)
(package private) static void
unloadIcon(java.io.RandomAccessFile raf, IconExe.ImageData icon)
(package private) static int
unloadIcons(java.lang.String program, IconExe.ImageData[] icons)
Replace the Desktop icons provided in the Windows executable program with icons provided by the user.(package private) static void
unloadMaskData(java.io.RandomAccessFile raf, IconExe.ImageData icon)
(package private) static void
unloadShapeData(java.io.RandomAccessFile raf, IconExe.ImageData icon)
(package private) static void
write4(java.io.RandomAccessFile raf, int value)
(package private) static void
writeU2(java.io.RandomAccessFile raf, int value)
-
-
-
Field Detail
-
VERSION
public static final java.lang.String VERSION
- See Also:
- Constant Field Values
-
DEBUG
static final boolean DEBUG
- See Also:
- Constant Field Values
-
iconInfo
IconExe.IconResInfo[] iconInfo
-
iconCnt
int iconCnt
-
IMAGE_DOS_SIGNATURE
static final int IMAGE_DOS_SIGNATURE
- See Also:
- Constant Field Values
-
IMAGE_NT_SIGNATURE
static final int IMAGE_NT_SIGNATURE
- See Also:
- Constant Field Values
-
IMAGE_DIRECTORY_ENTRY_RESOURCE
static final int IMAGE_DIRECTORY_ENTRY_RESOURCE
- See Also:
- Constant Field Values
-
RES_ICON
static final int RES_ICON
- See Also:
- Constant Field Values
-
RT_ICON
static final int RT_ICON
- See Also:
- Constant Field Values
-
RT_GROUP_ICON
static final int RT_GROUP_ICON
- See Also:
- Constant Field Values
-
BMPHeaderFixedSize
static final int BMPHeaderFixedSize
- See Also:
- Constant Field Values
-
IMAGE_NT_OPTIONAL_HDR64_MAGIC
static final int IMAGE_NT_OPTIONAL_HDR64_MAGIC
- See Also:
- Constant Field Values
-
IMAGE_NT_OPTIONAL_HDR32_MAGIC
static final int IMAGE_NT_OPTIONAL_HDR32_MAGIC
- See Also:
- Constant Field Values
-
-
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.exeicons
- 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)
-
loadPalette
static IconExe.PaletteData loadPalette(IconExe.BITMAPINFOHEADER bih, java.io.RandomAccessFile raf) throws java.io.IOException
- Throws:
java.io.IOException
-
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
-
paletteToBytes
static byte[] paletteToBytes(IconExe.PaletteData pal)
-
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.IMAGE_RESOURCE_DIRECTORY ird) throws java.io.IOException
- Throws:
java.io.IOException
-
read
static void read(java.io.RandomAccessFile raf, IconExe.IMAGE_RESOURCE_DIRECTORY_ENTRY irde) throws java.io.IOException
- Throws:
java.io.IOException
-
read
static void read(java.io.RandomAccessFile raf, IconExe.IMAGE_RESOURCE_DATA_ENTRY irde) 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
-
-