好的,我已经解决了。
首先,我在 NSBundle 上创建了一个类别,并创建了与从包中加载文件相关的几乎所有方法的新实现,直到我找到高通正在使用的方法,即:
- (NSString *)pathForResource:(NSString *)name ofType:(NSString *)ext inDirectory:(NSString *)subpath;
一旦我有了它,我将我的类别方法更改为:
#define XFILPATH4DOCUMENT(_value) [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:_value]
- (NSString *)pathForResourceOverride:(NSString *)name ofType:(NSString *)ext inDirectory:(NSString *)subpath
{
if (([name isEqualToString:@"config"] && [ext isEqualToString:@"xml"]) || ([name isEqualToString:@"qcar-resources"] && [ext isEqualToString:@"dat"]))
{
// OMG
NSString *fileName = [NSString stringWithFormat:@"%@.%@", name, ext];
NSString *path = XFILPATH4DOCUMENT(fileName);
NSLog(@"%@", path);
return path;
}
else
{
return [self pathForResourceOverride:name ofType:ext inDirectory:subpath];
}
}
然后,通过方法 swizzling 的魔力:
Swizzle([NSBundle class], @selector(pathForResource:ofType:inDirectory:), @selector(pathForResourceOverride:ofType:inDirectory:));
使用这种方法:
#import <objc/runtime.h>
#import <objc/message.h>
void Swizzle(Class c, SEL orig, SEL replacement)
{
Method origMethod = class_getInstanceMethod(c, orig);
Method newMethod = class_getInstanceMethod(c, replacement);
if(class_addMethod(c, orig, method_getImplementation(newMethod), method_getTypeEncoding(newMethod)))
class_replaceMethod(c, replacement, method_getImplementation(origMethod), method_getTypeEncoding(origMethod));
else
method_exchangeImplementations(origMethod, newMethod);
}
我从这里得到的答案:iPhone 设备上的 Method Swizzle
害怕?是的。
但它有效。