mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:38:11 +00:00
Utilities/readelf: Add support for printing the content of sections
This commit is contained in:
parent
4055c393fc
commit
b509d8a2f7
2 changed files with 19 additions and 2 deletions
|
@ -5,7 +5,7 @@ readelf
|
||||||
## Synopsis
|
## Synopsis
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
$ readelf [--all] [--file-header] [--program-headers] [--section-headers] [--headers] [--syms] [--dyn-syms] [--dynamic] [--notes] [--relocs] [--unwind] [--checksec] <path>
|
$ readelf [--all] [--file-header] [--program-headers] [--section-headers] [--headers] [--syms] [--dyn-syms] [--dynamic] [--notes] [--relocs] [--unwind] [--checksec] [--string-dump section-name] <path>
|
||||||
```
|
```
|
||||||
|
|
||||||
## Options:
|
## Options:
|
||||||
|
@ -24,6 +24,7 @@ $ readelf [--all] [--file-header] [--program-headers] [--section-headers] [--hea
|
||||||
* `-r`, `--relocs`: Display relocations
|
* `-r`, `--relocs`: Display relocations
|
||||||
* `-u`, `--unwind`: Display unwind info
|
* `-u`, `--unwind`: Display unwind info
|
||||||
* `-c`, `--checksec`: Display security hardening info
|
* `-c`, `--checksec`: Display security hardening info
|
||||||
|
* `-p section-name`, `--string-dump section-name`: Display the contents of a section as strings
|
||||||
|
|
||||||
## Arguments:
|
## Arguments:
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2020, the SerenityOS developers.
|
* Copyright (c) 2020-2022, the SerenityOS developers.
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
@ -242,6 +242,7 @@ int main(int argc, char** argv)
|
||||||
static bool display_unwind_info = false;
|
static bool display_unwind_info = false;
|
||||||
static bool display_dynamic_section = false;
|
static bool display_dynamic_section = false;
|
||||||
static bool display_hardening = false;
|
static bool display_hardening = false;
|
||||||
|
StringView string_dump_section {};
|
||||||
|
|
||||||
Core::ArgsParser args_parser;
|
Core::ArgsParser args_parser;
|
||||||
args_parser.add_option(display_all, "Display all", "all", 'a');
|
args_parser.add_option(display_all, "Display all", "all", 'a');
|
||||||
|
@ -256,6 +257,7 @@ int main(int argc, char** argv)
|
||||||
args_parser.add_option(display_relocations, "Display relocations", "relocs", 'r');
|
args_parser.add_option(display_relocations, "Display relocations", "relocs", 'r');
|
||||||
args_parser.add_option(display_unwind_info, "Display unwind info", "unwind", 'u');
|
args_parser.add_option(display_unwind_info, "Display unwind info", "unwind", 'u');
|
||||||
args_parser.add_option(display_hardening, "Display security hardening info", "checksec", 'c');
|
args_parser.add_option(display_hardening, "Display security hardening info", "checksec", 'c');
|
||||||
|
args_parser.add_option(string_dump_section, "Display the contents of a section as strings", "string-dump", 'p', "section-name");
|
||||||
args_parser.add_positional_argument(path, "ELF path", "path");
|
args_parser.add_positional_argument(path, "ELF path", "path");
|
||||||
args_parser.parse(argc, argv);
|
args_parser.parse(argc, argv);
|
||||||
|
|
||||||
|
@ -717,5 +719,19 @@ int main(int argc, char** argv)
|
||||||
outln();
|
outln();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!string_dump_section.is_null()) {
|
||||||
|
auto maybe_section = elf_image.lookup_section(string_dump_section);
|
||||||
|
if (maybe_section.has_value()) {
|
||||||
|
outln("String dump of section \'{}\':", string_dump_section);
|
||||||
|
StringView data(maybe_section->raw_data(), maybe_section->size());
|
||||||
|
data.for_each_split_view('\0', false, [&data](auto string) {
|
||||||
|
auto offset = string.characters_without_null_termination() - data.characters_without_null_termination();
|
||||||
|
outln("[{:6x}] {}", offset, string);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
warnln("Could not find section \'{}\'", string_dump_section);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue