Skip to content

Commit

Permalink
Added fatelf-info utility ...
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Sep 7, 2009
1 parent c6e9ed8 commit b83409a
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Expand Up @@ -5,6 +5,7 @@ INCLUDE_DIRECTORIES(include)
ADD_DEFINITIONS(-c99 -Wall -Werror)

ADD_EXECUTABLE(fatelf-glue utils/fatelf-glue.c utils/fatelf-utils.c)
ADD_EXECUTABLE(fatelf-info utils/fatelf-info.c utils/fatelf-utils.c)

# end of CMakeLists.txt ...

47 changes: 47 additions & 0 deletions utils/fatelf-info.c
@@ -0,0 +1,47 @@
/**
* FatELF; support multiple ELF binaries in one file.
*
* Please see the file LICENSE.txt in the source's root directory.
*
* This file written by Ryan C. Gordon.
*/

#define FATELF_UTILS 1
#include "fatelf-utils.h"

static int fatelf_info(const char *fname)
{
const int fd = xopen(fname, O_RDONLY, 0755);
FATELF_header *header = xread_fatelf_header(fname, fd);
int i = 0;

printf("%s: FatELF format version %d\n", fname, header->version);
printf("%d binaries:\n", header->num_binaries);

for (i = 0; i < header->num_binaries; i++)
{
const FATELF_binary_info *bin = &header->binaries[i];
printf(" - ABI %u (%s), version %u, cpu %u (%s), offset %llu\n",
(unsigned int) bin->abi, abi_name_string(bin->abi),
(unsigned int) bin->abi_version,
(unsigned int) bin->cpu, cpu_name_string(bin->cpu),
(unsigned long long) bin->offset);
} // for

xclose(fname, fd);
free(header);

return 0; // success.
} // fatelf_info


int main(int argc, const char **argv)
{
xfatelf_init(argc, argv);
if (argc != 2) // this could stand to use getopt(), later.
xfail("USAGE: %s <fname>", argv[0]);
return fatelf_info(argv[1]);
} // main

// end of fatelf-info.c ...

12 changes: 12 additions & 0 deletions utils/fatelf-utils.c
Expand Up @@ -303,6 +303,18 @@ uint64_t align_to_page(const uint64_t offset)
} // align_to_page


const char *abi_name_string(const uint16_t abitype)
{
return "???"; // !!! FIXME
} // abi_name_string


const char *cpu_name_string(const uint32_t cputype)
{
return "???"; // !!! FIXME
} // cpu_name_string


void xfatelf_init(int argc, const char **argv)
{
memset(zerobuf, '\0', sizeof (zerobuf)); // just in case.
Expand Down
3 changes: 3 additions & 0 deletions utils/fatelf-utils.h
Expand Up @@ -86,6 +86,9 @@ FATELF_header *xread_fatelf_header(const char *fname, const int fd);
// Align a value to the page size.
uint64_t align_to_page(const uint64_t offset);

const char *abi_name_string(const uint16_t abitype);
const char *cpu_name_string(const uint32_t cputype);

// Call this at the start of main().
void xfatelf_init(int argc, const char **argv);

Expand Down

0 comments on commit b83409a

Please sign in to comment.