2 Attachment(s)
[vb6] Patch Icon/Cursor Resource File Entries
Revised 24 Oct 17. Revamped to allow user to modify values and/or auto-correcting if desired.
The Resource Editor (ResEditor) in VB can corrupt icon/cursor group data. The corruption is minimal, except PNG-encoded related entries. This corruption should not harm anything except in rare scenarios. Typically, you can expect no harm in these scenarios:
1. The icon/cursor files you add to the resource file via ResEdit only contain one image
2. When the file contains multiple images and all images are square (width = height)
However, this 'corruption' does result in reporting icon/cursor heights and cursor bit depths incorrectly. When multiple images exist for the icon/cursor, there is a potential that Windows will select the wrong image when using resource-related APIs: LoadImage, LookupIconIdFromDirectoryEx, etc.
Examples of corruption:
1. A 32x32 icon is reported as shown. The correct values are to the right, in blue
Width 32 32
Height 64 32
2. A 128x128 icon is reported as shown. The correct values are to the right, in blue
Width 128 128
Height 0 128
3. A 32x32 cursor is reported as shown. The correct values are to the right, in blue
Width 32 32
Height 32 64
Planes 0 1
BitCount 0 4
4. A 128x128 PNG-encoded icon is reported as shown. The correct values are to the right, in blue
Width 0 128
Height 0 128
Planes 18505 1
BitCount 21060 32
Note. After scanning/comparing dozens upon dozens of Windows executables/DLLs and extracting icon/cursor information, it is clear that the ResEditor utility fails to fill the group data correctly. Not surprisingly, icon/cursor group data extracted from vb6.exe, itself, is correctly filled.
This utility will read a VB resource file (.res) and scan the icons/cursors. If any discrepancies are found, they will be displayed. You'll have the option of correcting them and rewriting the res file or saving the updates to a different res file. Might want to consider running this against your res file before you compile your app?
Point to take home. If you only use your resource file's Icons/Cursors section to store single-image icons/cursors, this tool really doesn't help you.
Attachment 153049
Re: [vb6] Patch Icon/Cursor Resource File Entries
Just FYI. The Icon Directory Entry within a resource is slightly different than what you'd see in an icon/cursor file. In a resource the structure is 14 bytes whereas in a file, it is 16 bytes. And the content between the two is also a bit different.
Resource Icons 14 byte structure
1 byte for width (actual)
1 byte for height (actual)
1 byte for color count
1 reserved byte
2 bytes for planes
2 bytes for bit count/depth
4 bytes for image data size
2 bytes for a numerical ID
Resource Cursors 14 byte structure
2 bytes for width (actual)
2 bytes for height (actual height doubled)
2 bytes for planes
2 bytes for bit count/depth
4 bytes for image data size
2 bytes for a numerical ID
Icon/Cursor File 16 byte structure
1 byte for width (actual)
1 byte for height (actual)
1 byte for color count
1 reserved byte
2 bytes for planes (icons) else 2 bytes for cursor X hotspot
2 bytes for bit count/depth (icons) else 2 bytes for cursor Y hotspot
4 bytes for image data size
4 bytes for offset into file where image data starts
The only thing I am not 100% sure on is whether cursors greater than 255 pixels would be entered in the structure as 256+ or 0 as is the case with icons. Since 256x256 and larger cursors are not commonplace, kinda hard to find a true example. If I can find such a credible example, the attached project may need to be tweaked for that specific case.
Edited: Wrote a quick script to process all binaries in the system32 folder. Found two dlls, ExplorerFrame.dll & comctl32.dll, that have cursors of 128x128. The heights (doubled) were written as 256, not zero. I tweaked the attached project to write large cursors using the same logic.
Re: [vb6] Patch Icon/Cursor Resource File Entries
Completely revamped the project. Again, as stated in post #1, if you only use the icon/cursor section of the resource file to store single-image icons/cursors, this project may not do anything for you.
Summary of changes:
1. Previous version only displayed icons/cursor with errors. This version displays all and marks those with errors
2. Previous version auto-corrected everything. This version allows that but also allows user to manually edit values
3. Previous version wrote all changes or none. This version optionally allows selecting resources to be rewritten