cocoapods-privacy 0.1.9 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3002f15cfb7bff2a3872ddceff7124881501695300162e37d9b0b4da6d197c55
4
- data.tar.gz: 0cec2084e455bef224bb7d08174c5e3b0df86d08285dc6564239594c0a01d93e
3
+ metadata.gz: 764dcd8e0be43bcb5ca3309ba79d166d19a3ac25ea641c397cc6cc66b9622f61
4
+ data.tar.gz: 1a4724dcc2a679182539db7f04901311b520c3e4dd2fee94f23b6aad6521ad43
5
5
  SHA512:
6
- metadata.gz: d514b38b91b5bd46947cba044beaea0269b56a6e0154e913ade8b91a6fb625e456f5f077dd9de005b2d00d6ecdcac48caf4c767d3b3a03bb8d931cced5af5973
7
- data.tar.gz: 69295dbcee5061ba3cc413b54da60d22870f1849d1dc5f2b8daaf9c4149ad830f1b25fdd63b23b99746c1b612c38071a08753a46daa4b2fabfbabe35ecd13021
6
+ metadata.gz: 29d51dce9a7bafb95aab4e5c0afd66357c66f540a30c031cdaece060b2eb7e7f2bb2b8ce80bc20315a4b2aac9ce7f639f742551167e6cdf8fc0e2160ae87a22f
7
+ data.tar.gz: 94fad012858ccbdd2080ae9ae3c2c9ea7b964c8d2c3bdda980f902fa2c47c78a4646e5a0eaff754c86e01c95d2e11f6c0725e5a4db380c7aed4a7931b85469c9
@@ -1,3 +1,3 @@
1
1
  module CocoapodsPrivacy
2
- VERSION = "0.1.9"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -14,51 +14,65 @@ module PrivacyHunter
14
14
  KReasons = "NSPrivacyAccessedAPITypeReasons"
15
15
  KAPI = "NSPrivacyAccessedAPI"
16
16
 
17
- # source_files = ARGV[0]#传入source文件路径,如有多个使用 “,” 逗号分割
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
- arr = map[KTypes]
24
+ type_datas = map[KTypes]
30
25
 
31
- #解析并按照API模版查询指定文件夹
32
- privacyArr = []
33
- arr.each do |value|
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
- reasons = []
37
- apis = value[KAPI]
38
- apis.each do |s_key, s_value|
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
- reasons = reasons.uniq
47
- if !reasons.empty?
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 privacyArr
72
+ puts datas
59
73
 
60
74
  # 转换成 JSON 字符串
61
- json_data = privacyArr.to_json
75
+ json_data = datas.to_json
62
76
  end
63
77
 
64
78
 
@@ -172,16 +186,25 @@ module PrivacyHunter
172
186
  end
173
187
 
174
188
  # 文件是否包含内容
175
- def self.contains_keyword?(file_path, keyword)
176
- File.read(file_path).include? keyword
189
+ def self.contains_apis?(file_path, apis)
190
+ file_content = File.read(file_path)
191
+ apis_found = {}
192
+ apis.each do |keyword, value|
193
+ if file_content.include?(keyword)
194
+ apis_found[keyword] = value
195
+ end
196
+ end
197
+
198
+ apis_found
177
199
  end
178
200
 
179
201
  #搜索所有子文件夹
180
- def self.search_files(folder_paths, keyword)
202
+ def self.search_files(folder_paths, apis)
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,12 @@ 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
- if contains_keyword?(file_path, keyword)
198
- puts "File #{file_path} contains the keyword '#{keyword}'."
199
- return true
200
- end
221
+ apis_found = apis_found.merge(contains_apis?(file_path, apis))
222
+ puts "File #{file_path} contains the keyword '#{apis_found.keys}'." unless apis_found.empty?
201
223
  end
202
- return false
224
+ apis_found
203
225
  end
204
226
  end
205
227
 
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.9
4
+ version: 0.2.0
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-07 00:00:00.000000000 Z
11
+ date: 2024-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler