//===================================================================
// Exe File Encrypter/Compressor Controller (EFECC) by Cronos
//-------------------------------------------------------------------
// Main Header File
//===================================================================


//-------------------------------------------------------------------
// Set-up includes,typedefs,etc
// ----------------------------
//
//
//-------------------------------------------------------------------

typedef unsigned long dword;
typedef unsigned short int word;
typedef unsigned char byte;

typedef enum {false=0,true} bool;

#define MAX_STRLEN 256

//-------------------------------------------------------------------
// PE File Structures
// ------------------
// IMAGE_FILE_HEADER		Expected at start of PE header
// IMAGE_OPTIONAL_HEADER	Additional header details.
// IMAGE_DATA_DIRECTORY		Data Directories
// IMAGE_SECTION_HEADER		Section Header details
// IMAGE_IMPORT_DIRECTORY	Import Directory
// IMAGE_IMPORT_DESCRIPTOR	Import Descriptor
// IMAGE_IMPORT_BY_NAME
// IMAGE_RELOCATION		Relocation Directory
//-------------------------------------------------------------------

#define PEMAGIC 0x00004550  

struct IMAGE_FILE_HEADER 
{ word   Machine;    
  word   NumberOfSections;
  dword  TimeDateStamp;    
  dword  PointerToSymbolTable;
  dword  NumberOfSymbols;    
  word   SizeOfOptionalHeader;
  word   Characteristics;
}; 

#define IMAGE_NUMBEROF_DIRECTORY_ENTRIES 13

struct IMAGE_DATA_DIRECTORY
{ dword   VirtualAddress;
  dword   Size;
};

struct IMAGE_OPTIONAL_HEADER 
{ //    
  // Standard fields.    
  //    
  word    Magic;
  byte    MajorLinkerVersion;    
  byte    MinorLinkerVersion;
  dword   SizeOfCode;    
  dword   SizeOfInitializedData;
  dword   SizeOfUninitializedData;    
  dword   AddressOfEntryPoint;
  dword   BaseOfCode;    
  dword   BaseOfData;    
  //    
  // NT [Windows] additional fields.
  //    
  dword   ImageBase;    
  dword   SectionAlignment;
  dword   FileAlignment;    
  word    MajorOperatingSystemVersion;
  word    MinorOperatingSystemVersion;    
  word    MajorImageVersion;
  word    MinorImageVersion;    
  word    MajorSubsystemVersion;
  word    MinorSubsystemVersion;    
  dword   Reserved1;    
  dword   SizeOfImage;
  dword   SizeOfHeaders;    
  dword   CheckSum;    
  word    Subsystem;
  word    DllCharacteristics;    
  dword   SizeOfStackReserve;
  dword   SizeOfStackCommit;    
  dword   SizeOfHeapReserve;
  dword   SizeOfHeapCommit;    
  dword   LoaderFlags;
  dword   NumberOfRvaAndSizes;
  struct IMAGE_DATA_DIRECTORY 
          DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
};

#define IMAGE_DIRECTORY_ENTRY_EXPORT         0  // Export Directory
#define IMAGE_DIRECTORY_ENTRY_IMPORT         1  // Import Directory
#define IMAGE_DIRECTORY_ENTRY_RESOURCE       2  // Resource Directory
#define IMAGE_DIRECTORY_ENTRY_EXCEPTION      3  // Exception Directory
#define IMAGE_DIRECTORY_ENTRY_SECURITY       4  // Security Directory
#define IMAGE_DIRECTORY_ENTRY_BASERELOC      5  // Base Relocation Table
#define IMAGE_DIRECTORY_ENTRY_DEBUG          6  // Debug Directory
#define IMAGE_DIRECTORY_ENTRY_COPYRIGHT      7  // Description String
#define IMAGE_DIRECTORY_ENTRY_GLOBALPTR      8  // Machine Value (MIPS GP)
#define IMAGE_DIRECTORY_ENTRY_TLS            9  // TLS Directory
#define IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG    10 // Load Configuration Directory
#define IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT   11 // Bound Import Directory in headers
#define IMAGE_DIRECTORY_ENTRY_IAT            12 // Import Address Table

#define IMAGE_SIZEOF_SHORT_NAME 8

struct IMAGE_SECTION_HEADER
{ byte    Name[IMAGE_SIZEOF_SHORT_NAME];
  union 
  { dword   PhysicalAddress;            
    dword   VirtualSize;
  } Misc;    
  dword   VirtualAddress;    
  dword   SizeOfRawData;
  dword   PointerToRawData;    
  dword   PointerToRelocations;
  dword   PointerToLinenumbers;    
  word    NumberOfRelocations;
  word    NumberOfLinenumbers;    
  dword   Characteristics;
}; 

struct IMAGE_IMPORT_DIRECTORY
{ dword   dwRVAFunctionNameList;
  dword   dwUseless1;    
  dword   dwUseless2;    
  dword   dwRVAModuleName;
  dword   dwRVAFunctionAddressList;    
};

struct IMAGE_IMPORT_DESCRIPTOR
{ dword   OriginalFirstThunk;
  dword   TimeDateStamp;
  dword   ForwarderChain;
  dword   Name;
  dword   FirstThunk;
};

struct IMAGE_IMPORT_BY_NAME
{ word    Hint;
  byte    Name[1];
}; 

#define IMAGE_ORDINAL_FLAG 0x80000000
#define IMAGE_ORDINAL(Ordinal) (Ordinal & 0xffff)

struct IMAGE_RELOCATION
{ union 
  { dword   VirtualAddress;
    dword   RelocCount;             
  }u;
  dword   SymbolTableIndex;
  word    Type;
};

//*******************************************************************

#define IMAGE_SIZEOF_RELOCATION  10

//
// I386 relocation types.
//

#define IMAGE_REL_I386_ABSOLUTE  0x0000  // Reference is absolute, no relocation is necessary
#define IMAGE_REL_I386_DIR16     0x0001  // Direct 16-bit reference to the symbols virtual address
#define IMAGE_REL_I386_REL16     0x0002  // PC-relative 16-bit reference to the symbols virtual address
#define IMAGE_REL_I386_DIR32     0x0006  // Direct 32-bit reference to the symbols virtual address
#define IMAGE_REL_I386_DIR32NB   0x0007  // Direct 32-bit reference to the symbols virtual address, base not included
#define IMAGE_REL_I386_SEG12     0x0009  // Direct 16-bit reference to the segment-selector bits of a 32-bit virtual address
#define IMAGE_REL_I386_SECTION   0x000A
#define IMAGE_REL_I386_SECREL    0x000B
#define IMAGE_REL_I386_REL32     0x0014  // PC-relative 32-bit reference to the symbols virtual address


