{"id":1393,"date":"2018-11-15T11:39:19","date_gmt":"2018-11-15T03:39:19","guid":{"rendered":"http:\/\/www.yusian.com\/blog\/?p=1393"},"modified":"2018-11-27T17:22:27","modified_gmt":"2018-11-27T09:22:27","slug":"%e5%89%96%e6%9e%90objective-c%e5%af%b9%e8%b1%a1%e6%9c%ac%e8%b4%a8%e7%bb%93%e6%9e%84mjclassinfo","status":"publish","type":"post","link":"https:\/\/www.yusian.com\/blog\/project\/2018\/11\/15\/1139191393.html","title":{"rendered":"\u5256\u6790Objective-C\u5bf9\u8c61\u672c\u8d28\u7ed3\u6784MJClassInfo"},"content":{"rendered":"<pre lang=\"objc\" line=\"1\">\/\/\r\n\/\/  MJClassInfo.h\r\n\/\/  TestClass\r\n\/\/\r\n\/\/  Created by MJ Lee on 2018\/3\/8.\r\n\/\/  Copyright \u00a9 2018\u5e74 MJ Lee. All rights reserved.\r\n\/\/\r\n\r\n#import <Foundation\/Foundation.h>\r\n\r\n#ifndef MJClassInfo_h\r\n#define MJClassInfo_h\r\n\r\n# if __arm64__\r\n#   define ISA_MASK        0x0000000ffffffff8ULL\r\n# elif __x86_64__\r\n#   define ISA_MASK        0x00007ffffffffff8ULL\r\n# endif\r\n\r\n#if __LP64__\r\ntypedef uint32_t mask_t;\r\n#else\r\ntypedef uint16_t mask_t;\r\n#endif\r\ntypedef uintptr_t cache_key_t;\r\n\r\nstruct bucket_t {\r\n    cache_key_t _key;\r\n    IMP _imp;\r\n};\r\n\r\nstruct cache_t {\r\n    bucket_t *_buckets;\r\n    mask_t _mask;\r\n    mask_t _occupied;\r\n};\r\n\r\nstruct entsize_list_tt {\r\n    uint32_t entsizeAndFlags;\r\n    uint32_t count;\r\n};\r\n\r\nstruct method_t {\r\n    SEL name;\r\n    const char *types;\r\n    IMP imp;\r\n};\r\n\r\nstruct method_list_t : entsize_list_tt {\r\n    method_t first;\r\n};\r\n\r\nstruct ivar_t {\r\n    int32_t *offset;\r\n    const char *name;\r\n    const char *type;\r\n    uint32_t alignment_raw;\r\n    uint32_t size;\r\n};\r\n\r\nstruct ivar_list_t : entsize_list_tt {\r\n    ivar_t first;\r\n};\r\n\r\nstruct property_t {\r\n    const char *name;\r\n    const char *attributes;\r\n};\r\n\r\nstruct property_list_t : entsize_list_tt {\r\n    property_t first;\r\n};\r\n\r\nstruct chained_property_list {\r\n    chained_property_list *next;\r\n    uint32_t count;\r\n    property_t list[0];\r\n};\r\n\r\ntypedef uintptr_t protocol_ref_t;\r\nstruct protocol_list_t {\r\n    uintptr_t count;\r\n    protocol_ref_t list[0];\r\n};\r\n\r\nstruct class_ro_t {\r\n    uint32_t flags;\r\n    uint32_t instanceStart;\r\n    uint32_t instanceSize;  \/\/ instance\u5bf9\u8c61\u5360\u7528\u7684\u5185\u5b58\u7a7a\u95f4\r\n#ifdef __LP64__\r\n    uint32_t reserved;\r\n#endif\r\n    const uint8_t * ivarLayout;\r\n    const char * name;  \/\/ \u7c7b\u540d\r\n    method_list_t * baseMethodList;\r\n    protocol_list_t * baseProtocols;\r\n    const ivar_list_t * ivars;  \/\/ \u6210\u5458\u53d8\u91cf\u5217\u8868\r\n    const uint8_t * weakIvarLayout;\r\n    property_list_t *baseProperties;\r\n};\r\n\r\nstruct class_rw_t {\r\n    uint32_t flags;\r\n    uint32_t version;\r\n    const class_ro_t *ro;\r\n    method_list_t * methods;    \/\/ \u65b9\u6cd5\u5217\u8868\r\n    property_list_t *properties;    \/\/ \u5c5e\u6027\u5217\u8868\r\n    const protocol_list_t * protocols;  \/\/ \u534f\u8bae\u5217\u8868\r\n    Class firstSubclass;\r\n    Class nextSiblingClass;\r\n    char *demangledName;\r\n};\r\n\r\n#define FAST_DATA_MASK          0x00007ffffffffff8UL\r\nstruct class_data_bits_t {\r\n    uintptr_t bits;\r\npublic:\r\n    class_rw_t* data() {\r\n        return (class_rw_t *)(bits & FAST_DATA_MASK);\r\n    }\r\n};\r\n\r\n\/* OC\u5bf9\u8c61 *\/\r\nstruct mj_objc_object {\r\n    void *isa;\r\n};\r\n\r\n\/* \u7c7b\u5bf9\u8c61 *\/\r\nstruct mj_objc_class : mj_objc_object {\r\n    Class superclass;\r\n    cache_t cache;\r\n    class_data_bits_t bits;\r\npublic:\r\n    class_rw_t* data() {\r\n        return bits.data();\r\n    }\r\n\r\n    mj_objc_class* metaClass() {\r\n        return (mj_objc_class *)((long long)isa & ISA_MASK);\r\n    }\r\n};<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\/\/ \/\/ MJClassInfo.h \/\/ TestClass \/\/ \/\/ Created by MJ Lee on 2018\/3\/8. \/\/ Copyright \u00a9 2018\u5e74 MJ Lee. All rights reserved. \/\/ #import #ifndef MJClassInfo_h #define MJClassInfo_h # if __arm64__ # define ISA_MASK 0x0000000ffffffff8ULL # elif __x86_64__ # define ISA_MASK 0x00007ffffffffff8ULL # endif #if __LP64__ typedef uint32_t mask_t; #else typedef uint16_t mask_t; #endif typedef [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[182,181,179,180],"class_list":["post-1393","post","type-post","status-publish","format-standard","hentry","category-project","tag-mjclassinfo","tag-oc","tag-runtime","tag-180"],"_links":{"self":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts\/1393","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/comments?post=1393"}],"version-history":[{"count":0,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts\/1393\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/media?parent=1393"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/categories?post=1393"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/tags?post=1393"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}