我正在尝试使用 DYLD_INSERT_LIBRARIES 在 OS X Lion 10.7 下覆盖 FSGetCatalogInfo 函数,并且一切正常,直到我实际调用原始 FSGetCatalogInfo 函数,此时我得到“总线错误:10”。
我的代码片段是:
OSErr (*original_FSGetCatalogInfo) (const FSRef *,FSCatalogInfoBitmap,FSCatalogInfo *,HFSUniStr255 *,FSSpecPtr,FSRef *) = NULL;
OSErr FSGetCatalogInfo (const FSRef *ref,FSCatalogInfoBitmap whichInfo,FSCatalogInfo *catalogInfo,HFSUniStr255 *outName,FSSpecPtr fsSpec,FSRef *parentRef)
{
if(!original_FSGetCatalogInfo) {
printf("== FSGetCatalogInfo - creating shim link ==\n");
original_FSGetCatalogInfo = dlsym(RTLD_NEXT, "FSGetCatalogInfo");
printf("== FSGetCatalogInfo - created shim link ==\n");
}
printf("== FSGetCatalogInfo - calling original function ==\n");
OSErr oserr = original_FSGetCatalogInfo(ref,whichInfo,catalogInfo,outName,fsSpec,parentRef);
printf("== FSGetCatalogInfo - called original function ==\n");
return oserr;
}
我在想我必须定义或调用原始的 FSGetCatalogInfo 错误,但我无法弄清楚我到底在哪里搞砸了 - 想法?