From 02018af0cc4f02c422f21c52694f94bd186066af Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Sat, 4 Jul 2020 17:39:27 -0600 Subject: [PATCH] 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. --- Demos/DynamicLink/LinkDemo/main.cpp | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) 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 +#include #include #include -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) {