Make your own free website on Tripod.com
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

rva.h

Go to the documentation of this file.
00001 /*
00002 PeRdr - PE file disassembler
00003 Copyright (C) 1999-2002 Frediano Ziglio
00004 -----
00005 
00006 This program is free software; you can redistribute it and/or modify
00007 it under the terms of the GNU General Public License as published by
00008 the Free Software Foundation; either version 2 of the License, or
00009 (at your option) any later version.
00010 
00011 This program is distributed in the hope that it will be useful,
00012 but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 GNU General Public License for more details.
00015 
00016 You should have received a copy of the GNU General Public License
00017 along with this program; if not, write to the Free Software
00018 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019 -----
00020 
00021 INFORMATION
00022   www: http://freddy77.tripod.com/perdr/
00023   e-mail: freddy77@angelfire.com
00024 */
00025 #ifndef FILE_RVA_H
00026 #define FILE_RVA_H
00027 
00028 #include <stdexcept>
00029 #include <utility>
00030 
00031 // forward declaration
00032 struct _PE_IMAGE_SECTION_HEADER;
00033 typedef struct _PE_IMAGE_SECTION_HEADER PE_IMAGE_SECTION_HEADER;
00034 
00035 //#include "code.h"
00036 class PeSection
00037 {
00038 public:
00039   PeSection() {};
00040   PeSection(const PE_IMAGE_SECTION_HEADER& section) { *this = section; };
00041   void operator=(const PE_IMAGE_SECTION_HEADER& section);
00042         bool IsCode() const;
00043   uint32_t RvaSize;
00044   uint32_t RvaAddress;
00045   uint32_t RawSize;
00046   uint32_t RawAddress;
00047 private:
00048   uint32_t Characteristics;
00049 };
00050 
00051 class RVAFileTranslator
00052 {
00053 public:
00054   RVAFileTranslator(const PE_IMAGE_SECTION_HEADER* _sections,unsigned _num_section);
00055   ~RVAFileTranslator();
00056   RVAFileTranslator(const RVAFileTranslator& rhs):section_infos(NULL)
00057   { (*this) = rhs; };
00058   void operator=(const RVAFileTranslator& rhs);
00059   long RVA2File(uint32_t rva) const;
00060   uint32_t File2RVA(long file) const;
00061   long RVA2FileSafe(uint32_t rva) const {
00062     long r = RVA2File(rva); if (r==0) throw std::runtime_error("Invalid RVA");
00063           return r;
00064   };
00065   uint32_t File2RVASafe(long file) const {
00066     uint32_t r = File2RVA(file); if (r==0) throw std::runtime_error("Invalid File offset");
00067           return r;
00068   };
00069   unsigned GetSectionCount() const
00070   { return num; }
00071   const PeSection* GetSection(unsigned n) const
00072   { return ((n<num)?&section_infos[n]:NULL); };
00073 private:
00074   unsigned num;
00075 //  section_info *section_infos;
00076   PeSection *section_infos;
00077 };
00078 
00079 #endif //FILE_RVA_H

Generated on Mon Jan 13 22:20:34 2003 for perdr by doxygen1.2.15