Skip to content

Commit

Permalink
* Fix load AMap.bundle image error by hook method
Browse files Browse the repository at this point in the history
  • Loading branch information
xushao1990 committed Aug 10, 2017
1 parent ff3950e commit 762a28b
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 1,112 deletions.
2 changes: 1 addition & 1 deletion MAMapKitDLL.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "MAMapKitDLL"
s.version = "4.6.0.1"
s.version = "4.6.0.2"
s.summary = "MAMapKit Dynamic Library for iOS."
s.description = "MAMapKit + AMapFoundationKit Dynamic Library for iOS."
s.homepage = "https://github.com/xushao1990/MAMapKitDLL"
Expand Down
4 changes: 4 additions & 0 deletions MAMapKitDLL.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
7B25247A1F3C415E0006185A /* BundleHook.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B2524791F3C415E0006185A /* BundleHook.m */; };
7B5477CD1F3BEF9E00E647AB /* MAMapKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7B5477CC1F3BEF9E00E647AB /* MAMapKit.framework */; };
7B5477D31F3BF02000E647AB /* AMapFoundationKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7B5477D21F3BF02000E647AB /* AMapFoundationKit.framework */; };
7B5477D51F3BF58B00E647AB /* AMap.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 7B5477D41F3BF58B00E647AB /* AMap.bundle */; };
Expand Down Expand Up @@ -72,6 +73,7 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
7B2524791F3C415E0006185A /* BundleHook.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BundleHook.m; sourceTree = "<group>"; };
7B5477C11F3BEF9200E647AB /* MAMapKitDLL.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = MAMapKitDLL.framework; sourceTree = BUILT_PRODUCTS_DIR; };
7B5477C51F3BEF9200E647AB /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
7B5477CC1F3BEF9E00E647AB /* MAMapKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = MAMapKit.framework; sourceTree = "<group>"; };
Expand Down Expand Up @@ -188,6 +190,7 @@
isa = PBXGroup;
children = (
7B54793F1F3BFF8300E647AB /* MAMapKitDLL.h */,
7B2524791F3C415E0006185A /* BundleHook.m */,
7B5478E61F3BFF0E00E647AB /* Headers */,
7B5477D41F3BF58B00E647AB /* AMap.bundle */,
7B5477D21F3BF02000E647AB /* AMapFoundationKit.framework */,
Expand Down Expand Up @@ -410,6 +413,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
7B25247A1F3C415E0006185A /* BundleHook.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
75 changes: 75 additions & 0 deletions MAMapKitDLL/BundleHook.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
@import ObjectiveC.runtime;
@import ObjectiveC.message;
@import Foundation.NSBundle;
@import Foundation.NSObject;
@import Foundation.NSObjCRuntime;

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"

struct CHClassDeclaration_ {
Class class_;
Class metaClass_;
Class superClass_;
};
typedef struct CHClassDeclaration_ CHClassDeclaration_;

static inline Class CHLoadClass_(CHClassDeclaration_ *declaration, Class value)
{
declaration->class_ = value;
declaration->metaClass_ = object_getClass(value);
declaration->superClass_ = class_getSuperclass(value);
return value;
}
__attribute__((unused)) inline __attribute__((always_inline))
static void *CHIvar_(id object, const char *name)
{
Ivar ivar = class_getInstanceVariable(object_getClass(object), name);
if (ivar)
return (void *)&((char *)(__bridge void *)object)[ivar_getOffset(ivar)];
return ((void*)0);
}

@class AMapResourceReader; static CHClassDeclaration_ AMapResourceReader$;;

static id (*$AMapResourceReader_bundleWithName$_super)(AMapResourceReader * self, SEL _cmd, id arg1);
static id $AMapResourceReader_bundleWithName$_closure(AMapResourceReader * self, SEL _cmd, id arg1) {
typedef id (*supType)(AMapResourceReader *, SEL, id arg1);
supType supFn = (supType)class_getMethodImplementation(AMapResourceReader$.superClass_, _cmd);
return supFn (self, _cmd, arg1);
}

static id $AMapResourceReader_bundleWithName$_method(AMapResourceReader * self, SEL _cmd, id arg1);

__attribute__((always_inline)) static inline void $AMapResourceReader_bundleWithName$_register() {
Method method = class_getInstanceMethod(AMapResourceReader$.class_, @selector(bundleWithName:));
if (method) {
$AMapResourceReader_bundleWithName$_super = (__typeof__($AMapResourceReader_bundleWithName$_super))method_getImplementation(method);
if (class_addMethod(AMapResourceReader$.class_, @selector(bundleWithName:), (IMP)&$AMapResourceReader_bundleWithName$_method, method_getTypeEncoding(method))) {
$AMapResourceReader_bundleWithName$_super = &$AMapResourceReader_bundleWithName$_closure;
} else {
method_setImplementation(method, (IMP)&$AMapResourceReader_bundleWithName$_method);
}
} else {
const char *return_ = @encode(id); size_t return_len = __builtin_strlen(return_);
const char *type1_ = @encode(id); size_t type1_len = __builtin_strlen(type1_);
char sig[return_len+2+type1_len+1]; __builtin_memcpy(sig, return_, return_len);
sig[return_len] = '@'; sig[return_len+1] = ':';
__builtin_memcpy(&sig[return_len+2], type1_, type1_len);
sig[return_len+type1_len+2] = '\0';
class_addMethod(AMapResourceReader$.class_, @selector(bundleWithName:), (IMP)&$AMapResourceReader_bundleWithName$_method, sig);
}
}
static id $AMapResourceReader_bundleWithName$_method(AMapResourceReader * self, SEL _cmd, id arg1)
{
NSString *path = [[NSBundle bundleForClass:NSClassFromString(@"AMapResourceReader")] pathForResource:arg1 ofType:@"bundle"];
return [NSBundle bundleWithPath:path];
}

__attribute__((constructor)) static void BundleHook()
{
CHLoadClass_(&AMapResourceReader$, objc_getClass("AMapResourceReader"));
$AMapResourceReader_bundleWithName$_register();
}

#pragma clang diagnostic pop
Binary file modified Product/MAMapKitDLL.framework/Info.plist
Binary file not shown.
Binary file modified Product/MAMapKitDLL.framework/MAMapKitDLL
Binary file not shown.
Loading

0 comments on commit 762a28b

Please sign in to comment.