cocoapods-privacy 0.1.8 → 0.2.0

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: 9b4a00e9abc854afbf658a6361ed8934fd35fa2c08acf7cc17e8a05ffa9f515d
4
- data.tar.gz: 70c3102a4c9b371f4c1eb38317dcc4e1f568c19a95349b146902126029742a08
3
+ metadata.gz: 764dcd8e0be43bcb5ca3309ba79d166d19a3ac25ea641c397cc6cc66b9622f61
4
+ data.tar.gz: 1a4724dcc2a679182539db7f04901311b520c3e4dd2fee94f23b6aad6521ad43
5
5
  SHA512:
6
- metadata.gz: 0d8074f3e754caa905a5452b9e232599654e626f0a119ec1dedf7c5c960c85826ed084a6d52f1f5d32afa81024a68782e4391bda61ca9114857f563722d58d6c
7
- data.tar.gz: 13248a72deadcf1117be0c135e1b2724a5106d99654f499081cbbfb53c50bf6c443bf9fe8e81d1ab0894a5e31168c98ea5a722c554ae9b41ad9d26c2ee54c3c5
6
+ metadata.gz: 29d51dce9a7bafb95aab4e5c0afd66357c66f540a30c031cdaece060b2eb7e7f2bb2b8ce80bc20315a4b2aac9ce7f639f742551167e6cdf8fc0e2160ae87a22f
7
+ data.tar.gz: 94fad012858ccbdd2080ae9ae3c2c9ea7b964c8d2c3bdda980f902fa2c47c78a4646e5a0eaff754c86e01c95d2e11f6c0725e5a4db380c7aed4a7931b85469c9
@@ -1,3 +1,3 @@
1
1
  module CocoapodsPrivacy
2
- VERSION = "0.1.8"
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
43
- end
44
-
45
- #按照隐私清单拼接数据
46
- reasons = reasons.uniq
47
- if !reasons.empty?
48
- privacyDict[KType] = type
49
- privacyDict[KReasons] = reasons
50
- privacyArr.push(privacyDict)
30
+ apis_inner = value[KAPI]
31
+ apis_inner.each do |keyword, reason|
32
+ keyword_type_map[keyword] = type
51
33
  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,28 +186,42 @@ 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|
185
- allowed_extensions = ['m', 'c', 'swift', 'mm', 'hap', 'cpp']
186
- pattern = File.join(folder, '**', '*.{'+allowed_extensions.join(',')+'}')
187
- all_files += Dir.glob(pattern, File::FNM_DOTMATCH).reject { |file| File.directory?(file) }
207
+ # 不再做额外格式过滤,避免和podspec中source_files 自带的格式冲突
208
+ # allowed_extensions = ['m', 'c', 'swift', 'mm', 'hap', 'cpp']
209
+ # pattern = File.join(folder, '**', '*.{'+allowed_extensions.join(',')+'}')
210
+ # all_files += Dir.glob(pattern, File::FNM_DOTMATCH).reject { |file| File.directory?(file) }
211
+
212
+ # 使用 Dir.glob 方法直接获取符合条件的文件路径
213
+ files_in_folder = Dir.glob(folder, File::FNM_DOTMATCH)
214
+
215
+ # 过滤掉目录路径,只保留文件路径,并将其添加到 all_files 数组中
216
+ all_files += files_in_folder.reject { |file| File.directory?(file) }
188
217
  end
189
218
  # 遍历文件进行检索
219
+ apis_found = {}
190
220
  all_files.uniq.each_with_index do |file_path, index|
191
- if contains_keyword?(file_path, keyword)
192
- puts "File #{file_path} contains the keyword '#{keyword}'."
193
- return true
194
- 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?
195
223
  end
196
- return false
224
+ apis_found
197
225
  end
198
226
  end
199
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.8
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-06 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