|
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' => function (string $value) : array { |
|
150
|
4 |
|
$parts = \explode('-', \str_replace('_', '-', \mb_substr($value, 5)), 4); |
|
151
|
4 |
|
$suffix = $parts[2] ?? $parts[1] ?? null; |
|
152
|
4 |
|
return [ |
|
153
|
4 |
|
'language' => \strtolower($parts[0]).($suffix !== null ? '-'.\strtoupper($suffix) : '') |
|
154
|
4 |
|
]; |
|
155
|
1 |
|
} |
|
156
|
1 |
|
], |
|
157
|
1 |
|
'FBDM/' => [ |
|
158
|
1 |
|
'match' => 'start', |
|
159
|
1 |
|
'categories' => function (string $value) : array { |
|
160
|
1 |
|
$data = []; |
|
161
|
1 |
|
foreach (\explode(',', \trim(\mb_substr($value, 5), '{}')) AS $item) { |
|
162
|
1 |
|
$parts = \explode('=', $item); |
|
163
|
1 |
|
if (!empty($parts[1])) { |
|
164
|
1 |
|
if (\is_numeric($parts[1])) { |
|
165
|
1 |
|
$parts[1] = \str_contains($parts[1], '.') ? \floatval($parts[1]) : \intval($parts[1]); |
|
166
|
|
|
} |
|
167
|
1 |
|
$data[$parts[0]] = $parts[1]; |
|
168
|
|
|
} |
|
169
|
|
|
} |
|
170
|
1 |
|
return $data; |
|
171
|
1 |
|
} |
|
172
|
1 |
|
], |
|
173
|
1 |
|
'width=' => [ |
|
174
|
1 |
|
'match' => 'start', |
|
175
|
1 |
|
'categories' => fn (string $value) : array => [ |
|
176
|
1 |
|
'width' => \intval(\mb_substr($value, 6)) |
|
177
|
1 |
|
] |
|
178
|
1 |
|
], |
|
179
|
1 |
|
'height=' => [ |
|
180
|
1 |
|
'match' => 'start', |
|
181
|
1 |
|
'categories' => fn (string $value) : array => [ |
|
182
|
1 |
|
'height' => \intval(\mb_substr($value, 7)) |
|
183
|
1 |
|
] |
|
184
|
1 |
|
], |
|
185
|
1 |
|
'dpi=' => [ |
|
186
|
1 |
|
'match' => 'start', |
|
187
|
1 |
|
'categories' => fn (string $value) : array => [ |
|
188
|
|
|
'dpi' => \mb_substr($value, 4) |
|
189
|
|
|
] |
|
190
|
1 |
|
], |
|
191
|
1 |
|
'FBSN/' => [ |
|
192
|
1 |
|
'match' => 'start', |
|
193
|
1 |
|
'categories' => fn (string $value) : array => [ |
|
194
|
2 |
|
'platform' => \mb_substr($value, 5) |
|
195
|
2 |
|
] |
|
196
|
1 |
|
], |
|
197
|
1 |
|
'FBSV' => [ |
|
198
|
1 |
|
'match' => 'start', |
|
199
|
1 |
|
'categories' => fn (string $value) : array => [ |
|
200
|
2 |
|
'platformversion' => \mb_substr($value, 5) |
|
201
|
2 |
|
] |
|
202
|
1 |
|
], |
|
203
|
|
|
|
|
204
|
|
|
// other |
|
205
|
1 |
|
'MAUI' => [ |
|
206
|
1 |
|
'match' => 'start', |
|
207
|
1 |
|
'categories' => fn (string $value) : array => [ |
|
208
|
1 |
|
'type' => 'human', |
|
209
|
1 |
|
'app' => $value |
|
210
|
1 |
|
] |
|
211
|
1 |
|
], |
|
212
|
1 |
|
'AppName/' => [ |
|
213
|
1 |
|
'match' => 'start', |
|
214
|
1 |
|
'categories' => fn(string $value) : array => [ |
|
215
|
1 |
|
'app' => \mb_substr($value, 8) |
|
216
|
1 |
|
] |
|
217
|
1 |
|
], |
|
218
|
1 |
|
'app_version/' => [ |
|
219
|
1 |
|
'match' => 'start', |
|
220
|
1 |
|
'categories' => fn(string $value) : array => [ |
|
221
|
1 |
|
'appversion' => \mb_substr($value, 12) |
|
222
|
1 |
|
] |
|
223
|
1 |
|
], |
|
224
|
|
|
|
|
225
|
|
|
// generic |
|
226
|
1 |
|
'App' => [ |
|
227
|
1 |
|
'match' => 'any', |
|
228
|
1 |
|
'categories' => $fn['appslash'] |
|
229
|
1 |
|
], |
|
230
|
1 |
|
]; |
|
231
|
|
|
} |
|
232
|
|
|
} |
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