1/* 2 Title: Export memory as a PE/COFF object 3 Author: David C. J. Matthews. 4 5 Copyright (c) 2006, 2013, 2016 David C. J. Matthews 6 7 8 This library is free software; you can redistribute it and/or 9 modify it under the terms of the GNU Lesser General Public 10 License version 2.1 as published by the Free Software Foundation. 11 12 This library is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR H PARTICULAR PURPOSE. See the GNU 15 Lesser General Public License for more details. 16 17 You should have received a copy of the GNU Lesser General Public 18 License along with this library; if not, write to the Free Software 19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20*/ 21 22#ifndef PECOFFEXPORT_H_INCLUDED 23#define PECOFFEXPORT_H_INCLUDED 24 25#include "scanaddrs.h" // For base class 26#include "exporter.h" 27 28#include <windows.h> 29#include <winnt.h> 30 31class PECOFFExport: public Exporter, public ScanAddress 32{ 33public: 34 PECOFFExport(): relocationCount(0), symbolNum(0) {} 35public: 36 virtual void exportStore(void); 37 38private: 39 // ScanAddress overrides 40 virtual void ScanConstant(PolyObject *base, byte *addrOfConst, ScanRelocationKind code); 41 42 // At the moment we should only get calls to ScanConstant. 43 virtual PolyObject *ScanObjectAddress(PolyObject *base) { return base; } 44 void alignFile(int align); 45 virtual void addExternalReference(void *addr, const char *name, bool isFuncPtr); 46 47private: 48 void setRelocationAddress(void *p, DWORD *reloc); 49 PolyWord createRelocation(PolyWord p, void *relocAddr); 50 void writeSymbol(const char *symbolName, __int32 value, int section, bool isExtern, int symType=0); 51 52 void writeRelocation(const IMAGE_RELOCATION* reloc); 53 unsigned relocationCount; 54 55 ExportStringTable stringTable; 56 57 // Table and count for external references. 58 ExportStringTable externTable; 59 unsigned symbolNum; 60 61 // Copy of the first relocation in case we 62 // have to overwrite it. 63 IMAGE_RELOCATION firstRelocation; 64}; 65 66#endif 67