-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
analyze: add inspect-elf verb to parse package metadata
Parses and prints package metadata from executables, libraries and core files $ systemd-analyze inspect-elf /tmp/core.fsverity.1000.f77dac5dc161402aa44e15b7dd9dcf97.58561.1637106137000000 ~/git/fsverity-utils/libfsverity.so.0 FILE /TMP/CORE.FSVERITY.1000.F77DAC5DC161402AA44E15B7DD9DCF97.58561.1637106137000000 module name /home/luca/git/fsverity-utils/fsverity type deb name fsverity-utils version 1.3-1 architecture amd64 os debian debugInfoUrl https://debuginfod.debian.net buildId f70ffd61ea22aee78c33c56aeda61c63309a55e3 FILE /HOME/LUCA/GIT/FSVERITY-UTILS/LIBFSVERITY.SO.0 type deb name fsverity-utils version 1.3-1 architecture amd64 os debian debugInfoUrl https://debuginfod.debian.net buildId bb9b8587ab7d114b0ddd762d8a1c030dee96fe2f $ systemd-analyze inspect-elf /tmp/core.fsverity.1000.f77dac5dc161402aa44e15b7dd9dcf97.58561.1637106137000000 ~/git/fsverity-utils/libfsverity.so.0 --json=pretty { "/home/luca/git/fsverity-utils/fsverity" : { "type" : "deb", "name" : "fsverity-utils", "version" : "1.3-1", "architecture" : "amd64", "os" : "debian", "debugInfoUrl" : "https://debuginfod.debian.net", "buildId" : "f70ffd61ea22aee78c33c56aeda61c63309a55e3" } } { "/home/luca/git/fsverity-utils/libfsverity.so.0" : { "type" : "deb", "name" : "fsverity-utils", "version" : "1.3-1", "architecture" : "amd64", "os" : "debian", "debugInfoUrl" : "https://debuginfod.debian.net", "buildId" : "bb9b8587ab7d114b0ddd762d8a1c030dee96fe2f" } }
- Loading branch information
Showing
8 changed files
with
141 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* SPDX-License-Identifier: LGPL-2.1-or-later */ | ||
|
||
|
||
#include "analyze-elf.h" | ||
#include "elf-util.h" | ||
#include "errno-util.h" | ||
#include "fd-util.h" | ||
#include "format-table.h" | ||
#include "format-util.h" | ||
#include "json.h" | ||
#include "path-util.h" | ||
#include "strv.h" | ||
|
||
int analyze_elf(char **filenames, JsonFormatFlags json_flags) { | ||
char **filename; | ||
int r; | ||
|
||
STRV_FOREACH(filename, filenames) { | ||
_cleanup_(json_variant_unrefp) JsonVariant *package_metadata = NULL; | ||
_cleanup_(table_unrefp) Table *t = NULL; | ||
_cleanup_free_ char *abspath = NULL; | ||
_cleanup_close_ int fd = -1; | ||
|
||
r = path_make_absolute_cwd(*filename, &abspath); | ||
if (r < 0) | ||
return log_error_errno(r, "Could not make an absolute path out of \"%s\": %m", *filename); | ||
|
||
path_simplify(abspath); | ||
|
||
fd = RET_NERRNO(open(abspath, O_RDONLY|O_CLOEXEC)); | ||
if (fd < 0) | ||
return log_error_errno(fd, "Could not open \"%s\": %m", abspath); | ||
|
||
r = parse_elf_object(fd, abspath, NULL, &package_metadata); | ||
if (r < 0) | ||
return log_error_errno(r, "Parsing \"%s\" as ELF object failed: %m", abspath); | ||
|
||
t = table_new("file", abspath); | ||
if (!t) | ||
return log_oom(); | ||
|
||
if (package_metadata) { | ||
const char *module_name; | ||
JsonVariant *module_json; | ||
|
||
JSON_VARIANT_OBJECT_FOREACH(module_name, module_json, package_metadata) { | ||
JsonVariant *field; | ||
const char *field_name; | ||
|
||
/* In case of core files the module name will be the executable, | ||
* but for binaries/libraries it's just the path, so don't print it | ||
* twice. */ | ||
if (!streq(abspath, module_name)) { | ||
r = table_add_many( | ||
t, | ||
TABLE_STRING, "module name", | ||
TABLE_STRING, module_name); | ||
if (r < 0) | ||
return table_log_add_error(r); | ||
} | ||
|
||
JSON_VARIANT_OBJECT_FOREACH(field_name, field, module_json) | ||
if (json_variant_is_string(field)) { | ||
r = table_add_many( | ||
t, | ||
TABLE_STRING, field_name, | ||
TABLE_STRING, json_variant_string(field)); | ||
if (r < 0) | ||
return table_log_add_error(r); | ||
} | ||
} | ||
} | ||
if (json_flags & JSON_FORMAT_OFF) { | ||
(void) table_set_header(t, true); | ||
|
||
r = table_print(t, NULL); | ||
if (r < 0) | ||
return table_log_print_error(r); | ||
} else | ||
json_variant_dump(package_metadata, json_flags, stdout, NULL); | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/* SPDX-License-Identifier: LGPL-2.1-or-later */ | ||
#pragma once | ||
|
||
#include "json.h" | ||
|
||
int analyze_elf(char **filenames, JsonFormatFlags json_flags); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters