home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / dosdisas.zip / dccsrcoo.zip / ExeLoader.h < prev    next >
C/C++ Source or Header  |  1997-10-14  |  3KB  |  83 lines

  1. /* This file contains the definition of the ExeLoader class, and some other
  2.     definitions specific to the exe version of the Loader object */
  3.  
  4. #include "Loader.h"        /* Abstract base class definitions */
  5. #include <stdio.h>        /* printf, etc */
  6. #include <assert.h>        /* assert() */
  7. #include <fcntl.h>        /* O_RDONLY */
  8. #ifdef __UNIX__
  9. #include <unistd.h>        /* lseek(), read() */
  10. #include <sys/types.h>    /* lseek(), read() */
  11. #else
  12. #include <io.h>
  13. #endif
  14. #include <stdlib.h>        /* malloc(), free() */
  15. #include <errno.h>        /* error numbers */
  16.  
  17. #define EXE_RELOCATION 0x10    // Exe relocated by 0x10 paragraphs
  18. #ifdef __MSDOS
  19. #define dword unsigned long
  20. #else
  21. #define dword unsigned int
  22. #endif
  23. #define word unsigned short
  24. #define byte unsigned char
  25. #define int16 short int
  26. #ifndef LH                    // Might be defined in dcc.h already
  27. #define LH(p)  ((int)((byte *)(p))[0] + ((int)((byte *)(p))[1] << 8))
  28. #endif
  29.  
  30. typedef struct {            /*        PSP structure                    */
  31.     word int20h;            /* interrupt 20h                        */
  32.     word eof;                /* segment, end of allocation block        */
  33.     byte res1;                /* reserved                             */
  34.     byte dosDisp[5];        /* far call to DOS function dispatcher    */
  35.     byte int22h[4];            /* vector for terminate routine            */
  36.     byte int23h[4];            /* vector for ctrl+break routine        */
  37.     byte int24h[4];            /* vector for error routine                */
  38.     byte res2[22];            /* reserved                                */
  39.     word segEnv;            /* segment address of environment block    */
  40.     byte res3[34];            /* reserved                                */
  41.     byte int21h[6];            /* opcode for int21h and far return        */
  42.     byte res4[6];            /* reserved                                */
  43.     byte fcb1[16];            /* default file control block 1            */
  44.     byte fcb2[16];          /* default file control block 2            */
  45.     byte res5[4];            /* reserved                                */
  46.     byte cmdTail[0x80];        /* command tail and disk transfer area    */
  47. } PSP;
  48.  
  49. typedef struct {            /*      EXE file header              */
  50.      byte    sigLo;            /* .EXE signature: 0x4D 0x5A     */
  51.      byte    sigHi;
  52.      word    lastPageSize;    /* Size of the last page         */
  53.      word    numPages;        /* Number of pages in the file     */
  54.      word    numReloc;        /* Number of relocation items     */
  55.      word    numParaHeader;    /* # of paragraphs in the header */
  56.      word    minAlloc;        /* Minimum number of paragraphs     */
  57.      word    maxAlloc;        /* Maximum number of paragraphs     */
  58.      word    initSS;            /* Segment displacement of stack */
  59.      word    initSP;            /* Contents of SP at entry       */
  60.      word    checkSum;        /* Complemented checksum         */
  61.      word    initIP;            /* Contents of IP at entry       */
  62.      word    initCS;            /* Segment displacement of code  */
  63.      word    relocTabOffset;    /* Relocation table offset       */
  64.      word    overlayNum;        /* Overlay number                */
  65. } HEADER;
  66.  
  67. class ExeLoader : public Loader
  68. {
  69. public:
  70.                 ExeLoader();                    // Default constructor
  71.   virtual int    Load(const char* sName);        // Load the file; pure virtual
  72.   virtual int    GetNextPart();                    // Load next part of archive
  73.   virtual void    UnLoad();                        // Unload the image
  74.  
  75. private:
  76.  
  77.     HEADER*    m_pHeader;                    // Pointer to header
  78.     byte*    m_pImage;                    // Pointer to image
  79.     int        m_cbImage;                    // Size of image
  80.     int        m_cReloc;                    // Number of relocation entries
  81.     dword*    m_pRelocTable;                // The relocation table
  82. };
  83.