lldb根据block地址一句话获取block签名
Arm64版:
po [NSMethodSignature signatureWithObjCTypes:*((char**)(*((char**)(0x16fd96a40/*换成你的block实例地址*/ + 24))+ 32))] # 或者 po [[NSMethodSignature signatureWithObjCTypes:*((char**)(*((char**)(blockAddress + 24))+ 32))] debugDescription]
Arm32版:
(iPhone5s以前的机型)
将上述 +24 , +32 改为 +16 , +16.
依据
block结构体源码
struct Block_literal_1 { void *isa; // initialized to &_NSConcreteStackBlock or &_NSConcreteGlobalBlock int flags; int reserved; void (*invoke)(void *, ...); // struct Block_descriptor_1 { unsigned long int reserved; // NULL unsigned long int size; // sizeof(struct Block_literal_1) // optional helper functions void (*copy_helper)(void *dst, void *src); // IFF (1<<25) void (*dispose_helper)(void *src); // IFF (1<<25) // required ABI.2010.3.16 const char *signature; // IFF (1<<30) } *descriptor; // imported variables };
一般block都会有签名, 当然科学的方法是根据结构体中的flags来判断是否有签名
enum { BLOCK_HAS_COPY_DISPOSE = (1 << 25), BLOCK_HAS_CTOR = (1 << 26), // helpers have C++ code BLOCK_IS_GLOBAL = (1 << 28), BLOCK_HAS_STRET = (1 << 29), // IFF BLOCK_HAS_SIGNATURE BLOCK_HAS_SIGNATURE = (1 << 30), };
如果 ((flags & (1 << 30)) == (1 << 30)) 的话证明该block是带签名的.