Lines Matching +full:0 +full:ms
66 (namesz == sizeof(v) && memcmp(n, v, namesz) == 0)
69 toomany(struct magic_set *ms, const char *name, uint16_t num) in toomany() argument
71 if (ms->flags & MAGIC_MIME) in toomany()
73 if (file_printf(ms, ", too many %s (%u)", name, num) == -1) in toomany()
89 retval.c[0] = tmpval.c[1]; in getu16()
90 retval.c[1] = tmpval.c[0]; in getu16()
108 retval.c[0] = tmpval.c[3]; in getu32()
111 retval.c[3] = tmpval.c[0]; in getu32()
129 retval.c[0] = tmpval.c[7]; in getu64()
136 retval.c[7] = tmpval.c[0]; in getu64()
325 #define OS_STYLE_SVR4 0
335 #define FLAGS_CORE_STYLE 0x0003
337 #define FLAGS_DID_CORE 0x0004
338 #define FLAGS_DID_OS_NOTE 0x0008
339 #define FLAGS_DID_BUILD_ID 0x0010
340 #define FLAGS_DID_CORE_STYLE 0x0020
341 #define FLAGS_DID_NETBSD_PAX 0x0040
342 #define FLAGS_DID_NETBSD_MARCH 0x0080
343 #define FLAGS_DID_NETBSD_CMODEL 0x0100
344 #define FLAGS_DID_NETBSD_EMULATION 0x0200
345 #define FLAGS_DID_NETBSD_UNKNOWN 0x0400
346 #define FLAGS_DID_ANDROID_MEMTAG 0x0800
347 #define FLAGS_IS_CORE 0x1000
348 #define FLAGS_DID_AUXV 0x2000
351 dophn_core(struct magic_set *ms, int clazz, int swap, int fd, off_t off, in dophn_core() argument
362 if (ms->flags & MAGIC_MIME) in dophn_core()
363 return 0; in dophn_core()
365 if (num == 0) { in dophn_core()
366 if (file_printf(ms, ", no program header") == -1) in dophn_core()
368 return 0; in dophn_core()
371 if (file_printf(ms, ", corrupted program header size") == -1) in dophn_core()
373 return 0; in dophn_core()
382 if (file_printf(ms, in dophn_core()
386 return 0; in dophn_core()
405 if (file_printf(ms, " can't read note section at %jd", in dophn_core()
408 return 0; in dophn_core()
410 offset = 0; in dophn_core()
414 offset = donote(ms, nbuf, offset, CAST(size_t, bufsize), in dophn_core()
417 if (offset == 0) in dophn_core()
422 return 0; in dophn_core()
427 do_note_netbsd_version(struct magic_set *ms, int swap, void *v) in do_note_netbsd_version() argument
433 if (file_printf(ms, ", for NetBSD") == -1) in do_note_netbsd_version()
453 if (file_printf(ms, " %u.%u", ver_maj, ver_min) == -1) in do_note_netbsd_version()
457 ver_rel = 0; in do_note_netbsd_version()
459 if (ver_rel == 0 && ver_patch != 0) { in do_note_netbsd_version()
460 if (file_printf(ms, ".%u", ver_patch) == -1) in do_note_netbsd_version()
462 } else if (ver_rel != 0) { in do_note_netbsd_version()
464 if (file_printf(ms, "Z") == -1) in do_note_netbsd_version()
468 if (file_printf(ms, "%c", 'A' + ver_rel - 1) == -1) in do_note_netbsd_version()
472 return 0; in do_note_netbsd_version()
476 do_note_freebsd_version(struct magic_set *ms, int swap, void *v) in do_note_freebsd_version() argument
482 if (file_printf(ms, ", for FreeBSD") == -1) in do_note_freebsd_version()
499 * M000xx (pre-M.0) in do_note_freebsd_version()
512 if (file_printf(ms, " 4.6.2") == -1) in do_note_freebsd_version()
515 if (file_printf(ms, " %d.%d", desc / 100000, in do_note_freebsd_version()
518 if (desc / 1000 % 10 > 0) in do_note_freebsd_version()
519 if (file_printf(ms, ".%d", desc / 1000 % 10) == -1) in do_note_freebsd_version()
521 if ((desc % 1000 > 0) || (desc % 100000 == 0)) in do_note_freebsd_version()
522 if (file_printf(ms, " (%d)", desc) == -1) in do_note_freebsd_version()
525 if (file_printf(ms, " %d.%d", desc / 100000, in do_note_freebsd_version()
528 if (desc / 100 % 10 > 0) { in do_note_freebsd_version()
529 if (file_printf(ms, " (%d)", desc) == -1) in do_note_freebsd_version()
531 } else if (desc / 10 % 10 > 0) { in do_note_freebsd_version()
532 if (file_printf(ms, ".%d", desc / 10 % 10) == -1) in do_note_freebsd_version()
536 if (file_printf(ms, " %d.%d", desc / 100000, in do_note_freebsd_version()
539 if ((desc / 100 % 10 > 0) || in do_note_freebsd_version()
540 (desc % 100000 / 100 == 0)) { in do_note_freebsd_version()
541 if (file_printf(ms, " (%d)", desc) == -1) in do_note_freebsd_version()
543 } else if (desc / 10 % 10 > 0) { in do_note_freebsd_version()
544 if (file_printf(ms, ".%d", desc / 10 % 10) == -1) in do_note_freebsd_version()
548 return 0; in do_note_freebsd_version()
553 do_bid_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type, in do_bid_note() argument
577 if (file_printf(ms, ", BuildID[%s]=", btype) == -1) in do_bid_note()
580 for (i = 0; i < descsz; i++) in do_bid_note()
581 if (file_printf(ms, "%02x", desc[i]) == -1) in do_bid_note()
585 if (namesz == 4 && memcmp(RCAST(char *, &nbuf[noff]), "Go", 3) == 0 && in do_bid_note()
588 if (file_printf(ms, ", Go BuildID=%s", in do_bid_note()
594 return 0; in do_bid_note()
598 do_os_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type, in do_os_note() argument
606 if (file_printf(ms, ", for SuSE %d.%d", nbuf[doff], in do_os_note()
617 if (file_printf(ms, ", for GNU/") == -1) in do_os_note()
619 switch (elf_getu32(swap, desc[0])) { in do_os_note()
621 if (file_printf(ms, "Linux") == -1) in do_os_note()
625 if (file_printf(ms, "Hurd") == -1) in do_os_note()
629 if (file_printf(ms, "Solaris") == -1) in do_os_note()
633 if (file_printf(ms, "kFreeBSD") == -1) in do_os_note()
637 if (file_printf(ms, "kNetBSD") == -1) in do_os_note()
641 if (file_printf(ms, "<unknown>") == -1) in do_os_note()
644 if (file_printf(ms, " %d.%d.%d", elf_getu32(swap, desc[1]), in do_os_note()
653 if (do_note_netbsd_version(ms, swap, &nbuf[doff]) == -1) in do_os_note()
661 if (do_note_freebsd_version(ms, swap, &nbuf[doff]) in do_os_note()
670 if (file_printf(ms, ", for OpenBSD") == -1) in do_os_note()
672 /* Content of note is always 0 */ in do_os_note()
680 if (file_printf(ms, ", for DragonFly") == -1) in do_os_note()
684 if (file_printf(ms, " %d.%d.%d", desc / 100000, in do_os_note()
696 if (file_printf(ms, ", for Android %d", api_level) == -1) in do_os_note()
705 if (file_printf(ms, ", built by NDK %.64s (%.64s)", in do_os_note()
711 return 0; in do_os_note()
715 do_pax_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type, in do_pax_note() argument
732 int did = 0; in do_pax_note()
738 if (desc && file_printf(ms, ", PaX: ") == -1) in do_pax_note()
741 for (i = 0; i < __arraycount(pax); i++) { in do_pax_note()
742 if (((1 << CAST(int, i)) & desc) == 0) in do_pax_note()
744 if (file_printf(ms, "%s%s", did++ ? "," : "", in do_pax_note()
750 return 0; in do_pax_note()
754 do_memtag_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type, in do_memtag_note() argument
771 int did = 0; in do_memtag_note()
777 if (desc && file_printf(ms, ", Android Memtag: ") == -1) in do_memtag_note()
780 for (i = 0; i < __arraycount(memtag); i++) { in do_memtag_note()
781 if (((1 << CAST(int, i)) & desc) == 0) in do_memtag_note()
783 if (file_printf(ms, "%s%s", did++ ? "," : "", in do_memtag_note()
789 return 0; in do_memtag_note()
793 do_core_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type, in do_core_note() argument
816 if ((namesz == 4 && memcmp(name, "CORE", 4) == 0) || in do_core_note()
825 if ((namesz >= 11 && memcmp(name, "NetBSD-CORE", 11) == 0)) { in do_core_note()
829 if (os_style != -1 && (*flags & FLAGS_DID_CORE_STYLE) == 0) { in do_core_note()
830 if (file_printf(ms, ", %s-style", os_style_names[os_style]) in do_core_note()
842 memset(&pi, 0, sizeof(pi)); in do_core_note()
845 if (file_printf(ms, ", from '%.31s', pid=%u, uid=%u, " in do_core_note()
847 file_printable(ms, sbuf, sizeof(sbuf), in do_core_note()
871 if (file_printf(ms, ", from '%.80s'", nbuf + doff + in do_core_note()
876 if (file_printf(ms, ", pid=%u", in do_core_note()
899 for (i = 0; i < NOFFSETS; i++) { in do_core_note()
904 for (j = 0; j < 16; j++, noffset++, in do_core_note()
924 if (c == '\0') { in do_core_note()
926 * A '\0' at the in do_core_note()
929 * Any other '\0' in do_core_note()
932 if (j == 0) in do_core_note()
985 if (file_printf(ms, ", from '%s'", in do_core_note()
1000 return 0; in do_core_note()
1004 get_offset_from_virtaddr(struct magic_set *ms, int swap, int clazz, int fd, in get_offset_from_virtaddr() argument
1017 if (file_printf(ms, in get_offset_from_virtaddr()
1021 return 0; in get_offset_from_virtaddr()
1034 return 0; in get_offset_from_virtaddr()
1038 get_string_on_virtaddr(struct magic_set *ms, in get_string_on_virtaddr() argument
1045 if (buflen == 0) in get_string_on_virtaddr()
1046 return 0; in get_string_on_virtaddr()
1048 offset = get_offset_from_virtaddr(ms, swap, clazz, fd, ph_off, ph_num, in get_string_on_virtaddr()
1050 if (offset < 0 || in get_string_on_virtaddr()
1051 (buflen = pread(fd, buf, CAST(size_t, buflen), offset)) <= 0) { in get_string_on_virtaddr()
1052 (void)file_printf(ms, ", can't read elf string at %jd", in get_string_on_virtaddr()
1054 return 0; in get_string_on_virtaddr()
1057 buf[buflen - 1] = '\0'; in get_string_on_virtaddr()
1060 * non-printable character before the '\0' or just '\0'. */ in get_string_on_virtaddr()
1063 if (*bptr != '\0') in get_string_on_virtaddr()
1064 return 0; in get_string_on_virtaddr()
1072 do_auxv_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type, in do_auxv_note() argument
1089 return 0; in do_auxv_note()
1094 return 0; in do_auxv_note()
1099 return 0; in do_auxv_note()
1103 return 0; in do_auxv_note()
1107 return 0; in do_auxv_note()
1112 nval = 0; in do_auxv_note()
1113 for (off = 0; off + elsize <= descsz; off += elsize) { in do_auxv_note()
1117 file_error(ms, 0, "Too many ELF Auxv elements"); in do_auxv_note()
1131 is_string = 0; in do_auxv_note()
1135 is_string = 0; in do_auxv_note()
1139 is_string = 0; in do_auxv_note()
1143 is_string = 0; in do_auxv_note()
1147 is_string = 0; in do_auxv_note()
1158 buflen = get_string_on_virtaddr(ms, swap, clazz, fd, in do_auxv_note()
1161 if (buflen == 0) in do_auxv_note()
1164 if (file_printf(ms, ", %s: '%s'", tag, buf) == -1) in do_auxv_note()
1167 if (file_printf(ms, ", %s: %d", tag, in do_auxv_note()
1174 return 0; in do_auxv_note()
1179 dodynamic(struct magic_set *ms, void *vbuf, size_t offset, size_t size, in dodynamic() argument
1200 ms->mode |= 0111; in dodynamic()
1202 ms->mode &= ~0111; in dodynamic()
1215 donote(struct magic_set *ms, void *vbuf, size_t offset, size_t size, in donote() argument
1226 if (*notecount == 0) in donote()
1227 return 0; in donote()
1237 memset(&nh32, 0, sizeof(nh32)); in donote()
1238 memset(&nh64, 0, sizeof(nh64)); in donote()
1246 if ((namesz == 0) && (descsz == 0)) { in donote()
1253 if (namesz & 0x80000000) { in donote()
1254 (void)file_printf(ms, ", bad note name size %#lx", in donote()
1256 return 0; in donote()
1259 if (descsz & 0x80000000) { in donote()
1260 (void)file_printf(ms, ", bad note description size %#lx", in donote()
1262 return 0; in donote()
1284 if ((*flags & FLAGS_DID_OS_NOTE) == 0) { in donote()
1285 if (do_os_note(ms, nbuf, xnh_type, swap, in donote()
1290 if ((*flags & FLAGS_DID_BUILD_ID) == 0) { in donote()
1291 if (do_bid_note(ms, nbuf, xnh_type, swap, in donote()
1296 if ((*flags & FLAGS_DID_NETBSD_PAX) == 0) { in donote()
1297 if (do_pax_note(ms, nbuf, xnh_type, swap, in donote()
1301 if ((*flags & FLAGS_DID_ANDROID_MEMTAG) == 0) { in donote()
1302 if (do_memtag_note(ms, nbuf, xnh_type, swap, in donote()
1307 if ((*flags & FLAGS_DID_CORE) == 0) { in donote()
1308 if (do_core_note(ms, nbuf, xnh_type, swap, in donote()
1313 if ((*flags & FLAGS_DID_AUXV) == 0) { in donote()
1314 if (do_auxv_note(ms, nbuf, xnh_type, swap, in donote()
1344 if (file_printf(ms, ", note=%u", xnh_type) == -1) in donote()
1354 file_printf(ms, ", %s: %s", tag, in donote()
1380 { 0, NULL }
1409 { 0, NULL }
1413 doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num, in doshn() argument
1419 int stripped = 1, has_debug_info = 0; in doshn()
1420 size_t nbadcap = 0; in doshn()
1423 uint64_t cap_hw1 = 0; /* SunOS 5.x hardware capabilities */ in doshn()
1424 uint64_t cap_sf1 = 0; /* SunOS 5.x software capabilities */ in doshn()
1428 if (ms->flags & MAGIC_MIME) in doshn()
1429 return 0; in doshn()
1431 if (num == 0) { in doshn()
1432 if (file_printf(ms, ", no section header") == -1) in doshn()
1434 return 0; in doshn()
1437 if (file_printf(ms, ", corrupted section header size") == -1) in doshn()
1439 return 0; in doshn()
1445 if (file_printf(ms, ", missing section headers at %jd", in doshn()
1448 return 0; in doshn()
1453 if (file_printf(ms, ", too large section header offset %jd", in doshn()
1456 return 0; in doshn()
1464 if (file_printf(ms, in doshn()
1468 return 0; in doshn()
1470 name[namesize] = '\0'; in doshn()
1471 if (strcmp(name, ".debug_info") == 0) { in doshn()
1473 stripped = 0; in doshn()
1478 if (file_printf(ms, ", can't read elf section at %jd", in doshn()
1481 return 0; in doshn()
1488 #if 0 in doshn()
1491 stripped = 0; in doshn()
1507 if (file_printf(ms, in doshn()
1515 return 0; in doshn()
1517 if (xsh_size > ms->elf_shsize_max) { in doshn()
1518 file_error(ms, errno, "Note section size too " in doshn()
1520 ms->elf_shsize_max); in doshn()
1524 file_error(ms, errno, "Cannot allocate memory" in doshn()
1532 if (file_printf(ms, in doshn()
1536 return 0; in doshn()
1539 noff = 0; in doshn()
1543 noff = donote(ms, nbuf, CAST(size_t, noff), in doshn()
1545 fd, 0, 0, 0); in doshn()
1546 if (noff == 0) in doshn()
1567 file_badseek(ms); in doshn()
1570 coff = 0; in doshn()
1574 cap32.c_un.c_val = 0; in doshn()
1575 cap64.c_un.c_val = 0; in doshn()
1583 file_badread(ms); in doshn()
1586 if (cbuf[0] == 'A') { in doshn()
1593 if (memcmp("gnu", p, 3) != 0) { in doshn()
1594 if (file_printf(ms, in doshn()
1606 if (file_printf(ms, ", unknown gnu" in doshn()
1627 if (file_printf(ms, in doshn()
1648 if (file_printf(ms, ", with debug_info") == -1) in doshn()
1651 if (file_printf(ms, ", %sstripped", stripped ? "" : "not ") == -1) in doshn()
1670 if (file_printf(ms, ", uses") == -1) in doshn()
1675 if (file_printf(ms, in doshn()
1683 if (file_printf(ms, in doshn()
1689 if (file_printf(ms, in doshn()
1697 if (file_printf(ms, in doshn()
1705 if (file_printf(ms, in doshn()
1711 return 0; in doshn()
1721 dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off, in dophn_exec() argument
1731 size_t offset, align, need = 0; in dophn_exec()
1732 int pie = 0, dynamic = 0; in dophn_exec()
1734 if (num == 0) { in dophn_exec()
1735 if (file_printf(ms, ", no program header") == -1) in dophn_exec()
1737 return 0; in dophn_exec()
1740 if (file_printf(ms, ", corrupted program header size") == -1) in dophn_exec()
1742 return 0; in dophn_exec()
1745 interp[0] = '\0'; in dophn_exec()
1750 if (file_printf(ms, in dophn_exec()
1754 return 0; in dophn_exec()
1758 bufsize = 0; in dophn_exec()
1769 if (((align = xph_align) & 0x80000000UL) != 0 || in dophn_exec()
1771 if (file_printf(ms, in dophn_exec()
1782 doread = 0; in dophn_exec()
1796 if (file_printf(ms, in dophn_exec()
1800 return 0; in dophn_exec()
1808 offset = 0; in dophn_exec()
1810 ms->mode &= ~0111; in dophn_exec()
1814 offset = dodynamic(ms, nbuf, offset, in dophn_exec()
1817 if (offset == 0) in dophn_exec()
1820 if (ms->flags & MAGIC_MIME) in dophn_exec()
1826 if (ms->flags & MAGIC_MIME) in dophn_exec()
1828 if (bufsize && nbuf[0]) { in dophn_exec()
1829 nbuf[bufsize - 1] = '\0'; in dophn_exec()
1835 if (ms->flags & MAGIC_MIME) in dophn_exec()
1836 return 0; in dophn_exec()
1841 offset = 0; in dophn_exec()
1845 offset = donote(ms, nbuf, offset, in dophn_exec()
1847 flags, notecount, fd, 0, 0, 0); in dophn_exec()
1848 if (offset == 0) in dophn_exec()
1853 if (ms->flags & MAGIC_MIME) in dophn_exec()
1858 if (ms->flags & MAGIC_MIME) in dophn_exec()
1859 return 0; in dophn_exec()
1861 if (pie && need == 0) in dophn_exec()
1868 if (file_printf(ms, ", %s linked", linking_style) == -1) in dophn_exec()
1870 if (interp[0]) in dophn_exec()
1871 if (file_printf(ms, ", interpreter %s", file_printable(ms, in dophn_exec()
1875 return 0; in dophn_exec()
1880 file_tryelf(struct magic_set *ms, const struct buffer *b) in file_tryelf() argument
1894 int flags = 0; in file_tryelf()
1899 if (ms->flags & (MAGIC_APPLE|MAGIC_EXTENSION)) in file_tryelf()
1900 return 0; in file_tryelf()
1912 return 0; in file_tryelf()
1917 if((lseek(fd, CAST(off_t, 0), SEEK_SET) == CAST(off_t, -1)) in file_tryelf()
1919 fd = file_pipe2file(ms, fd, buf, nbytes); in file_tryelf()
1922 file_badread(ms); in file_tryelf()
1928 * b->st.st_size != 0 if previous fstat() succeeded, in file_tryelf()
1931 if (b->st.st_size == 0) { in file_tryelf()
1934 file_badread(ms); in file_tryelf()
1938 if (S_ISREG(stp->st_mode) || stp->st_size != 0) in file_tryelf()
1959 if (file_printf(ms, ", unknown class %d", clazz) == -1) in file_tryelf()
1963 return 0; in file_tryelf()