1
|
|
|
<?php |
2
|
|
|
declare(strict_types = 1); |
3
|
|
|
namespace hexydec\agentzero; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* @phpstan-import-type MatchConfig from config |
7
|
|
|
*/ |
8
|
|
|
class apps { |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Generates a configuration array for matching apps |
12
|
|
|
* |
13
|
|
|
* @return MatchConfig An array with keys representing the string to match, and a value of an array containing parsing and output settings |
|
|
|
|
14
|
|
|
*/ |
15
|
39 |
|
public static function get() : array { |
16
|
1 |
|
$fn = [ |
17
|
1 |
|
'appslash' => function (string $value) : ?array { |
18
|
39 |
|
if (!\str_starts_with($value, 'AppleWebKit') && !\str_contains($value, '://')) { |
19
|
12 |
|
$parts = \explode('/', $value, 2); |
20
|
12 |
|
return [ |
21
|
12 |
|
'app' => $parts[0], |
22
|
12 |
|
'appversion' => $parts[1] ?? null |
23
|
12 |
|
]; |
24
|
|
|
} |
25
|
35 |
|
return null; |
26
|
1 |
|
} |
27
|
1 |
|
]; |
28
|
1 |
|
return [ |
29
|
1 |
|
'com.google.android.apps.' => [ |
30
|
1 |
|
'match' => 'any', |
31
|
1 |
|
'categories' => $fn['appslash'] |
32
|
1 |
|
], |
33
|
1 |
|
'Instagram' => [ |
34
|
1 |
|
'match' => 'any', |
35
|
1 |
|
'categories' => function (string $value, int $i, array $tokens) : array { |
36
|
5 |
|
$data = [ |
37
|
5 |
|
'app' => 'Instagram', |
38
|
5 |
|
'appversion' => \explode(' ', $value, 3)[1] ?? null |
39
|
5 |
|
]; |
40
|
5 |
|
foreach (\array_slice($tokens, $i + 1) AS $item) { |
41
|
5 |
|
if (\str_starts_with($item, 'scale=')) { |
42
|
2 |
|
$data['density'] = \floatval(\mb_substr($item, 6)); |
43
|
5 |
|
} elseif (\str_ends_with($item, 'dpi')) { |
44
|
4 |
|
$data['dpi'] = \intval(\mb_substr($item, 0, -3)); |
45
|
5 |
|
} elseif (\str_contains($item, 'x') && \strspn($item, '0123456789x') === \strlen($item)) { |
46
|
5 |
|
list($data['width'], $data['height']) = \array_map('intval', \explode('x', $item, 2)); |
47
|
|
|
} |
48
|
|
|
} |
49
|
5 |
|
return $data; |
50
|
1 |
|
} |
51
|
1 |
|
], |
52
|
1 |
|
'GSA/' => [ |
53
|
1 |
|
'match' => 'any', |
54
|
1 |
|
'categories' => $fn['appslash'] |
55
|
1 |
|
], |
56
|
1 |
|
'DuckDuckGo/' => [ |
57
|
1 |
|
'match' => 'start', |
58
|
1 |
|
'categories' => $fn['appslash'] |
59
|
1 |
|
], |
60
|
1 |
|
'FlipboardProxy/' => [ |
61
|
1 |
|
'match' => 'start', |
62
|
1 |
|
'categories' => $fn['appslash'] |
63
|
1 |
|
], |
64
|
1 |
|
'Google-Read-Aloud' => [ |
65
|
1 |
|
'match' => 'exact', |
66
|
1 |
|
'categories' => [ |
67
|
1 |
|
'type' => 'human', |
68
|
1 |
|
'app' => 'Google-Read-Aloud' |
69
|
1 |
|
] |
70
|
1 |
|
], |
71
|
1 |
|
'Zoom ' => [ |
72
|
1 |
|
'match' => 'start', |
73
|
1 |
|
'categories' => fn (string $value) : array => [ |
74
|
1 |
|
'app' => 'Zoom', |
75
|
1 |
|
'appversion' => \mb_substr($value, 5) |
76
|
1 |
|
] |
77
|
1 |
|
], |
78
|
|
|
|
79
|
|
|
// special parser for Facebook app because it is completely different to any other |
80
|
1 |
|
'FBAN/' => [ |
81
|
1 |
|
'match' => 'start', |
82
|
1 |
|
'categories' => function (string $value) : array { |
83
|
4 |
|
$map = [ |
84
|
4 |
|
'FBAN/MessengerLiteForiOS' => [ |
85
|
4 |
|
'type' => 'human', |
86
|
4 |
|
'app' => 'Facebook Messenger Lite', |
87
|
4 |
|
'platform' => 'iOS' |
88
|
4 |
|
], |
89
|
4 |
|
'FBAN/FB4A' => [ |
90
|
4 |
|
'type' => 'human', |
91
|
4 |
|
'app' => 'Facebook', |
92
|
4 |
|
'platform' => 'Android' |
93
|
4 |
|
], |
94
|
4 |
|
'FBAN/FBIOS' => [ |
95
|
4 |
|
'type' => 'human', |
96
|
4 |
|
'app' => 'Facebook', |
97
|
4 |
|
'platform' => 'iOS' |
98
|
4 |
|
], |
99
|
4 |
|
'FBAN/FB4FireTV' => [ |
100
|
4 |
|
'type' => 'human', |
101
|
4 |
|
'category' => 'tv', |
102
|
4 |
|
'app' => 'Facebook', |
103
|
4 |
|
'platform' => 'Android' |
104
|
4 |
|
], |
105
|
4 |
|
'FBAN/MessengerDesktop' => [ |
106
|
4 |
|
'type' => 'human', |
107
|
4 |
|
'category' => 'desktop', |
108
|
4 |
|
'app' => 'Facebook Messenger Desktop' |
109
|
4 |
|
] |
110
|
4 |
|
]; |
111
|
4 |
|
return $map[$value] ?? [ |
112
|
4 |
|
'app' => 'Facebook', |
113
|
4 |
|
'type' => 'human' |
114
|
|
|
]; |
115
|
1 |
|
} |
116
|
1 |
|
], |
117
|
1 |
|
'FB_IAB/' => [ |
118
|
1 |
|
'match' => 'start', |
119
|
1 |
|
'categories' => [ |
120
|
1 |
|
'app' => 'Facebook' |
121
|
1 |
|
] |
122
|
1 |
|
], |
123
|
1 |
|
'FBAV/' => [ |
124
|
1 |
|
'match' => 'start', |
125
|
1 |
|
'categories' => fn (string $value) : array => [ |
126
|
8 |
|
'appversion' => \mb_substr($value, 5) |
127
|
8 |
|
] |
128
|
1 |
|
], |
129
|
1 |
|
'FBMF/' => [ |
130
|
1 |
|
'match' => 'start', |
131
|
1 |
|
'categories' => fn (string $value) : array => [ |
132
|
1 |
|
'vendor' => \mb_substr($value, 5) |
133
|
1 |
|
] |
134
|
1 |
|
], |
135
|
1 |
|
'FBDV/' => [ |
136
|
1 |
|
'match' => 'start', |
137
|
1 |
|
'categories' => fn (string $value) : array => [ |
138
|
2 |
|
'device' => \mb_substr($value, 5) |
139
|
2 |
|
] |
140
|
1 |
|
], |
141
|
1 |
|
'FBMD/' => [ |
142
|
1 |
|
'match' => 'start', |
143
|
1 |
|
'categories' => fn (string $value) : array => [ |
144
|
2 |
|
'model' => \mb_substr($value, 5) |
145
|
2 |
|
] |
146
|
1 |
|
], |
147
|
1 |
|
'FBLC/' => [ |
148
|
1 |
|
'match' => 'start', |
149
|
1 |
|
'categories' => fn (string $value) : array => [ |
150
|
4 |
|
'language' => \str_replace('_', '-', \mb_substr($value, 5)) |
151
|
4 |
|
] |
152
|
1 |
|
], |
153
|
1 |
|
'FBDM/' => [ |
154
|
1 |
|
'match' => 'start', |
155
|
1 |
|
'categories' => function (string $value) : array { |
156
|
1 |
|
$data = []; |
157
|
1 |
|
foreach (\explode(',', \trim(\mb_substr($value, 5), '{}')) AS $item) { |
158
|
1 |
|
$parts = \explode('=', $item); |
159
|
1 |
|
if (!empty($parts[1])) { |
160
|
1 |
|
if (\is_numeric($parts[1])) { |
161
|
1 |
|
$parts[1] = \str_contains($parts[1], '.') ? \floatval($parts[1]) : \intval($parts[1]); |
162
|
|
|
} |
163
|
1 |
|
$data[$parts[0]] = $parts[1]; |
164
|
|
|
} |
165
|
|
|
} |
166
|
1 |
|
return $data; |
167
|
1 |
|
} |
168
|
1 |
|
], |
169
|
1 |
|
'width=' => [ |
170
|
1 |
|
'match' => 'start', |
171
|
1 |
|
'categories' => fn (string $value) : array => [ |
172
|
1 |
|
'width' => \intval(\mb_substr($value, 6)) |
173
|
1 |
|
] |
174
|
1 |
|
], |
175
|
1 |
|
'height=' => [ |
176
|
1 |
|
'match' => 'start', |
177
|
1 |
|
'categories' => fn (string $value) : array => [ |
178
|
1 |
|
'height' => \intval(\mb_substr($value, 7)) |
179
|
1 |
|
] |
180
|
1 |
|
], |
181
|
1 |
|
'dpi=' => [ |
182
|
1 |
|
'match' => 'start', |
183
|
1 |
|
'categories' => fn (string $value) : array => [ |
184
|
|
|
'dpi' => \mb_substr($value, 4) |
185
|
|
|
] |
186
|
1 |
|
], |
187
|
1 |
|
'FBSN/' => [ |
188
|
1 |
|
'match' => 'start', |
189
|
1 |
|
'categories' => fn (string $value) : array => [ |
190
|
2 |
|
'platform' => \mb_substr($value, 5) |
191
|
2 |
|
] |
192
|
1 |
|
], |
193
|
1 |
|
'FBSV' => [ |
194
|
1 |
|
'match' => 'start', |
195
|
1 |
|
'categories' => fn (string $value) : array => [ |
196
|
2 |
|
'platformversion' => \mb_substr($value, 5) |
197
|
2 |
|
] |
198
|
1 |
|
], |
199
|
|
|
|
200
|
|
|
// other |
201
|
1 |
|
'MAUI' => [ |
202
|
1 |
|
'match' => 'start', |
203
|
1 |
|
'categories' => fn (string $value) : array => [ |
204
|
1 |
|
'type' => 'human', |
205
|
1 |
|
'app' => $value |
206
|
1 |
|
] |
207
|
1 |
|
], |
208
|
1 |
|
'AppName/' => [ |
209
|
1 |
|
'match' => 'start', |
210
|
1 |
|
'categories' => fn(string $value) : array => [ |
211
|
1 |
|
'app' => \mb_substr($value, 8) |
212
|
1 |
|
] |
213
|
1 |
|
], |
214
|
1 |
|
'app_version/' => [ |
215
|
1 |
|
'match' => 'start', |
216
|
1 |
|
'categories' => fn(string $value) : array => [ |
217
|
1 |
|
'appversion' => \mb_substr($value, 12) |
218
|
1 |
|
] |
219
|
1 |
|
], |
220
|
|
|
|
221
|
|
|
// generic |
222
|
1 |
|
'App' => [ |
223
|
1 |
|
'match' => 'any', |
224
|
1 |
|
'categories' => $fn['appslash'] |
225
|
1 |
|
], |
226
|
1 |
|
]; |
227
|
|
|
} |
228
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths