diff options
author | Andrew Kaster <andrewdkaster@gmail.com> | 2020-07-04 17:39:27 -0600 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-07-07 10:38:54 +0200 |
commit | 02018af0cc4f02c422f21c52694f94bd186066af (patch) | |
tree | a144aa2612a437e7ba988a1f4f989ea89486af3b /Demos/DynamicLink | |
parent | f96b8279902f92a057030d51cd0b25f82c1a14c4 (diff) | |
download | serenity-02018af0cc4f02c422f21c52694f94bd186066af.zip |
Demos: Print out ELF Auxiliary Vector in LinkDemo
This is a test program anyway, so let's double check that the auxv
is done properly here.
Diffstat (limited to 'Demos/DynamicLink')
-rw-r--r-- | Demos/DynamicLink/LinkDemo/main.cpp | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/Demos/DynamicLink/LinkDemo/main.cpp b/Demos/DynamicLink/LinkDemo/main.cpp index 8afc648a5d..d6c21cc63a 100644 --- a/Demos/DynamicLink/LinkDemo/main.cpp +++ b/Demos/DynamicLink/LinkDemo/main.cpp @@ -25,12 +25,37 @@ */ #include <AK/String.h> +#include <LibELF/AuxiliaryVector.h> #include <dlfcn.h> #include <stdio.h> -int main() +int main(int argc, char** argv, char** envp) { + for (int i = 0; i < argc; ++i) { + printf("argv[%d]: %s\n", i, argv[i]); + } + + char** env; + for (env = envp; *env; ++env) { + printf("env: %s\n", *env); + } + for (auxv_t* auxvp = (auxv_t*)++env; auxvp->a_type != AT_NULL; ++auxvp) { + printf("AuxVal: Type=%ld, Val/Ptr=%p\n", auxvp->a_type, auxvp->a_un.a_ptr); + if (auxvp->a_type == AT_PLATFORM) { + printf(" Platform: %s\n", (char*)auxvp->a_un.a_ptr); + } else if (auxvp->a_type == AT_EXECFN) { + printf(" Filename: %s\n", (char*)auxvp->a_un.a_ptr); + } else if (auxvp->a_type == AT_RANDOM) { + auto byte_ptr = (uint8_t*)auxvp->a_un.a_ptr; + printf(" My Random bytes are: "); + for (size_t i = 0; i < 16; ++i) { + printf("0x%2x ", byte_ptr[i]); + } + printf("\n"); + } + } + void* handle = dlopen("/usr/lib/libDynamicLib.so", RTLD_LAZY | RTLD_GLOBAL); if (!handle) { |