mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:08:11 +00:00
readelf: Port to LibMain
This commit is contained in:
parent
575fcc42c3
commit
0a9e84aff0
2 changed files with 10 additions and 15 deletions
|
@ -168,6 +168,7 @@ target_link_libraries(profile LibMain)
|
||||||
target_link_libraries(ps LibMain)
|
target_link_libraries(ps LibMain)
|
||||||
target_link_libraries(purge LibMain)
|
target_link_libraries(purge LibMain)
|
||||||
target_link_libraries(pwd LibMain)
|
target_link_libraries(pwd LibMain)
|
||||||
|
target_link_libraries(readelf LibMain)
|
||||||
target_link_libraries(realpath LibMain)
|
target_link_libraries(realpath LibMain)
|
||||||
target_link_libraries(reboot LibMain)
|
target_link_libraries(reboot LibMain)
|
||||||
target_link_libraries(rev LibMain)
|
target_link_libraries(rev LibMain)
|
||||||
|
|
|
@ -10,10 +10,12 @@
|
||||||
#include <LibCore/ArgsParser.h>
|
#include <LibCore/ArgsParser.h>
|
||||||
#include <LibCore/File.h>
|
#include <LibCore/File.h>
|
||||||
#include <LibCore/MappedFile.h>
|
#include <LibCore/MappedFile.h>
|
||||||
|
#include <LibCore/System.h>
|
||||||
#include <LibELF/DynamicLoader.h>
|
#include <LibELF/DynamicLoader.h>
|
||||||
#include <LibELF/DynamicObject.h>
|
#include <LibELF/DynamicObject.h>
|
||||||
#include <LibELF/Image.h>
|
#include <LibELF/Image.h>
|
||||||
#include <LibELF/Validation.h>
|
#include <LibELF/Validation.h>
|
||||||
|
#include <LibMain/Main.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -224,12 +226,9 @@ static const char* object_relocation_type_to_string(ElfW(Word) type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
{
|
{
|
||||||
if (pledge("stdio rpath", nullptr) < 0) {
|
TRY(Core::System::pledge("stdio rpath"));
|
||||||
perror("pledge");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* path;
|
const char* path;
|
||||||
static bool display_all = false;
|
static bool display_all = false;
|
||||||
|
@ -261,11 +260,11 @@ int main(int argc, char** argv)
|
||||||
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_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(arguments);
|
||||||
|
|
||||||
if (argc < 3) {
|
if (arguments.argc < 3) {
|
||||||
args_parser.print_usage(stderr, argv[0]);
|
args_parser.print_usage(stderr, arguments.argv[0]);
|
||||||
return -1;
|
return Error::from_errno(EINVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (display_headers) {
|
if (display_headers) {
|
||||||
|
@ -336,12 +335,7 @@ int main(int argc, char** argv)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int fd = open(path, O_RDONLY);
|
int fd = TRY(Core::System::open(path, O_RDONLY));
|
||||||
if (fd < 0) {
|
|
||||||
outln("Unable to open file {}", path);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto result = ELF::DynamicLoader::try_create(fd, path);
|
auto result = ELF::DynamicLoader::try_create(fd, path);
|
||||||
if (result.is_error()) {
|
if (result.is_error()) {
|
||||||
outln("{}", result.error().text);
|
outln("{}", result.error().text);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue