ios使用私有api被拒

簡介

  • 直接被拒,被拒緣由以下圖.Your app uses or references the following non-public APIs:PrivateFrameworks/WebCore.framework.The use of non-public APIs is not permitted on the App Store because it can lead to a poor user experience should these APIs change.html

  • 什麼都沒說就是一個坑,因此要完全排查.ios

輸入圖片說明

備註

  • 暫時未肯定處理後是否解決問題,年後繼續跟進問題..

參考解決

處理思路

  • 使用class-dump導出 PrivateFrameworks/WebCore 庫裏的全部api,
  • 使用grep全局掃描整個項目
//導出*.h文件
class-dump -H /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/WebCore.framework -o ./WebCore

//grep 且用法
grep -Rnis "$keyword1" $projectPath/* | grep "$keyword2" | grep "$keyword3" | grep "$keyword4>> $searchFuntcionNameResultPath" | grep "$keyword5>> $searchFuntcionNameResultPath" >> $searchFuntcionNameResultPath

//grep 或用法
grep -Rnis -E "$tmpfilterKeyword|=====" $searchFuntcionNameResultPath >> $filterResultPath

處理腳本

  • 文件路徑以下,其中WebCore是導出framework的*.h

輸入圖片說明

  • 具體掃描腳本,分開掃描方法和掃描類名,在此基礎上,還須要小部分人工辨別.
#!/bin/sh

projectPath=/Users/zhouqirui/Desktop/Ios/TouchTV

#全部api名字
functionListPath=./allFunctionList.txt

#類名路徑
classKeyWordPath=./classKeyworkResult.txt
searchClassResultPath=./classSearchResult.txt

#方法名路徑
functionNameKeyWordPath=./nameKeyworkResult.txt
searchFuntcionNameResultPath=./nameSearchResult.txt

#過濾路徑
filterResultPath=./filterFinshList.txt
filterKeyword=web 

#過濾關鍵字
function filterList(){
	tmpfilterResultPath=$1
	tmpfilterKeyword=$2
	rm $tmpfilterResultPath | true
	grep -Rnis -E "$tmpfilterKeyword|=====" $searchFuntcionNameResultPath >> $filterResultPath
}


#grep -Rnis 'setResult:' *
#遍歷方法名
function searchFuntcionName(){
	rm $searchFuntcionNameResultPath | true
	path=$1
	totalText=""
	echo "path:$path"
	cat $path | while read line
	do
		keyword=${line%>>>*} 
		if [[ $totalText  =~ $keyword ]]
		then
			echo "已處理keyword:$keyword"
		else
			totalText="$totalText$keyword"
			echo "keyword:$keyword"
			
			echo "">> $searchFuntcionNameResultPath
			echo "==========================================keyword:$line==========================================" >> $searchFuntcionNameResultPath
			
			OLD_IFS="$IFS"
			IFS=","
			arr=($keyword)
			IFS="$OLD_IFS"
			
			keyword1=${arr[0]}
			keyword2=${arr[1]}
			keyword3=${arr[2]}
			keyword4=${arr[3]}
			keyword5=${arr[4]}
		
			count=${#arr[@]}
			if [[ $count  == 1 ]]
			then
				grep -Rnis "$keyword1" $projectPath/* >> $searchFuntcionNameResultPath
			elif [[ $count  == 2 ]]
			then
				grep -Rnis "$keyword1" $projectPath/* | grep "$keyword2">> $searchFuntcionNameResultPath
			elif [[ $count  == 3 ]]
			then
				grep -Rnis "$keyword1" $projectPath/* | grep "$keyword2" | grep "$keyword3">> $searchFuntcionNameResultPath
			elif [[ $count  == 4 ]]
			then
				grep -Rnis "$keyword1" $projectPath/* | grep "$keyword2" | grep "$keyword3" | grep "$keyword4>> $searchFuntcionNameResultPath" >> $searchFuntcionNameResultPath
			elif [[ $count  == 5 ]]
			then
				grep -Rnis "$keyword1" $projectPath/* | grep "$keyword2" | grep "$keyword3" | grep "$keyword4>> $searchFuntcionNameResultPath" | grep "$keyword5>> $searchFuntcionNameResultPath" >> $searchFuntcionNameResultPath
			else
				echo "$line"
				#echo "aaaaa====="${keyword}
				#echo "aaa:----$keyword1 bbb:----$keyword2 ccc:----$keyword3 ddd:----$keyword4"
				#grep -Rnis "$keyword" $projectPath/* >> $searchFuntcionNameResultPath
				#grep -Rnis 'setResult:' *
			fi
		fi
	done
}

function searchClassName(){
	rm $searchClassResultPath | true
	path=$1
	totalText=""
	echo "path:$path"
	cat $path | while read line
	do
		keyword=${line%>>>*} 
		if [[ $totalText  =~ $keyword ]]
		then
			echo "已處理keyword:$keyword"
		else
			totalText="$totalText$keyword"
			echo "keyword:$keyword"
			
			echo "">> $searchClassResultPath
			echo "==========================================keyword:$line==========================================" >> $searchClassResultPath
			grep -Rnis -E "$keyword" $projectPath/*  >> $searchClassResultPath
	
		fi
	done
}

function findClassKeyWord(){
	line=$1
	res=""
	if [[ $line  =~ "@interface" ]]
	then
	
			if [[ $line  =~ " (" ]]
			then
				tmp=${line%)*}
				param1=${tmp#*(}
				res=$param1
			else
				tmp=${line% : *}
				param1=${tmp#*@interface }
				param2=""
				if [[ $line  =~ "<" ]]
				then
					tmp=${line%>*}
					param2=${tmp#*<}
					param2=${param2// /}
				fi
			
				if [[ $param2 != "" ]]
					then
					res="$param1,$param2"
				else
					res="$param1"
				fi
					res=${res//,/|}
			fi
	#elif [[ $line =~ "@class" ]]
	#then
	# 	echo "不處理$line"
	elif [[ $line =~ "@protocol" ]]
	then
	
		 	tmp=${line% : *}
			param1=${tmp#*@protocol }
			param1=${param1#*<}
			param1=${param1//;/}
			param1=${param1// /}
			
	 		#echo "line====="${line}
			#echo "aaa:----$param1 bbb:----$param2 ccc:----$param3 ddd:----$param4"
	fi
	
	if [[ $res  != "" ]]
	then
		echo "$res>>>$line" >> $classKeyWordPath
	fi
	
}

#單個文件轉關鍵字
function findFunctionNameKeyWord(){
	line=$1
	res=""
	
	if [[ $line  =~ "arg4" ]]
	then
			tmp=${line%:(*}
			tmp2=${tmp%:(*}
			tmp3=${tmp2%:(*}
			param1=${tmp3%:(*}
			
			tmp=${line%:(*}
			tmp2=${tmp%:(*}
			tmp3=${tmp2%:(*}
			param2=${tmp3#*rg1 }
			
			tmp=${line%:(*}
			tmp2=${tmp%:(*}
			param3=${tmp2#*rg2 }
			
			tmp=${line%:(*}
			param4=${tmp#*rg3 }
			
			res="$param1,$param2,$param3,$param4"
			#echo "line====="${line}
			#echo "aaa:----$param1 bbb:----$param2 ccc:----$param3 ddd:----$param4"
			#echo "mmmm:----$res"
	elif [[ $line  =~ "arg3" ]]
	then
			#tmp=${line%:(*}
			#tmp2=${tmp%:(*}
			#res=${tmp2%:(*}
			
			tmp=${line%:(*}
			tmp2=${tmp%:(*}
			param1=${tmp2%:(*}
			
			tmp=${line%:(*}
			tmp2=${tmp%:(*}
			param2=${tmp2#*rg1 }
			
			tmp=${line%:(*}
			param3=${tmp#*rg2 }
			
			res="$param1,$param2,$param3"
		
	elif [[ $line  =~ "arg2" ]]
	then
		tmp=${line%:(*}
		param1=${tmp%:(*}
		
		tmp=${line%:(*}
		param2=${tmp#*rg1 }
	
		res="$param1,$param2"
		
	elif [[ $line  =~ "arg1" ]]
	then
		res=${line%:(*}
	fi
	
	res=${res#*)}
	
	if [[ $res  != "" ]]
	then
		echo "$res>>>$line" >> $functionNameKeyWordPath
	fi
}

#讀取單個文件每一行
function readLine(){
	#echo $1
	echo "==========================================" >> $functionListPath
	echo "$1" >> $functionListPath
	totalText=""
	cat $1 | while read line
	do
	#if [[ ($line  =~ "- (" || $line  =~ "+ (") && ($line  =~ ")_") ]]
	if [[ ($line  =~ "- (" || $line  =~ "+ (" ) ]]
	then
		#echo "${line}"
		echo "${line}" >> $functionListPath
		findFunctionNameKeyWord "$line"
	elif [[ ($line =~ "@interface" || $line =~ "@class" || $line =~ "@protocol") ]]
	then
		echo "${line}" >> $functionListPath
		findClassKeyWord "$line"
	fi
	#echo "File:${line}"
	
	done
}

#遞歸獲取全部文件路徑
function getdir(){
    echo $1
    for file in $1/*
    do
    if test -f $file
    then
        #echo $file
        readLine $file
        arr=(${arr[*]} $file)
    else
        getdir $file
    fi
    done
}

#移除 函數名關鍵字列表文檔
rm $functionListPath | true
rm $functionNameKeyWordPath | true

#移除 類名關鍵字列表文檔
rm $searchClassResultPath | true
rm $classKeyWordPath | true

getdir ./WebCore
#搜索方法名
searchClassName "$classKeyWordPath"
#搜索類名
searchFuntcionName "$functionNameKeyWordPath"
#過濾部分結構
#filterList "$filterResultPath" "$filterKeyword"

原文:http://raychow.linkfun.top/2018/02/14/archives/1_ios/privateApi/index/web

相關文章
相關標籤/搜索