root/tools/elf2flt/main.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. main

   1 #include <stdio.h>                                                   
   2 #include <unistd.h>
   3 #include <fcntl.h>
   4 
   5 #include "myio.h"
   6 #include "elfflt.h"
   7 
   8 int FLAG_DUMP_SOURCE = 0;
   9 int FLAG_DUMP_SYMBOLS = 0;
  10 int FLAG_DUMP_RELOC = 0;
  11 int FLAG_DUMP_FLT_HEADERS = 0;
  12 int FLAG_DUMP_FLAT = 0;
  13 int FLAG_VERBOSE = 0;
  14 int FLAG_DUMP_SECTIONS = 0;
  15 int FLAG_WARNSYMBOL=0;
  16 
  17 char* filename_elf;
  18 char* filename_flt;
  19 
  20 int main(int argc, char **argv)
  21 {
  22 
  23     if ( argc < 3 )
  24     {
  25         printf("elfflt.exe filename.elf filename.flt [-vefrhsS] [-iIMPORTFILE.TXT]\n");
  26                 printf("  -iPATH/TO/exportlist.txt for list of imported symbols\n");
  27                 printf("  -!PATH/TO/stoplist.txt for list of unsafe symbols\n");
  28                 printf("  -e dump elf\n  -S show elf sections\n  -f dump flat\n  -r show relocations\n  -h show flat headers\n  -s dump elf symbols\n  -v verbose");
  29         return 1;
  30     }
  31     
  32     filename_elf = argv[1];
  33     filename_flt = argv[2];
  34 
  35         char* filename_import =0;
  36         char* filename_stoplist =0;
  37 
  38         int i;
  39         for(i=3;i<argc;i++)
  40         {
  41                 if (argv[i][0]!='-') continue;
  42                 switch ( argv[i][1] )
  43                 {
  44                   case 'e': FLAG_DUMP_SOURCE = 1; break;
  45                   case 'S': FLAG_DUMP_SECTIONS = 1; break;
  46                   case 's': FLAG_DUMP_SYMBOLS = 1; break;
  47                   case 'r': FLAG_DUMP_RELOC = 1; break;
  48                   case 'h': FLAG_DUMP_FLT_HEADERS = 1; break;
  49                   case 'f': FLAG_DUMP_FLAT = 1; break;
  50                   case 'v': FLAG_VERBOSE = 1; break;
  51                   case 'i': filename_import = argv[i]+2; break; 
  52                   case '!': filename_stoplist = argv[i]+2; break;
  53                 }
  54     }
  55 
  56     if (FLAG_VERBOSE)
  57                 printf("elf2flt: %s -> %s\n", filename_elf, filename_flt);
  58 
  59     int rv;
  60     if ( (rv=b_file_preload(filename_elf)) <= 0 )
  61     {
  62         fprintf(stderr, "Error load file '%s': loaded %d\n",filename_elf,rv);
  63         return ELFFLT_INPUT_ERROR;
  64     }
  65 
  66         load_import(filename_import);
  67         load_stoplist(filename_stoplist);
  68       
  69     int err = elfloader_load(filename_elf, filename_flt);
  70 
  71         if ( err == ELFFLT_OUTPUT_ERROR || err == ELFFLT_INPUT_ERROR )
  72         PRINTERR(stderr, "elf2flt: Internal error\n");
  73 
  74     return err;    
  75 }

/* [<][>][^][v][top][bottom][index][help] */