ExeBinaryFile.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 1998-2001, The University of Queensland
00003  * Copyright (C) 2001, Sun Microsystems, Inc
00004  *
00005  * See the file "LICENSE.TERMS" for information on usage and
00006  * redistribution of this file, and for a DISCLAIMER OF ALL
00007  * WARRANTIES.
00008  *
00009  */
00010 
00011 /* File: ExeBinaryFile.h
00012  * Desc: This file contains the definition of the class ExeBinaryFile.
00013 */
00014 
00015 /* $Revision: 1.5 $
00016  * This file contains the definition of the ExeBinaryFile class, and some other
00017     definitions specific to the exe version of the BinaryFile object/
00018    At present, there is no support for a symbol table. Exe files do
00019     not use dynamic linking, but it is possible that some files may
00020     have debug symbols (in Microsoft Codeview or Borland formats),
00021     and these may be implemented in the future. The debug info may
00022     even be exposed as another pseudo section 
00023  * 16 Mar 01 - Mike: Added the needed definitions of new virtual functions
00024  * 17 Mar 01 - Mike: Removed EXE_RELOCATION (no longer fake a PSP)
00025  * 16 Apr 01 - Brian: Moved definition of the LH macro to BinaryFile.h.
00026 */
00027 
00028 #ifndef __EXEBINARYFILE_H__
00029 #define __EXEBINARYFILE_H_
00030 
00031 #include "BinaryFile.h"
00032 
00033 typedef struct {            /*        PSP structure                 */
00034     SWord int20h;           /* interrupt 20h                        */
00035     SWord eof;              /* segment, end of allocation block     */
00036     Byte res1;              /* reserved                             */
00037     Byte dosDisp[5];        /* far call to DOS function dispatcher  */
00038     Byte int22h[4];         /* vector for terminate routine         */
00039     Byte int23h[4];         /* vector for ctrl+break routine        */
00040     Byte int24h[4];         /* vector for error routine             */
00041     Byte res2[22];          /* reserved                             */
00042     SWord segEnv;           /* segment address of environment block */
00043     Byte res3[34];          /* reserved                             */
00044     Byte int21h[6];         /* opcode for int21h and far return     */
00045     Byte res4[6];           /* reserved                             */
00046     Byte fcb1[16];          /* default file control block 1         */
00047     Byte fcb2[16];          /* default file control block 2         */
00048     Byte res5[4];           /* reserved                             */
00049     Byte cmdTail[0x80];     /* command tail and disk transfer area  */
00050 } PSP;
00051 
00052 typedef struct {            /*      EXE file header          */
00053      Byte   sigLo;          /* .EXE signature: 0x4D 0x5A     */
00054      Byte   sigHi;
00055      SWord  lastPageSize;   /* Size of the last page         */
00056      SWord  numPages;       /* Number of pages in the file   */
00057      SWord  numReloc;       /* Number of relocation items    */
00058      SWord  numParaHeader;  /* # of paragraphs in the header */
00059      SWord  minAlloc;       /* Minimum number of paragraphs  */
00060      SWord  maxAlloc;       /* Maximum number of paragraphs  */
00061      SWord  initSS;         /* Segment displacement of stack */
00062      SWord  initSP;         /* Contents of SP at entry       */
00063      SWord  checkSum;       /* Complemented checksum         */
00064      SWord  initIP;         /* Contents of IP at entry       */
00065      SWord  initCS;         /* Segment displacement of code  */
00066      SWord  relocTabOffset; /* Relocation table offset       */
00067      SWord  overlayNum;     /* Overlay number                */
00068 } exeHeader;
00069 
00070 class ExeBinaryFile : public BinaryFile
00071 {
00072 public:
00073                 ExeBinaryFile();                // Default constructor
00074   virtual void  UnLoad();                       // Unload the image
00075   virtual bool  Open(const char* sName);        // Open the file for r/w; pv
00076   virtual void  Close();                        // Close file opened with Open()
00077   virtual bool  PostLoad(void* handle);         // For archive files only
00078   virtual LOAD_FMT GetFormat() const;           // Get format (i.e. LOADFMT_EXE)
00079   virtual MACHINE GetMachine() const;           // Get machine (i.e. MACHINE_PENTIUM)
00080   virtual const char *getFilename() const { return m_pFileName; }
00081 
00082   virtual bool isLibrary() const;
00083   virtual std::list<const char *> getDependencyList();
00084   virtual ADDRESS getImageBase();
00085   virtual size_t getImageSize();
00086 
00087   virtual char* SymbolByAddr(ADDRESS a);
00088 
00089     // Analysis functions
00090     virtual std::list<SectionInfo*>& GetEntryPoints(const char* pEntry = "main");
00091     virtual ADDRESS GetMainEntryPoint();
00092     virtual ADDRESS GetEntryPoint();
00093 
00094 //
00095 //  --  --  --  --  --  --  --  --  --  --  --
00096 //
00097                 // Internal information
00098     // Dump headers, etc
00099 virtual bool    DisplayDetails(const char* fileName, FILE* f = stdout);
00100 
00101   protected:
00102     virtual bool  RealLoad(const char* sName); // Load the file; pure virtual
00103 private:
00104 
00105 
00106     exeHeader* m_pHeader;               // Pointer to header
00107     Byte*   m_pImage;                   // Pointer to image
00108     int     m_cbImage;                  // Size of image
00109     int     m_cReloc;                   // Number of relocation entries
00110     DWord*  m_pRelocTable;              // The relocation table
00111     const char *m_pFileName;
00112 };
00113 
00114 #endif      // ifndef __EXEBINARYFILE_H__

Generated on Tue Sep 19 21:18:23 2006 for Boomerang by  doxygen 1.4.6