rsrc-lib provides an API for editing and manipulating Mac Resource Files (.rsrc)
.rsrc files are Mac Resource Files. Their typical structure consists of multiple types of resources with said resource files directly embedded into the .rsrc file. File layout is as follows:
- The first 16 bytes are the header signature
- Bytes 4-8 are the offset the actual header (or "footer" in this case) can be found at
- The next 256 bytes are padding
- The next section is the majority of the file, containing all embedded resources, each separated by 4 bytes representing the length of the following resource.
- The header follows the last resource.
- Then there will be 12-16 unknown bytes separating the first resource type.
- The resource type will be followed by 8 padding bytes, then will list all resources of that type
- Each resource entry is 14 bytes, no padding. Format is 3A 99 FF FF 00 03 0D 00 00 00 00 00, where the first two bytes are the resource ID, the next two are stop bytes, and the last 8 are the resource offset location in the rsrc file.
Create an RsrcFile
object with your .rsrc file:
new RsrcFile(File file)
To get information about the resource types and IDs in the file:
rsrc.getResourceByID(int id, ResourceType type)
rsrc.getResourceListByType(ResourceType type)
rsrc.getResourceTypesInFile()
Where ResourceType is an enum of the data type such as PNG, ICN, etc.
You can extract resources with the following:
rsrc.loadResourceData(int id, ResourceType type)
And you can replace resources like so:
rsrc.saveResourceData(byte[] data, int id, ResourceType type)
Where data is the bytes from the file you'd like to place in the rsrc file. Note that resources can only be replaced, not added.
To update the .rsrc file after a resource has been replaced, you must explicitly call:
rsrc.saveRsrcFile()