个人原创,转帖请注明来源:cnblogs.com/jailbreaker
class_dump这个工具,可以导出sdk中似有api的头文件,也可以导出别人的app中使用的头文件,工具是开源的,作者网站:http://stevenygard.com/projects/class-dump/。
去网站下载后 dmg后 打开并把 class-dump copy 到 /usr/bin/ 目录下(这是我的bin目录,可能和你自己的路径不同),可以是使用 open -a finder /usr/bin 命令打开。
接着修改下 class-dump 权限,终端输入 chmod 777 /usr/bin/class-dump。
网上有个perl写的脚本(DumpFrameworks.pl),可以直接导出Frameworks 和 PrivateFrameworks 的头文件,2个Frameworks的路径更改下,我直接贴上DumpFrameworks.pl的源码。
#!/usr/bin/perl
#
# 24 November 2008
# Framework Dumping utility; requires class-dump
#
use strict;
use Cwd;
use File::Path;
my $HOME = (getpwuid($<))[7] || $ENV{‘HOME‘}
ordie"Could not find your home directory!";
# This command must be in your path.
# http://www.codethecode.com/projects/class-dump/
my $CLASS_DUMP = ‘class-dump‘;
# Public Frameworks
dump_frameworks(‘/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.1.sdk/System/Library/Frameworks‘,
‘Frameworks‘);
# Private Frameworks
dump_frameworks(‘/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.1.sdk/System/Library/PrivateFrameworks‘,
‘PrivateFrameworks‘);
sub dump_frameworks
{
my($dir, $subdir) = @_;
opendir(my $dirh, $dir) ordie"Could not opendir($dir) - $!";
# Iterate through each framework found in the directory
foreach my $file (grep { /\.framework$/ } readdir($dirh))
{
# Extract the framework name
(my $fname = $file) =~ s/\.framework$//;
print"Framework: $fname\n";
my $headers_dir = "$HOME/Headers/$subdir/$fname";
# Create the folder to store the headers
mkpath($headers_dir);
# Perform the class-dump
my $cwd = cwd();
chdir($headers_dir) ordie"Could not chdir($headers_dir) - $!";
system($CLASS_DUMP, ‘-H‘, "$dir/$file");
if($? == -1)
{
die"Could not execute $CLASS_DUMP - $!\n";
}
chdir($cwd) ordie"Could not chdir($cwd) - $!";
}
}
保存好之后,终端进入DumpFrameworks.pl所在的目录 执行命令 ./DumpFrameworks.pl
命令执行完,在用户目录下 会出现 Headers,里面包括了我们导出的Frameworks 和PrivateFrameworks 文件夹,见下图: