1 #include "relocs.h" 2 3 void die(char *fmt, ...) 4 { 5 va_list ap; 6 va_start(ap, fmt); 7 vfprintf(stderr, fmt, ap); 8 va_end(ap); 9 exit(1); 10 } 11 12 static void usage(void) 13 { 14 die("relocs [--abs-syms|--abs-relocs|--text|--realmode] vmlinux\n"); 15 } 16 17 int main(int argc, char **argv) 18 { 19 int show_absolute_syms, show_absolute_relocs; 20 int as_text, use_real_mode; 21 const char *fname; 22 FILE *fp; 23 int i; 24 unsigned char e_ident[EI_NIDENT]; 25 26 show_absolute_syms = 0; 27 show_absolute_relocs = 0; 28 as_text = 0; 29 use_real_mode = 0; 30 fname = NULL; 31 for (i = 1; i < argc; i++) { 32 char *arg = argv[i]; 33 if (*arg == '-') { 34 if (strcmp(arg, "--abs-syms") == 0) { 35 show_absolute_syms = 1; 36 continue; 37 } 38 if (strcmp(arg, "--abs-relocs") == 0) { 39 show_absolute_relocs = 1; 40 continue; 41 } 42 if (strcmp(arg, "--text") == 0) { 43 as_text = 1; 44 continue; 45 } 46 if (strcmp(arg, "--realmode") == 0) { 47 use_real_mode = 1; 48 continue; 49 } 50 } 51 else if (!fname) { 52 fname = arg; 53 continue; 54 } 55 usage(); 56 } 57 if (!fname) { 58 usage(); 59 } 60 fp = fopen(fname, "r"); 61 if (!fp) { 62 die("Cannot open %s: %s\n", fname, strerror(errno)); 63 } 64 if (fread(&e_ident, 1, EI_NIDENT, fp) != EI_NIDENT) { 65 die("Cannot read %s: %s", fname, strerror(errno)); 66 } 67 rewind(fp); 68 if (e_ident[EI_CLASS] == ELFCLASS64) 69 process_64(fp, use_real_mode, as_text, 70 show_absolute_syms, show_absolute_relocs); 71 else 72 process_32(fp, use_real_mode, as_text, 73 show_absolute_syms, show_absolute_relocs); 74 fclose(fp); 75 return 0; 76 } 77