|
@@ -27,13 +27,14 @@
|
|
|
#include "file.h"
|
|
#include "file.h"
|
|
|
|
|
|
|
|
#ifndef lint
|
|
#ifndef lint
|
|
|
-FILE_RCSID("@(#)$File: readelf.c,v 1.196 2024/11/11 15:49:11 christos Exp $")
|
|
|
|
|
|
|
+FILE_RCSID("@(#)$File: readelf.c,v 1.204 2025/06/27 16:57:44 christos Exp $")
|
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef BUILTIN_ELF
|
|
#ifdef BUILTIN_ELF
|
|
|
#include <string.h>
|
|
#include <string.h>
|
|
|
#include <ctype.h>
|
|
#include <ctype.h>
|
|
|
#include <stdlib.h>
|
|
#include <stdlib.h>
|
|
|
|
|
+#include <stdarg.h>
|
|
|
#ifdef HAVE_UNISTD_H
|
|
#ifdef HAVE_UNISTD_H
|
|
|
#include <unistd.h>
|
|
#include <unistd.h>
|
|
|
#endif
|
|
#endif
|
|
@@ -65,12 +66,25 @@ file_private uint64_t getu64(int, uint64_t);
|
|
|
#define NAMEEQUALS(n, v) \
|
|
#define NAMEEQUALS(n, v) \
|
|
|
(namesz == sizeof(v) && memcmp(n, v, namesz) == 0)
|
|
(namesz == sizeof(v) && memcmp(n, v, namesz) == 0)
|
|
|
|
|
|
|
|
|
|
+__attribute__((__format__(__printf__, 2, 3)))
|
|
|
file_private int
|
|
file_private int
|
|
|
-toomany(struct magic_set *ms, const char *name, uint16_t num)
|
|
|
|
|
|
|
+elf_printf(struct magic_set *ms, const char *fmt, ...)
|
|
|
{
|
|
{
|
|
|
|
|
+ va_list ap;
|
|
|
|
|
+ int rv;
|
|
|
|
|
+
|
|
|
if (ms->flags & MAGIC_MIME)
|
|
if (ms->flags & MAGIC_MIME)
|
|
|
return 1;
|
|
return 1;
|
|
|
- if (file_printf(ms, ", too many %s (%u)", name, num) == -1)
|
|
|
|
|
|
|
+
|
|
|
|
|
+ va_start(ap, fmt);
|
|
|
|
|
+ rv = file_vprintf(ms, fmt, ap);
|
|
|
|
|
+ va_end(ap);
|
|
|
|
|
+ return rv;
|
|
|
|
|
+}
|
|
|
|
|
+file_private int
|
|
|
|
|
+toomany(struct magic_set *ms, const char *name, uint16_t num)
|
|
|
|
|
+{
|
|
|
|
|
+ if (elf_printf(ms, ", too many %s (%u)", name, num) == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
return 1;
|
|
return 1;
|
|
|
}
|
|
}
|
|
@@ -363,12 +377,12 @@ dophn_core(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
|
|
|
return 0;
|
|
return 0;
|
|
|
|
|
|
|
|
if (num == 0) {
|
|
if (num == 0) {
|
|
|
- if (file_printf(ms, ", no program header") == -1)
|
|
|
|
|
|
|
+ if (elf_printf(ms, ", no program header") == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
if (size != xph_sizeof) {
|
|
if (size != xph_sizeof) {
|
|
|
- if (file_printf(ms, ", corrupted program header size") == -1)
|
|
|
|
|
|
|
+ if (elf_printf(ms, ", corrupted program header size") == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
@@ -379,7 +393,7 @@ dophn_core(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
|
|
|
for ( ; num; num--) {
|
|
for ( ; num; num--) {
|
|
|
if (pread(fd, xph_addr, xph_sizeof, off) <
|
|
if (pread(fd, xph_addr, xph_sizeof, off) <
|
|
|
CAST(ssize_t, xph_sizeof)) {
|
|
CAST(ssize_t, xph_sizeof)) {
|
|
|
- if (file_printf(ms,
|
|
|
|
|
|
|
+ if (elf_printf(ms,
|
|
|
", can't read elf program headers at %jd",
|
|
", can't read elf program headers at %jd",
|
|
|
(intmax_t)off) == -1)
|
|
(intmax_t)off) == -1)
|
|
|
return -1;
|
|
return -1;
|
|
@@ -402,7 +416,7 @@ dophn_core(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
|
|
|
len = xph_filesz < sizeof(nbuf) ? xph_filesz : sizeof(nbuf);
|
|
len = xph_filesz < sizeof(nbuf) ? xph_filesz : sizeof(nbuf);
|
|
|
offs = xph_offset;
|
|
offs = xph_offset;
|
|
|
if ((bufsize = pread(fd, nbuf, len, offs)) == -1) {
|
|
if ((bufsize = pread(fd, nbuf, len, offs)) == -1) {
|
|
|
- if (file_printf(ms, " can't read note section at %jd",
|
|
|
|
|
|
|
+ if (elf_printf(ms, " can't read note section at %jd",
|
|
|
(intmax_t)offs) == -1)
|
|
(intmax_t)offs) == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
return 0;
|
|
return 0;
|
|
@@ -430,7 +444,7 @@ do_note_netbsd_version(struct magic_set *ms, int swap, void *v)
|
|
|
memcpy(&desc, v, sizeof(desc));
|
|
memcpy(&desc, v, sizeof(desc));
|
|
|
desc = elf_getu32(swap, desc);
|
|
desc = elf_getu32(swap, desc);
|
|
|
|
|
|
|
|
- if (file_printf(ms, ", for NetBSD") == -1)
|
|
|
|
|
|
|
+ if (elf_printf(ms, ", for NetBSD") == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
/*
|
|
/*
|
|
|
* The version number used to be stuck as 199905, and was thus
|
|
* The version number used to be stuck as 199905, and was thus
|
|
@@ -450,22 +464,22 @@ do_note_netbsd_version(struct magic_set *ms, int swap, void *v)
|
|
|
uint32_t ver_min = (desc / 1000000) % 100;
|
|
uint32_t ver_min = (desc / 1000000) % 100;
|
|
|
uint32_t ver_maj = desc / 100000000;
|
|
uint32_t ver_maj = desc / 100000000;
|
|
|
|
|
|
|
|
- if (file_printf(ms, " %u.%u", ver_maj, ver_min) == -1)
|
|
|
|
|
|
|
+ if (elf_printf(ms, " %u.%u", ver_maj, ver_min) == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
if (ver_maj >= 9) {
|
|
if (ver_maj >= 9) {
|
|
|
ver_patch += 100 * ver_rel;
|
|
ver_patch += 100 * ver_rel;
|
|
|
ver_rel = 0;
|
|
ver_rel = 0;
|
|
|
}
|
|
}
|
|
|
if (ver_rel == 0 && ver_patch != 0) {
|
|
if (ver_rel == 0 && ver_patch != 0) {
|
|
|
- if (file_printf(ms, ".%u", ver_patch) == -1)
|
|
|
|
|
|
|
+ if (elf_printf(ms, ".%u", ver_patch) == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
} else if (ver_rel != 0) {
|
|
} else if (ver_rel != 0) {
|
|
|
while (ver_rel > 26) {
|
|
while (ver_rel > 26) {
|
|
|
- if (file_printf(ms, "Z") == -1)
|
|
|
|
|
|
|
+ if (elf_printf(ms, "Z") == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
ver_rel -= 26;
|
|
ver_rel -= 26;
|
|
|
}
|
|
}
|
|
|
- if (file_printf(ms, "%c", 'A' + ver_rel - 1) == -1)
|
|
|
|
|
|
|
+ if (elf_printf(ms, "%c", 'A' + ver_rel - 1) == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -479,7 +493,7 @@ do_note_freebsd_version(struct magic_set *ms, int swap, void *v)
|
|
|
|
|
|
|
|
memcpy(&desc, v, sizeof(desc));
|
|
memcpy(&desc, v, sizeof(desc));
|
|
|
desc = elf_getu32(swap, desc);
|
|
desc = elf_getu32(swap, desc);
|
|
|
- if (file_printf(ms, ", for FreeBSD") == -1)
|
|
|
|
|
|
|
+ if (elf_printf(ms, ", for FreeBSD") == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
|
|
|
|
|
/*
|
|
/*
|
|
@@ -509,39 +523,39 @@ do_note_freebsd_version(struct magic_set *ms, int swap, void *v)
|
|
|
* was version 3.0.
|
|
* was version 3.0.
|
|
|
*/
|
|
*/
|
|
|
if (desc == 460002) {
|
|
if (desc == 460002) {
|
|
|
- if (file_printf(ms, " 4.6.2") == -1)
|
|
|
|
|
|
|
+ if (elf_printf(ms, " 4.6.2") == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
} else if (desc < 460100) {
|
|
} else if (desc < 460100) {
|
|
|
- if (file_printf(ms, " %d.%d", desc / 100000,
|
|
|
|
|
|
|
+ if (elf_printf(ms, " %d.%d", desc / 100000,
|
|
|
desc / 10000 % 10) == -1)
|
|
desc / 10000 % 10) == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
if (desc / 1000 % 10 > 0)
|
|
if (desc / 1000 % 10 > 0)
|
|
|
- if (file_printf(ms, ".%d", desc / 1000 % 10) == -1)
|
|
|
|
|
|
|
+ if (elf_printf(ms, ".%d", desc / 1000 % 10) == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
if ((desc % 1000 > 0) || (desc % 100000 == 0))
|
|
if ((desc % 1000 > 0) || (desc % 100000 == 0))
|
|
|
- if (file_printf(ms, " (%d)", desc) == -1)
|
|
|
|
|
|
|
+ if (elf_printf(ms, " (%d)", desc) == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
} else if (desc < 500000) {
|
|
} else if (desc < 500000) {
|
|
|
- if (file_printf(ms, " %d.%d", desc / 100000,
|
|
|
|
|
|
|
+ if (elf_printf(ms, " %d.%d", desc / 100000,
|
|
|
desc / 10000 % 10 + desc / 1000 % 10) == -1)
|
|
desc / 10000 % 10 + desc / 1000 % 10) == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
if (desc / 100 % 10 > 0) {
|
|
if (desc / 100 % 10 > 0) {
|
|
|
- if (file_printf(ms, " (%d)", desc) == -1)
|
|
|
|
|
|
|
+ if (elf_printf(ms, " (%d)", desc) == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
} else if (desc / 10 % 10 > 0) {
|
|
} else if (desc / 10 % 10 > 0) {
|
|
|
- if (file_printf(ms, ".%d", desc / 10 % 10) == -1)
|
|
|
|
|
|
|
+ if (elf_printf(ms, ".%d", desc / 10 % 10) == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
- if (file_printf(ms, " %d.%d", desc / 100000,
|
|
|
|
|
|
|
+ if (elf_printf(ms, " %d.%d", desc / 100000,
|
|
|
desc / 1000 % 100) == -1)
|
|
desc / 1000 % 100) == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
if ((desc / 100 % 10 > 0) ||
|
|
if ((desc / 100 % 10 > 0) ||
|
|
|
(desc % 100000 / 100 == 0)) {
|
|
(desc % 100000 / 100 == 0)) {
|
|
|
- if (file_printf(ms, " (%d)", desc) == -1)
|
|
|
|
|
|
|
+ if (elf_printf(ms, " (%d)", desc) == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
} else if (desc / 10 % 10 > 0) {
|
|
} else if (desc / 10 % 10 > 0) {
|
|
|
- if (file_printf(ms, ".%d", desc / 10 % 10) == -1)
|
|
|
|
|
|
|
+ if (elf_printf(ms, ".%d", desc / 10 % 10) == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -574,18 +588,18 @@ do_bid_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type,
|
|
|
btype = "unknown";
|
|
btype = "unknown";
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
- if (file_printf(ms, ", BuildID[%s]=", btype) == -1)
|
|
|
|
|
|
|
+ if (elf_printf(ms, ", BuildID[%s]=", btype) == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
memcpy(desc, &nbuf[doff], descsz);
|
|
memcpy(desc, &nbuf[doff], descsz);
|
|
|
for (i = 0; i < descsz; i++)
|
|
for (i = 0; i < descsz; i++)
|
|
|
- if (file_printf(ms, "%02x", desc[i]) == -1)
|
|
|
|
|
|
|
+ if (elf_printf(ms, "%02x", desc[i]) == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
return 1;
|
|
return 1;
|
|
|
}
|
|
}
|
|
|
if (namesz == 4 && memcmp(RCAST(char *, &nbuf[noff]), "Go", 3) == 0 &&
|
|
if (namesz == 4 && memcmp(RCAST(char *, &nbuf[noff]), "Go", 3) == 0 &&
|
|
|
type == NT_GO_BUILD_ID && descsz < 128) {
|
|
type == NT_GO_BUILD_ID && descsz < 128) {
|
|
|
char buf[256];
|
|
char buf[256];
|
|
|
- if (file_printf(ms, ", Go BuildID=%s",
|
|
|
|
|
|
|
+ if (elf_printf(ms, ", Go BuildID=%s",
|
|
|
file_copystr(buf, sizeof(buf), descsz,
|
|
file_copystr(buf, sizeof(buf), descsz,
|
|
|
RCAST(const char *, &nbuf[doff]))) == -1)
|
|
RCAST(const char *, &nbuf[doff]))) == -1)
|
|
|
return -1;
|
|
return -1;
|
|
@@ -603,7 +617,7 @@ do_os_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type,
|
|
|
|
|
|
|
|
if (NAMEEQUALS(name, "SuSE") && type == NT_GNU_VERSION && descsz == 2) {
|
|
if (NAMEEQUALS(name, "SuSE") && type == NT_GNU_VERSION && descsz == 2) {
|
|
|
*flags |= FLAGS_DID_OS_NOTE;
|
|
*flags |= FLAGS_DID_OS_NOTE;
|
|
|
- if (file_printf(ms, ", for SuSE %d.%d", nbuf[doff],
|
|
|
|
|
|
|
+ if (elf_printf(ms, ", for SuSE %d.%d", nbuf[doff],
|
|
|
nbuf[doff + 1]) == -1)
|
|
nbuf[doff + 1]) == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
return 1;
|
|
return 1;
|
|
@@ -614,34 +628,34 @@ do_os_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type,
|
|
|
memcpy(desc, &nbuf[doff], sizeof(desc));
|
|
memcpy(desc, &nbuf[doff], sizeof(desc));
|
|
|
|
|
|
|
|
*flags |= FLAGS_DID_OS_NOTE;
|
|
*flags |= FLAGS_DID_OS_NOTE;
|
|
|
- if (file_printf(ms, ", for GNU/") == -1)
|
|
|
|
|
|
|
+ if (elf_printf(ms, ", for GNU/") == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
switch (elf_getu32(swap, desc[0])) {
|
|
switch (elf_getu32(swap, desc[0])) {
|
|
|
case GNU_OS_LINUX:
|
|
case GNU_OS_LINUX:
|
|
|
- if (file_printf(ms, "Linux") == -1)
|
|
|
|
|
|
|
+ if (elf_printf(ms, "Linux") == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
break;
|
|
break;
|
|
|
case GNU_OS_HURD:
|
|
case GNU_OS_HURD:
|
|
|
- if (file_printf(ms, "Hurd") == -1)
|
|
|
|
|
|
|
+ if (elf_printf(ms, "Hurd") == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
break;
|
|
break;
|
|
|
case GNU_OS_SOLARIS:
|
|
case GNU_OS_SOLARIS:
|
|
|
- if (file_printf(ms, "Solaris") == -1)
|
|
|
|
|
|
|
+ if (elf_printf(ms, "Solaris") == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
break;
|
|
break;
|
|
|
case GNU_OS_KFREEBSD:
|
|
case GNU_OS_KFREEBSD:
|
|
|
- if (file_printf(ms, "kFreeBSD") == -1)
|
|
|
|
|
|
|
+ if (elf_printf(ms, "kFreeBSD") == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
break;
|
|
break;
|
|
|
case GNU_OS_KNETBSD:
|
|
case GNU_OS_KNETBSD:
|
|
|
- if (file_printf(ms, "kNetBSD") == -1)
|
|
|
|
|
|
|
+ if (elf_printf(ms, "kNetBSD") == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
break;
|
|
break;
|
|
|
default:
|
|
default:
|
|
|
- if (file_printf(ms, "<unknown>") == -1)
|
|
|
|
|
|
|
+ if (elf_printf(ms, "<unknown>") == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
}
|
|
}
|
|
|
- if (file_printf(ms, " %d.%d.%d", elf_getu32(swap, desc[1]),
|
|
|
|
|
|
|
+ if (elf_printf(ms, " %d.%d.%d", elf_getu32(swap, desc[1]),
|
|
|
elf_getu32(swap, desc[2]), elf_getu32(swap, desc[3])) == -1)
|
|
elf_getu32(swap, desc[2]), elf_getu32(swap, desc[3])) == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
return 1;
|
|
return 1;
|
|
@@ -667,7 +681,7 @@ do_os_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type,
|
|
|
if (NAMEEQUALS(name, "OpenBSD") &&
|
|
if (NAMEEQUALS(name, "OpenBSD") &&
|
|
|
type == NT_OPENBSD_VERSION && descsz == 4) {
|
|
type == NT_OPENBSD_VERSION && descsz == 4) {
|
|
|
*flags |= FLAGS_DID_OS_NOTE;
|
|
*flags |= FLAGS_DID_OS_NOTE;
|
|
|
- if (file_printf(ms, ", for OpenBSD") == -1)
|
|
|
|
|
|
|
+ if (elf_printf(ms, ", for OpenBSD") == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
/* Content of note is always 0 */
|
|
/* Content of note is always 0 */
|
|
|
return 1;
|
|
return 1;
|
|
@@ -677,11 +691,11 @@ do_os_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type,
|
|
|
type == NT_DRAGONFLY_VERSION && descsz == 4) {
|
|
type == NT_DRAGONFLY_VERSION && descsz == 4) {
|
|
|
uint32_t desc;
|
|
uint32_t desc;
|
|
|
*flags |= FLAGS_DID_OS_NOTE;
|
|
*flags |= FLAGS_DID_OS_NOTE;
|
|
|
- if (file_printf(ms, ", for DragonFly") == -1)
|
|
|
|
|
|
|
+ if (elf_printf(ms, ", for DragonFly") == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
memcpy(&desc, &nbuf[doff], sizeof(desc));
|
|
memcpy(&desc, &nbuf[doff], sizeof(desc));
|
|
|
desc = elf_getu32(swap, desc);
|
|
desc = elf_getu32(swap, desc);
|
|
|
- if (file_printf(ms, " %d.%d.%d", desc / 100000,
|
|
|
|
|
|
|
+ if (elf_printf(ms, " %d.%d.%d", desc / 100000,
|
|
|
desc / 10000 % 10, desc % 10000) == -1)
|
|
desc / 10000 % 10, desc % 10000) == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
return 1;
|
|
return 1;
|
|
@@ -693,7 +707,7 @@ do_os_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type,
|
|
|
*flags |= FLAGS_DID_OS_NOTE;
|
|
*flags |= FLAGS_DID_OS_NOTE;
|
|
|
memcpy(&api_level, &nbuf[doff], sizeof(api_level));
|
|
memcpy(&api_level, &nbuf[doff], sizeof(api_level));
|
|
|
api_level = elf_getu32(swap, api_level);
|
|
api_level = elf_getu32(swap, api_level);
|
|
|
- if (file_printf(ms, ", for Android %d", api_level) == -1)
|
|
|
|
|
|
|
+ if (elf_printf(ms, ", for Android %d", api_level) == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
/*
|
|
/*
|
|
|
* NDK r14 and later also include details of the NDK that
|
|
* NDK r14 and later also include details of the NDK that
|
|
@@ -702,7 +716,7 @@ do_os_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type,
|
|
|
* are both 64-byte strings.
|
|
* are both 64-byte strings.
|
|
|
*/
|
|
*/
|
|
|
if (descsz >= 4 + 64 + 64) {
|
|
if (descsz >= 4 + 64 + 64) {
|
|
|
- if (file_printf(ms, ", built by NDK %.64s (%.64s)",
|
|
|
|
|
|
|
+ if (elf_printf(ms, ", built by NDK %.64s (%.64s)",
|
|
|
&nbuf[doff + 4], &nbuf[doff + 4 + 64]) == -1)
|
|
&nbuf[doff + 4], &nbuf[doff + 4 + 64]) == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
}
|
|
}
|
|
@@ -735,13 +749,13 @@ do_pax_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type,
|
|
|
memcpy(&desc, &nbuf[doff], sizeof(desc));
|
|
memcpy(&desc, &nbuf[doff], sizeof(desc));
|
|
|
desc = elf_getu32(swap, desc);
|
|
desc = elf_getu32(swap, desc);
|
|
|
|
|
|
|
|
- if (desc && file_printf(ms, ", PaX: ") == -1)
|
|
|
|
|
|
|
+ if (desc && elf_printf(ms, ", PaX: ") == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
|
|
|
|
|
for (i = 0; i < __arraycount(pax); i++) {
|
|
for (i = 0; i < __arraycount(pax); i++) {
|
|
|
if (((1 << CAST(int, i)) & desc) == 0)
|
|
if (((1 << CAST(int, i)) & desc) == 0)
|
|
|
continue;
|
|
continue;
|
|
|
- if (file_printf(ms, "%s%s", did++ ? "," : "",
|
|
|
|
|
|
|
+ if (elf_printf(ms, "%s%s", did++ ? "," : "",
|
|
|
pax[i]) == -1)
|
|
pax[i]) == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
}
|
|
}
|
|
@@ -774,13 +788,13 @@ do_memtag_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type,
|
|
|
memcpy(&desc, &nbuf[doff], sizeof(desc));
|
|
memcpy(&desc, &nbuf[doff], sizeof(desc));
|
|
|
desc = elf_getu32(swap, desc);
|
|
desc = elf_getu32(swap, desc);
|
|
|
|
|
|
|
|
- if (desc && file_printf(ms, ", Android Memtag: ") == -1)
|
|
|
|
|
|
|
+ if (desc && elf_printf(ms, ", Android Memtag: ") == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
|
|
|
|
|
for (i = 0; i < __arraycount(memtag); i++) {
|
|
for (i = 0; i < __arraycount(memtag); i++) {
|
|
|
if (((1 << CAST(int, i)) & desc) == 0)
|
|
if (((1 << CAST(int, i)) & desc) == 0)
|
|
|
continue;
|
|
continue;
|
|
|
- if (file_printf(ms, "%s%s", did++ ? "," : "",
|
|
|
|
|
|
|
+ if (elf_printf(ms, "%s%s", did++ ? "," : "",
|
|
|
memtag[i]) == -1)
|
|
memtag[i]) == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
}
|
|
}
|
|
@@ -827,7 +841,7 @@ do_core_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (os_style != -1 && (*flags & FLAGS_DID_CORE_STYLE) == 0) {
|
|
if (os_style != -1 && (*flags & FLAGS_DID_CORE_STYLE) == 0) {
|
|
|
- if (file_printf(ms, ", %s-style", os_style_names[os_style])
|
|
|
|
|
|
|
+ if (elf_printf(ms, ", %s-style", os_style_names[os_style])
|
|
|
== -1)
|
|
== -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
*flags |= FLAGS_DID_CORE_STYLE;
|
|
*flags |= FLAGS_DID_CORE_STYLE;
|
|
@@ -842,7 +856,7 @@ do_core_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type,
|
|
|
memset(&pi, 0, sizeof(pi));
|
|
memset(&pi, 0, sizeof(pi));
|
|
|
memcpy(&pi, nbuf + doff, MIN(descsz, sizeof(pi)));
|
|
memcpy(&pi, nbuf + doff, MIN(descsz, sizeof(pi)));
|
|
|
|
|
|
|
|
- if (file_printf(ms, ", from '%.31s', pid=%u, uid=%u, "
|
|
|
|
|
|
|
+ if (elf_printf(ms, ", from '%.31s', pid=%u, uid=%u, "
|
|
|
"gid=%u, nlwps=%u, lwp=%u (signal %u/code %u)",
|
|
"gid=%u, nlwps=%u, lwp=%u (signal %u/code %u)",
|
|
|
file_printable(ms, sbuf, sizeof(sbuf),
|
|
file_printable(ms, sbuf, sizeof(sbuf),
|
|
|
RCAST(char *, pi.cpi_name), sizeof(pi.cpi_name)),
|
|
RCAST(char *, pi.cpi_name), sizeof(pi.cpi_name)),
|
|
@@ -868,12 +882,12 @@ do_core_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type,
|
|
|
argoff = 4 + 4 + 17;
|
|
argoff = 4 + 4 + 17;
|
|
|
else
|
|
else
|
|
|
argoff = 4 + 4 + 8 + 17;
|
|
argoff = 4 + 4 + 8 + 17;
|
|
|
- if (file_printf(ms, ", from '%.80s'", nbuf + doff +
|
|
|
|
|
|
|
+ if (elf_printf(ms, ", from '%.80s'", nbuf + doff +
|
|
|
argoff) == -1)
|
|
argoff) == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
pidoff = argoff + 81 + 2;
|
|
pidoff = argoff + 81 + 2;
|
|
|
if (doff + pidoff + 4 <= size) {
|
|
if (doff + pidoff + 4 <= size) {
|
|
|
- if (file_printf(ms, ", pid=%u",
|
|
|
|
|
|
|
+ if (elf_printf(ms, ", pid=%u",
|
|
|
elf_getu32(swap, *RCAST(uint32_t *, (nbuf +
|
|
elf_getu32(swap, *RCAST(uint32_t *, (nbuf +
|
|
|
doff + pidoff)))) == -1)
|
|
doff + pidoff)))) == -1)
|
|
|
return -1;
|
|
return -1;
|
|
@@ -982,7 +996,7 @@ do_core_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type,
|
|
|
*/
|
|
*/
|
|
|
while (cp > cname && isspace(cp[-1]))
|
|
while (cp > cname && isspace(cp[-1]))
|
|
|
cp--;
|
|
cp--;
|
|
|
- if (file_printf(ms, ", from '%s'",
|
|
|
|
|
|
|
+ if (elf_printf(ms, ", from '%s'",
|
|
|
file_copystr(buf, sizeof(buf),
|
|
file_copystr(buf, sizeof(buf),
|
|
|
CAST(size_t, cp - cname),
|
|
CAST(size_t, cp - cname),
|
|
|
RCAST(char *, cname))) == -1)
|
|
RCAST(char *, cname))) == -1)
|
|
@@ -1014,7 +1028,7 @@ get_offset_from_virtaddr(struct magic_set *ms, int swap, int clazz, int fd,
|
|
|
for ( ; num; num--) {
|
|
for ( ; num; num--) {
|
|
|
if (pread(fd, xph_addr, xph_sizeof, off) <
|
|
if (pread(fd, xph_addr, xph_sizeof, off) <
|
|
|
CAST(ssize_t, xph_sizeof)) {
|
|
CAST(ssize_t, xph_sizeof)) {
|
|
|
- if (file_printf(ms,
|
|
|
|
|
|
|
+ if (elf_printf(ms,
|
|
|
", can't read elf program header at %jd",
|
|
", can't read elf program header at %jd",
|
|
|
(intmax_t)off) == -1)
|
|
(intmax_t)off) == -1)
|
|
|
return -1;
|
|
return -1;
|
|
@@ -1049,7 +1063,7 @@ get_string_on_virtaddr(struct magic_set *ms,
|
|
|
fsize, virtaddr);
|
|
fsize, virtaddr);
|
|
|
if (offset < 0 ||
|
|
if (offset < 0 ||
|
|
|
(buflen = pread(fd, buf, CAST(size_t, buflen), offset)) <= 0) {
|
|
(buflen = pread(fd, buf, CAST(size_t, buflen), offset)) <= 0) {
|
|
|
- (void)file_printf(ms, ", can't read elf string at %jd",
|
|
|
|
|
|
|
+ (void)elf_printf(ms, ", can't read elf string at %jd",
|
|
|
(intmax_t)offset);
|
|
(intmax_t)offset);
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
@@ -1161,10 +1175,10 @@ do_auxv_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type,
|
|
|
if (buflen == 0)
|
|
if (buflen == 0)
|
|
|
continue;
|
|
continue;
|
|
|
|
|
|
|
|
- if (file_printf(ms, ", %s: '%s'", tag, buf) == -1)
|
|
|
|
|
|
|
+ if (elf_printf(ms, ", %s: '%s'", tag, buf) == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
} else {
|
|
} else {
|
|
|
- if (file_printf(ms, ", %s: %d", tag,
|
|
|
|
|
|
|
+ if (elf_printf(ms, ", %s: %d", tag,
|
|
|
CAST(int, xauxv_val)) == -1)
|
|
CAST(int, xauxv_val)) == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
}
|
|
}
|
|
@@ -1251,13 +1265,13 @@ donote(struct magic_set *ms, void *vbuf, size_t offset, size_t size,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (namesz & 0x80000000) {
|
|
if (namesz & 0x80000000) {
|
|
|
- (void)file_printf(ms, ", bad note name size %#lx",
|
|
|
|
|
|
|
+ (void)elf_printf(ms, ", bad note name size %#lx",
|
|
|
CAST(unsigned long, namesz));
|
|
CAST(unsigned long, namesz));
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (descsz & 0x80000000) {
|
|
if (descsz & 0x80000000) {
|
|
|
- (void)file_printf(ms, ", bad note description size %#lx",
|
|
|
|
|
|
|
+ (void)elf_printf(ms, ", bad note description size %#lx",
|
|
|
CAST(unsigned long, descsz));
|
|
CAST(unsigned long, descsz));
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
@@ -1341,7 +1355,7 @@ donote(struct magic_set *ms, void *vbuf, size_t offset, size_t size,
|
|
|
if (*flags & FLAGS_DID_NETBSD_UNKNOWN)
|
|
if (*flags & FLAGS_DID_NETBSD_UNKNOWN)
|
|
|
return offset;
|
|
return offset;
|
|
|
*flags |= FLAGS_DID_NETBSD_UNKNOWN;
|
|
*flags |= FLAGS_DID_NETBSD_UNKNOWN;
|
|
|
- if (file_printf(ms, ", note=%u", xnh_type) == -1)
|
|
|
|
|
|
|
+ if (elf_printf(ms, ", note=%u", xnh_type) == -1)
|
|
|
return offset;
|
|
return offset;
|
|
|
return offset;
|
|
return offset;
|
|
|
}
|
|
}
|
|
@@ -1351,7 +1365,7 @@ donote(struct magic_set *ms, void *vbuf, size_t offset, size_t size,
|
|
|
str = RCAST(const char *, &nbuf[doff]);
|
|
str = RCAST(const char *, &nbuf[doff]);
|
|
|
descw = CAST(int, descsz);
|
|
descw = CAST(int, descsz);
|
|
|
*flags |= flag;
|
|
*flags |= flag;
|
|
|
- file_printf(ms, ", %s: %s", tag,
|
|
|
|
|
|
|
+ elf_printf(ms, ", %s: %s", tag,
|
|
|
file_copystr(buf, sizeof(buf), descw, str));
|
|
file_copystr(buf, sizeof(buf), descw, str));
|
|
|
return offset;
|
|
return offset;
|
|
|
}
|
|
}
|
|
@@ -1429,12 +1443,12 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
|
|
|
return 0;
|
|
return 0;
|
|
|
|
|
|
|
|
if (num == 0) {
|
|
if (num == 0) {
|
|
|
- if (file_printf(ms, ", no section header") == -1)
|
|
|
|
|
|
|
+ if (elf_printf(ms, ", no section header") == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
if (size != xsh_sizeof) {
|
|
if (size != xsh_sizeof) {
|
|
|
- if (file_printf(ms, ", corrupted section header size") == -1)
|
|
|
|
|
|
|
+ if (elf_printf(ms, ", corrupted section header size") == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
@@ -1442,7 +1456,7 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
|
|
|
/* Read offset of name section to be able to read section names later */
|
|
/* Read offset of name section to be able to read section names later */
|
|
|
offs = CAST(off_t, (off + size * strtab));
|
|
offs = CAST(off_t, (off + size * strtab));
|
|
|
if (pread(fd, xsh_addr, xsh_sizeof, offs) < CAST(ssize_t, xsh_sizeof)) {
|
|
if (pread(fd, xsh_addr, xsh_sizeof, offs) < CAST(ssize_t, xsh_sizeof)) {
|
|
|
- if (file_printf(ms, ", missing section headers at %jd",
|
|
|
|
|
|
|
+ if (elf_printf(ms, ", missing section headers at %jd",
|
|
|
(intmax_t)offs) == -1)
|
|
(intmax_t)offs) == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
return 0;
|
|
return 0;
|
|
@@ -1450,7 +1464,7 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
|
|
|
name_off = xsh_offset;
|
|
name_off = xsh_offset;
|
|
|
|
|
|
|
|
if (fsize != SIZE_UNKNOWN && fsize < name_off) {
|
|
if (fsize != SIZE_UNKNOWN && fsize < name_off) {
|
|
|
- if (file_printf(ms, ", too large section header offset %jd",
|
|
|
|
|
|
|
+ if (elf_printf(ms, ", too large section header offset %jd",
|
|
|
(intmax_t)name_off) == -1)
|
|
(intmax_t)name_off) == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
return 0;
|
|
return 0;
|
|
@@ -1461,7 +1475,7 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
|
|
|
offs = name_off + xsh_name;
|
|
offs = name_off + xsh_name;
|
|
|
if ((namesize = pread(fd, name, sizeof(name) - 1, offs))
|
|
if ((namesize = pread(fd, name, sizeof(name) - 1, offs))
|
|
|
== -1) {
|
|
== -1) {
|
|
|
- if (file_printf(ms,
|
|
|
|
|
|
|
+ if (elf_printf(ms,
|
|
|
", can't read name of elf section at %jd",
|
|
", can't read name of elf section at %jd",
|
|
|
(intmax_t)offs) == -1)
|
|
(intmax_t)offs) == -1)
|
|
|
return -1;
|
|
return -1;
|
|
@@ -1475,7 +1489,7 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
|
|
|
|
|
|
|
|
if (pread(fd, xsh_addr, xsh_sizeof, off) <
|
|
if (pread(fd, xsh_addr, xsh_sizeof, off) <
|
|
|
CAST(ssize_t, xsh_sizeof)) {
|
|
CAST(ssize_t, xsh_sizeof)) {
|
|
|
- if (file_printf(ms, ", can't read elf section at %jd",
|
|
|
|
|
|
|
+ if (elf_printf(ms, ", can't read elf section at %jd",
|
|
|
(intmax_t)off) == -1)
|
|
(intmax_t)off) == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
return 0;
|
|
return 0;
|
|
@@ -1504,7 +1518,7 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
|
|
|
case SHT_NOTE:
|
|
case SHT_NOTE:
|
|
|
if (CAST(uintmax_t, (xsh_size + xsh_offset)) >
|
|
if (CAST(uintmax_t, (xsh_size + xsh_offset)) >
|
|
|
CAST(uintmax_t, fsize)) {
|
|
CAST(uintmax_t, fsize)) {
|
|
|
- if (file_printf(ms,
|
|
|
|
|
|
|
+ if (elf_printf(ms,
|
|
|
", note offset/size %#" INTMAX_T_FORMAT
|
|
", note offset/size %#" INTMAX_T_FORMAT
|
|
|
"x+%#" INTMAX_T_FORMAT "x exceeds"
|
|
"x+%#" INTMAX_T_FORMAT "x exceeds"
|
|
|
" file size %#" INTMAX_T_FORMAT "x",
|
|
" file size %#" INTMAX_T_FORMAT "x",
|
|
@@ -1529,7 +1543,7 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
|
|
|
if (pread(fd, nbuf, xsh_size, offs) <
|
|
if (pread(fd, nbuf, xsh_size, offs) <
|
|
|
CAST(ssize_t, xsh_size)) {
|
|
CAST(ssize_t, xsh_size)) {
|
|
|
free(nbuf);
|
|
free(nbuf);
|
|
|
- if (file_printf(ms,
|
|
|
|
|
|
|
+ if (elf_printf(ms,
|
|
|
", can't read elf note at %jd",
|
|
", can't read elf note at %jd",
|
|
|
(intmax_t)offs) == -1)
|
|
(intmax_t)offs) == -1)
|
|
|
return -1;
|
|
return -1;
|
|
@@ -1591,7 +1605,7 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
|
|
|
p += 4;
|
|
p += 4;
|
|
|
len = getu32(swap, len);
|
|
len = getu32(swap, len);
|
|
|
if (memcmp("gnu", p, 3) != 0) {
|
|
if (memcmp("gnu", p, 3) != 0) {
|
|
|
- if (file_printf(ms,
|
|
|
|
|
|
|
+ if (elf_printf(ms,
|
|
|
", unknown capability %.3s", p)
|
|
", unknown capability %.3s", p)
|
|
|
== -1)
|
|
== -1)
|
|
|
return -1;
|
|
return -1;
|
|
@@ -1603,7 +1617,7 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
|
|
|
p += 4;
|
|
p += 4;
|
|
|
len = getu32(swap, len);
|
|
len = getu32(swap, len);
|
|
|
if (tag != 1) {
|
|
if (tag != 1) {
|
|
|
- if (file_printf(ms, ", unknown gnu"
|
|
|
|
|
|
|
+ if (elf_printf(ms, ", unknown gnu"
|
|
|
" capability tag %d", tag)
|
|
" capability tag %d", tag)
|
|
|
== -1)
|
|
== -1)
|
|
|
return -1;
|
|
return -1;
|
|
@@ -1624,7 +1638,7 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
|
|
|
cap_sf1 |= xcap_val;
|
|
cap_sf1 |= xcap_val;
|
|
|
break;
|
|
break;
|
|
|
default:
|
|
default:
|
|
|
- if (file_printf(ms,
|
|
|
|
|
|
|
+ if (elf_printf(ms,
|
|
|
", with unknown capability "
|
|
", with unknown capability "
|
|
|
"%#" INT64_T_FORMAT "x = %#"
|
|
"%#" INT64_T_FORMAT "x = %#"
|
|
|
INT64_T_FORMAT "x",
|
|
INT64_T_FORMAT "x",
|
|
@@ -1633,7 +1647,7 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
|
|
|
== -1)
|
|
== -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
if (nbadcap++ > 2)
|
|
if (nbadcap++ > 2)
|
|
|
- coff = xsh_size;
|
|
|
|
|
|
|
+ goto skip;
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -1645,10 +1659,10 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (has_debug_info) {
|
|
if (has_debug_info) {
|
|
|
- if (file_printf(ms, ", with debug_info") == -1)
|
|
|
|
|
|
|
+ if (elf_printf(ms, ", with debug_info") == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
}
|
|
}
|
|
|
- if (file_printf(ms, ", %sstripped", stripped ? "" : "not ") == -1)
|
|
|
|
|
|
|
+ if (elf_printf(ms, ", %sstripped", stripped ? "" : "not ") == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
if (cap_hw1) {
|
|
if (cap_hw1) {
|
|
|
const cap_desc_t *cdp;
|
|
const cap_desc_t *cdp;
|
|
@@ -1667,12 +1681,12 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
|
|
|
cdp = NULL;
|
|
cdp = NULL;
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
- if (file_printf(ms, ", uses") == -1)
|
|
|
|
|
|
|
+ if (elf_printf(ms, ", uses") == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
if (cdp) {
|
|
if (cdp) {
|
|
|
while (cdp->cd_name) {
|
|
while (cdp->cd_name) {
|
|
|
if (cap_hw1 & cdp->cd_mask) {
|
|
if (cap_hw1 & cdp->cd_mask) {
|
|
|
- if (file_printf(ms,
|
|
|
|
|
|
|
+ if (elf_printf(ms,
|
|
|
" %s", cdp->cd_name) == -1)
|
|
" %s", cdp->cd_name) == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
cap_hw1 &= ~cdp->cd_mask;
|
|
cap_hw1 &= ~cdp->cd_mask;
|
|
@@ -1680,13 +1694,13 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
|
|
|
++cdp;
|
|
++cdp;
|
|
|
}
|
|
}
|
|
|
if (cap_hw1)
|
|
if (cap_hw1)
|
|
|
- if (file_printf(ms,
|
|
|
|
|
|
|
+ if (elf_printf(ms,
|
|
|
" unknown hardware capability %#"
|
|
" unknown hardware capability %#"
|
|
|
INT64_T_FORMAT "x",
|
|
INT64_T_FORMAT "x",
|
|
|
CAST(unsigned long long, cap_hw1)) == -1)
|
|
CAST(unsigned long long, cap_hw1)) == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
} else {
|
|
} else {
|
|
|
- if (file_printf(ms,
|
|
|
|
|
|
|
+ if (elf_printf(ms,
|
|
|
" hardware capability %#" INT64_T_FORMAT "x",
|
|
" hardware capability %#" INT64_T_FORMAT "x",
|
|
|
CAST(unsigned long long, cap_hw1)) == -1)
|
|
CAST(unsigned long long, cap_hw1)) == -1)
|
|
|
return -1;
|
|
return -1;
|
|
@@ -1694,7 +1708,7 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
|
|
|
}
|
|
}
|
|
|
if (cap_sf1) {
|
|
if (cap_sf1) {
|
|
|
if (cap_sf1 & SF1_SUNW_FPUSED) {
|
|
if (cap_sf1 & SF1_SUNW_FPUSED) {
|
|
|
- if (file_printf(ms,
|
|
|
|
|
|
|
+ if (elf_printf(ms,
|
|
|
(cap_sf1 & SF1_SUNW_FPKNWN)
|
|
(cap_sf1 & SF1_SUNW_FPKNWN)
|
|
|
? ", uses frame pointer"
|
|
? ", uses frame pointer"
|
|
|
: ", not known to use frame pointer") == -1)
|
|
: ", not known to use frame pointer") == -1)
|
|
@@ -1702,7 +1716,7 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
|
|
|
}
|
|
}
|
|
|
cap_sf1 &= ~SF1_SUNW_MASK;
|
|
cap_sf1 &= ~SF1_SUNW_MASK;
|
|
|
if (cap_sf1)
|
|
if (cap_sf1)
|
|
|
- if (file_printf(ms,
|
|
|
|
|
|
|
+ if (elf_printf(ms,
|
|
|
", with unknown software capability %#"
|
|
", with unknown software capability %#"
|
|
|
INT64_T_FORMAT "x",
|
|
INT64_T_FORMAT "x",
|
|
|
CAST(unsigned long long, cap_sf1)) == -1)
|
|
CAST(unsigned long long, cap_sf1)) == -1)
|
|
@@ -1724,20 +1738,20 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
|
|
|
{
|
|
{
|
|
|
Elf32_Phdr ph32;
|
|
Elf32_Phdr ph32;
|
|
|
Elf64_Phdr ph64;
|
|
Elf64_Phdr ph64;
|
|
|
- const char *linking_style;
|
|
|
|
|
|
|
+ const char *str;
|
|
|
unsigned char nbuf[NBUFSIZE];
|
|
unsigned char nbuf[NBUFSIZE];
|
|
|
- char interp[128];
|
|
|
|
|
|
|
+ char interp[NBUFSIZE];
|
|
|
ssize_t bufsize;
|
|
ssize_t bufsize;
|
|
|
size_t offset, align, need = 0;
|
|
size_t offset, align, need = 0;
|
|
|
int pie = 0, dynamic = 0;
|
|
int pie = 0, dynamic = 0;
|
|
|
|
|
|
|
|
if (num == 0) {
|
|
if (num == 0) {
|
|
|
- if (file_printf(ms, ", no program header") == -1)
|
|
|
|
|
|
|
+ if (elf_printf(ms, ", no program header") == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
if (size != xph_sizeof) {
|
|
if (size != xph_sizeof) {
|
|
|
- if (file_printf(ms, ", corrupted program header size") == -1)
|
|
|
|
|
|
|
+ if (elf_printf(ms, ", corrupted program header size") == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
@@ -1747,7 +1761,7 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
|
|
|
int doread;
|
|
int doread;
|
|
|
if (pread(fd, xph_addr, xph_sizeof, off) <
|
|
if (pread(fd, xph_addr, xph_sizeof, off) <
|
|
|
CAST(ssize_t, xph_sizeof)) {
|
|
CAST(ssize_t, xph_sizeof)) {
|
|
|
- if (file_printf(ms,
|
|
|
|
|
|
|
+ if (elf_printf(ms,
|
|
|
", can't read elf program headers at %jd",
|
|
", can't read elf program headers at %jd",
|
|
|
(intmax_t)off) == -1)
|
|
(intmax_t)off) == -1)
|
|
|
return -1;
|
|
return -1;
|
|
@@ -1768,7 +1782,7 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
|
|
|
continue;
|
|
continue;
|
|
|
if (((align = xph_align) & 0x80000000UL) != 0 ||
|
|
if (((align = xph_align) & 0x80000000UL) != 0 ||
|
|
|
align < 4) {
|
|
align < 4) {
|
|
|
- if (file_printf(ms,
|
|
|
|
|
|
|
+ if (elf_printf(ms,
|
|
|
", invalid note alignment %#lx",
|
|
", invalid note alignment %#lx",
|
|
|
CAST(unsigned long, align)) == -1)
|
|
CAST(unsigned long, align)) == -1)
|
|
|
return -1;
|
|
return -1;
|
|
@@ -1793,7 +1807,7 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
|
|
|
off_t offs = xph_offset;
|
|
off_t offs = xph_offset;
|
|
|
bufsize = pread(fd, nbuf, len, offs);
|
|
bufsize = pread(fd, nbuf, len, offs);
|
|
|
if (bufsize == -1) {
|
|
if (bufsize == -1) {
|
|
|
- if (file_printf(ms,
|
|
|
|
|
|
|
+ if (elf_printf(ms,
|
|
|
", can't read section at %jd",
|
|
", can't read section at %jd",
|
|
|
(intmax_t)offs) == -1)
|
|
(intmax_t)offs) == -1)
|
|
|
return -1;
|
|
return -1;
|
|
@@ -1817,8 +1831,6 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
|
|
|
if (offset == 0)
|
|
if (offset == 0)
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
- if (ms->flags & MAGIC_MIME)
|
|
|
|
|
- continue;
|
|
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
case PT_INTERP:
|
|
case PT_INTERP:
|
|
@@ -1827,9 +1839,10 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
|
|
|
continue;
|
|
continue;
|
|
|
if (bufsize && nbuf[0]) {
|
|
if (bufsize && nbuf[0]) {
|
|
|
nbuf[bufsize - 1] = '\0';
|
|
nbuf[bufsize - 1] = '\0';
|
|
|
- memcpy(interp, nbuf, CAST(size_t, bufsize));
|
|
|
|
|
|
|
+ str = CAST(const char *, nbuf);
|
|
|
} else
|
|
} else
|
|
|
- strlcpy(interp, "*empty*", sizeof(interp));
|
|
|
|
|
|
|
+ str = "*empty*";
|
|
|
|
|
+ strlcpy(interp, str, sizeof(interp));
|
|
|
break;
|
|
break;
|
|
|
case PT_NOTE:
|
|
case PT_NOTE:
|
|
|
if (ms->flags & MAGIC_MIME)
|
|
if (ms->flags & MAGIC_MIME)
|
|
@@ -1859,17 +1872,17 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
|
|
|
return 0;
|
|
return 0;
|
|
|
if (dynamic) {
|
|
if (dynamic) {
|
|
|
if (pie && need == 0)
|
|
if (pie && need == 0)
|
|
|
- linking_style = "static-pie";
|
|
|
|
|
|
|
+ str = "static-pie";
|
|
|
else
|
|
else
|
|
|
- linking_style = "dynamically";
|
|
|
|
|
|
|
+ str = "dynamically";
|
|
|
} else {
|
|
} else {
|
|
|
- linking_style = "statically";
|
|
|
|
|
|
|
+ str = "statically";
|
|
|
}
|
|
}
|
|
|
- if (file_printf(ms, ", %s linked", linking_style) == -1)
|
|
|
|
|
|
|
+ if (elf_printf(ms, ", %s linked", str) == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
if (interp[0])
|
|
if (interp[0])
|
|
|
- if (file_printf(ms, ", interpreter %s", file_printable(ms,
|
|
|
|
|
- CAST(char *, nbuf), sizeof(nbuf),
|
|
|
|
|
|
|
+ if (elf_printf(ms, ", interpreter %s", file_printable(ms,
|
|
|
|
|
+ RCAST(char *, nbuf), sizeof(nbuf),
|
|
|
interp, sizeof(interp))) == -1)
|
|
interp, sizeof(interp))) == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
return 0;
|
|
return 0;
|
|
@@ -1956,7 +1969,7 @@ file_tryelf(struct magic_set *ms, const struct buffer *b)
|
|
|
#define elfhdr elf64hdr
|
|
#define elfhdr elf64hdr
|
|
|
#include "elfclass.h"
|
|
#include "elfclass.h"
|
|
|
default:
|
|
default:
|
|
|
- if (file_printf(ms, ", unknown class %d", clazz) == -1)
|
|
|
|
|
|
|
+ if (elf_printf(ms, ", unknown class %d", clazz) == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|