Giter Site home page Giter Site logo

signatureextractor's Introduction

objc metadata generator - gathering signatures for all methods/functions/variable etc

Prerequisites

  • brew install jsoncpp llvm

Usage:


$ SignatureExtractor -isysroot <SDK> -arch <ARCH> [-I <INCLUDE_PATH>] <HEADER>

ARCH:
  iPhoneOS.sdk: armv7 or arm64
  iPhoneSimulator.sdk i386 or x86_64

e.g.:

$ SignatureExtractor -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk -arch i386 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSArray.h
$ SignatureExtractor -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk -arch x86_64 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSArray.h
$ SignatureExtractor -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk -arch armv7 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSArray.h
$ SignatureExtractor -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk -arch arm64 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSArray.h

Output

{
	"class" : 
	{
		"NSArray" : 
		{
			"array" : "@8@0:4",
			"enumerateObjectsUsingBlock:" : "v12@0:4@?<v@?@I^c>8",
			...
		},
	},
	"enum" : 
	{
		"CFComparisonResult" : 
		{
			"kCFCompareEqualTo" : "0",
			"kCFCompareGreaterThan" : "1",
			"kCFCompareLessThan" : "-1"
		},
		...
	},
	"func" : 
	{
		"NSStringFromClass" : "@4#0",
		...
	},
	"protocols" : 
	[
		"NSObject",
		...
	],
	"var" : 
	{
		"NSFoundationVersionNumber" : "d",
		"kCFNull" : "r^{__CFNull=}"
		...
	}
}

输出内容有:

  • 所有的类的方法 methods。特别的,block 参数不仅仅是 @?,而是完整签名 signature!
  • 所有的全局函数 functions 和其签名 signature!
  • 所有的全局变量 variables 和其签名 signature!
  • 所有枚举 enum 的常量值
  1. 用途1

    对于使用 block 对象作为参数的方法,反射返回的 signature 是 @?,如

    -[NSArray enumerateObjectsUsingBlock:] 的签名可得到 v12@0:4@?8

    如果事先用扫描头文件可得到:v12@0:4@?<v@?@I^c>8 其第三个参数 block 的签名应是 v@?@I^cvoid (blockSelf, NSUInteger, Pointer to Char/Bool),动态构建此参数时,可按此解析其输入输出。

  2. 用途2

    全局方法 functions、variables 无法反射获取签名,必须扫描头文件。dlsym 获得地址后,可根据 signature 解析输入与输出。

  3. 用途3

    enum 编译后不复存在,只能在头文件中获取其取值。

signatureextractor's People

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.