00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #ifndef pair_H
00043 #include <pair.h>
00044 #endif
00045
00046 #ifndef FUNCTION_H
00047 #include <function.h>
00048 #endif
00049
00050 typedef Elf32_Shdr * Shdr32_tag;
00051 typedef Elf64_Shdr * Shdr64_tag;
00052
00053
00054 template <class Shdr>
00055 struct Proc_Iter
00056 {
00057 char *strtab;
00058 Shdr *current;
00059 Shdr *last;
00060
00061 Proc_Iter (char *str, Shdr *first, Shdr *end)
00062 : strtab (str), current (first), last (end) {}
00063 Proc_Iter *operator ++ () {
00064 ++current;
00065 while (current != last && (current->sh_type != SHT_PROGBITS ||
00066 (current->sh_flags & SHF_EXECINSTR) == 0))
00067 ++current;
00068
00069 return this;
00070 }
00071
00072 pair<char *,long> operator * () {
00073 return make_pair (strtab + current->sh_name, current->sh_size);
00074 }
00075
00076 };
00077
00078
00079 template <class Shdr>
00080 inline bool
00081 operator == (const Proc_Iter<Shdr> &x, const Proc_Iter<Shdr> &y)
00082 {
00083 return x.current == y.current;
00084 }
00085
00086 class File_Info
00087 {
00088 private:
00089 void *mmap_handle;
00090 long file_size;
00091
00092 char obj_class;
00093 char *strtab;
00094
00095 void *shdr_begin;
00096 void *shdr_end;
00097
00098 template <class HEADER, class SHDR>
00099 void fill_file_info (HEADER *ehdr, SHDR *shdr);
00100
00101 inline void process_file ();
00102 public:
00103
00104 File_Info (char *name);
00105
00106 ~File_Info () { munmap (mmap_handle, file_size); }
00107
00108 char Get_obj_class () const { return obj_class; }
00109
00110 template <class Shdr>
00111 Proc_Iter<Shdr> begin (Shdr *shdr) const {
00112 return Proc_Iter<Shdr> (strtab, (Shdr *) shdr_begin,
00113 (Shdr *) shdr_end);
00114 }
00115
00116 template <class Shdr>
00117 Proc_Iter<Shdr> end (Shdr *shdr) const {
00118 return Proc_Iter<Shdr> (strtab, (Shdr *) shdr_end,
00119 (Shdr *) shdr_end);
00120 }
00121 };
00122
00123