If cab support it to much work, I think it would be enough if wimlib_reference_resource_files()
could use a already extracted cab content.
If that's the case, what about just doing something like the following:
wimlib_open_wim(wimfile, 0, &wim);
wimlib_add_image(wim, reference_dir, NULL, NULL, 0);
wimlib_extract_image(wim, 1, target_dir, 0);
It adds the reference directory to the WIMStruct as a temporary image, without actually committing it to disk. Then it extracts a different image that references files from that directory.
A less optimized version that would work with current wimlib-imagex would be to capture the reference_dir to an on-disk WIM file first. But the API can work with uncommitted images.
Of course it won't know to do anything special with "$filehashes$.dat", but if I understand correctly that's not strictly required; it would just be another optimization.