cocoapods-privacy 0.1.9 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 11b2bf9e6e9cd3c863067c2e4e4bcf9db70d734b2d3786dfba8c881dcdc58a16
|
4
|
+
data.tar.gz: 4bf64cdce7e18acfef794f43a92371a2633bdcfae75d593a60c7c0e481975235
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 228886b2f261e7850e7531ceecdd282fe483589f8abf014c3e27fa933cb652c941c7e50276d7d13f50487cd5e5d97d9c04c47bbc62bb110502e0f573ac59f410
|
7
|
+
data.tar.gz: f2b7d99c39f6cd2e15f1943ac49fa6285595632fdef523504d973cb5e0f652daee9ace8bed17dc1652ae87a8b776c93b920272aae131796718004953aef2c6ee
|
@@ -14,51 +14,65 @@ module PrivacyHunter
|
|
14
14
|
KReasons = "NSPrivacyAccessedAPITypeReasons"
|
15
15
|
KAPI = "NSPrivacyAccessedAPI"
|
16
16
|
|
17
|
-
|
18
|
-
# privacyInfo_file = ARGV[1]#传入目标 PrivacyInfo.xcprivacy
|
19
|
-
|
20
|
-
def self.search_pricacy_apis(source_folders)
|
21
|
-
# #读取源文件,也就是搜索目标文件
|
22
|
-
# source_folders = source_files.split(",")
|
17
|
+
def self.formatter_privacy_template()
|
23
18
|
#模版数据源plist文件
|
24
19
|
template_plist_file = fetch_template_plist_file()
|
25
20
|
|
26
21
|
# 读取并解析 数据源 plist 文件
|
27
22
|
json_str = `plutil -convert json -o - "#{template_plist_file}"`.chomp
|
28
23
|
map = JSON.parse(json_str)
|
29
|
-
|
24
|
+
type_datas = map[KTypes]
|
30
25
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
privacyDict = {}
|
26
|
+
apis = {}
|
27
|
+
keyword_type_map = {} #{systemUptime:NSPrivacyAccessedAPICategorySystemBootTime,mach_absolute_time:NSPrivacyAccessedAPICategorySystemBootTime .....}
|
28
|
+
type_datas.each do |value|
|
35
29
|
type = value[KType]
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
if search_files(source_folders, s_key)
|
40
|
-
s_vlaue_split = s_value.split(',')
|
41
|
-
reasons += s_vlaue_split
|
42
|
-
end
|
30
|
+
apis_inner = value[KAPI]
|
31
|
+
apis_inner.each do |keyword, reason|
|
32
|
+
keyword_type_map[keyword] = type
|
43
33
|
end
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
privacyDict[KType] = type
|
49
|
-
privacyDict[KReasons] = reasons
|
50
|
-
privacyArr.push(privacyDict)
|
51
|
-
end
|
52
|
-
# puts "type: #{type}"
|
53
|
-
# puts "reasons: #{reasons.uniq}"
|
34
|
+
apis = apis.merge(apis_inner)
|
35
|
+
end
|
36
|
+
[apis,keyword_type_map]
|
37
|
+
end
|
54
38
|
|
39
|
+
def self.search_pricacy_apis(source_folders)
|
40
|
+
apis,keyword_type_map = formatter_privacy_template()
|
41
|
+
|
42
|
+
# 优化写法,一次循环完成所有查询
|
43
|
+
datas = []
|
44
|
+
apis_found = search_files(source_folders, apis)
|
45
|
+
unless apis_found.empty?
|
46
|
+
apis_found.each do |keyword,reason|
|
47
|
+
reasons = reason.split(',')
|
48
|
+
type = keyword_type_map[keyword]
|
49
|
+
|
50
|
+
# 如果有数据 给data增加reasons
|
51
|
+
datas.map! do |data|
|
52
|
+
if data[KType] == type
|
53
|
+
data[KReasons] += reasons
|
54
|
+
data[KReasons] = data[KReasons].uniq
|
55
|
+
end
|
56
|
+
data
|
57
|
+
end
|
58
|
+
|
59
|
+
# 如果没数据,新建data
|
60
|
+
unless datas.any? { |data| data[KType] == type }
|
61
|
+
data = {}
|
62
|
+
data[KType] = type
|
63
|
+
data[KReasons] ||= []
|
64
|
+
data[KReasons] += reasons
|
65
|
+
data[KReasons] = data[KReasons].uniq
|
66
|
+
datas.push(data)
|
67
|
+
end
|
68
|
+
end
|
55
69
|
end
|
56
70
|
|
57
71
|
# 打印出搜索结果
|
58
|
-
puts
|
72
|
+
puts datas
|
59
73
|
|
60
74
|
# 转换成 JSON 字符串
|
61
|
-
json_data =
|
75
|
+
json_data = datas.to_json
|
62
76
|
end
|
63
77
|
|
64
78
|
|
@@ -94,13 +108,11 @@ module PrivacyHunter
|
|
94
108
|
|
95
109
|
# 删除临时文件
|
96
110
|
File.delete(temp_plist)
|
97
|
-
|
98
111
|
end
|
99
112
|
|
100
113
|
|
101
114
|
private
|
102
115
|
|
103
|
-
|
104
116
|
def self.fetch_template_plist_file
|
105
117
|
|
106
118
|
unless File.exist?(PrivacyUtils.cache_config_file)
|
@@ -172,16 +184,27 @@ module PrivacyHunter
|
|
172
184
|
end
|
173
185
|
|
174
186
|
# 文件是否包含内容
|
175
|
-
def self.
|
176
|
-
File.read(file_path)
|
187
|
+
def self.contains_apis?(file_path, apis)
|
188
|
+
file_content = File.read(file_path)
|
189
|
+
apis_found = {}
|
190
|
+
apis.each do |keyword, value|
|
191
|
+
if file_content.include?(keyword)
|
192
|
+
apis_found[keyword] = value
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
apis_found
|
177
197
|
end
|
178
198
|
|
179
199
|
#搜索所有子文件夹
|
180
|
-
def self.search_files(folder_paths,
|
200
|
+
def self.search_files(folder_paths, apis)
|
201
|
+
#清除上一次log
|
202
|
+
clean_log()
|
181
203
|
|
182
204
|
# 获取文件夹下所有文件(包括子文件夹)
|
183
205
|
all_files = []
|
184
206
|
folder_paths.each do |folder|
|
207
|
+
# 不再做额外格式过滤,避免和podspec中source_files 自带的格式冲突
|
185
208
|
# allowed_extensions = ['m', 'c', 'swift', 'mm', 'hap', 'cpp']
|
186
209
|
# pattern = File.join(folder, '**', '*.{'+allowed_extensions.join(',')+'}')
|
187
210
|
# all_files += Dir.glob(pattern, File::FNM_DOTMATCH).reject { |file| File.directory?(file) }
|
@@ -193,13 +216,35 @@ module PrivacyHunter
|
|
193
216
|
all_files += files_in_folder.reject { |file| File.directory?(file) }
|
194
217
|
end
|
195
218
|
# 遍历文件进行检索
|
219
|
+
apis_found = {}
|
196
220
|
all_files.uniq.each_with_index do |file_path, index|
|
197
|
-
|
198
|
-
|
199
|
-
|
221
|
+
api_contains = contains_apis?(file_path, apis)
|
222
|
+
apis_found = apis_found.merge(api_contains)
|
223
|
+
|
224
|
+
unless api_contains.empty?
|
225
|
+
log = "File #{file_path} contains the keyword '#{api_contains.keys}'.\n"
|
226
|
+
write_log(log)
|
200
227
|
end
|
201
228
|
end
|
202
|
-
|
229
|
+
puts "详细log请查看 #{PrivacyUtils.cache_log_file} 文件"
|
230
|
+
apis_found
|
231
|
+
end
|
232
|
+
|
233
|
+
def self.write_log(log)
|
234
|
+
log_file_path = PrivacyUtils.cache_log_file
|
235
|
+
is_create = PrivacyUtils.create_file_and_fold_if_no_exit(log_file_path,log)
|
236
|
+
unless is_create
|
237
|
+
File.open(log_file_path, "a") do |file|
|
238
|
+
file << log
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
def self.clean_log()
|
244
|
+
File.open(PrivacyUtils.cache_log_file, "w") do |file|
|
245
|
+
# 写入空字符串,清空文件内容
|
246
|
+
file.write("")
|
247
|
+
end
|
203
248
|
end
|
204
249
|
end
|
205
250
|
|
@@ -71,6 +71,11 @@ module PrivacyUtils
|
|
71
71
|
config_file = File.join(cache_privacy_fold, 'config.json')
|
72
72
|
end
|
73
73
|
|
74
|
+
# config.json 文件
|
75
|
+
def self.cache_log_file
|
76
|
+
config_file = File.join(cache_privacy_fold, 'privacy.log')
|
77
|
+
end
|
78
|
+
|
74
79
|
# 创建默认隐私协议文件
|
75
80
|
def self.create_privacy_if_empty(file_path)
|
76
81
|
# 文件内容
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cocoapods-privacy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- youhui
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-02-
|
11
|
+
date: 2024-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|