ctb_formats_detection/readelf.rs
1/*
2$File: COPYING,v 1.2 2018/09/09 20:33:28 christos Exp $
3Copyright (c) Ian F. Darwin 1986, 1987, 1989, 1990, 1991, 1992, 1994, 1995.
4Software written by Ian F. Darwin and others;
5maintained 1994- Christos Zoulas.
6
7This software is not subject to any export provision of the United States
8Department of Commerce, and may be exported to any country or planet.
9
10Redistribution and use in source and binary forms, with or without
11modification, are permitted provided that the following conditions
12are met:
131. Redistributions of source code must retain the above copyright
14 notice immediately at the beginning of the file, without modification,
15 this list of conditions, and the following disclaimer.
162. Redistributions in binary form must reproduce the above copyright
17 notice, this list of conditions and the following disclaimer in the
18 documentation and/or other materials provided with the distribution.
19
20THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
24ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30SUCH DAMAGE.
31
32The preceding notice is from COPYING in `file`.
33
34
35
36/*
37 * Copyright (c) Ian F. Darwin 1986-1995.
38 * Software written by Ian F. Darwin and others;
39 * maintained 1995-present by Christos Zoulas and others.
40 *
41 * Redistribution and use in source and binary forms, with or without
42 * modification, are permitted provided that the following conditions
43 * are met:
44 * 1. Redistributions of source code must retain the above copyright
45 * notice immediately at the beginning of the file, without modification,
46 * this list of conditions, and the following disclaimer.
47 * 2. Redistributions in binary form must reproduce the above copyright
48 * notice, this list of conditions and the following disclaimer in the
49 * documentation and/or other materials provided with the distribution.
50 *
51 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
52 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
53 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
54 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
55 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
56 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
57 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
58 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
59 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
60 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
61 * SUCH DAMAGE.
62 */
63
64The preceding notice is from src/apprentice.c, src/ascmagic.c, src/compress.c, src/encoding.c, src/file.c, src/file.h, src/fsmagic.c, src/missing/asprintf.c, src/missing/dprintf.c, src/print.c, src/softmagic.c, src/swap.c, and src/swap.h in `file`.
65
66
67
68/*
69 * Copyright (c) Christos Zoulas 2017.
70 * All Rights Reserved.
71 *
72 * Redistribution and use in source and binary forms, with or without
73 * modification, are permitted provided that the following conditions
74 * are met:
75 * 1. Redistributions of source code must retain the above copyright
76 * notice immediately at the beginning of the file, without modification,
77 * this list of conditions, and the following disclaimer.
78 * 2. Redistributions in binary form must reproduce the above copyright
79 * notice, this list of conditions and the following disclaimer in the
80 * documentation and/or other materials provided with the distribution.
81 *
82 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
83 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
84 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
85 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
86 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
87 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
88 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
89 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
90 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
91 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
92 * SUCH DAMAGE.
93 */
94
95The preceding notice is from src/buffer.c in `file`.
96
97
98
99/*
100 * Copyright (c) Christos Zoulas 2008.
101 * All Rights Reserved.
102 *
103 * Redistribution and use in source and binary forms, with or without
104 * modification, are permitted provided that the following conditions
105 * are met:
106 * 1. Redistributions of source code must retain the above copyright
107 * notice immediately at the beginning of the file, without modification,
108 * this list of conditions, and the following disclaimer.
109 * 2. Redistributions in binary form must reproduce the above copyright
110 * notice, this list of conditions and the following disclaimer in the
111 * documentation and/or other materials provided with the distribution.
112 *
113 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
114 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
115 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
116 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
117 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
118 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
119 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
120 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
121 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
122 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
123 * SUCH DAMAGE.
124 */
125
126The preceding notice is from src/elfclass.h in `file`.
127
128
129
130/*
131 * Copyright (c) Christos Zoulas 2003.
132 * All Rights Reserved.
133 *
134 * Redistribution and use in source and binary forms, with or without
135 * modification, are permitted provided that the following conditions
136 * are met:
137 * 1. Redistributions of source code must retain the above copyright
138 * notice immediately at the beginning of the file, without modification,
139 * this list of conditions, and the following disclaimer.
140 * 2. Redistributions in binary form must reproduce the above copyright
141 * notice, this list of conditions and the following disclaimer in the
142 * documentation and/or other materials provided with the distribution.
143 *
144 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
145 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
146 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
147 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
148 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
149 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
150 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
151 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
152 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
153 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
154 * SUCH DAMAGE.
155 */
156
157The preceding notice is from src/funcs.c, src/magic.c, src/magic.h.in, src/readelf.c, and src/readelf.h in `file`.
158
159
160
161/*
162 * Copyright (c) Ian F. Darwin 1986-1995.
163 * Software written by Ian F. Darwin and others;
164 * maintained 1995-present by Christos Zoulas and others.
165 *
166 * Redistribution and use in source and binary forms, with or without
167 * modification, are permitted provided that the following conditions
168 * are met:
169 * 1. Redistributions of source code must retain the above copyright
170 * notice immediately at the beginning of the file, without modification,
171 * this list of conditions, and the following disclaimer.
172 * 2. Redistributions in binary form must reproduce the above copyright
173 * notice, this list of conditions and the following disclaimer in the
174 * documentation and/or other materials provided with the distribution.
175 *
176 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
177 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
178 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
179 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
180 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
181 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
182 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
183 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
184 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
185 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
186 * SUCH DAMAGE.
187 */
188
189/*
190 * is_tar() -- figure out whether file is a tar archive.
191 *
192 * Stolen (by the author!) from the file_public domain tar program:
193 * Public Domain version written 26 Aug 1985 John Gilmore (ihnp4!hoptoad!gnu).
194 *
195 * @(#)list.c 1.18 9/23/86 Public Domain - gnu
196 *
197 * Comments changed and some code/comments reformatted
198 * for file command by Ian Darwin.
199 */
200
201The preceding notice is from src/is_tar.c in `file`.
202
203
204
205/*
206 * Redistribution and use in source and binary forms, with or without
207 * modification, are permitted provided that the following conditions
208 * are met:
209 * 1. Redistributions of source code must retain the above copyright
210 * notice immediately at the beginning of the file, without modification,
211 * this list of conditions, and the following disclaimer.
212 * 2. Redistributions in binary form must reproduce the above copyright
213 * notice, this list of conditions and the following disclaimer in the
214 * documentation and/or other materials provided with the distribution.
215 *
216 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
217 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
218 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
219 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
220 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
221 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
222 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
223 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
224 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
225 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
226 * SUCH DAMAGE.
227 */
228
229The preceding notice is from src/landlock.c and src/seccomp.c in `file`.
230
231
232
233/*
234 * Copyright (c) Christos Zoulas 2021.
235 * All Rights Reserved.
236 *
237 * Redistribution and use in source and binary forms, with or without
238 * modification, are permitted provided that the following conditions
239 * are met:
240 * 1. Redistributions of source code must retain the above copyright
241 * notice immediately at the beginning of the file, without modification,
242 * this list of conditions, and the following disclaimer.
243 * 2. Redistributions in binary form must reproduce the above copyright
244 * notice, this list of conditions and the following disclaimer in the
245 * documentation and/or other materials provided with the distribution.
246 *
247 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
248 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
249 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
250 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
251 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
252 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
253 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
254 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
255 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
256 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
257 * SUCH DAMAGE.
258 */
259
260The preceding notice is from src/memtest.c in `file`.
261
262
263
264/*
265 * Copyright (c) Ian F. Darwin 1986-1995.
266 * Software written by Ian F. Darwin and others;
267 * maintained 1995-present by Christos Zoulas and others.
268 *
269 * Redistribution and use in source and binary forms, with or without
270 * modification, are permitted provided that the following conditions
271 * are met:
272 * 1. Redistributions of source code must retain the above copyright
273 * notice immediately at the beginning of the file, without modification,
274 * this list of conditions, and the following disclaimer.
275 * 2. Redistributions in binary form must reproduce the above copyright
276 * notice, this list of conditions and the following disclaimer in the
277 * documentation and/or other materials provided with the distribution.
278 *
279 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
280 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
281 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
282 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
283 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
284 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
285 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
286 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
287 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
288 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
289 * SUCH DAMAGE.
290 */
291
292/*###########################################################################
293 # #
294 # vasprintf #
295 # #
296 # Copyright (c) 2002-2005 David TAILLANDIER #
297 # #
298 ###########################################################################*/
299
300/*
301
302This software is distributed under the "modified BSD licence".
303
304This software is also released with GNU license (GPL) in another file (same
305source-code, only license differ).
306
307
308
309Redistribution and use in source and binary forms, with or without
310modification, are permitted provided that the following conditions are met:
311
312Redistributions of source code must retain the above copyright notice, this
313list of conditions and the following disclaimer. Redistributions in binary
314form must reproduce the above copyright notice, this list of conditions and
315the following disclaimer in the documentation and/or other materials
316provided with the distribution. The name of the author may not be used to
317endorse or promote products derived from this software without specific
318prior written permission.
319
320THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
321WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
322MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
323EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
324SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
325PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
326OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
327WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
328OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
329ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
330
331====================
332
333Hacked from xnprintf version of 26th February 2005 to provide only
334vasprintf by Reuben Thomas <rrt@sc3d.org>.
335
336====================
337
338
339'printf' function family use the following format string:
340
341%[flag][width][.prec][modifier]type
342
343%% is the escape sequence to print a '%'
344% followed by an unknown format will print the characters without
345trying to do any interpretation
346
347flag: none + - # (blank)
348width: n 0n *
349prec: none .0 .n .*
350modifier: F N L h l ll z t ('F' and 'N' are ms-dos/16-bit specific)
351type: d i o u x X f e g E G c s p n
352
353
354The function needs to allocate memory to store the full text before to
355actually writing it. i.e if you want to fnprintf() 1000 characters, the
356functions will allocate 1000 bytes.
357This behaviour can be modified: you have to customise the code to flush the
358internal buffer (writing to screen or file) when it reach a given size. Then
359the buffer can have a shorter length. But what? If you really need to write
360HUGE string, don't use printf!
361During the process, some other memory is allocated (1024 bytes minimum)
362to handle the output of partial sprintf() calls. If you have only 10000 bytes
363free in memory, you *may* not be able to nprintf() an 8000 bytes-long text.
364
365note: if a buffer overflow occurs, exit() is called. This situation should
366never appear ... but if you want to be *really* sure, you have to modify the
367code to handle those situations (only one place to modify).
368A buffer overflow can only occur if your sprintf() do strange things or when
369you use strange formats.
370
371*/
372
373The preceding notice is from src/missing/vasprintf.c in `file`.
374
375
376
377/*
378 * Copyright (c) Ian F. Darwin 1986-1995.
379 * Software written by Ian F. Darwin and others;
380 * maintained 1995-present by Christos Zoulas and others.
381 *
382 * Redistribution and use in source and binary forms, with or without
383 * modification, are permitted provided that the following conditions
384 * are met:
385 * 1. Redistributions of source code must retain the above copyright
386 * notice immediately at the beginning of the file, without modification,
387 * this list of conditions, and the following disclaimer.
388 * 2. Redistributions in binary form must reproduce the above copyright
389 * notice, this list of conditions and the following disclaimer in the
390 * documentation and/or other materials provided with the distribution.
391 *
392 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
393 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
394 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
395 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
396 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
397 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
398 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
399 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
400 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
401 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
402 * SUCH DAMAGE.
403 */
404
405/*
406 * Header file for file_public domain tar (tape archive) program.
407 *
408 * @(#)tar.h 1.20 86/10/29 Public Domain.
409 *
410 * Created 25 August 1985 by John Gilmore, ihnp4!hoptoad!gnu.
411 *
412 * $File: tar.h,v 1.16 2022/12/26 17:31:14 christos Exp $ # checkin only
413 */
414
415The preceding notice is from src/tar.h in `file`.
416*/
417
418// SPDX-License-Identifier: AGPL-3.0-or-later AND BSD-2-Clause-Darwin AND Apache-2.0 AND MIT AND BSD-3-Clause
419// SPDX-License-Identifier for parts derived from `file` (libmagic): BSD-2-Clause-Darwin AND BSD-3-Clause
420// SPDX-License-Identifier for parts derived from polyfile: Apache-2.0
421// SPDX-License-Identifier for parts derived from fileid and binwalk: MIT
422// SPDX-License-Identifier for parts derived from DROID: BSD-3-Clause
423/*
424This file is part of Collective Toolbox, a database and document workspace and utilities.
425Copyright (C) 2026 Collective Toolbox Developers
426Contact: info@collectivetoolbox.com
427
428This program is free software: you can redistribute it and/or modify it under
429the terms of the GNU Affero General Public License as published by the Free
430Software Foundation, either version 3 of the License, or (at your option) any
431later version.
432
433This program is distributed in the hope that it will be useful, but WITHOUT ANY
434WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
435A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
436
437You should have received a copy of the GNU Affero General Public License along
438with this program. If not, see <https://www.gnu.org/licenses/>.
439*/
440
441// The Collective Toolbox file detection tools, of which this file is a part, combine elements from several other similar tools: `file`, polyfile, binwalk, fileid, and DROID.
442// See license texts at the beginning and end of this file for full license details for parts derived from `file` <https://www.darwinsys.com/file/>.
443// See the full license details for parts derived from polyfile <https://github.com/trailofbits/polyfile>, binwalk <https://github.com/ReFirmLabs/binwalk>, fileid <https://github.com/DBHeise/fileid>, and DROID <https://github.com/digital-preservation/droid> at the end of this file.
444
445//! In-depth ELF container introspection and structural analysis matching `readelf.c`.
446//!
447//! Provides structural parsing of ELF program headers (dynamic linking, static-pie,
448//! interpreter), section headers (stripped status, debug info), and note segments
449//! (GNU Build-ID, Go Build-ID, GNU/Linux/BSD OS ABI tags).
450
451/*
452 * Copyright (c) Christos Zoulas 2003.
453 * All Rights Reserved.
454 *
455 * Redistribution and use in source and binary forms, with or without
456 * modification, are permitted provided that the following conditions
457 * are met:
458 * 1. Redistributions of source code must retain the above copyright
459 * notice immediately at the beginning of the file, without modification,
460 * this list of conditions, and the following disclaimer.
461 * 2. Redistributions in binary form must reproduce the above copyright
462 * notice, this list of conditions and the following disclaimer in the
463 * documentation and/or other materials provided with the distribution.
464 *
465 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
466 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
467 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
468 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
469 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
470 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
471 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
472 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
473 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
474 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
475 * SUCH DAMAGE.
476 */
477
478#[allow(
479 unused_imports,
480 clippy::wildcard_imports,
481 reason = "Standard workspace module prelude"
482)]
483use crate::utilities::*;
484
485use super::source::DetectionSource;
486use std::fmt::Write as _;
487
488/// Parsed structural inspection details extracted from an ELF file.
489/// Core dump introspection details extracted from note segments.
490#[derive(Debug, Clone, PartialEq, Eq, Default)]
491pub struct ElfCoreDetails {
492 /// Operating system core dump style ("SVR4", "FreeBSD", "NetBSD").
493 pub os_style: Option<&'static str>,
494 /// Command line or executable name of the process that dumped core.
495 pub command_line: Option<String>,
496 /// Process ID (PID) of the dumped process.
497 pub pid: Option<u32>,
498 /// Real user ID (UID).
499 pub uid: Option<u32>,
500 /// Effective user ID (EUID).
501 pub euid: Option<u32>,
502 /// Real group ID (GID).
503 pub gid: Option<u32>,
504 /// Effective group ID (EGID).
505 pub egid: Option<u32>,
506 /// Terminating signal number.
507 pub signal: Option<u32>,
508 /// Signal code.
509 pub signal_code: Option<u32>,
510 /// Number of lightweight processes / threads.
511 pub nlwps: Option<u32>,
512 /// Terminated thread ID (LWP).
513 pub lwp: Option<u32>,
514 /// Executable filename from auxiliary vector (`AT_LINUX_EXECFN`).
515 pub execfn: Option<String>,
516 /// Target hardware platform from auxiliary vector (`AT_LINUX_PLATFORM`).
517 pub platform: Option<String>,
518 /// Faulting instruction pointer register (e.g. RIP / EIP / PC) if extracted from `NT_PRSTATUS`.
519 pub register_ip: Option<u64>,
520}
521
522/// Parsed structural inspection details extracted from an ELF file.
523#[derive(Debug, Clone, PartialEq, Eq)]
524pub struct ElfDetails {
525 /// True if 64-bit ELF, false if 32-bit ELF.
526 pub is_64bit: bool,
527 /// True if little-endian (LSB), false if big-endian (MSB).
528 pub is_le: bool,
529 /// ELF header `e_type` field (1=REL, 2=EXEC, 3=DYN, 4=CORE).
530 pub e_type: u16,
531 /// Operating system / ABI descriptor (e.g. "SYSV", "GNU/Linux").
532 pub osabi_str: &'static str,
533 /// Architecture descriptor (e.g. "x86-64", "Intel 80386", "ARM aarch64").
534 pub arch_str: &'static str,
535 /// Whether Position Independent Executable (PIE) flags were detected.
536 pub is_pie: bool,
537 /// Whether the file is classified as an executable binary.
538 pub is_executable: bool,
539 /// Linkage descriptor string (e.g. "static-pie", "dynamically", "statically").
540 pub linking_str: Option<&'static str>,
541 /// Dynamic linker interpreter path (e.g. "/lib64/ld-linux-x86-64.so.2").
542 pub interpreter: Option<String>,
543 /// GNU or Go build ID note if extracted.
544 pub build_id: Option<String>,
545 /// OS ABI target note string if extracted (e.g. "for GNU/Linux 3.2.0").
546 pub os_note: Option<String>,
547 /// Extracted Intel CET / x86 GNU properties (e.g. "x86-64-v3", "IBT", "SHSTK").
548 pub x86_properties: Vec<String>,
549 /// Extracted `AArch64` security properties (e.g. "BTI", "PAC").
550 pub aarch64_properties: Vec<String>,
551 /// `PaX` / hardened Linux execution flags if present.
552 pub pax_flags: Option<String>,
553 /// Android Memtag / MTE mode if present.
554 pub android_memtag: Option<String>,
555 /// Core dump introspected details if `e_type` == 4 (`ET_CORE`).
556 pub core_details: Option<ElfCoreDetails>,
557 /// Whether `.debug_info` debug symbols section was found.
558 pub has_debug_info: bool,
559 /// Whether symbol table (`SHT_SYMTAB`) is absent (stripped).
560 pub is_stripped: bool,
561 /// Formatted compatibility suffix matching upstream `file` / `readelf.c`.
562 pub suffix: String,
563 /// Total logical bytes evaluated across headers, sections, and notes.
564 pub bytes_evaluated: u64,
565}
566
567const PT_LOAD: u32 = 1;
568const PT_DYNAMIC: u32 = 2;
569const PT_INTERP: u32 = 3;
570const PT_NOTE: u32 = 4;
571const PT_PAX_FLAGS: u32 = 0x6504_1580;
572
573const DT_NULL: u64 = 0;
574const DT_NEEDED: u64 = 1;
575const DT_FLAGS_1: u64 = 0x6fff_fffb;
576const DF_1_PIE: u64 = 0x0800_0000;
577
578const SHT_SYMTAB: u32 = 2;
579const SHT_NOTE: u32 = 7;
580const SHT_SUNW_CAP: u32 = 0x6fff_fff5;
581
582const NT_PRSTATUS: u32 = 1;
583const NT_PRPSINFO: u32 = 3;
584const NT_AUXV: u32 = 6;
585const NT_NETBSD_CORE_PROCINFO: u32 = 1;
586
587const NT_GNU_ABI_TAG: u32 = 1;
588const NT_GNU_BUILD_ID: u32 = 3;
589const NT_GO_BUILD_ID: u32 = 4;
590const NT_GNU_PROPERTY_TYPE_0: u32 = 5;
591
592const NT_NETBSD_VERSION: u32 = 1;
593const NT_NETBSD_EMULATION: u32 = 2;
594const NT_NETBSD_PAX: u32 = 3;
595const NT_NETBSD_MARCH: u32 = 5;
596const NT_NETBSD_CMODEL: u32 = 6;
597
598const NT_FREEBSD_VERSION: u32 = 1;
599const NT_OPENBSD_VERSION: u32 = 1;
600const NT_DRAGONFLY_VERSION: u32 = 1;
601const NT_ANDROID_VERSION: u32 = 1;
602const NT_ANDROID_MEMTAG: u32 = 4;
603
604const GNU_PROPERTY_X86_FEATURE_1_AND: u32 = 0xc000_0002;
605const GNU_PROPERTY_X86_ISA_1_NEEDED: u32 = 0xc000_8002;
606const GNU_PROPERTY_X86_ISA_1_USED: u32 = 0xc001_0002;
607const GNU_PROPERTY_AARCH64_FEATURE_1_AND: u32 = 0xc000_0000;
608
609const GNU_PROPERTY_X86_FEATURE_1_IBT: u32 = 1 << 0;
610const GNU_PROPERTY_X86_FEATURE_1_SHSTK: u32 = 1 << 1;
611const GNU_PROPERTY_X86_FEATURE_1_LAM_U48: u32 = 1 << 2;
612const GNU_PROPERTY_X86_FEATURE_1_LAM_U57: u32 = 1 << 3;
613
614const GNU_PROPERTY_AARCH64_FEATURE_1_BTI: u32 = 1 << 0;
615const GNU_PROPERTY_AARCH64_FEATURE_1_PAC: u32 = 1 << 1;
616
617const AT_LINUX_UID: u64 = 11;
618const AT_LINUX_EUID: u64 = 12;
619const AT_LINUX_GID: u64 = 13;
620const AT_LINUX_EGID: u64 = 14;
621const AT_LINUX_PLATFORM: u64 = 15;
622const AT_LINUX_EXECFN: u64 = 31;
623
624const PRPSOFFSETS32: [usize; 7] = [100, 84, 44, 28, 48, 32, 8];
625const PRPSOFFSETS64: [usize; 5] = [136, 120, 56, 40, 16];
626
627fn read_u16(slice: &[u8], is_le: bool) -> Option<u16> {
628 let arr: [u8; 2] = slice.get(..2)?.try_into().ok()?;
629 Some(if is_le {
630 u16::from_le_bytes(arr)
631 } else {
632 u16::from_be_bytes(arr)
633 })
634}
635
636fn read_u32(slice: &[u8], is_le: bool) -> Option<u32> {
637 let arr: [u8; 4] = slice.get(..4)?.try_into().ok()?;
638 Some(if is_le {
639 u32::from_le_bytes(arr)
640 } else {
641 u32::from_be_bytes(arr)
642 })
643}
644
645fn read_u64(slice: &[u8], is_le: bool) -> Option<u64> {
646 let arr: [u8; 8] = slice.get(..8)?.try_into().ok()?;
647 Some(if is_le {
648 u64::from_le_bytes(arr)
649 } else {
650 u64::from_be_bytes(arr)
651 })
652}
653
654fn read_exact_at<S: DetectionSource + ?Sized>(
655 source: &mut S,
656 offset: u64,
657 buf: &mut [u8],
658) -> bool {
659 let Ok(n) = source.read_at(offset, buf) else {
660 return false;
661 };
662 n == buf.len()
663}
664
665fn map_vaddr_to_file_offset(
666 vaddr: u64,
667 pt_loads: &[(u64, u64, u64)],
668) -> Option<u64> {
669 for &(va, off, sz) in pt_loads {
670 if vaddr >= va && vaddr < va.saturating_add(sz) {
671 let delta = vaddr.saturating_sub(va);
672 return Some(off.saturating_add(delta));
673 }
674 }
675 None
676}
677
678/// Inspects source payload for detailed ELF container structures matching `readelf.c`.
679pub fn inspect_elf_details<S: DetectionSource + ?Sized>(
680 source: &mut S,
681 hint_mode: Option<u32>,
682) -> Option<ElfDetails> {
683 let mut hdr = [0u8; 64];
684 let n = source.read_at(0, &mut hdr).ok()?;
685 if n < 52 || !hdr.starts_with(b"\x7fELF") {
686 return None;
687 }
688
689 let class_byte = *hdr.get(4)?;
690 let is_64bit = match class_byte {
691 1 => false,
692 2 => true,
693 _ => return None,
694 };
695
696 let data_byte = *hdr.get(5)?;
697 let is_le = match data_byte {
698 1 => true,
699 2 => false,
700 _ => return None,
701 };
702
703 // Reason for fallback: default to SYSV (0) if byte 7 is absent in truncated ELF ident
704 let osabi_byte = hdr.get(7).copied().unwrap_or(0);
705 let osabi_str = match osabi_byte {
706 0 => "SYSV",
707 1 => "HP-UX",
708 2 => "NetBSD",
709 3 => "GNU/Linux",
710 4 => "GNU/Hurd",
711 5 => "86Open",
712 6 => "Solaris",
713 7 => "Monterey",
714 8 => "IRIX",
715 9 => "FreeBSD",
716 10 => "Tru64",
717 11 => "Novell Modesto",
718 12 => "OpenBSD",
719 13 => "OpenVMS",
720 14 => "HP NonStop Kernel",
721 15 => "AROS Research Operating System",
722 16 => "FenixOS",
723 17 => "Nuxi CloudABI",
724 97 => "ARM",
725 102 => "Cell LV2",
726 202 => "Cafe OS",
727 255 => "embedded",
728 _ => "SYSV",
729 };
730
731 let e_type = read_u16(hdr.get(16..18)?, is_le)?;
732 let e_machine = read_u16(hdr.get(18..20)?, is_le)?;
733
734 let arch_str = match e_machine {
735 0x02 => "SPARC",
736 0x03 => "Intel 80386",
737 0x08 => "MIPS",
738 0x14 => "PowerPC",
739 0x15 => "PowerPC 64-bit",
740 0x16 => "IBM S/390",
741 0x28 => "ARM",
742 0x2B => "SPARC V9",
743 0x3E => "x86-64",
744 0xB7 => "ARM aarch64",
745 0xF3 => "RISC-V",
746 _ => "unknown architecture",
747 };
748
749 let (
750 e_phoff,
751 e_shoff,
752 e_phentsize,
753 e_phnum,
754 e_shentsize,
755 e_shnum,
756 e_shstrndx,
757 ) = if is_64bit {
758 if n < 64 {
759 return None;
760 }
761 let phoff = read_u64(hdr.get(32..40)?, is_le)?;
762 let shoff = read_u64(hdr.get(40..48)?, is_le)?;
763 let phentsize = usize::from(read_u16(hdr.get(54..56)?, is_le)?);
764 let phnum = usize::from(read_u16(hdr.get(56..58)?, is_le)?);
765 let shentsize = usize::from(read_u16(hdr.get(58..60)?, is_le)?);
766 let shnum = usize::from(read_u16(hdr.get(60..62)?, is_le)?);
767 let shstrndx = usize::from(read_u16(hdr.get(62..64)?, is_le)?);
768 (phoff, shoff, phentsize, phnum, shentsize, shnum, shstrndx)
769 } else {
770 let phoff = u64::from(read_u32(hdr.get(28..32)?, is_le)?);
771 let shoff = u64::from(read_u32(hdr.get(32..36)?, is_le)?);
772 let phentsize = usize::from(read_u16(hdr.get(42..44)?, is_le)?);
773 let phnum = usize::from(read_u16(hdr.get(44..46)?, is_le)?);
774 let shentsize = usize::from(read_u16(hdr.get(46..48)?, is_le)?);
775 let shnum = usize::from(read_u16(hdr.get(48..50)?, is_le)?);
776 let shstrndx = usize::from(read_u16(hdr.get(50..52)?, is_le)?);
777 (phoff, shoff, phentsize, phnum, shentsize, shnum, shstrndx)
778 };
779
780 let mut max_evaluated = if is_64bit { 64u64 } else { 52u64 };
781
782 // 1. Traverse Program Headers (PT_DYNAMIC, PT_INTERP, PT_NOTE, PT_LOAD, PT_PAX_FLAGS)
783 let mut dynamic = false;
784 let mut pie = false;
785 let mut needed_count = 0usize;
786 let mut interpreter: Option<String> = None;
787 let mut pt_notes: Vec<(u64, u64)> = Vec::new();
788 let mut pt_loads: Vec<(u64, u64, u64)> = Vec::new();
789 let mut detected_pax_flags: Option<String> = None;
790
791 let min_phentsize = if is_64bit { 56 } else { 32 };
792 let clamped_phnum = e_phnum.min(2048);
793
794 if (e_type == 2 || e_type == 3 || e_type == 4)
795 && clamped_phnum > 0
796 && e_phentsize >= min_phentsize
797 {
798 let mut phdr_buf = vec![0u8; e_phentsize];
799 for i in 0..clamped_phnum {
800 let Ok(i_u64) = u64::try_from(i) else {
801 break;
802 };
803 let Ok(sz_u64) = u64::try_from(e_phentsize) else {
804 break;
805 };
806 let ph_offset =
807 e_phoff.saturating_add(i_u64.saturating_mul(sz_u64));
808 max_evaluated = max_evaluated.max(ph_offset.saturating_add(sz_u64));
809
810 if !read_exact_at(source, ph_offset, &mut phdr_buf) {
811 break;
812 }
813
814 let p_type = read_u32(phdr_buf.get(0..4)?, is_le)?;
815 let (p_offset, p_filesz, p_vaddr, p_flags) = if is_64bit {
816 // Reason for fallback: flags default to 0 if segment header is truncated
817 let flags = phdr_buf
818 .get(4..8)
819 .and_then(|s| read_u32(s, is_le))
820 .unwrap_or(0);
821 let off = read_u64(phdr_buf.get(8..16)?, is_le)?;
822 // Reason for fallback: virtual address defaults to 0 if absent in segment
823 let va = phdr_buf
824 .get(16..24)
825 .and_then(|s| read_u64(s, is_le))
826 .unwrap_or(0);
827 let fsz = read_u64(phdr_buf.get(32..40)?, is_le)?;
828 (off, fsz, va, flags)
829 } else {
830 let off = u64::from(read_u32(phdr_buf.get(4..8)?, is_le)?);
831 // Reason for fallback: virtual address defaults to 0 if absent in segment
832 let va = phdr_buf
833 .get(8..12)
834 .and_then(|s| read_u32(s, is_le))
835 .map_or(0, u64::from);
836 let fsz = u64::from(read_u32(phdr_buf.get(16..20)?, is_le)?);
837 // Reason for fallback: flags default to 0 if segment header is truncated
838 let flags = phdr_buf
839 .get(24..28)
840 .and_then(|s| read_u32(s, is_le))
841 .unwrap_or(0);
842 (off, fsz, va, flags)
843 };
844
845 match p_type {
846 PT_LOAD => {
847 pt_loads.push((p_vaddr, p_offset, p_filesz));
848 }
849 PT_DYNAMIC => {
850 dynamic = true;
851 let dyn_entry_size = if is_64bit { 16 } else { 8 };
852 let max_dyn_entries = 512usize;
853 let clamped_filesz = p_filesz.min(65_536);
854 max_evaluated = max_evaluated
855 .max(p_offset.saturating_add(clamped_filesz));
856
857 // Reason for fallback: invalid dynamic segment size yields zero dynamic entries
858 let total_entries = usize::try_from(clamped_filesz)
859 .ok()
860 .and_then(|sz| sz.checked_div(dyn_entry_size))
861 .map_or(0, |n| n.min(max_dyn_entries));
862
863 let mut dyn_buf = vec![0u8; dyn_entry_size];
864 for d_idx in 0..total_entries {
865 let Ok(d_u64) = u64::try_from(d_idx) else {
866 break;
867 };
868 let Ok(e_sz) = u64::try_from(dyn_entry_size) else {
869 break;
870 };
871 let d_offset =
872 p_offset.saturating_add(d_u64.saturating_mul(e_sz));
873
874 if !read_exact_at(source, d_offset, &mut dyn_buf) {
875 break;
876 }
877
878 let (d_tag, d_val) = if is_64bit {
879 let tag = read_u64(dyn_buf.get(0..8)?, is_le)?;
880 let val = read_u64(dyn_buf.get(8..16)?, is_le)?;
881 (tag, val)
882 } else {
883 let tag =
884 u64::from(read_u32(dyn_buf.get(0..4)?, is_le)?);
885 let val =
886 u64::from(read_u32(dyn_buf.get(4..8)?, is_le)?);
887 (tag, val)
888 };
889
890 if d_tag == DT_NULL {
891 break;
892 }
893 if d_tag == DT_NEEDED {
894 needed_count = needed_count.saturating_add(1);
895 } else if d_tag == DT_FLAGS_1 && (d_val & DF_1_PIE) != 0
896 {
897 pie = true;
898 }
899 }
900 }
901 PT_INTERP => {
902 needed_count = needed_count.saturating_add(1);
903 if let Ok(read_len) = usize::try_from(p_filesz.min(512)) {
904 if read_len > 0 {
905 let mut interp_buf = vec![0u8; read_len];
906 if read_exact_at(source, p_offset, &mut interp_buf)
907 {
908 if let Ok(rlen_u64) = u64::try_from(read_len) {
909 max_evaluated = max_evaluated
910 .max(p_offset.saturating_add(rlen_u64));
911 }
912 let clean_len = match interp_buf
913 .iter()
914 .position(|&b| b == 0)
915 {
916 Some(p) => p,
917 None => interp_buf.len(),
918 };
919 if clean_len > 0 {
920 if let Some(sub) =
921 interp_buf.get(..clean_len)
922 {
923 let interp_str =
924 String::from_utf8_lossy(sub)
925 .to_string();
926 interpreter = Some(interp_str);
927 }
928 }
929 }
930 }
931 }
932 }
933 PT_NOTE => {
934 if p_filesz > 0 {
935 pt_notes.push((p_offset, p_filesz));
936 }
937 }
938 PT_PAX_FLAGS => {
939 let mut flags_strs = Vec::new();
940 if p_flags & 0x0010 != 0 {
941 flags_strs.push("+PAGEEXEC");
942 } else if p_flags & 0x0020 != 0 {
943 flags_strs.push("-PAGEEXEC");
944 }
945 if p_flags & 0x0040 != 0 {
946 flags_strs.push("+EMUTRAMP");
947 } else if p_flags & 0x0080 != 0 {
948 flags_strs.push("-EMUTRAMP");
949 }
950 if p_flags & 0x0100 != 0 {
951 flags_strs.push("+MPROTECT");
952 } else if p_flags & 0x0200 != 0 {
953 flags_strs.push("-MPROTECT");
954 }
955 if p_flags & 0x0400 != 0 {
956 flags_strs.push("+RANDMMAP");
957 } else if p_flags & 0x0800 != 0 {
958 flags_strs.push("-RANDMMAP");
959 }
960 if p_flags & 0x1000 != 0 {
961 flags_strs.push("+RANDEXEC");
962 } else if p_flags & 0x2000 != 0 {
963 flags_strs.push("-RANDEXEC");
964 }
965 if p_flags & 0x4000 != 0 {
966 flags_strs.push("+SEGMEXEC");
967 } else if p_flags & 0x8000 != 0 {
968 flags_strs.push("-SEGMEXEC");
969 }
970 if !flags_strs.is_empty() {
971 detected_pax_flags = Some(flags_strs.join(","));
972 }
973 }
974 _ => {}
975 }
976 }
977 }
978
979 // 2. Traverse Section Headers (.debug_info, SHT_SYMTAB, SHT_NOTE, SHT_SUNW_cap)
980 let min_shentsize = if is_64bit { 64 } else { 40 };
981 let clamped_shnum = e_shnum.min(4096);
982 let mut is_stripped = true;
983 let mut has_debug_info = false;
984 let mut sh_notes: Vec<(u64, u64)> = Vec::new();
985 let mut sunw_hw_caps = 0u64;
986 let mut sunw_sf_caps = 0u64;
987
988 if clamped_shnum > 0 && e_shentsize >= min_shentsize && e_shoff > 0 {
989 // Read section header string table
990 let mut shstrtab = Vec::new();
991 if e_shstrndx < clamped_shnum {
992 let Ok(ndx_u64) = u64::try_from(e_shstrndx) else {
993 return None;
994 };
995 let Ok(s_sz_u64) = u64::try_from(e_shentsize) else {
996 return None;
997 };
998 let shstr_hdr_offset =
999 e_shoff.saturating_add(ndx_u64.saturating_mul(s_sz_u64));
1000 let mut shstr_hdr_buf = vec![0u8; e_shentsize];
1001 if read_exact_at(source, shstr_hdr_offset, &mut shstr_hdr_buf) {
1002 let (sh_off, sh_size) = if is_64bit {
1003 // Reason for fallback: offset defaults to 0 if section header is truncated
1004 let off = read_u64(shstr_hdr_buf.get(24..32)?, is_le)
1005 .unwrap_or(0);
1006 // Reason for fallback: size defaults to 0 if section header is truncated
1007 let sz = read_u64(shstr_hdr_buf.get(32..40)?, is_le)
1008 .unwrap_or(0);
1009 (off, sz)
1010 } else {
1011 // Reason for fallback: offset defaults to 0 if section header is truncated
1012 let off = u64::from(
1013 read_u32(shstr_hdr_buf.get(16..20)?, is_le)
1014 .unwrap_or(0),
1015 );
1016 // Reason for fallback: size defaults to 0 if section header is truncated
1017 let sz = u64::from(
1018 read_u32(shstr_hdr_buf.get(20..24)?, is_le)
1019 .unwrap_or(0),
1020 );
1021 (off, sz)
1022 };
1023 if let Ok(strtab_len) = usize::try_from(sh_size.min(131_072)) {
1024 if strtab_len > 0 {
1025 shstrtab = vec![0u8; strtab_len];
1026 let _ = read_exact_at(source, sh_off, &mut shstrtab);
1027 if let Ok(slen_u64) = u64::try_from(strtab_len) {
1028 max_evaluated = max_evaluated
1029 .max(sh_off.saturating_add(slen_u64));
1030 }
1031 }
1032 }
1033 }
1034 }
1035
1036 let mut shdr_buf = vec![0u8; e_shentsize];
1037 for s_idx in 0..clamped_shnum {
1038 let Ok(s_u64) = u64::try_from(s_idx) else {
1039 break;
1040 };
1041 let Ok(s_sz_u64) = u64::try_from(e_shentsize) else {
1042 break;
1043 };
1044 let sh_offset =
1045 e_shoff.saturating_add(s_u64.saturating_mul(s_sz_u64));
1046 max_evaluated =
1047 max_evaluated.max(sh_offset.saturating_add(s_sz_u64));
1048
1049 if !read_exact_at(source, sh_offset, &mut shdr_buf) {
1050 break;
1051 }
1052
1053 let Ok(sh_name) =
1054 usize::try_from(read_u32(shdr_buf.get(0..4)?, is_le)?)
1055 else {
1056 continue;
1057 };
1058 let sh_type = read_u32(shdr_buf.get(4..8)?, is_le)?;
1059 let (sec_off, sec_size) = if is_64bit {
1060 let off = read_u64(shdr_buf.get(24..32)?, is_le)?;
1061 let sz = read_u64(shdr_buf.get(32..40)?, is_le)?;
1062 (off, sz)
1063 } else {
1064 let off = u64::from(read_u32(shdr_buf.get(16..20)?, is_le)?);
1065 let sz = u64::from(read_u32(shdr_buf.get(20..24)?, is_le)?);
1066 (off, sz)
1067 };
1068
1069 if sh_name < shstrtab.len() {
1070 if let Some(name_bytes) = shstrtab.get(sh_name..) {
1071 let name_len = match name_bytes.iter().position(|&b| b == 0)
1072 {
1073 Some(p) => p,
1074 None => name_bytes.len(),
1075 };
1076 if let Some(sub) = name_bytes.get(..name_len) {
1077 let name_str = String::from_utf8_lossy(sub);
1078 if name_str == ".debug_info" {
1079 has_debug_info = true;
1080 is_stripped = false;
1081 }
1082 }
1083 }
1084 }
1085
1086 if sh_type == SHT_SYMTAB {
1087 is_stripped = false;
1088 } else if sh_type == SHT_NOTE && sec_size > 0 {
1089 sh_notes.push((sec_off, sec_size));
1090 } else if sh_type == SHT_SUNW_CAP && sec_size > 0 {
1091 let cap_entry_sz = if is_64bit { 16 } else { 8 };
1092 if let Ok(clamped_cap_sz) = usize::try_from(sec_size.min(1024))
1093 {
1094 let mut cap_buf = vec![0u8; clamped_cap_sz];
1095 if read_exact_at(source, sec_off, &mut cap_buf) {
1096 let mut cap_pos = 0usize;
1097 while cap_pos.saturating_add(cap_entry_sz)
1098 <= cap_buf.len()
1099 {
1100 let (c_tag, c_val) = if is_64bit {
1101 let Some(tag) = cap_buf
1102 .get(cap_pos..cap_pos.saturating_add(8))
1103 .and_then(|s| read_u64(s, is_le))
1104 else {
1105 break;
1106 };
1107 let Some(val) = cap_buf
1108 .get(
1109 cap_pos.saturating_add(8)
1110 ..cap_pos.saturating_add(16),
1111 )
1112 .and_then(|s| read_u64(s, is_le))
1113 else {
1114 break;
1115 };
1116 (tag, val)
1117 } else {
1118 let Some(tag) = cap_buf
1119 .get(cap_pos..cap_pos.saturating_add(4))
1120 .and_then(|s| read_u32(s, is_le))
1121 .map(u64::from)
1122 else {
1123 break;
1124 };
1125 let Some(val) = cap_buf
1126 .get(
1127 cap_pos.saturating_add(4)
1128 ..cap_pos.saturating_add(8),
1129 )
1130 .and_then(|s| read_u32(s, is_le))
1131 .map(u64::from)
1132 else {
1133 break;
1134 };
1135 (tag, val)
1136 };
1137 cap_pos = cap_pos.saturating_add(cap_entry_sz);
1138 if c_tag == 0 {
1139 break;
1140 }
1141 if c_tag == 1 {
1142 sunw_hw_caps |= c_val;
1143 } else if c_tag == 2 {
1144 sunw_sf_caps |= c_val;
1145 }
1146 }
1147 }
1148 }
1149 }
1150 }
1151 }
1152
1153 // 3. Parse Notes
1154 let notes_to_read = if clamped_shnum > 0 && e_type != 4 {
1155 &sh_notes
1156 } else {
1157 &pt_notes
1158 };
1159
1160 let mut ordered_notes = Vec::new();
1161 let mut did_build_id = false;
1162 let mut did_os_note = false;
1163 let mut primary_build_id: Option<String> = None;
1164 let mut primary_os_note: Option<String> = None;
1165 let mut x86_properties: Vec<String> = Vec::new();
1166 let mut aarch64_properties: Vec<String> = Vec::new();
1167 let mut pax_flags: Option<String> = detected_pax_flags;
1168 let mut android_memtag: Option<String> = None;
1169 let mut core_details: Option<ElfCoreDetails> = if e_type == 4 {
1170 Some(ElfCoreDetails::default())
1171 } else {
1172 None
1173 };
1174
1175 for &(n_off, n_size) in notes_to_read {
1176 let Ok(read_size) = usize::try_from(n_size.min(65_536)) else {
1177 continue;
1178 };
1179 if read_size < 12 {
1180 continue;
1181 }
1182 let mut note_buf = vec![0u8; read_size];
1183 if !read_exact_at(source, n_off, &mut note_buf) {
1184 continue;
1185 }
1186 if let Ok(rs_u64) = u64::try_from(read_size) {
1187 max_evaluated = max_evaluated.max(n_off.saturating_add(rs_u64));
1188 }
1189
1190 let mut pos = 0usize;
1191 while pos.saturating_add(12) <= note_buf.len() {
1192 let Some(namesz_u32) = note_buf
1193 .get(pos..pos.saturating_add(4))
1194 .and_then(|s| read_u32(s, is_le))
1195 else {
1196 break;
1197 };
1198 let Some(descsz_u32) = note_buf
1199 .get(pos.saturating_add(4)..pos.saturating_add(8))
1200 .and_then(|s| read_u32(s, is_le))
1201 else {
1202 break;
1203 };
1204 let Ok(namesz) = usize::try_from(namesz_u32) else {
1205 break;
1206 };
1207 let Ok(descsz) = usize::try_from(descsz_u32) else {
1208 break;
1209 };
1210 let note_type = read_u32(
1211 note_buf.get(pos.saturating_add(8)..pos.saturating_add(12))?,
1212 is_le,
1213 )?;
1214
1215 if namesz == 0 && descsz == 0 {
1216 break;
1217 }
1218
1219 let name_offset = pos.saturating_add(12);
1220 let name_aligned = (namesz.saturating_add(3)) & !3;
1221 let desc_offset = name_offset.saturating_add(name_aligned);
1222 let desc_aligned = (descsz.saturating_add(3)) & !3;
1223 let next_pos = desc_offset.saturating_add(desc_aligned);
1224
1225 if desc_offset.saturating_add(descsz) > note_buf.len() {
1226 break;
1227 }
1228
1229 let Some(name_slice) =
1230 note_buf.get(name_offset..name_offset.saturating_add(namesz))
1231 else {
1232 break;
1233 };
1234 let Some(desc_slice) =
1235 note_buf.get(desc_offset..desc_offset.saturating_add(descsz))
1236 else {
1237 break;
1238 };
1239 pos = next_pos;
1240
1241 let clean_name = String::from_utf8_lossy(name_slice)
1242 .trim_matches('\0')
1243 .to_string();
1244
1245 // Core dump note handling
1246 if e_type == 4 {
1247 if let Some(ref mut core) = core_details {
1248 // Identify core OS style
1249 if core.os_style.is_none() {
1250 if clean_name == "CORE"
1251 || name_slice.starts_with(b"CORE")
1252 {
1253 core.os_style = Some("SVR4");
1254 } else if clean_name == "FreeBSD" {
1255 core.os_style = Some("FreeBSD");
1256 } else if clean_name.starts_with("NetBSD-CORE")
1257 || name_slice.starts_with(b"NetBSD-CORE")
1258 {
1259 core.os_style = Some("NetBSD");
1260 }
1261 }
1262
1263 match core.os_style {
1264 Some("NetBSD") => {
1265 if note_type == NT_NETBSD_CORE_PROCINFO
1266 && descsz >= 128
1267 {
1268 if let (
1269 Some(signo),
1270 Some(sigcode),
1271 Some(pid),
1272 Some(euid),
1273 Some(egid),
1274 Some(nlwps),
1275 ) = (
1276 desc_slice
1277 .get(8..12)
1278 .and_then(|s| read_u32(s, is_le)),
1279 desc_slice
1280 .get(12..16)
1281 .and_then(|s| read_u32(s, is_le)),
1282 desc_slice
1283 .get(80..84)
1284 .and_then(|s| read_u32(s, is_le)),
1285 desc_slice
1286 .get(100..104)
1287 .and_then(|s| read_u32(s, is_le)),
1288 desc_slice
1289 .get(112..116)
1290 .and_then(|s| read_u32(s, is_le)),
1291 desc_slice
1292 .get(120..124)
1293 .and_then(|s| read_u32(s, is_le)),
1294 ) {
1295 if let Some(name_raw) =
1296 desc_slice.get(124..156)
1297 {
1298 let name_len = match name_raw
1299 .iter()
1300 .position(|&b| b == 0)
1301 {
1302 Some(p) => p,
1303 None => name_raw.len(),
1304 };
1305 if let Some(name_bytes) =
1306 name_raw.get(..name_len)
1307 {
1308 let cmd = String::from_utf8_lossy(
1309 name_bytes,
1310 )
1311 .to_string();
1312 core.command_line = Some(cmd);
1313 }
1314 }
1315 let siglwp = if descsz >= 160 {
1316 desc_slice
1317 .get(156..160)
1318 .and_then(|s| read_u32(s, is_le))
1319 } else {
1320 None
1321 };
1322
1323 core.pid = Some(pid);
1324 core.euid = Some(euid);
1325 core.egid = Some(egid);
1326 core.nlwps = Some(nlwps);
1327 core.lwp = siglwp;
1328 core.signal = Some(signo);
1329 core.signal_code = Some(sigcode);
1330 }
1331 }
1332 }
1333 Some("FreeBSD") => {
1334 if note_type == NT_PRPSINFO {
1335 let argoff = if is_64bit { 33 } else { 25 };
1336 if let Some(str_bytes) =
1337 desc_slice.get(argoff..)
1338 {
1339 let max_len = str_bytes.len().min(80);
1340 if let Some(sub) = str_bytes.get(..max_len)
1341 {
1342 let clean_len = match sub
1343 .iter()
1344 .position(|&b| b == 0)
1345 {
1346 Some(p) => p,
1347 None => max_len,
1348 };
1349 if let Some(raw_cmd) =
1350 str_bytes.get(..clean_len)
1351 {
1352 let cmd = String::from_utf8_lossy(
1353 raw_cmd,
1354 )
1355 .trim()
1356 .to_string();
1357 if !cmd.is_empty() {
1358 core.command_line = Some(cmd);
1359 }
1360 }
1361 }
1362 }
1363 let pidoff = argoff.saturating_add(83);
1364 if let Some(pid_slice) = desc_slice
1365 .get(pidoff..pidoff.saturating_add(4))
1366 {
1367 core.pid = read_u32(pid_slice, is_le);
1368 }
1369 }
1370 }
1371 _ => {
1372 // Default: SVR4 / Linux
1373 if note_type == NT_PRPSINFO
1374 && core.command_line.is_none()
1375 {
1376 let offsets = if is_64bit {
1377 &PRPSOFFSETS64[..]
1378 } else {
1379 &PRPSOFFSETS32[..]
1380 };
1381 for &off in offsets {
1382 let Some(probe_slice) =
1383 desc_slice.get(off..)
1384 else {
1385 continue;
1386 };
1387 let max_probe = probe_slice.len().min(80);
1388 let Some(probe) =
1389 probe_slice.get(..max_probe)
1390 else {
1391 continue;
1392 };
1393 if probe.is_empty()
1394 || probe.first().copied() == Some(0)
1395 {
1396 continue;
1397 }
1398 let clean_len = match probe
1399 .iter()
1400 .position(|&b| b == 0)
1401 {
1402 Some(p) => p,
1403 None => probe.len(),
1404 };
1405 let Some(clean_slice) =
1406 probe.get(..clean_len)
1407 else {
1408 continue;
1409 };
1410 let non_printable =
1411 clean_slice.iter().any(|&b| {
1412 !(0x20..=0x7E).contains(&b)
1413 || b == b'\''
1414 || b == b'"'
1415 || b == b'`'
1416 });
1417 if !non_printable && clean_len >= 1 {
1418 let cmd = String::from_utf8_lossy(
1419 clean_slice,
1420 )
1421 .trim()
1422 .to_string();
1423 if !cmd.is_empty() {
1424 core.command_line = Some(cmd);
1425 break;
1426 }
1427 }
1428 }
1429 } else if note_type == NT_PRSTATUS {
1430 if is_64bit {
1431 if desc_slice.len() >= 36 {
1432 core.signal = read_u32(
1433 desc_slice.get(0..4)?,
1434 is_le,
1435 );
1436 core.signal_code = read_u32(
1437 desc_slice.get(4..8)?,
1438 is_le,
1439 );
1440 core.pid = read_u32(
1441 desc_slice.get(32..36)?,
1442 is_le,
1443 );
1444 }
1445 if desc_slice.len() >= 248
1446 && e_machine == 0x3E
1447 {
1448 // x86_64: rip is at offset 240
1449 core.register_ip = read_u64(
1450 desc_slice.get(240..248)?,
1451 is_le,
1452 );
1453 } else if desc_slice.len() >= 344
1454 && e_machine == 0xB7
1455 {
1456 // AArch64: pc is at offset 336
1457 core.register_ip = read_u64(
1458 desc_slice.get(336..344)?,
1459 is_le,
1460 );
1461 }
1462 } else {
1463 if desc_slice.len() >= 28 {
1464 core.signal = read_u32(
1465 desc_slice.get(0..4)?,
1466 is_le,
1467 );
1468 core.signal_code = read_u32(
1469 desc_slice.get(4..8)?,
1470 is_le,
1471 );
1472 core.pid = read_u32(
1473 desc_slice.get(24..28)?,
1474 is_le,
1475 );
1476 }
1477 if desc_slice.len() >= 120
1478 && e_machine == 0x03
1479 {
1480 // i386: eip is at offset 116
1481 core.register_ip = read_u32(
1482 desc_slice.get(116..120)?,
1483 is_le,
1484 )
1485 .map(u64::from);
1486 }
1487 }
1488 } else if note_type == NT_AUXV {
1489 let elsize = if is_64bit { 16 } else { 8 };
1490 let mut a_pos = 0usize;
1491 let mut entries_seen = 0usize;
1492 while a_pos.saturating_add(elsize)
1493 <= desc_slice.len()
1494 && entries_seen < 50
1495 {
1496 entries_seen =
1497 entries_seen.saturating_add(1);
1498 let (a_type, a_val) = if is_64bit {
1499 let Some(t) = desc_slice
1500 .get(a_pos..a_pos.saturating_add(8))
1501 .and_then(|s| read_u64(s, is_le))
1502 else {
1503 break;
1504 };
1505 let Some(v) = desc_slice
1506 .get(
1507 a_pos.saturating_add(8)
1508 ..a_pos.saturating_add(16),
1509 )
1510 .and_then(|s| read_u64(s, is_le))
1511 else {
1512 break;
1513 };
1514 (t, v)
1515 } else {
1516 let Some(t) = desc_slice
1517 .get(a_pos..a_pos.saturating_add(4))
1518 .and_then(|s| read_u32(s, is_le))
1519 .map(u64::from)
1520 else {
1521 break;
1522 };
1523 let Some(v) = desc_slice
1524 .get(
1525 a_pos.saturating_add(4)
1526 ..a_pos.saturating_add(8),
1527 )
1528 .and_then(|s| read_u32(s, is_le))
1529 .map(u64::from)
1530 else {
1531 break;
1532 };
1533 (t, v)
1534 };
1535 a_pos = a_pos.saturating_add(elsize);
1536
1537 match a_type {
1538 AT_LINUX_UID => {
1539 core.uid =
1540 u32::try_from(a_val).ok();
1541 }
1542 AT_LINUX_EUID => {
1543 core.euid =
1544 u32::try_from(a_val).ok();
1545 }
1546 AT_LINUX_GID => {
1547 core.gid =
1548 u32::try_from(a_val).ok();
1549 }
1550 AT_LINUX_EGID => {
1551 core.egid =
1552 u32::try_from(a_val).ok();
1553 }
1554 AT_LINUX_PLATFORM => {
1555 if let Some(off) =
1556 map_vaddr_to_file_offset(
1557 a_val, &pt_loads,
1558 )
1559 {
1560 let mut str_buf = [0u8; 64];
1561 if source
1562 .read_at(off, &mut str_buf)
1563 .is_ok()
1564 {
1565 let len = match str_buf
1566 .iter()
1567 .position(|&b| b == 0)
1568 {
1569 Some(p) => p,
1570 None => str_buf.len(),
1571 };
1572 if let Some(slice) =
1573 str_buf.get(..len)
1574 {
1575 let s = String::from_utf8_lossy(slice).to_string();
1576 if !s.is_empty() {
1577 core.platform =
1578 Some(s);
1579 }
1580 }
1581 }
1582 }
1583 }
1584 AT_LINUX_EXECFN => {
1585 if let Some(off) =
1586 map_vaddr_to_file_offset(
1587 a_val, &pt_loads,
1588 )
1589 {
1590 let mut str_buf = [0u8; 128];
1591 if source
1592 .read_at(off, &mut str_buf)
1593 .is_ok()
1594 {
1595 let len = match str_buf
1596 .iter()
1597 .position(|&b| b == 0)
1598 {
1599 Some(p) => p,
1600 None => str_buf.len(),
1601 };
1602 if let Some(slice) =
1603 str_buf.get(..len)
1604 {
1605 let s = String::from_utf8_lossy(slice).to_string();
1606 if !s.is_empty() {
1607 core.execfn =
1608 Some(s);
1609 }
1610 }
1611 }
1612 }
1613 }
1614 _ => {}
1615 }
1616 }
1617 }
1618 }
1619 }
1620 }
1621 continue;
1622 }
1623
1624 // GNU Build-ID
1625 if clean_name == "GNU"
1626 && note_type == NT_GNU_BUILD_ID
1627 && (4..=64).contains(&descsz)
1628 {
1629 if !did_build_id {
1630 did_build_id = true;
1631 let btype = match descsz {
1632 8 => "xxHash",
1633 16 => "md5/uuid",
1634 20 => "sha1",
1635 _ => "unknown",
1636 };
1637 let mut hex =
1638 String::with_capacity(descsz.saturating_mul(2));
1639 for b in desc_slice {
1640 let _ = write!(hex, "{b:02x}");
1641 }
1642 let bid_entry = format!("BuildID[{btype}]={hex}");
1643 primary_build_id = Some(bid_entry.clone());
1644 ordered_notes.push(bid_entry);
1645 }
1646 continue;
1647 }
1648
1649 // Go BuildID
1650 if clean_name.starts_with("Go")
1651 && note_type == NT_GO_BUILD_ID
1652 && descsz > 0
1653 && descsz < 256
1654 {
1655 if !did_build_id {
1656 did_build_id = true;
1657 let s = String::from_utf8_lossy(desc_slice)
1658 .trim_matches('\0')
1659 .to_string();
1660 let bid_entry = format!("Go BuildID={s}");
1661 primary_build_id = Some(bid_entry.clone());
1662 ordered_notes.push(bid_entry);
1663 }
1664 continue;
1665 }
1666
1667 // GNU Program Properties (CET / AArch64 / ISA)
1668 if clean_name == "GNU"
1669 && note_type == NT_GNU_PROPERTY_TYPE_0
1670 && descsz >= 8
1671 {
1672 let align: usize = if is_64bit { 8 } else { 4 };
1673 let mut prop_pos = 0usize;
1674 let mut found_props = Vec::new();
1675
1676 while prop_pos.saturating_add(8) <= desc_slice.len() {
1677 let Some(pr_type) = desc_slice
1678 .get(prop_pos..prop_pos.saturating_add(4))
1679 .and_then(|s| read_u32(s, is_le))
1680 else {
1681 break;
1682 };
1683 let Some(pr_datasz_raw) = desc_slice
1684 .get(
1685 prop_pos.saturating_add(4)
1686 ..prop_pos.saturating_add(8),
1687 )
1688 .and_then(|s| read_u32(s, is_le))
1689 else {
1690 break;
1691 };
1692 let Ok(pr_datasz) = usize::try_from(pr_datasz_raw) else {
1693 break;
1694 };
1695
1696 if pr_type == 0 && pr_datasz == 0 {
1697 break;
1698 }
1699
1700 let data_offset = prop_pos.saturating_add(8);
1701 let align_mask = align.saturating_sub(1);
1702 let aligned_datasz =
1703 (pr_datasz.saturating_add(align_mask)) & !align_mask;
1704 let next_prop = data_offset.saturating_add(aligned_datasz);
1705
1706 let Some(prop_data) = desc_slice.get(
1707 data_offset..data_offset.saturating_add(pr_datasz),
1708 ) else {
1709 break;
1710 };
1711 prop_pos = next_prop;
1712
1713 match pr_type {
1714 GNU_PROPERTY_X86_FEATURE_1_AND => {
1715 if let Some(val) = read_u32(prop_data, is_le) {
1716 if val & GNU_PROPERTY_X86_FEATURE_1_IBT != 0 {
1717 x86_properties.push("IBT".to_string());
1718 found_props.push("IBT".to_string());
1719 }
1720 if val & GNU_PROPERTY_X86_FEATURE_1_SHSTK != 0 {
1721 x86_properties.push("SHSTK".to_string());
1722 found_props.push("SHSTK".to_string());
1723 }
1724 if val & GNU_PROPERTY_X86_FEATURE_1_LAM_U48 != 0
1725 {
1726 x86_properties.push("LAM_U48".to_string());
1727 found_props.push("LAM_U48".to_string());
1728 }
1729 if val & GNU_PROPERTY_X86_FEATURE_1_LAM_U57 != 0
1730 {
1731 x86_properties.push("LAM_U57".to_string());
1732 found_props.push("LAM_U57".to_string());
1733 }
1734 }
1735 }
1736 GNU_PROPERTY_X86_ISA_1_NEEDED
1737 | GNU_PROPERTY_X86_ISA_1_USED => {
1738 if let Some(val) = read_u32(prop_data, is_le) {
1739 let isa_name = if val & (1 << 3) != 0 {
1740 "x86-64-v4"
1741 } else if val & (1 << 2) != 0 {
1742 "x86-64-v3"
1743 } else if val & (1 << 1) != 0 {
1744 "x86-64-v2"
1745 } else if val & (1 << 0) != 0 {
1746 "x86-64-baseline"
1747 } else {
1748 ""
1749 };
1750 if !isa_name.is_empty() {
1751 x86_properties.push(isa_name.to_string());
1752 found_props.push(isa_name.to_string());
1753 }
1754 }
1755 }
1756 GNU_PROPERTY_AARCH64_FEATURE_1_AND => {
1757 if let Some(val) = read_u32(prop_data, is_le) {
1758 if val & GNU_PROPERTY_AARCH64_FEATURE_1_BTI != 0
1759 {
1760 aarch64_properties.push("BTI".to_string());
1761 found_props.push("BTI".to_string());
1762 }
1763 if val & GNU_PROPERTY_AARCH64_FEATURE_1_PAC != 0
1764 {
1765 aarch64_properties.push("PAC".to_string());
1766 found_props.push("PAC".to_string());
1767 }
1768 }
1769 }
1770 _ => {}
1771 }
1772 }
1773
1774 if !found_props.is_empty() {
1775 ordered_notes.push(format!(
1776 "properties: {}",
1777 found_props.join(", ")
1778 ));
1779 }
1780 continue;
1781 }
1782
1783 // NetBSD PaX Note
1784 if clean_name == "PaX" && note_type == NT_NETBSD_PAX && descsz == 4
1785 {
1786 if let Some(desc) = read_u32(desc_slice, is_le) {
1787 let mut flags_strs = Vec::new();
1788 if desc & 0x01 != 0 {
1789 flags_strs.push("+mprotect");
1790 }
1791 if desc & 0x02 != 0 {
1792 flags_strs.push("-mprotect");
1793 }
1794 if desc & 0x04 != 0 {
1795 flags_strs.push("+segvguard");
1796 }
1797 if desc & 0x08 != 0 {
1798 flags_strs.push("-segvguard");
1799 }
1800 if desc & 0x10 != 0 {
1801 flags_strs.push("+ASLR");
1802 }
1803 if desc & 0x20 != 0 {
1804 flags_strs.push("-ASLR");
1805 }
1806 if !flags_strs.is_empty() {
1807 let note_str = format!("PaX: {}", flags_strs.join(","));
1808 pax_flags = Some(flags_strs.join(","));
1809 ordered_notes.push(note_str);
1810 }
1811 }
1812 continue;
1813 }
1814
1815 // Android Memtag Note
1816 if clean_name == "Android"
1817 && note_type == NT_ANDROID_MEMTAG
1818 && descsz == 4
1819 {
1820 if let Some(desc) = read_u32(desc_slice, is_le) {
1821 let mut tags = Vec::new();
1822 if desc & (1 << 0) != 0 {
1823 tags.push("none");
1824 }
1825 if desc & (1 << 1) != 0 {
1826 tags.push("async");
1827 }
1828 if desc & (1 << 2) != 0 {
1829 tags.push("sync");
1830 }
1831 if desc & (1 << 3) != 0 {
1832 tags.push("heap");
1833 }
1834 if desc & (1 << 4) != 0 {
1835 tags.push("stack");
1836 }
1837 if !tags.is_empty() {
1838 let note_str =
1839 format!("Android Memtag: {}", tags.join(","));
1840 android_memtag = Some(tags.join(","));
1841 ordered_notes.push(note_str);
1842 }
1843 }
1844 continue;
1845 }
1846
1847 // GNU OS ABI Version tag
1848 if clean_name == "GNU"
1849 && note_type == NT_GNU_ABI_TAG
1850 && descsz >= 16
1851 {
1852 if !did_os_note {
1853 if let (Some(os_val), Some(maj), Some(min), Some(pat)) = (
1854 desc_slice.get(0..4).and_then(|s| read_u32(s, is_le)),
1855 desc_slice.get(4..8).and_then(|s| read_u32(s, is_le)),
1856 desc_slice.get(8..12).and_then(|s| read_u32(s, is_le)),
1857 desc_slice.get(12..16).and_then(|s| read_u32(s, is_le)),
1858 ) {
1859 did_os_note = true;
1860 let os_name = match os_val {
1861 0 => "Linux",
1862 1 => "Hurd",
1863 2 => "Solaris",
1864 3 => "kFreeBSD",
1865 4 => "kNetBSD",
1866 _ => "<unknown>",
1867 };
1868 let os_entry =
1869 format!("for GNU/{os_name} {maj}.{min}.{pat}");
1870 primary_os_note = Some(os_entry.clone());
1871 ordered_notes.push(os_entry);
1872 }
1873 }
1874 continue;
1875 }
1876
1877 // SuSE Version tag
1878 if clean_name == "SuSE" && note_type == 1 && descsz == 2 {
1879 if !did_os_note {
1880 if let (Some(&maj), Some(&min)) =
1881 (desc_slice.first(), desc_slice.get(1))
1882 {
1883 did_os_note = true;
1884 let os_entry = format!("for SuSE {maj}.{min}");
1885 primary_os_note = Some(os_entry.clone());
1886 ordered_notes.push(os_entry);
1887 }
1888 }
1889 continue;
1890 }
1891
1892 // FreeBSD Version tag
1893 if clean_name == "FreeBSD" && note_type == 1 && descsz >= 4 {
1894 if !did_os_note {
1895 if let Some(ver) =
1896 desc_slice.get(0..4).and_then(|s| read_u32(s, is_le))
1897 {
1898 if let (Some(maj), Some(min)) = (
1899 ver.checked_div(100_000),
1900 ver.checked_div(1_000)
1901 .and_then(|v| v.checked_rem(100)),
1902 ) {
1903 did_os_note = true;
1904 let os_entry = format!("for FreeBSD {maj}.{min}");
1905 primary_os_note = Some(os_entry.clone());
1906 ordered_notes.push(os_entry);
1907 }
1908 }
1909 }
1910 continue;
1911 }
1912
1913 // NetBSD Version tag
1914 if clean_name == "NetBSD" && note_type == 1 && descsz >= 4 {
1915 if !did_os_note {
1916 if let Some(ver) =
1917 desc_slice.get(0..4).and_then(|s| read_u32(s, is_le))
1918 {
1919 if let (Some(maj), Some(min)) = (
1920 ver.checked_div(100_000_000),
1921 ver.checked_div(1_000_000)
1922 .and_then(|v| v.checked_rem(100)),
1923 ) {
1924 did_os_note = true;
1925 let os_entry = format!("for NetBSD {maj}.{min}");
1926 primary_os_note = Some(os_entry.clone());
1927 ordered_notes.push(os_entry);
1928 }
1929 }
1930 }
1931 continue;
1932 }
1933
1934 // NetBSD Architecture / Compilation tags
1935 if clean_name == "NetBSD" {
1936 if note_type == NT_NETBSD_MARCH && !desc_slice.is_empty() {
1937 let clean = String::from_utf8_lossy(desc_slice)
1938 .trim_matches('\0')
1939 .to_string();
1940 if !clean.is_empty() {
1941 ordered_notes.push(format!("compiled for: {clean}"));
1942 }
1943 continue;
1944 } else if note_type == NT_NETBSD_CMODEL
1945 && !desc_slice.is_empty()
1946 {
1947 let clean = String::from_utf8_lossy(desc_slice)
1948 .trim_matches('\0')
1949 .to_string();
1950 if !clean.is_empty() {
1951 ordered_notes.push(format!("compiler model: {clean}"));
1952 }
1953 continue;
1954 } else if note_type == NT_NETBSD_EMULATION
1955 && !desc_slice.is_empty()
1956 {
1957 let clean = String::from_utf8_lossy(desc_slice)
1958 .trim_matches('\0')
1959 .to_string();
1960 if !clean.is_empty() {
1961 ordered_notes.push(format!("emulation: {clean}"));
1962 }
1963 continue;
1964 }
1965 }
1966
1967 // OpenBSD Version tag
1968 if clean_name == "OpenBSD" && note_type == 1 {
1969 if !did_os_note {
1970 did_os_note = true;
1971 let os_entry = "for OpenBSD".to_string();
1972 primary_os_note = Some(os_entry.clone());
1973 ordered_notes.push(os_entry);
1974 }
1975 continue;
1976 }
1977
1978 // DragonFly Version tag
1979 if clean_name == "DragonFly" && note_type == 1 && descsz >= 4 {
1980 if !did_os_note {
1981 if let Some(ver) =
1982 desc_slice.get(0..4).and_then(|s| read_u32(s, is_le))
1983 {
1984 if let (Some(maj), Some(min), Some(patch)) = (
1985 ver.checked_div(100_000),
1986 ver.checked_div(10_000)
1987 .and_then(|v| v.checked_rem(10)),
1988 ver.checked_rem(10_000),
1989 ) {
1990 did_os_note = true;
1991 let os_entry =
1992 format!("for DragonFly {maj}.{min}.{patch}");
1993 primary_os_note = Some(os_entry.clone());
1994 ordered_notes.push(os_entry);
1995 }
1996 }
1997 }
1998 continue;
1999 }
2000
2001 // Android Version tag
2002 if clean_name == "Android" && note_type == 1 && descsz >= 4 {
2003 if !did_os_note {
2004 if let Some(api) =
2005 desc_slice.get(0..4).and_then(|s| read_u32(s, is_le))
2006 {
2007 did_os_note = true;
2008 let os_entry = format!("for Android {api}");
2009 primary_os_note = Some(os_entry.clone());
2010 ordered_notes.push(os_entry);
2011 }
2012 }
2013 if descsz >= 132 {
2014 if let (Some(rel_bytes), Some(bld_bytes)) =
2015 (desc_slice.get(4..68), desc_slice.get(68..132))
2016 {
2017 let rel_len =
2018 match rel_bytes.iter().position(|&b| b == 0) {
2019 Some(p) => p,
2020 None => rel_bytes.len(),
2021 };
2022 let bld_len =
2023 match bld_bytes.iter().position(|&b| b == 0) {
2024 Some(p) => p,
2025 None => bld_bytes.len(),
2026 };
2027 if let (Some(rel_sub), Some(bld_sub)) =
2028 (rel_bytes.get(..rel_len), bld_bytes.get(..bld_len))
2029 {
2030 let rel_str = String::from_utf8_lossy(rel_sub)
2031 .trim()
2032 .to_string();
2033 let bld_str = String::from_utf8_lossy(bld_sub)
2034 .trim()
2035 .to_string();
2036
2037 if !rel_str.is_empty() && !bld_str.is_empty() {
2038 ordered_notes.push(format!(
2039 "built by NDK {rel_str} ({bld_str})"
2040 ));
2041 }
2042 }
2043 }
2044 }
2045 }
2046 }
2047 }
2048
2049 // 4. Determine Linkage and Executable Status
2050 let linking_str = if dynamic {
2051 if pie && needed_count == 0 {
2052 Some("static-pie")
2053 } else {
2054 Some("dynamically")
2055 }
2056 } else if e_type == 2 || e_type == 3 {
2057 Some("statically")
2058 } else {
2059 None
2060 };
2061
2062 let is_executable = if dynamic {
2063 pie
2064 } else if e_type == 2 {
2065 true
2066 } else {
2067 hint_mode.is_some_and(|m| (m & 0o111) != 0)
2068 };
2069
2070 // 5. Assemble Compatibility Suffix String
2071 let mut suffix = String::new();
2072 if e_type == 4 {
2073 // Core dump format
2074 if let Some(ref core) = core_details {
2075 if let Some(style) = core.os_style {
2076 let _ = write!(suffix, ", {style}-style");
2077 }
2078 if let Some(style) = core.os_style {
2079 if style == "NetBSD" {
2080 if let Some(ref cmd) = core.command_line {
2081 // Reason for fallback: NetBSD core dump procinfo field defaults to 0 if note is truncated
2082 let pid = core.pid.unwrap_or(0);
2083 // Reason for fallback: NetBSD core dump procinfo field defaults to 0 if note is truncated
2084 let euid = core.euid.unwrap_or(0);
2085 // Reason for fallback: NetBSD core dump procinfo field defaults to 0 if note is truncated
2086 let egid = core.egid.unwrap_or(0);
2087 // Reason for fallback: NetBSD core dump procinfo field defaults to 0 if note is truncated
2088 let nlwps = core.nlwps.unwrap_or(0);
2089 // Reason for fallback: NetBSD core dump procinfo field defaults to 0 if note is truncated
2090 let lwp = core.lwp.unwrap_or(0);
2091 // Reason for fallback: NetBSD core dump procinfo field defaults to 0 if note is truncated
2092 let signal = core.signal.unwrap_or(0);
2093 // Reason for fallback: NetBSD core dump procinfo field defaults to 0 if note is truncated
2094 let signal_code = core.signal_code.unwrap_or(0);
2095 let _ = write!(
2096 suffix,
2097 ", from '{cmd}', pid={pid}, uid={euid}, gid={egid}, nlwps={nlwps}, lwp={lwp} (signal {signal}/code {signal_code})"
2098 );
2099 }
2100 } else if style == "FreeBSD" {
2101 if let Some(ref cmd) = core.command_line {
2102 let _ = write!(suffix, ", from '{cmd}'");
2103 if let Some(pid) = core.pid {
2104 let _ = write!(suffix, ", pid={pid}");
2105 }
2106 }
2107 } else {
2108 if let Some(ref cmd) = core.command_line {
2109 let _ = write!(suffix, ", from '{cmd}'");
2110 }
2111 if let Some(uid) = core.uid {
2112 let _ = write!(suffix, ", real uid: {uid}");
2113 }
2114 if let Some(euid) = core.euid {
2115 let _ = write!(suffix, ", effective uid: {euid}");
2116 }
2117 if let Some(gid) = core.gid {
2118 let _ = write!(suffix, ", real gid: {gid}");
2119 }
2120 if let Some(egid) = core.egid {
2121 let _ = write!(suffix, ", effective gid: {egid}");
2122 }
2123 if let Some(ref execfn) = core.execfn {
2124 let _ = write!(suffix, ", execfn: '{execfn}'");
2125 }
2126 if let Some(ref platform) = core.platform {
2127 let _ = write!(suffix, ", platform: '{platform}'");
2128 }
2129 }
2130 }
2131 }
2132 } else {
2133 if let Some(link) = linking_str {
2134 let _ = write!(suffix, ", {link} linked");
2135 }
2136 if let Some(ref interp) = interpreter {
2137 let _ = write!(suffix, ", interpreter {interp}");
2138 }
2139 for note in &ordered_notes {
2140 let _ = write!(suffix, ", {note}");
2141 }
2142 if let Some(ref pax) = pax_flags {
2143 if !ordered_notes.iter().any(|n| n.starts_with("PaX:")) {
2144 let _ = write!(suffix, ", PaX: {pax}");
2145 }
2146 }
2147 if sunw_hw_caps != 0 {
2148 let _ = write!(suffix, ", hardware capability 0x{sunw_hw_caps:x}");
2149 }
2150 if sunw_sf_caps & 1 != 0 {
2151 suffix.push_str(", uses frame pointer");
2152 }
2153 if has_debug_info {
2154 suffix.push_str(", with debug_info");
2155 }
2156 if clamped_shnum > 0 {
2157 suffix.push_str(if is_stripped {
2158 ", stripped"
2159 } else {
2160 ", not stripped"
2161 });
2162 }
2163 }
2164
2165 Some(ElfDetails {
2166 is_64bit,
2167 is_le,
2168 e_type,
2169 osabi_str,
2170 arch_str,
2171 is_pie: pie,
2172 is_executable,
2173 linking_str,
2174 interpreter,
2175 build_id: primary_build_id,
2176 os_note: primary_os_note,
2177 x86_properties,
2178 aarch64_properties,
2179 pax_flags,
2180 android_memtag,
2181 core_details,
2182 has_debug_info,
2183 is_stripped,
2184 suffix,
2185 bytes_evaluated: max_evaluated,
2186 })
2187}
2188
2189#[cfg(test)]
2190#[allow(
2191 unused_imports,
2192 clippy::unwrap_used,
2193 clippy::expect_used,
2194 clippy::panic,
2195 clippy::unwrap_in_result,
2196 clippy::panic_in_result_fn,
2197 clippy::indexing_slicing,
2198 clippy::arithmetic_side_effects,
2199 reason = "Standard repository test boilerplate"
2200)]
2201mod tests {
2202 use super::*;
2203
2204 #[crate::ctb_test]
2205 fn test_readelf_non_elf() {
2206 let data = b"not an elf file";
2207 let mut source: &[u8] = data;
2208 assert_eq!(inspect_elf_details(&mut source, None), None);
2209 }
2210
2211 #[crate::ctb_test]
2212 fn test_readelf_minimal_exec() {
2213 let mut elf_bytes = vec![0u8; 64];
2214 elf_bytes[..4].copy_from_slice(b"\x7fELF");
2215 elf_bytes[4] = 2; // 64-bit
2216 elf_bytes[5] = 1; // LSB
2217 elf_bytes[6] = 1; // version
2218 elf_bytes[7] = 0; // SYSV
2219 elf_bytes[16] = 2; // e_type: ET_EXEC
2220 elf_bytes[18] = 0x3E; // e_machine: x86-64
2221
2222 let mut source: &[u8] = &elf_bytes;
2223 let details = inspect_elf_details(&mut source, None)
2224 .expect("Should parse ELF header");
2225 assert!(details.is_64bit);
2226 assert!(details.is_le);
2227 assert_eq!(details.e_type, 2);
2228 assert_eq!(details.arch_str, "x86-64");
2229 assert!(details.is_executable);
2230 assert!(!details.is_pie);
2231 }
2232
2233 #[crate::ctb_test]
2234 fn test_readelf_pie_and_interp() {
2235 // Construct 64-bit ELF with PT_INTERP and PT_DYNAMIC
2236 let mut elf = vec![0u8; 512];
2237 elf[..4].copy_from_slice(b"\x7fELF");
2238 elf[4] = 2; // 64-bit
2239 elf[5] = 1; // LSB
2240 elf[6] = 1; // version
2241 elf[7] = 0; // SYSV
2242 elf[16] = 3; // e_type: ET_DYN
2243 elf[18] = 0x3E; // e_machine: x86-64
2244
2245 // e_phoff = 64 (0x40)
2246 elf[32..40].copy_from_slice(&64u64.to_le_bytes());
2247 // e_phentsize = 56 (0x38)
2248 elf[54..56].copy_from_slice(&56u16.to_le_bytes());
2249 // e_phnum = 2
2250 elf[56..58].copy_from_slice(&2u16.to_le_bytes());
2251
2252 // Phdr 0: PT_INTERP (3) at offset 200, size 28
2253 let ph0 = 64usize;
2254 elf[ph0..ph0 + 4].copy_from_slice(&3u32.to_le_bytes()); // p_type = PT_INTERP
2255 elf[ph0 + 8..ph0 + 16].copy_from_slice(&200u64.to_le_bytes()); // p_offset = 200
2256 elf[ph0 + 32..ph0 + 40].copy_from_slice(&28u64.to_le_bytes()); // p_filesz = 28
2257 let interp_str = b"/lib64/ld-linux-x86-64.so.2\0";
2258 elf[200..200 + interp_str.len()].copy_from_slice(interp_str);
2259
2260 // Phdr 1: PT_DYNAMIC (2) at offset 300, size 32
2261 let ph1 = 64usize + 56;
2262 elf[ph1..ph1 + 4].copy_from_slice(&2u32.to_le_bytes()); // p_type = PT_DYNAMIC
2263 elf[ph1 + 8..ph1 + 16].copy_from_slice(&300u64.to_le_bytes()); // p_offset = 300
2264 elf[ph1 + 32..ph1 + 40].copy_from_slice(&32u64.to_le_bytes()); // p_filesz = 32
2265
2266 // Dynamic entries: DT_FLAGS_1 (0x6ffffffb) = DF_1_PIE (0x08000000)
2267 let dyn0 = 300usize;
2268 elf[dyn0..dyn0 + 8].copy_from_slice(&0x6ffffffbu64.to_le_bytes());
2269 elf[dyn0 + 8..dyn0 + 16].copy_from_slice(&0x08000000u64.to_le_bytes());
2270 // DT_NULL (0)
2271 let dyn1 = 300usize + 16;
2272 elf[dyn1..dyn1 + 8].copy_from_slice(&0u64.to_le_bytes());
2273 elf[dyn1 + 8..dyn1 + 16].copy_from_slice(&0u64.to_le_bytes());
2274
2275 let mut source: &[u8] = &elf;
2276 let details =
2277 inspect_elf_details(&mut source, None).expect("Should parse ELF");
2278 assert!(details.is_pie);
2279 assert_eq!(
2280 details.interpreter.as_deref(),
2281 Some("/lib64/ld-linux-x86-64.so.2")
2282 );
2283 assert_eq!(details.linking_str, Some("dynamically"));
2284 assert!(details.suffix.contains("dynamically linked"));
2285 assert!(
2286 details
2287 .suffix
2288 .contains("interpreter /lib64/ld-linux-x86-64.so.2")
2289 );
2290 }
2291
2292 #[crate::ctb_test]
2293 fn test_readelf_build_id_note() {
2294 let mut elf = vec![0u8; 256];
2295 elf[..4].copy_from_slice(b"\x7fELF");
2296 elf[4] = 2; // 64-bit
2297 elf[5] = 1; // LSB
2298 elf[6] = 1; // version
2299 elf[7] = 0; // SYSV
2300 elf[16] = 2; // ET_EXEC
2301 elf[18] = 0x3E; // x86-64
2302
2303 // e_phoff = 64
2304 elf[32..40].copy_from_slice(&64u64.to_le_bytes());
2305 // e_phentsize = 56
2306 elf[54..56].copy_from_slice(&56u16.to_le_bytes());
2307 // e_phnum = 1
2308 elf[56..58].copy_from_slice(&1u16.to_le_bytes());
2309
2310 // Phdr 0: PT_NOTE (4) at offset 150, size 36
2311 let ph0 = 64usize;
2312 elf[ph0..ph0 + 4].copy_from_slice(&4u32.to_le_bytes());
2313 elf[ph0 + 8..ph0 + 16].copy_from_slice(&150u64.to_le_bytes());
2314 elf[ph0 + 32..ph0 + 40].copy_from_slice(&36u64.to_le_bytes());
2315
2316 // Note header at offset 150:
2317 // namesz = 4 ("GNU\0"), descsz = 20 (sha1), type = 3 (NT_GNU_BUILD_ID)
2318 let n = 150usize;
2319 elf[n..n + 4].copy_from_slice(&4u32.to_le_bytes());
2320 elf[n + 4..n + 8].copy_from_slice(&20u32.to_le_bytes());
2321 elf[n + 8..n + 12].copy_from_slice(&3u32.to_le_bytes());
2322 elf[n + 12..n + 16].copy_from_slice(b"GNU\0");
2323 // 20 bytes of sha1 = all 0xaa
2324 for i in 0..20 {
2325 elf[n + 16 + i] = 0xaa;
2326 }
2327
2328 let mut source: &[u8] = &elf;
2329 let details =
2330 inspect_elf_details(&mut source, None).expect("Should parse ELF");
2331 assert!(details.build_id.is_some());
2332 let expected_sha1 =
2333 "BuildID[sha1]=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
2334 assert_eq!(details.build_id.as_deref(), Some(expected_sha1));
2335 assert!(details.suffix.contains(&format!(", {expected_sha1}")));
2336 }
2337
2338 #[crate::ctb_test]
2339 fn test_readelf_intel_cet_properties() {
2340 let mut elf = vec![0u8; 512];
2341 elf[..4].copy_from_slice(b"\x7fELF");
2342 elf[4] = 2; // 64-bit
2343 elf[5] = 1; // LSB
2344 elf[6] = 1;
2345 elf[7] = 0; // SYSV
2346 elf[16] = 2; // ET_EXEC
2347 elf[18] = 0x3E; // x86-64
2348
2349 // e_phoff = 64
2350 elf[32..40].copy_from_slice(&64u64.to_le_bytes());
2351 // e_phentsize = 56
2352 elf[54..56].copy_from_slice(&56u16.to_le_bytes());
2353 // e_phnum = 1
2354 elf[56..58].copy_from_slice(&1u16.to_le_bytes());
2355
2356 // Phdr 0: PT_NOTE at offset 128, size 80
2357 let ph0 = 64usize;
2358 elf[ph0..ph0 + 4].copy_from_slice(&4u32.to_le_bytes());
2359 elf[ph0 + 8..ph0 + 16].copy_from_slice(&128u64.to_le_bytes());
2360 elf[ph0 + 32..ph0 + 40].copy_from_slice(&80u64.to_le_bytes());
2361
2362 // Note header at offset 128:
2363 // namesz = 4 ("GNU\0"), descsz = 48, type = 5 (NT_GNU_PROPERTY_TYPE_0)
2364 let n = 128usize;
2365 elf[n..n + 4].copy_from_slice(&4u32.to_le_bytes());
2366 elf[n + 4..n + 8].copy_from_slice(&48u32.to_le_bytes());
2367 elf[n + 8..n + 12].copy_from_slice(&5u32.to_le_bytes());
2368 elf[n + 12..n + 16].copy_from_slice(b"GNU\0");
2369
2370 // Property 1: GNU_PROPERTY_X86_FEATURE_1_AND (0xc0000002), size 4, val = IBT (1) | SHSTK (2) = 3
2371 let p1 = n + 16;
2372 elf[p1..p1 + 4].copy_from_slice(&0xc0000002u32.to_le_bytes());
2373 elf[p1 + 4..p1 + 8].copy_from_slice(&4u32.to_le_bytes());
2374 elf[p1 + 8..p1 + 12].copy_from_slice(&3u32.to_le_bytes());
2375 // 4 bytes padding to 8-byte alignment
2376
2377 // Property 2: GNU_PROPERTY_X86_ISA_1_NEEDED (0xc0008002), size 4, val = x86-64-v3 (4)
2378 let p2 = p1 + 16;
2379 elf[p2..p2 + 4].copy_from_slice(&0xc0008002u32.to_le_bytes());
2380 elf[p2 + 4..p2 + 8].copy_from_slice(&4u32.to_le_bytes());
2381 elf[p2 + 8..p2 + 12].copy_from_slice(&4u32.to_le_bytes());
2382
2383 let mut source: &[u8] = &elf;
2384 let details =
2385 inspect_elf_details(&mut source, None).expect("Should parse ELF");
2386 assert!(details.x86_properties.contains(&"IBT".to_string()));
2387 assert!(details.x86_properties.contains(&"SHSTK".to_string()));
2388 assert!(details.x86_properties.contains(&"x86-64-v3".to_string()));
2389 assert!(details.suffix.contains("properties: IBT, SHSTK, x86-64-v3"));
2390 }
2391
2392 #[crate::ctb_test]
2393 fn test_readelf_aarch64_security_features() {
2394 let mut elf = vec![0u8; 512];
2395 elf[..4].copy_from_slice(b"\x7fELF");
2396 elf[4] = 2; // 64-bit
2397 elf[5] = 1; // LSB
2398 elf[6] = 1;
2399 elf[7] = 0; // SYSV
2400 elf[16] = 2; // ET_EXEC
2401 elf[18] = 0xB7; // ARM aarch64
2402
2403 // e_phoff = 64
2404 elf[32..40].copy_from_slice(&64u64.to_le_bytes());
2405 elf[54..56].copy_from_slice(&56u16.to_le_bytes());
2406 elf[56..58].copy_from_slice(&1u16.to_le_bytes());
2407
2408 // Phdr 0: PT_NOTE at offset 128, size 48
2409 let ph0 = 64usize;
2410 elf[ph0..ph0 + 4].copy_from_slice(&4u32.to_le_bytes());
2411 elf[ph0 + 8..ph0 + 16].copy_from_slice(&128u64.to_le_bytes());
2412 elf[ph0 + 32..ph0 + 40].copy_from_slice(&48u64.to_le_bytes());
2413
2414 // Note header at offset 128:
2415 let n = 128usize;
2416 elf[n..n + 4].copy_from_slice(&4u32.to_le_bytes());
2417 elf[n + 4..n + 8].copy_from_slice(&16u32.to_le_bytes());
2418 elf[n + 8..n + 12].copy_from_slice(&5u32.to_le_bytes());
2419 elf[n + 12..n + 16].copy_from_slice(b"GNU\0");
2420
2421 // Property: GNU_PROPERTY_AARCH64_FEATURE_1_AND (0xc0000000), size 4, val = BTI (1) | PAC (2) = 3
2422 let p1 = n + 16;
2423 elf[p1..p1 + 4].copy_from_slice(&0xc0000000u32.to_le_bytes());
2424 elf[p1 + 4..p1 + 8].copy_from_slice(&4u32.to_le_bytes());
2425 elf[p1 + 8..p1 + 12].copy_from_slice(&3u32.to_le_bytes());
2426
2427 let mut source: &[u8] = &elf;
2428 let details =
2429 inspect_elf_details(&mut source, None).expect("Should parse ELF");
2430 assert_eq!(details.arch_str, "ARM aarch64");
2431 assert!(details.aarch64_properties.contains(&"BTI".to_string()));
2432 assert!(details.aarch64_properties.contains(&"PAC".to_string()));
2433 assert!(details.suffix.contains("properties: BTI, PAC"));
2434 }
2435
2436 #[crate::ctb_test]
2437 fn test_readelf_pax_flags_phdr_and_note() {
2438 let mut elf = vec![0u8; 512];
2439 elf[..4].copy_from_slice(b"\x7fELF");
2440 elf[4] = 2; // 64-bit
2441 elf[5] = 1; // LSB
2442 elf[6] = 1;
2443 elf[7] = 0; // SYSV
2444 elf[16] = 2; // ET_EXEC
2445 elf[18] = 0x3E; // x86-64
2446
2447 // e_phoff = 64, phnum = 2
2448 elf[32..40].copy_from_slice(&64u64.to_le_bytes());
2449 elf[54..56].copy_from_slice(&56u16.to_le_bytes());
2450 elf[56..58].copy_from_slice(&2u16.to_le_bytes());
2451
2452 // Phdr 0: PT_PAX_FLAGS (0x65041580), p_flags = 0x0010 (PAGEEXEC) | 0x0100 (MPROTECT)
2453 let ph0 = 64usize;
2454 elf[ph0..ph0 + 4].copy_from_slice(&0x65041580u32.to_le_bytes());
2455 elf[ph0 + 4..ph0 + 8].copy_from_slice(&0x0110u32.to_le_bytes());
2456
2457 // Phdr 1: PT_NOTE at offset 200, size 32
2458 let ph1 = 64usize + 56;
2459 elf[ph1..ph1 + 4].copy_from_slice(&4u32.to_le_bytes());
2460 elf[ph1 + 8..ph1 + 16].copy_from_slice(&200u64.to_le_bytes());
2461 elf[ph1 + 32..ph1 + 40].copy_from_slice(&32u64.to_le_bytes());
2462
2463 // Note: PaX note (name "PaX\0", type 3, desc = +mprotect (1) | +ASLR (16) = 17)
2464 let n = 200usize;
2465 elf[n..n + 4].copy_from_slice(&4u32.to_le_bytes());
2466 elf[n + 4..n + 8].copy_from_slice(&4u32.to_le_bytes());
2467 elf[n + 8..n + 12].copy_from_slice(&3u32.to_le_bytes());
2468 elf[n + 12..n + 16].copy_from_slice(b"PaX\0");
2469 elf[n + 16..n + 20].copy_from_slice(&17u32.to_le_bytes());
2470
2471 let mut source: &[u8] = &elf;
2472 let details =
2473 inspect_elf_details(&mut source, None).expect("Should parse ELF");
2474 assert!(details.pax_flags.is_some());
2475 assert!(details.suffix.contains("PaX: +mprotect,+ASLR"));
2476 }
2477
2478 #[crate::ctb_test]
2479 fn test_readelf_core_dump_svr4() {
2480 let mut elf = vec![0u8; 1024];
2481 elf[..4].copy_from_slice(b"\x7fELF");
2482 elf[4] = 2; // 64-bit
2483 elf[5] = 1; // LSB
2484 elf[6] = 1;
2485 elf[7] = 0; // SYSV
2486 elf[16] = 4; // e_type: ET_CORE
2487 elf[18] = 0x3E; // x86-64
2488
2489 // e_phoff = 64, phnum = 2
2490 elf[32..40].copy_from_slice(&64u64.to_le_bytes());
2491 elf[54..56].copy_from_slice(&56u16.to_le_bytes());
2492 elf[56..58].copy_from_slice(&2u16.to_le_bytes());
2493
2494 // Phdr 0: PT_LOAD at offset 512, filesz 256, vaddr 0x400000
2495 let ph0 = 64usize;
2496 elf[ph0..ph0 + 4].copy_from_slice(&1u32.to_le_bytes()); // PT_LOAD
2497 elf[ph0 + 8..ph0 + 16].copy_from_slice(&512u64.to_le_bytes());
2498 elf[ph0 + 16..ph0 + 24].copy_from_slice(&0x400000u64.to_le_bytes());
2499 elf[ph0 + 32..ph0 + 40].copy_from_slice(&256u64.to_le_bytes());
2500
2501 // String at vaddr 0x400000 (offset 512): "/bin/myprog\0"
2502 let execfn_bytes = b"/bin/myprog\0";
2503 elf[512..512 + execfn_bytes.len()].copy_from_slice(execfn_bytes);
2504
2505 // Phdr 1: PT_NOTE at offset 200, size 512
2506 let ph1 = 64usize + 56;
2507 elf[ph1..ph1 + 4].copy_from_slice(&4u32.to_le_bytes()); // PT_NOTE
2508 elf[ph1 + 8..ph1 + 16].copy_from_slice(&200u64.to_le_bytes());
2509 elf[ph1 + 32..ph1 + 40].copy_from_slice(&512u64.to_le_bytes());
2510
2511 // Note 1: NT_PRPSINFO (3), name "CORE\0", size 128
2512 let n1 = 200usize;
2513 elf[n1..n1 + 4].copy_from_slice(&5u32.to_le_bytes());
2514 elf[n1 + 4..n1 + 8].copy_from_slice(&128u32.to_le_bytes());
2515 elf[n1 + 8..n1 + 12].copy_from_slice(&3u32.to_le_bytes()); // NT_PRPSINFO
2516 elf[n1 + 12..n1 + 17].copy_from_slice(b"CORE\0");
2517 // PRPSOFFSETS64[2] is 56 (Linux command line): write "myprog -v\0" at n1 + 20 + 56
2518 let cmd_bytes = b"myprog -v\0";
2519 elf[n1 + 20 + 56..n1 + 20 + 56 + cmd_bytes.len()]
2520 .copy_from_slice(cmd_bytes);
2521
2522 // Note 2: NT_PRSTATUS (1), size 256
2523 let n2 = n1 + 20 + 128;
2524 elf[n2..n2 + 4].copy_from_slice(&5u32.to_le_bytes());
2525 elf[n2 + 4..n2 + 8].copy_from_slice(&256u32.to_le_bytes());
2526 elf[n2 + 8..n2 + 12].copy_from_slice(&1u32.to_le_bytes()); // NT_PRSTATUS
2527 elf[n2 + 12..n2 + 17].copy_from_slice(b"CORE\0");
2528 // signal = 11 (SIGSEGV) at n2 + 20 + 0
2529 elf[n2 + 20..n2 + 20 + 4].copy_from_slice(&11u32.to_le_bytes());
2530 // pid = 4321 at n2 + 20 + 32
2531 elf[n2 + 20 + 32..n2 + 20 + 36].copy_from_slice(&4321u32.to_le_bytes());
2532 // rip = 0x401234 at n2 + 20 + 240
2533 elf[n2 + 20 + 240..n2 + 20 + 248]
2534 .copy_from_slice(&0x401234u64.to_le_bytes());
2535
2536 let mut source: &[u8] = &elf;
2537 let details = inspect_elf_details(&mut source, None)
2538 .expect("Should parse ELF core");
2539 assert_eq!(details.e_type, 4);
2540 let core = details.core_details.expect("Should have core details");
2541 assert_eq!(core.os_style, Some("SVR4"));
2542 assert_eq!(core.command_line.as_deref(), Some("myprog -v"));
2543 assert_eq!(core.signal, Some(11));
2544 assert_eq!(core.pid, Some(4321));
2545 assert_eq!(core.register_ip, Some(0x401234));
2546 assert!(details.suffix.contains(", SVR4-style, from 'myprog -v'"));
2547 }
2548
2549 #[crate::ctb_test]
2550 fn test_readelf_core_dump_netbsd() {
2551 let mut elf = vec![0u8; 512];
2552 elf[..4].copy_from_slice(b"\x7fELF");
2553 elf[4] = 2; // 64-bit
2554 elf[5] = 1; // LSB
2555 elf[6] = 1;
2556 elf[7] = 2; // NetBSD
2557 elf[16] = 4; // ET_CORE
2558 elf[18] = 0x3E; // x86-64
2559
2560 elf[32..40].copy_from_slice(&64u64.to_le_bytes());
2561 elf[54..56].copy_from_slice(&56u16.to_le_bytes());
2562 elf[56..58].copy_from_slice(&1u16.to_le_bytes());
2563
2564 // Phdr 0: PT_NOTE at offset 128, size 200
2565 let ph0 = 64usize;
2566 elf[ph0..ph0 + 4].copy_from_slice(&4u32.to_le_bytes());
2567 elf[ph0 + 8..ph0 + 16].copy_from_slice(&128u64.to_le_bytes());
2568 elf[ph0 + 32..ph0 + 40].copy_from_slice(&200u64.to_le_bytes());
2569
2570 // Note: NT_NETBSD_CORE_PROCINFO (1), name "NetBSD-CORE\0", size 160
2571 let n = 128usize;
2572 elf[n..n + 4].copy_from_slice(&12u32.to_le_bytes());
2573 elf[n + 4..n + 8].copy_from_slice(&160u32.to_le_bytes());
2574 elf[n + 8..n + 12].copy_from_slice(&1u32.to_le_bytes());
2575 elf[n + 12..n + 24].copy_from_slice(b"NetBSD-CORE\0");
2576
2577 let d = n + 24;
2578 // signo = 6 (SIGABRT) at d + 8
2579 elf[d + 8..d + 12].copy_from_slice(&6u32.to_le_bytes());
2580 // pid = 999 at d + 80
2581 elf[d + 80..d + 84].copy_from_slice(&999u32.to_le_bytes());
2582 // euid = 1000 at d + 100
2583 elf[d + 100..d + 104].copy_from_slice(&1000u32.to_le_bytes());
2584 // egid = 1000 at d + 112
2585 elf[d + 112..d + 116].copy_from_slice(&1000u32.to_le_bytes());
2586 // nlwps = 1 at d + 120
2587 elf[d + 120..d + 124].copy_from_slice(&1u32.to_le_bytes());
2588 // name = "sh" at d + 124
2589 elf[d + 124..d + 127].copy_from_slice(b"sh\0");
2590
2591 let mut source: &[u8] = &elf;
2592 let details = inspect_elf_details(&mut source, None)
2593 .expect("Should parse NetBSD core");
2594 let core = details.core_details.expect("Should have core details");
2595 assert_eq!(core.os_style, Some("NetBSD"));
2596 assert_eq!(core.command_line.as_deref(), Some("sh"));
2597 assert_eq!(core.pid, Some(999));
2598 assert_eq!(core.signal, Some(6));
2599 assert!(details.suffix.contains(
2600 ", NetBSD-style, from 'sh', pid=999, uid=1000, gid=1000, nlwps=1"
2601 ));
2602 }
2603
2604 #[crate::ctb_test]
2605 fn test_readelf_android_memtag_and_ndk() {
2606 let mut elf = vec![0u8; 512];
2607 elf[..4].copy_from_slice(b"\x7fELF");
2608 elf[4] = 2; // 64-bit
2609 elf[5] = 1; // LSB
2610 elf[6] = 1;
2611 elf[7] = 0;
2612 elf[16] = 2; // ET_EXEC
2613 elf[18] = 0xB7; // ARM aarch64
2614
2615 elf[32..40].copy_from_slice(&64u64.to_le_bytes());
2616 elf[54..56].copy_from_slice(&56u16.to_le_bytes());
2617 elf[56..58].copy_from_slice(&1u16.to_le_bytes());
2618
2619 // Phdr 0: PT_NOTE at offset 128, size 200
2620 let ph0 = 64usize;
2621 elf[ph0..ph0 + 4].copy_from_slice(&4u32.to_le_bytes());
2622 elf[ph0 + 8..ph0 + 16].copy_from_slice(&128u64.to_le_bytes());
2623 elf[ph0 + 32..ph0 + 40].copy_from_slice(&200u64.to_le_bytes());
2624
2625 // Note 1: Android Memtag (type 4), name "Android\0", desc = async (2) | heap (8) = 10
2626 let n1 = 128usize;
2627 elf[n1..n1 + 4].copy_from_slice(&8u32.to_le_bytes());
2628 elf[n1 + 4..n1 + 8].copy_from_slice(&4u32.to_le_bytes());
2629 elf[n1 + 8..n1 + 12].copy_from_slice(&4u32.to_le_bytes()); // NT_ANDROID_MEMTAG
2630 elf[n1 + 12..n1 + 20].copy_from_slice(b"Android\0");
2631 elf[n1 + 20..n1 + 24].copy_from_slice(&10u32.to_le_bytes());
2632
2633 // Note 2: Android Version + NDK (type 1), descsz = 132
2634 let n2 = n1 + 24;
2635 elf[n2..n2 + 4].copy_from_slice(&8u32.to_le_bytes());
2636 elf[n2 + 4..n2 + 8].copy_from_slice(&132u32.to_le_bytes());
2637 elf[n2 + 8..n2 + 12].copy_from_slice(&1u32.to_le_bytes()); // NT_ANDROID_VERSION
2638 elf[n2 + 12..n2 + 20].copy_from_slice(b"Android\0");
2639 // API level 33 at n2 + 20
2640 elf[n2 + 20..n2 + 24].copy_from_slice(&33u32.to_le_bytes());
2641 // Release "r25b" at n2 + 24
2642 elf[n2 + 24..n2 + 29].copy_from_slice(b"r25b\0");
2643 // Build "8937345" at n2 + 20 + 4 + 64
2644 elf[n2 + 88..n2 + 96].copy_from_slice(b"8937345\0");
2645
2646 let mut source: &[u8] = &elf;
2647 let details = inspect_elf_details(&mut source, None)
2648 .expect("Should parse Android notes");
2649 assert_eq!(details.android_memtag.as_deref(), Some("async,heap"));
2650 assert!(details.suffix.contains(", Android Memtag: async,heap"));
2651 assert!(details.suffix.contains(", for Android 33"));
2652 assert!(details.suffix.contains(", built by NDK r25b (8937345)"));
2653 }
2654
2655 #[crate::ctb_test]
2656 fn test_readelf_dragonfly_and_suse() {
2657 let mut elf = vec![0u8; 512];
2658 elf[..4].copy_from_slice(b"\x7fELF");
2659 elf[4] = 2; // 64-bit
2660 elf[5] = 1; // LSB
2661 elf[6] = 1;
2662 elf[7] = 0;
2663 elf[16] = 2;
2664 elf[18] = 0x3E;
2665
2666 elf[32..40].copy_from_slice(&64u64.to_le_bytes());
2667 elf[54..56].copy_from_slice(&56u16.to_le_bytes());
2668 elf[56..58].copy_from_slice(&1u16.to_le_bytes());
2669
2670 let ph0 = 64usize;
2671 elf[ph0..ph0 + 4].copy_from_slice(&4u32.to_le_bytes());
2672 elf[ph0 + 8..ph0 + 16].copy_from_slice(&128u64.to_le_bytes());
2673 elf[ph0 + 32..ph0 + 40].copy_from_slice(&64u64.to_le_bytes());
2674
2675 // Note: DragonFly (type 1), descsz 4, ver = 580002 -> 5.8.2
2676 let n = 128usize;
2677 elf[n..n + 4].copy_from_slice(&10u32.to_le_bytes());
2678 elf[n + 4..n + 8].copy_from_slice(&4u32.to_le_bytes());
2679 elf[n + 8..n + 12].copy_from_slice(&1u32.to_le_bytes());
2680 elf[n + 12..n + 22].copy_from_slice(b"DragonFly\0");
2681 let d = n + 24; // aligned to 4
2682 elf[d..d + 4].copy_from_slice(&580002u32.to_le_bytes());
2683
2684 let mut source: &[u8] = &elf;
2685 let details = inspect_elf_details(&mut source, None)
2686 .expect("Should parse DragonFly note");
2687 assert!(details.suffix.contains(", for DragonFly 5.8.2"));
2688 }
2689}
2690/*
2691/*
2692 * Adapted from: apptype.c, Written by Eberhard Mattes and put into the
2693 * file_public domain
2694 *
2695 * Notes: 1. Qualify the filename so that DosQueryAppType does not do extraneous
2696 * searches.
2697 *
2698 * 2. DosQueryAppType will return FAPPTYP_DOS on a file ending with ".com"
2699 * (other than an OS/2 exe or Win exe with this name). Eberhard Mattes
2700 * remarks Tue, 6 Apr 93: Moreover, it reports the type of the (new and very
2701 * bug ridden) Win Emacs as "OS/2 executable".
2702 *
2703 * 3. apptype() uses the filename if given, otherwise a tmp file is created with
2704 * the contents of buf. If buf is not the complete file, apptype can
2705 * incorrectly identify the exe type. The "-z" option of "file" is the reason
2706 * for this ugly code.
2707 */
2708
2709The preceding notice is from src/apptype.c in `file`.
2710
2711
2712
2713/*-
2714 * Copyright (c) 2008 Christos Zoulas
2715 * All rights reserved.
2716 *
2717 * Redistribution and use in source and binary forms, with or without
2718 * modification, are permitted provided that the following conditions
2719 * are met:
2720 * 1. Redistributions of source code must retain the above copyright
2721 * notice, this list of conditions and the following disclaimer.
2722 * 2. Redistributions in binary form must reproduce the above copyright
2723 * notice, this list of conditions and the following disclaimer in the
2724 * documentation and/or other materials provided with the distribution.
2725 *
2726 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2727 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2728 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2729 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2730 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2731 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2732 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2733 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2734 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2735 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2736 * POSSIBILITY OF SUCH DAMAGE.
2737 */
2738
2739The preceding notice is from src/cdf.c, src/cdf.h, and src/cdf_time.c in `file`.
2740
2741
2742
2743/*-
2744 * Copyright (c) 2016 Christos Zoulas
2745 * All rights reserved.
2746 *
2747 * Redistribution and use in source and binary forms, with or without
2748 * modification, are permitted provided that the following conditions
2749 * are met:
2750 * 1. Redistributions of source code must retain the above copyright
2751 * notice, this list of conditions and the following disclaimer.
2752 * 2. Redistributions in binary form must reproduce the above copyright
2753 * notice, this list of conditions and the following disclaimer in the
2754 * documentation and/or other materials provided with the distribution.
2755 *
2756 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2757 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2758 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2759 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2760 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2761 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2762 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2763 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2764 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2765 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2766 * POSSIBILITY OF SUCH DAMAGE.
2767 */
2768
2769The preceding notice is from src/der.c and src/der.h in `file`.
2770
2771
2772
2773/*-
2774 * Copyright (c) 2019 Christos Zoulas
2775 * All rights reserved.
2776 *
2777 * Redistribution and use in source and binary forms, with or without
2778 * modification, are permitted provided that the following conditions
2779 * are met:
2780 * 1. Redistributions of source code must retain the above copyright
2781 * notice, this list of conditions and the following disclaimer.
2782 * 2. Redistributions in binary form must reproduce the above copyright
2783 * notice, this list of conditions and the following disclaimer in the
2784 * documentation and/or other materials provided with the distribution.
2785 *
2786 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2787 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2788 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2789 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2790 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2791 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2792 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2793 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2794 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2795 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2796 * POSSIBILITY OF SUCH DAMAGE.
2797 */
2798
2799The preceding notice is from src/is_csv.c in `file`.
2800
2801
2802
2803/*-
2804 * Copyright (c) 2018 Christos Zoulas
2805 * All rights reserved.
2806 *
2807 * Redistribution and use in source and binary forms, with or without
2808 * modification, are permitted provided that the following conditions
2809 * are met:
2810 * 1. Redistributions of source code must retain the above copyright
2811 * notice, this list of conditions and the following disclaimer.
2812 * 2. Redistributions in binary form must reproduce the above copyright
2813 * notice, this list of conditions and the following disclaimer in the
2814 * documentation and/or other materials provided with the distribution.
2815 *
2816 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2817 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2818 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2819 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2820 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2821 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2822 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2823 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2824 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2825 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2826 * POSSIBILITY OF SUCH DAMAGE.
2827 */
2828
2829The preceding notice is from src/is_json.c in `file`.
2830
2831
2832
2833/*-
2834 * Copyright (c) 2023 Christos Zoulas
2835 * All rights reserved.
2836 *
2837 * Redistribution and use in source and binary forms, with or without
2838 * modification, are permitted provided that the following conditions
2839 * are met:
2840 * 1. Redistributions of source code must retain the above copyright
2841 * notice, this list of conditions and the following disclaimer.
2842 * 2. Redistributions in binary form must reproduce the above copyright
2843 * notice, this list of conditions and the following disclaimer in the
2844 * documentation and/or other materials provided with the distribution.
2845 *
2846 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2847 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2848 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2849 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2850 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2851 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2852 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2853 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2854 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2855 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2856 * POSSIBILITY OF SUCH DAMAGE.
2857 */
2858
2859The preceding notice is from src/is_simh.c in `file`.
2860
2861
2862
2863/*-
2864 * SPDX-License-Identifier: BSD-3-Clause
2865 *
2866 * Copyright (c) 1992, 1993, 1994 Henry Spencer.
2867 * Copyright (c) 1992, 1993, 1994
2868 * The Regents of the University of California. All rights reserved.
2869 *
2870 * This code is derived from software contributed to Berkeley by
2871 * Henry Spencer.
2872 *
2873 * Redistribution and use in source and binary forms, with or without
2874 * modification, are permitted provided that the following conditions
2875 * are met:
2876 * 1. Redistributions of source code must retain the above copyright
2877 * notice, this list of conditions and the following disclaimer.
2878 * 2. Redistributions in binary form must reproduce the above copyright
2879 * notice, this list of conditions and the following disclaimer in the
2880 * documentation and/or other materials provided with the distribution.
2881 * 3. Neither the name of the University nor the names of its contributors
2882 * may be used to endorse or promote products derived from this software
2883 * without specific prior written permission.
2884 *
2885 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2886 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2887 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2888 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2889 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2890 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2891 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2892 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2893 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2894 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2895 * SUCH DAMAGE.
2896 *
2897 * @(#)cname.h 8.3 (Berkeley) 3/20/94
2898 * $FreeBSD: head/lib/libc/regex/cname.h 326025 2017-11-20 19:49:47Z pfg $
2899 */
2900
2901The preceding notice is from src/missing/cname.h in `file`.
2902
2903
2904
2905/*-
2906 * SPDX-License-Identifier: BSD-3-Clause
2907 *
2908 * Copyright (c) 1992, 1993, 1994 Henry Spencer.
2909 * Copyright (c) 1992, 1993, 1994
2910 * The Regents of the University of California. All rights reserved.
2911 *
2912 * This code is derived from software contributed to Berkeley by
2913 * Henry Spencer.
2914 *
2915 * Redistribution and use in source and binary forms, with or without
2916 * modification, are permitted provided that the following conditions
2917 * are met:
2918 * 1. Redistributions of source code must retain the above copyright
2919 * notice, this list of conditions and the following disclaimer.
2920 * 2. Redistributions in binary form must reproduce the above copyright
2921 * notice, this list of conditions and the following disclaimer in the
2922 * documentation and/or other materials provided with the distribution.
2923 * 3. Neither the name of the University nor the names of its contributors
2924 * may be used to endorse or promote products derived from this software
2925 * without specific prior written permission.
2926 *
2927 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2928 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2929 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2930 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2931 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2932 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2933 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2934 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2935 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2936 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2937 * SUCH DAMAGE.
2938 *
2939 * @(#)engine.c 8.5 (Berkeley) 3/20/94
2940 */
2941
2942The preceding notice is from src/missing/engine.c in `file`.
2943
2944
2945
2946/*-
2947 * Copyright (c) 2000 The NetBSD Foundation, Inc.
2948 * All rights reserved.
2949 *
2950 * This code was contributed to The NetBSD Foundation by Allen Briggs.
2951 *
2952 * Redistribution and use in source and binary forms, with or without
2953 * modification, are permitted provided that the following conditions
2954 * are met:
2955 * 1. Redistributions of source code must retain the above copyright
2956 * notice, this list of conditions and the following disclaimer.
2957 * 2. Redistributions in binary form must reproduce the above copyright
2958 * notice, this list of conditions and the following disclaimer in the
2959 * documentation and/or other materials provided with the distribution.
2960 *
2961 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2962 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2963 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2964 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2965 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2966 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2967 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2968 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2969 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2970 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2971 * POSSIBILITY OF SUCH DAMAGE.
2972 */
2973
2974The preceding notice is from src/missing/fmtcheck.c in `file`.
2975
2976
2977
2978/*-
2979 * Copyright (c) 2011 The NetBSD Foundation, Inc.
2980 * All rights reserved.
2981 *
2982 * This code is derived from software contributed to The NetBSD Foundation
2983 * by Christos Zoulas.
2984 *
2985 * Redistribution and use in source and binary forms, with or without
2986 * modification, are permitted provided that the following conditions
2987 * are met:
2988 * 1. Redistributions of source code must retain the above copyright
2989 * notice, this list of conditions and the following disclaimer.
2990 * 2. Redistributions in binary form must reproduce the above copyright
2991 * notice, this list of conditions and the following disclaimer in the
2992 * documentation and/or other materials provided with the distribution.
2993 *
2994 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2995 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2996 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2997 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2998 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2999 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
3000 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
3001 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
3002 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3003 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3004 * POSSIBILITY OF SUCH DAMAGE.
3005 */
3006
3007The preceding notice is from src/missing/getline.c in `file`.
3008
3009
3010
3011/*-
3012 * Copyright (c) 2000 The NetBSD Foundation, Inc.
3013 * All rights reserved.
3014 *
3015 * This code is derived from software contributed to The NetBSD Foundation
3016 * by Dieter Baron and Thomas Klausner.
3017 *
3018 * Redistribution and use in source and binary forms, with or without
3019 * modification, are permitted provided that the following conditions
3020 * are met:
3021 * 1. Redistributions of source code must retain the above copyright
3022 * notice, this list of conditions and the following disclaimer.
3023 * 2. Redistributions in binary form must reproduce the above copyright
3024 * notice, this list of conditions and the following disclaimer in the
3025 * documentation and/or other materials provided with the distribution.
3026 *
3027 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
3028 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
3029 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
3030 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
3031 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
3032 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
3033 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
3034 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
3035 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3036 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3037 * POSSIBILITY OF SUCH DAMAGE.
3038 */
3039
3040The preceding notice is from src/missing/getopt_long.c and src/mygetopt.h in `file`.
3041
3042
3043
3044/*
3045 * Public domain fallback for reallocarray(3), for platforms (e.g.
3046 * AmigaOS/libnix) whose C library declares it but does not implement it.
3047 */
3048
3049The preceding notice is from src/missing/reallocarray.c in `file`.
3050
3051
3052
3053/*-
3054 * SPDX-License-Identifier: BSD-3-Clause
3055 *
3056 * Copyright (c) 1992, 1993, 1994 Henry Spencer.
3057 * Copyright (c) 1992, 1993, 1994
3058 * The Regents of the University of California. All rights reserved.
3059 *
3060 * Copyright (c) 2011 The FreeBSD Foundation
3061 * All rights reserved.
3062 * Portions of this software were developed by David Chisnall
3063 * under sponsorship from the FreeBSD Foundation.
3064 *
3065 * This code is derived from software contributed to Berkeley by
3066 * Henry Spencer.
3067 *
3068 * Redistribution and use in source and binary forms, with or without
3069 * modification, are permitted provided that the following conditions
3070 * are met:
3071 * 1. Redistributions of source code must retain the above copyright
3072 * notice, this list of conditions and the following disclaimer.
3073 * 2. Redistributions in binary form must reproduce the above copyright
3074 * notice, this list of conditions and the following disclaimer in the
3075 * documentation and/or other materials provided with the distribution.
3076 * 3. Neither the name of the University nor the names of its contributors
3077 * may be used to endorse or promote products derived from this software
3078 * without specific prior written permission.
3079 *
3080 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
3081 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3082 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3083 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
3084 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3085 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3086 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3087 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3088 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3089 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3090 * SUCH DAMAGE.
3091 *
3092 * @(#)regcomp.c 8.5 (Berkeley) 3/20/94
3093 */
3094
3095The preceding notice is from src/missing/regcomp.c in `file`.
3096
3097
3098
3099/*-
3100 * SPDX-License-Identifier: BSD-3-Clause
3101 *
3102 * Copyright (c) 1992, 1993, 1994 Henry Spencer.
3103 * Copyright (c) 1992, 1993, 1994
3104 * The Regents of the University of California. All rights reserved.
3105 *
3106 * This code is derived from software contributed to Berkeley by
3107 * Henry Spencer.
3108 *
3109 * Redistribution and use in source and binary forms, with or without
3110 * modification, are permitted provided that the following conditions
3111 * are met:
3112 * 1. Redistributions of source code must retain the above copyright
3113 * notice, this list of conditions and the following disclaimer.
3114 * 2. Redistributions in binary form must reproduce the above copyright
3115 * notice, this list of conditions and the following disclaimer in the
3116 * documentation and/or other materials provided with the distribution.
3117 * 3. Neither the name of the University nor the names of its contributors
3118 * may be used to endorse or promote products derived from this software
3119 * without specific prior written permission.
3120 *
3121 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
3122 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3123 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3124 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
3125 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3126 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3127 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3128 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3129 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3130 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3131 * SUCH DAMAGE.
3132 *
3133 * @(#)regerror.c 8.4 (Berkeley) 3/20/94
3134 */
3135
3136The preceding notice is from src/missing/regerror.c in `file`.
3137
3138
3139
3140$NetBSD: COPYRIGHT,v 1.5 2003/08/07 16:43:19 agc Exp $
3141
3142Copyright 1992, 1993, 1994 Henry Spencer. All rights reserved.
3143This software is not subject to any license of the American Telephone
3144and Telegraph Company or of the Regents of the University of California.
3145
3146Permission is granted to anyone to use this software for any purpose on
3147any computer system, and to alter it and redistribute it, subject
3148to the following restrictions:
3149
31501. The author is not responsible for the consequences of use of this
3151 software, no matter how awful, even if they arise from flaws in it.
3152
31532. The origin of this software must not be misrepresented, either by
3154 explicit claim or by omission. Since few users ever read sources,
3155 credits must appear in the documentation.
3156
31573. Altered versions must be plainly marked as such, and must not be
3158 misrepresented as being the original software. Since few users
3159 ever read sources, credits must appear in the documentation.
3160
31614. This notice may not be removed or altered.
3162
3163=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
3164/*-
3165 * Copyright (c) 1994
3166 * The Regents of the University of California. All rights reserved.
3167 *
3168 * Redistribution and use in source and binary forms, with or without
3169 * modification, are permitted provided that the following conditions
3170 * are met:
3171 * 1. Redistributions of source code must retain the above copyright
3172 * notice, this list of conditions and the following disclaimer.
3173 * 2. Redistributions in binary form must reproduce the above copyright
3174 * notice, this list of conditions and the following disclaimer in the
3175 * documentation and/or other materials provided with the distribution.
3176 * 3. Neither the name of the University nor the names of its contributors
3177 * may be used to endorse or promote products derived from this software
3178 * without specific prior written permission.
3179 *
3180 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
3181 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3182 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3183 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
3184 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3185 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3186 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3187 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3188 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3189 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3190 * SUCH DAMAGE.
3191 *
3192 * @(#)COPYRIGHT 8.1 (Berkeley) 3/16/94
3193 */
3194
3195The preceding notice is from src/missing/REGEX-COPYRIGHT in `file`.
3196
3197
3198
3199/*-
3200 * SPDX-License-Identifier: BSD-3-Clause
3201 *
3202 * Copyright (c) 1992, 1993, 1994 Henry Spencer.
3203 * Copyright (c) 1992, 1993, 1994
3204 * The Regents of the University of California. All rights reserved.
3205 *
3206 * This code is derived from software contributed to Berkeley by
3207 * Henry Spencer.
3208 *
3209 * Redistribution and use in source and binary forms, with or without
3210 * modification, are permitted provided that the following conditions
3211 * are met:
3212 * 1. Redistributions of source code must retain the above copyright
3213 * notice, this list of conditions and the following disclaimer.
3214 * 2. Redistributions in binary form must reproduce the above copyright
3215 * notice, this list of conditions and the following disclaimer in the
3216 * documentation and/or other materials provided with the distribution.
3217 * 3. Neither the name of the University nor the names of its contributors
3218 * may be used to endorse or promote products derived from this software
3219 * without specific prior written permission.
3220 *
3221 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
3222 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3223 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3224 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
3225 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3226 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3227 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3228 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3229 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3230 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3231 * SUCH DAMAGE.
3232 *
3233 * @(#)regex2.h 8.4 (Berkeley) 3/20/94
3234 * $FreeBSD: head/lib/libc/regex/regex2.h 368359 2020-12-05 03:18:48Z kevans $
3235 */
3236
3237The preceding notice is from src/missing/regex2.h in `file`.
3238
3239
3240
3241/*-
3242 * SPDX-License-Identifier: BSD-3-Clause
3243 *
3244 * Copyright (c) 1992, 1993, 1994 Henry Spencer.
3245 * Copyright (c) 1992, 1993, 1994
3246 * The Regents of the University of California. All rights reserved.
3247 *
3248 * This code is derived from software contributed to Berkeley by
3249 * Henry Spencer.
3250 *
3251 * Redistribution and use in source and binary forms, with or without
3252 * modification, are permitted provided that the following conditions
3253 * are met:
3254 * 1. Redistributions of source code must retain the above copyright
3255 * notice, this list of conditions and the following disclaimer.
3256 * 2. Redistributions in binary form must reproduce the above copyright
3257 * notice, this list of conditions and the following disclaimer in the
3258 * documentation and/or other materials provided with the distribution.
3259 * 3. Neither the name of the University nor the names of its contributors
3260 * may be used to endorse or promote products derived from this software
3261 * without specific prior written permission.
3262 *
3263 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
3264 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3265 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3266 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
3267 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3268 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3269 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3270 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3271 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3272 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3273 * SUCH DAMAGE.
3274 *
3275 * @(#)regexec.c 8.3 (Berkeley) 3/20/94
3276 */
3277
3278The preceding notice is from src/missing/regexec.c in `file`.
3279
3280
3281
3282/*-
3283 * SPDX-License-Identifier: BSD-3-Clause
3284 *
3285 * Copyright (c) 1992, 1993, 1994 Henry Spencer.
3286 * Copyright (c) 1992, 1993, 1994
3287 * The Regents of the University of California. All rights reserved.
3288 *
3289 * This code is derived from software contributed to Berkeley by
3290 * Henry Spencer.
3291 *
3292 * Redistribution and use in source and binary forms, with or without
3293 * modification, are permitted provided that the following conditions
3294 * are met:
3295 * 1. Redistributions of source code must retain the above copyright
3296 * notice, this list of conditions and the following disclaimer.
3297 * 2. Redistributions in binary form must reproduce the above copyright
3298 * notice, this list of conditions and the following disclaimer in the
3299 * documentation and/or other materials provided with the distribution.
3300 * 3. Neither the name of the University nor the names of its contributors
3301 * may be used to endorse or promote products derived from this software
3302 * without specific prior written permission.
3303 *
3304 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
3305 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3306 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3307 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
3308 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3309 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3310 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3311 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3312 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3313 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3314 * SUCH DAMAGE.
3315 *
3316 * @(#)regfree.c 8.3 (Berkeley) 3/20/94
3317 */
3318
3319The preceding notice is from src/missing/regfree.c in `file`.
3320
3321
3322
3323/*-
3324 * Copyright (c) 1990, 1993
3325 * The Regents of the University of California. All rights reserved.
3326 *
3327 * This code is derived from software contributed to Berkeley by
3328 * Chris Torek.
3329 *
3330 * Redistribution and use in source and binary forms, with or without
3331 * modification, are permitted provided that the following conditions
3332 * are met:
3333 * 1. Redistributions of source code must retain the above copyright
3334 * notice, this list of conditions and the following disclaimer.
3335 * 2. Redistributions in binary form must reproduce the above copyright
3336 * notice, this list of conditions and the following disclaimer in the
3337 * documentation and/or other materials provided with the distribution.
3338 * 3. Neither the name of the University nor the names of its contributors
3339 * may be used to endorse or promote products derived from this software
3340 * without specific prior written permission.
3341 *
3342 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
3343 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3344 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3345 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
3346 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3347 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3348 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3349 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3350 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3351 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3352 * SUCH DAMAGE.
3353 */
3354
3355The preceding notice is from src/missing/strcasestr.c in `file`.
3356
3357
3358
3359/*
3360 * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
3361 *
3362 * Permission to use, copy, modify, and distribute this software for any
3363 * purpose with or without fee is hereby granted, provided that the above
3364 * copyright notice and this permission notice appear in all copies.
3365 *
3366 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
3367 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
3368 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
3369 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
3370 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
3371 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
3372 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
3373 */
3374
3375The preceding notice is from src/missing/strlcat.c and src/missing/strlcpy.c in `file`.
3376
3377
3378
3379/*-
3380 * SPDX-License-Identifier: BSD-3-Clause
3381 *
3382 * Copyright (c) 1992, 1993, 1994 Henry Spencer.
3383 * Copyright (c) 1992, 1993, 1994
3384 * The Regents of the University of California. All rights reserved.
3385 *
3386 * This code is derived from software contributed to Berkeley by
3387 * Henry Spencer.
3388 *
3389 * Redistribution and use in source and binary forms, with or without
3390 * modification, are permitted provided that the following conditions
3391 * are met:
3392 * 1. Redistributions of source code must retain the above copyright
3393 * notice, this list of conditions and the following disclaimer.
3394 * 2. Redistributions in binary form must reproduce the above copyright
3395 * notice, this list of conditions and the following disclaimer in the
3396 * documentation and/or other materials provided with the distribution.
3397 * 3. Neither the name of the University nor the names of its contributors
3398 * may be used to endorse or promote products derived from this software
3399 * without specific prior written permission.
3400 *
3401 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
3402 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3403 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3404 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
3405 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3406 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3407 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3408 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3409 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3410 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3411 * SUCH DAMAGE.
3412 *
3413 * @(#)utils.h 8.3 (Berkeley) 3/20/94
3414 * $FreeBSD: head/lib/libc/regex/utils.h 341838 2018-12-12 04:23:00Z yuripv $
3415 */
3416
3417The preceding notice is from src/missing/utils.h in `file`.
3418
3419
3420
3421/*-
3422 * Copyright (c) 2008, 2016 Christos Zoulas
3423 * All rights reserved.
3424 *
3425 * Redistribution and use in source and binary forms, with or without
3426 * modification, are permitted provided that the following conditions
3427 * are met:
3428 * 1. Redistributions of source code must retain the above copyright
3429 * notice, this list of conditions and the following disclaimer.
3430 * 2. Redistributions in binary form must reproduce the above copyright
3431 * notice, this list of conditions and the following disclaimer in the
3432 * documentation and/or other materials provided with the distribution.
3433 *
3434 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
3435 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
3436 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
3437 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
3438 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
3439 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
3440 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
3441 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
3442 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3443 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3444 * POSSIBILITY OF SUCH DAMAGE.
3445 */
3446
3447The preceding notice is from src/readcdf.c in `file`.
3448
3449
3450
3451/*-
3452 * Copyright (c) 1992 Henry Spencer.
3453 * Copyright (c) 1992, 1993
3454 * The Regents of the University of California. All rights reserved.
3455 *
3456 * This code is derived from software contributed to Berkeley by
3457 * Henry Spencer of the University of Toronto.
3458 *
3459 * Redistribution and use in source and binary forms, with or without
3460 * modification, are permitted provided that the following conditions
3461 * are met:
3462 * 1. Redistributions of source code must retain the above copyright
3463 * notice, this list of conditions and the following disclaimer.
3464 * 2. Redistributions in binary form must reproduce the above copyright
3465 * notice, this list of conditions and the following disclaimer in the
3466 * documentation and/or other materials provided with the distribution.
3467 * 3. Neither the name of the University nor the names of its contributors
3468 * may be used to endorse or promote products derived from this software
3469 * without specific prior written permission.
3470 *
3471 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
3472 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3473 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3474 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
3475 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3476 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3477 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3478 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3479 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3480 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3481 * SUCH DAMAGE.
3482 *
3483 * @(#)regex.h 8.2 (Berkeley) 1/3/94
3484 * $FreeBSD: src/include/regex.h,v 1.12 2010/02/16 19:39:50 imp Exp $
3485 */
3486
3487The preceding notice is from src/regex-bsd.h in `file`.
3488*/
3489/*
3490
3491Text of LICENSE from DROID:
3492
3493Copyright (c) 2016, The National Archives <pronom@nationalarchives.gov.uk>
3494All rights reserved.
3495
3496Redistribution and use in source and binary forms, with or without
3497modification, are permitted provided that the following
3498conditions are met:
3499
3500 * Redistributions of source code must retain the above copyright
3501 notice, this list of conditions and the following disclaimer.
3502
3503 * Redistributions in binary form must reproduce the above copyright
3504 notice, this list of conditions and the following disclaimer in the
3505 documentation and/or other materials provided with the distribution.
3506
3507 * Neither the name of the The National Archives nor the
3508 names of its contributors may be used to endorse or promote products
3509 derived from this software without specific prior written permission.
3510
3511THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
3512AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3513IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
3514PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
3515CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
3516EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
3517PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
3518PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
3519LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
3520NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
3521SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3522*/
3523
3524/*
3525
3526Text of LICENSE from fileid:
3527
3528The MIT License (MIT)
3529
3530Copyright (c) 2015 David B Heise
3531
3532Permission is hereby granted, free of charge, to any person obtaining a copy of
3533this software and associated documentation files (the "Software"), to deal in
3534the Software without restriction, including without limitation the rights to
3535use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
3536the Software, and to permit persons to whom the Software is furnished to do so,
3537subject to the following conditions:
3538
3539The above copyright notice and this permission notice shall be included in all
3540copies or substantial portions of the Software.
3541
3542THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3543IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
3544FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
3545COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
3546IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
3547CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3548
3549
3550*/
3551
3552/*
3553Text of LICENSE from binwalk:
3554
3555
3556MIT License
3557
3558Copyright (c) 2024 devttys0
3559
3560Permission is hereby granted, free of charge, to any person obtaining a copy
3561of this software and associated documentation files (the "Software"), to deal
3562in the Software without restriction, including without limitation the rights
3563to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
3564copies of the Software, and to permit persons to whom the Software is
3565furnished to do so, subject to the following conditions:
3566
3567The above copyright notice and this permission notice shall be included in all
3568copies or substantial portions of the Software.
3569
3570THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3571IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3572FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3573AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3574LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3575OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3576SOFTWARE.
3577
3578*/
3579
3580/*
3581Text of LICENSE from polyfile:
3582
3583
3584 Apache License
3585 Version 2.0, January 2004
3586 http://www.apache.org/licenses/
3587
3588 TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
3589
3590 1. Definitions.
3591
3592 "License" shall mean the terms and conditions for use, reproduction,
3593 and distribution as defined by Sections 1 through 9 of this document.
3594
3595 "Licensor" shall mean the copyright owner or entity authorized by
3596 the copyright owner that is granting the License.
3597
3598 "Legal Entity" shall mean the union of the acting entity and all
3599 other entities that control, are controlled by, or are under common
3600 control with that entity. For the purposes of this definition,
3601 "control" means (i) the power, direct or indirect, to cause the
3602 direction or management of such entity, whether by contract or
3603 otherwise, or (ii) ownership of fifty percent (50%) or more of the
3604 outstanding shares, or (iii) beneficial ownership of such entity.
3605
3606 "You" (or "Your") shall mean an individual or Legal Entity
3607 exercising permissions granted by this License.
3608
3609 "Source" form shall mean the preferred form for making modifications,
3610 including but not limited to software source code, documentation
3611 source, and configuration files.
3612
3613 "Object" form shall mean any form resulting from mechanical
3614 transformation or translation of a Source form, including but
3615 not limited to compiled object code, generated documentation,
3616 and conversions to other media types.
3617
3618 "Work" shall mean the work of authorship, whether in Source or
3619 Object form, made available under the License, as indicated by a
3620 copyright notice that is included in or attached to the work
3621 (an example is provided in the Appendix below).
3622
3623 "Derivative Works" shall mean any work, whether in Source or Object
3624 form, that is based on (or derived from) the Work and for which the
3625 editorial revisions, annotations, elaborations, or other modifications
3626 represent, as a whole, an original work of authorship. For the purposes
3627 of this License, Derivative Works shall not include works that remain
3628 separable from, or merely link (or bind by name) to the interfaces of,
3629 the Work and Derivative Works thereof.
3630
3631 "Contribution" shall mean any work of authorship, including
3632 the original version of the Work and any modifications or additions
3633 to that Work or Derivative Works thereof, that is intentionally
3634 submitted to Licensor for inclusion in the Work by the copyright owner
3635 or by an individual or Legal Entity authorized to submit on behalf of
3636 the copyright owner. For the purposes of this definition, "submitted"
3637 means any form of electronic, verbal, or written communication sent
3638 to the Licensor or its representatives, including but not limited to
3639 communication on electronic mailing lists, source code control systems,
3640 and issue tracking systems that are managed by, or on behalf of, the
3641 Licensor for the purpose of discussing and improving the Work, but
3642 excluding communication that is conspicuously marked or otherwise
3643 designated in writing by the copyright owner as "Not a Contribution."
3644
3645 "Contributor" shall mean Licensor and any individual or Legal Entity
3646 on behalf of whom a Contribution has been received by Licensor and
3647 subsequently incorporated within the Work.
3648
3649 2. Grant of Copyright License. Subject to the terms and conditions of
3650 this License, each Contributor hereby grants to You a perpetual,
3651 worldwide, non-exclusive, no-charge, royalty-free, irrevocable
3652 copyright license to reproduce, prepare Derivative Works of,
3653 publicly display, publicly perform, sublicense, and distribute the
3654 Work and such Derivative Works in Source or Object form.
3655
3656 3. Grant of Patent License. Subject to the terms and conditions of
3657 this License, each Contributor hereby grants to You a perpetual,
3658 worldwide, non-exclusive, no-charge, royalty-free, irrevocable
3659 (except as stated in this section) patent license to make, have made,
3660 use, offer to sell, sell, import, and otherwise transfer the Work,
3661 where such license applies only to those patent claims licensable
3662 by such Contributor that are necessarily infringed by their
3663 Contribution(s) alone or by combination of their Contribution(s)
3664 with the Work to which such Contribution(s) was submitted. If You
3665 institute patent litigation against any entity (including a
3666 cross-claim or counterclaim in a lawsuit) alleging that the Work
3667 or a Contribution incorporated within the Work constitutes direct
3668 or contributory patent infringement, then any patent licenses
3669 granted to You under this License for that Work shall terminate
3670 as of the date such litigation is filed.
3671
3672 4. Redistribution. You may reproduce and distribute copies of the
3673 Work or Derivative Works thereof in any medium, with or without
3674 modifications, and in Source or Object form, provided that You
3675 meet the following conditions:
3676
3677 (a) You must give any other recipients of the Work or
3678 Derivative Works a copy of this License; and
3679
3680 (b) You must cause any modified files to carry prominent notices
3681 stating that You changed the files; and
3682
3683 (c) You must retain, in the Source form of any Derivative Works
3684 that You distribute, all copyright, patent, trademark, and
3685 attribution notices from the Source form of the Work,
3686 excluding those notices that do not pertain to any part of
3687 the Derivative Works; and
3688
3689 (d) If the Work includes a "NOTICE" text file as part of its
3690 distribution, then any Derivative Works that You distribute must
3691 include a readable copy of the attribution notices contained
3692 within such NOTICE file, excluding those notices that do not
3693 pertain to any part of the Derivative Works, in at least one
3694 of the following places: within a NOTICE text file distributed
3695 as part of the Derivative Works; within the Source form or
3696 documentation, if provided along with the Derivative Works; or,
3697 within a display generated by the Derivative Works, if and
3698 wherever such third-party notices normally appear. The contents
3699 of the NOTICE file are for informational purposes only and
3700 do not modify the License. You may add Your own attribution
3701 notices within Derivative Works that You distribute, alongside
3702 or as an addendum to the NOTICE text from the Work, provided
3703 that such additional attribution notices cannot be construed
3704 as modifying the License.
3705
3706 You may add Your own copyright statement to Your modifications and
3707 may provide additional or different license terms and conditions
3708 for use, reproduction, or distribution of Your modifications, or
3709 for any such Derivative Works as a whole, provided Your use,
3710 reproduction, and distribution of the Work otherwise complies with
3711 the conditions stated in this License.
3712
3713 5. Submission of Contributions. Unless You explicitly state otherwise,
3714 any Contribution intentionally submitted for inclusion in the Work
3715 by You to the Licensor shall be under the terms and conditions of
3716 this License, without any additional terms or conditions.
3717 Notwithstanding the above, nothing herein shall supersede or modify
3718 the terms of any separate license agreement you may have executed
3719 with Licensor regarding such Contributions.
3720
3721 6. Trademarks. This License does not grant permission to use the trade
3722 names, trademarks, service marks, or product names of the Licensor,
3723 except as required for reasonable and customary use in describing the
3724 origin of the Work and reproducing the content of the NOTICE file.
3725
3726 7. Disclaimer of Warranty. Unless required by applicable law or
3727 agreed to in writing, Licensor provides the Work (and each
3728 Contributor provides its Contributions) on an "AS IS" BASIS,
3729 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
3730 implied, including, without limitation, any warranties or conditions
3731 of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
3732 PARTICULAR PURPOSE. You are solely responsible for determining the
3733 appropriateness of using or redistributing the Work and assume any
3734 risks associated with Your exercise of permissions under this License.
3735
3736 8. Limitation of Liability. In no event and under no legal theory,
3737 whether in tort (including negligence), contract, or otherwise,
3738 unless required by applicable law (such as deliberate and grossly
3739 negligent acts) or agreed to in writing, shall any Contributor be
3740 liable to You for damages, including any direct, indirect, special,
3741 incidental, or consequential damages of any character arising as a
3742 result of this License or out of the use or inability to use the
3743 Work (including but not limited to damages for loss of goodwill,
3744 work stoppage, computer failure or malfunction, or any and all
3745 other commercial damages or losses), even if such Contributor
3746 has been advised of the possibility of such damages.
3747
3748 9. Accepting Warranty or Additional Liability. While redistributing
3749 the Work or Derivative Works thereof, You may choose to offer,
3750 and charge a fee for, acceptance of support, warranty, indemnity,
3751 or other liability obligations and/or rights consistent with this
3752 License. However, in accepting such obligations, You may act only
3753 on Your own behalf and on Your sole responsibility, not on behalf
3754 of any other Contributor, and only if You agree to indemnify,
3755 defend, and hold each Contributor harmless for any liability
3756 incurred by, or claims asserted against, such Contributor by reason
3757 of your accepting any such warranty or additional liability.
3758
3759 END OF TERMS AND CONDITIONS
3760
3761 APPENDIX: How to apply the Apache License to your work.
3762
3763 To apply the Apache License to your work, attach the following
3764 boilerplate notice, with the fields enclosed by brackets "[]"
3765 replaced with your own identifying information. (Don't include
3766 the brackets!) The text should be enclosed in the appropriate
3767 comment syntax for the file format. We also recommend that a
3768 file or class name and description of purpose be included on the
3769 same "printed page" as the copyright notice for easier
3770 identification within third-party archives.
3771
3772 Copyright [yyyy] [name of copyright owner]
3773
3774 Licensed under the Apache License, Version 2.0 (the "License");
3775 you may not use this file except in compliance with the License.
3776 You may obtain a copy of the License at
3777
3778 http://www.apache.org/licenses/LICENSE-2.0
3779
3780 Unless required by applicable law or agreed to in writing, software
3781 distributed under the License is distributed on an "AS IS" BASIS,
3782 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3783 See the License for the specific language governing permissions and
3784 limitations under the License.
3785
3786*/